• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "common/plugin_utils.h"
22 #include "foundation/osal/thread/task.h"
23 #include "plugin/common/plugin_tags.h"
24 #include "pipeline/core/filter_base.h"
25 #include "pipeline/core/type_define.h"
26 #include "pipeline/filters/codec/codec_mode.h"
27 #include "plugin/core/codec.h"
28 #include "plugin/core/plugin_info.h"
29 #include "plugin/core/plugin_meta.h"
30 #include "utils/blocking_queue.h"
31 #include "utils/buffer_pool.h"
32 
33 namespace OHOS {
34 namespace Media {
35 namespace Pipeline {
36 using MapCandidate = std::pair<std::shared_ptr<Plugin::PluginInfo>, Capability>;
37 class CodecFilterBase : public FilterBase, public Plugin::DataCallbackHelper {
38 public:
39     explicit CodecFilterBase(const std::string &name);
40     ~CodecFilterBase() override;
41 
42     ErrorCode Start() override;
43 
44     ErrorCode Stop() override;
45 
46     ErrorCode Prepare() override;
47 
48     ErrorCode SetParameter(int32_t key, const Plugin::Any& value) override;
49 
50     ErrorCode GetParameter(int32_t key, Plugin::Any& outVal) override;
51 
52     bool Negotiate(const std::string& inPort,
53                    const std::shared_ptr<const Plugin::Capability>& upstreamCap,
54                    Plugin::Capability& negotiatedCap,
55                    const Plugin::TagMap& upstreamParams,
56                    Plugin::TagMap& downstreamParams) override;
57 
58     bool Configure(const std::string &inPort, const std::shared_ptr<const Plugin::Meta> &upstreamMeta,
59                    Plugin::TagMap &upstreamParams, Plugin::TagMap &downstreamParams) override;
60 
61     void FlushStart() override;
62 
63     void FlushEnd() override;
64 
65 protected:
66     virtual uint32_t GetOutBufferPoolSize();
67 
68     virtual uint32_t CalculateBufferSize(const std::shared_ptr<const OHOS::Media::Plugin::Meta> &meta);
69 
70     virtual Plugin::TagMap GetNegotiateParams(const Plugin::TagMap& upstreamParams);
71 
72     bool CheckRequiredOutCapKeys(const Capability& capability);
73 
74     virtual std::vector<Capability::Key> GetRequiredOutCapKeys();
75 
76     virtual ErrorCode ConfigureToStartPluginLocked(const std::shared_ptr<const Plugin::Meta> &meta);
77 
78     ErrorCode UpdateMetaFromPlugin(Plugin::Meta& meta);
79 
80     ErrorCode SetPluginParameterLocked(Tag tag, const Plugin::ValueType& value);
81 
82     virtual void UpdateParams(const std::shared_ptr<const Plugin::Meta>& upMeta,
83                               std::shared_ptr<Plugin::Meta>& meta);
84 
85     template<typename T>
GetPluginParameterLocked(Tag tag,T & value)86     ErrorCode GetPluginParameterLocked(Tag tag, T& value)
87     {
88         Plugin::Any tmp;
89         auto err = TranslatePluginStatus(plugin_->GetParameter(tag, tmp));
90         if (err == ErrorCode::SUCCESS && tmp.SameTypeWith(typeid(T))) {
91             value = Plugin::AnyCast<T>(tmp);
92         }
93         return err;
94     }
95 
96     bool isFlushing_ {false};
97     Plugin::TagMap sinkParams_ {};
98     std::shared_ptr<Plugin::Codec> plugin_ {};
99     Plugin::BufferMetaType bufferMetaType_ = {};
100     std::shared_ptr<CodecMode> codecMode_ {nullptr};
101 
102 private:
103     virtual std::shared_ptr<Allocator> GetAllocator();
104     Capability capNegWithDownstream_ {};
105 };
106 } // namespace Pipeline
107 } // namespace Media
108 } // namespace OHOS
109 #endif // HISTREAMER_PIPELINE_FILTER_CODEC_BASE_H
110