1 /* 2 * Copyright (c) 2022-2022 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_MODE_H 17 #define HISTREAMER_PIPELINE_FILTER_CODEC_MODE_H 18 19 #include <iostream> 20 #include "filter.h" 21 #include "pipeline/core/error_code.h" 22 #include "pipeline/core/type_define.h" 23 #include "plugin/core/codec.h" 24 25 namespace OHOS { 26 namespace Media { 27 namespace Pipeline { 28 class CodecMode { 29 public: CodecMode(std::string name)30 explicit CodecMode(std::string name) : codecName_(std::move(name)) {} 31 virtual ~CodecMode() = default; 32 33 bool Init(std::shared_ptr<Plugin::Codec>& plugin, std::vector<POutPort>& outPorts); 34 35 virtual ErrorCode Configure(); 36 37 virtual ErrorCode PushData(const std::string &inPort, const AVBufferPtr& buffer, int64_t offset) = 0; 38 39 virtual ErrorCode Stop() = 0; 40 41 virtual void FlushStart() = 0; 42 43 virtual void FlushEnd() = 0; 44 45 virtual void OnOutputBufferDone(const std::shared_ptr<Plugin::Buffer>& output) = 0; 46 47 virtual ErrorCode Prepare(); 48 49 virtual ErrorCode Release(); 50 51 void SetBufferPoolSize(uint32_t inBufPoolSize, uint32_t outBufPoolSize); 52 53 void CreateOutBufferPool(std::shared_ptr<Allocator>& outAllocator, 54 uint32_t bufferCnt, uint32_t bufferSize, Plugin::BufferMetaType bufferMetaType); 55 56 protected: 57 uint32_t GetInBufferPoolSize() const; 58 uint32_t GetOutBufferPoolSize() const; 59 60 std::shared_ptr<Plugin::Codec> plugin_ {nullptr}; 61 std::vector<POutPort> outPorts_ {}; 62 std::shared_ptr<BufferPool<AVBuffer>> outBufPool_ {nullptr}; 63 std::string codecName_ {}; 64 65 private: 66 uint32_t inBufPoolSize_ {0}; 67 uint32_t outBufPoolSize_ {0}; 68 }; 69 } // namespace Pipeline 70 } // namespace Media 71 } // namespace OHOS 72 #endif // HISTREAMER_PIPELINE_FILTER_CODEC_MODE_H 73