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_CODEC_BASE_H 17 #define HISTREAMER_PIPELINE_FILTER_CODEC_BASE_H 18 19 #include <string> 20 21 #include "utils/blocking_queue.h" 22 #include "utils/buffer_pool.h" 23 #include "utils/type_define.h" 24 #include "utils/utils.h" 25 #include "foundation/osal/thread/task.h" 26 #include "pipeline/core/filter_base.h" 27 #include "plugin/common/plugin_tags.h" 28 #include "plugin/core/codec.h" 29 #include "plugin/core/plugin_info.h" 30 #include "plugin/core/plugin_meta.h" 31 #include "common/plugin_utils.h" 32 33 namespace OHOS { 34 namespace Media { 35 namespace Pipeline { 36 class CodecFilterBase : public FilterBase, public Plugin::DataCallbackHelper { 37 public: 38 explicit CodecFilterBase(const std::string &name); 39 ~CodecFilterBase() override; 40 41 ErrorCode SetParameter(int32_t key, const Plugin::Any& value) override; 42 43 ErrorCode GetParameter(int32_t key, Plugin::Any& outVal) override; 44 45 void OnInputBufferDone(std::shared_ptr<Plugin::Buffer>& input) override; 46 47 void OnOutputBufferDone(std::shared_ptr<Plugin::Buffer>& output) override; 48 49 protected: 50 ErrorCode ConfigureWithMetaLocked(const std::shared_ptr<const Plugin::Meta>& meta); 51 52 ErrorCode UpdateMetaAccordingToPlugin(Plugin::Meta& meta); 53 54 ErrorCode SetPluginParameterLocked(Tag tag, const Plugin::ValueType& value); 55 56 template<typename T> GetPluginParameterLocked(Tag tag,T & value)57 ErrorCode GetPluginParameterLocked(Tag tag, T& value) 58 { 59 Plugin::Any tmp; 60 auto err = TranslatePluginStatus(plugin_->GetParameter(tag, tmp)); 61 if (err == ErrorCode::SUCCESS && tmp.SameTypeWith(typeid(T))) { 62 value = Plugin::AnyCast<T>(tmp); 63 } 64 return err; 65 } 66 67 std::shared_ptr<Plugin::Codec> plugin_ {}; 68 }; 69 } // namespace Pipeline 70 } // namespace Media 71 } // namespace OHOS 72 #endif // HISTREAMER_PIPELINE_FILTER_CODEC_BASE_H 73