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 "pipeline/core/error_code.h" 21 #include "pipeline/core/filter.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 enum struct FilterCodecMode : uint32_t { 29 AUDIO_SYNC_DECODER = 1, 30 AUDIO_ASYNC_DECODER, 31 AUDIO_SYNC_ENCODER, 32 AUDIO_ASYNC_ENCODER, 33 VIDEO_SYNC_DECODER, 34 VIDEO_ASYNC_DECODER, 35 VIDEO_SYNC_ENCODER, 36 VIDEO_ASYNC_ENCODER, 37 }; 38 class CodecMode { 39 public: CodecMode(std::string name)40 explicit CodecMode(std::string name) : codecName_(std::move(name)) {} 41 virtual ~CodecMode() = default; 42 43 bool Init(std::shared_ptr<Plugin::Codec>& plugin, std::vector<POutPort>& outPorts); 44 45 virtual ErrorCode Configure(); 46 47 virtual ErrorCode PushData(const std::string &inPort, const AVBufferPtr& buffer, int64_t offset) = 0; 48 49 virtual ErrorCode Stop() = 0; 50 51 virtual void FlushStart() = 0; 52 53 virtual void FlushEnd() = 0; 54 55 virtual void OnOutputBufferDone(const std::shared_ptr<Plugin::Buffer>& output) = 0; 56 57 virtual ErrorCode Prepare(); 58 59 virtual ErrorCode Release(); 60 61 void SetBufferPoolSize(uint32_t inBufPoolSize, uint32_t outBufPoolSize); 62 63 void CreateOutBufferPool(std::shared_ptr<Allocator>& outAllocator, 64 uint32_t bufferCnt, uint32_t bufferSize, Plugin::BufferMetaType bufferMetaType); 65 66 protected: 67 uint32_t GetInBufferPoolSize() const; 68 uint32_t GetOutBufferPoolSize() const; 69 70 std::shared_ptr<Plugin::Codec> plugin_ {nullptr}; 71 std::vector<POutPort> outPorts_ {}; 72 std::shared_ptr<BufferPool<AVBuffer>> outBufPool_ {nullptr}; 73 std::string codecName_ {}; 74 75 private: 76 uint32_t inBufPoolSize_ {0}; 77 uint32_t outBufPoolSize_ {0}; 78 }; 79 } // namespace Pipeline 80 } // namespace Media 81 } // namespace OHOS 82 #endif // HISTREAMER_PIPELINE_FILTER_CODEC_MODE_H 83