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 #define HST_LOG_TAG "CodecFilterBase"
17
18 #include "codec_filter_base.h"
19
20 #include "pipeline/core/plugin_attr_desc.h"
21 #include "pipeline/filters/common/plugin_settings.h"
22 #include "utils/memory_helper.h"
23
24 namespace OHOS {
25 namespace Media {
26 namespace Pipeline {
CodecFilterBase(const std::string & name)27 CodecFilterBase::CodecFilterBase(const std::string &name): FilterBase(name) {}
28
29 CodecFilterBase::~CodecFilterBase() = default;
30
ConfigureWithMetaLocked(const std::shared_ptr<const Plugin::Meta> & meta)31 ErrorCode CodecFilterBase::ConfigureWithMetaLocked(const std::shared_ptr<const Plugin::Meta>& meta)
32 {
33 auto parameterMap = PluginParameterTable::FindAllowedParameterMap(filterType_);
34 for (const auto& keyPair : parameterMap) {
35 if ((keyPair.second.second & PARAM_SET) == 0) {
36 continue;
37 }
38 auto outValPtr = meta->GetData(static_cast<Plugin::MetaID>(keyPair.first));
39 if (outValPtr && keyPair.second.first(keyPair.first, *outValPtr)) {
40 SetPluginParameterLocked(keyPair.first, *outValPtr);
41 } else {
42 if (g_tagInfoMap.count(keyPair.first) == 0) {
43 MEDIA_LOG_W("tag %" PUBLIC_LOG_D32 " is not in map, may be update it?", keyPair.first);
44 } else {
45 MEDIA_LOG_W("parameter %" PUBLIC_LOG_S " in meta is not found or type mismatch",
46 std::get<0>(g_tagInfoMap.at(keyPair.first)));
47 }
48 }
49 }
50 return ErrorCode::SUCCESS;
51 }
52
UpdateMetaAccordingToPlugin(Plugin::Meta & meta)53 ErrorCode CodecFilterBase::UpdateMetaAccordingToPlugin(Plugin::Meta& meta)
54 {
55 auto parameterMap = PluginParameterTable::FindAllowedParameterMap(filterType_);
56 for (const auto& keyPair : parameterMap) {
57 if ((keyPair.second.second & PARAM_GET) == 0) {
58 continue;
59 }
60 Plugin::ValueType tmpVal;
61 auto ret = TranslatePluginStatus(plugin_->GetParameter(keyPair.first, tmpVal));
62 if (ret != ErrorCode::SUCCESS) {
63 if (g_tagInfoMap.count(keyPair.first) != 0) {
64 MEDIA_LOG_I("GetParameter %" PUBLIC_LOG_S " from plugin %" PUBLIC_LOG_S "failed with code %"
65 PUBLIC_LOG_D32, std::get<0>(g_tagInfoMap.at(keyPair.first)), pluginInfo_->name.c_str(), ret);
66 } else {
67 MEDIA_LOG_I("Tag %" PUBLIC_LOG_D32 " is not is map, may be update it?", keyPair.first);
68 MEDIA_LOG_I("GetParameter %" PUBLIC_LOG_D32 " from plugin %" PUBLIC_LOG_S " failed with code %"
69 PUBLIC_LOG_D32, keyPair.first, pluginInfo_->name.c_str(), ret);
70 }
71 continue;
72 }
73 if (!keyPair.second.first(keyPair.first, tmpVal)) {
74 if (g_tagInfoMap.count(keyPair.first) != 0) {
75 MEDIA_LOG_I("Type of Tag %" PUBLIC_LOG_S " should be %" PUBLIC_LOG_S,
76 std::get<0>(g_tagInfoMap.at(keyPair.first)), std::get<2>(g_tagInfoMap.at(keyPair.first)));
77 } else {
78 MEDIA_LOG_I("Tag %" PUBLIC_LOG_D32 " is not is map, may be update it?", keyPair.first);
79 MEDIA_LOG_I("Type of Tag %" PUBLIC_LOG_D32 "mismatch", keyPair.first);
80 }
81 continue;
82 }
83 meta.SetData(static_cast<Plugin::MetaID>(keyPair.first), tmpVal);
84 }
85 return ErrorCode::SUCCESS;
86 }
87
SetPluginParameterLocked(Tag tag,const Plugin::ValueType & value)88 ErrorCode CodecFilterBase::SetPluginParameterLocked(Tag tag, const Plugin::ValueType& value)
89 {
90 return TranslatePluginStatus(plugin_->SetParameter(tag, value));
91 }
92
SetParameter(int32_t key,const Plugin::Any & inVal)93 ErrorCode CodecFilterBase::SetParameter(int32_t key, const Plugin::Any& inVal)
94 {
95 if (state_.load() == FilterState::CREATED) {
96 return ErrorCode::ERROR_AGAIN;
97 }
98 Tag tag = Tag::INVALID;
99 FALSE_RET_V_MSG_E(TranslateIntoParameter(key, tag), ErrorCode::ERROR_INVALID_PARAMETER_VALUE,
100 "key %" PUBLIC_LOG_D32 " is out of boundary", key);
101 RETURN_AGAIN_IF_NULL(plugin_);
102 return SetPluginParameterLocked(tag, inVal);
103 }
104
GetParameter(int32_t key,Plugin::Any & outVal)105 ErrorCode CodecFilterBase::GetParameter(int32_t key, Plugin::Any& outVal)
106 {
107 if (state_.load() == FilterState::CREATED) {
108 return ErrorCode::ERROR_AGAIN;
109 }
110 Tag tag = Tag::INVALID;
111 FALSE_RET_V_MSG_E(TranslateIntoParameter(key, tag), ErrorCode::ERROR_INVALID_PARAMETER_VALUE,
112 "key %" PUBLIC_LOG_D32 " is out of boundary", key);
113 RETURN_AGAIN_IF_NULL(plugin_);
114 return TranslatePluginStatus(plugin_->GetParameter(tag, outVal));
115 }
116
OnInputBufferDone(std::shared_ptr<Plugin::Buffer> & input)117 void CodecFilterBase::OnInputBufferDone(std::shared_ptr<Plugin::Buffer>& input)
118 {
119 MEDIA_LOG_I("CodecFilterBase::OnInputBufferDone");
120 }
121
OnOutputBufferDone(std::shared_ptr<Plugin::Buffer> & output)122 void CodecFilterBase::OnOutputBufferDone(std::shared_ptr<Plugin::Buffer>& output)
123 {
124 MEDIA_LOG_I("CodecFilterBase::OnOutputBufferDone");
125 }
126 } // namespace Pipeline
127 } // namespace Media
128 } // namespace OHOS
129