1 /*
2  * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HISTREAMER_PIPELINE_FILTER_PLUGIN_UTILS_H
17 #define HISTREAMER_PIPELINE_FILTER_PLUGIN_UTILS_H
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "pipeline/core/error_code.h"
23 #include "pipeline/core/compatible_check.h"
24 #include "pipeline/core/type_define.h"
25 #include "plugin/common/plugin_types.h"
26 #include "plugin/common/plugin_tags.h"
27 #include "plugin/common/plugin_buffer.h"
28 #include "plugin/core/plugin_info.h"
29 #include "plugin/core/plugin_manager.h"
30 
31 namespace OHOS {
32 namespace Media {
33 namespace Pipeline {
34 #define RETURN_AGAIN_IF_NULL(plugin) \
35 do { \
36     if ((plugin) == nullptr) { \
37         return ErrorCode::ERROR_AGAIN; \
38     } \
39 } while (0)
40 
41 template<typename T>
42 bool AssignParameterIfMatch(Tag tag, T& ret, const Plugin::ValueType& val);
43 
44 /**
45  * translate plugin error into pipeline error code
46  * @param pluginError
47  * @return
48  */
49 ErrorCode TranslatePluginStatus(Plugin::Status pluginError);
50 
51 bool TranslateIntoParameter(const int &key, OHOS::Media::Plugin::Tag &tag);
52 
53 std::vector<std::pair<std::shared_ptr<Plugin::PluginInfo>, Plugin::Capability>> FindAvailablePlugins(
54     const Plugin::Capability& upStreamCaps, Plugin::PluginType pluginType,
55     Plugin::CodecMode preferredCodecMode = Plugin::CodecMode::HARDWARE);
56 
57 std::vector<std::shared_ptr<Plugin::PluginInfo>> FindAvailablePluginsByOutputMime(const std::string& outputMime,
58                                                                                   Plugin::PluginType pluginType);
59 uint8_t GetBytesPerSample(Plugin::AudioSampleFormat fmt);
60 
61 std::string Capability2String(const Capability& capability);
62 
63 std::string Meta2String(const Plugin::Meta& meta);
64 } // Pipeline
65 } // Media
66 } // OHOS
67 #endif // HISTREAMER_PIPELINE_FILTER_PLUGIN_UTILS_H
68