1 /* 2 * Copyright (C) 2023 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 #ifndef CODECBASE_H 16 #define CODECBASE_H 17 18 #include <string> 19 #include "avcodec_common.h" 20 #include "buffer/avsharedmemorybase.h" 21 #include "surface.h" 22 #include "buffer/avbuffer.h" 23 #include "buffer/avbuffer_queue.h" 24 #include "buffer/avbuffer_queue_consumer.h" 25 #include "buffer/avbuffer_queue_define.h" 26 #include "buffer/avbuffer_queue_producer.h" 27 28 namespace OHOS { 29 namespace MediaAVCodec { 30 class CodecBase { 31 public: 32 CodecBase() = default; 33 virtual ~CodecBase() = default; 34 virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback); 35 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback); 36 virtual int32_t Configure(const Format &format) = 0; 37 virtual int32_t Start() = 0; 38 virtual int32_t Stop() = 0; 39 virtual int32_t Flush() = 0; 40 virtual int32_t Reset() = 0; 41 virtual int32_t Release() = 0; 42 virtual int32_t SetParameter(const Format& format) = 0; 43 virtual int32_t GetOutputFormat(Format &format) = 0; 44 virtual int32_t QueueInputBuffer(uint32_t index, const AVCodecBufferInfo &info, AVCodecBufferFlag flag); 45 virtual int32_t QueueInputBuffer(uint32_t index); 46 virtual int32_t ReleaseOutputBuffer(uint32_t index) = 0; 47 48 virtual int32_t NotifyEos(); 49 virtual sptr<Surface> CreateInputSurface(); 50 virtual int32_t SetInputSurface(sptr<Surface> surface); 51 virtual int32_t SetOutputSurface(sptr<Surface> surface); 52 virtual int32_t RenderOutputBuffer(uint32_t index); 53 virtual int32_t SignalRequestIDRFrame(); 54 virtual int32_t GetInputFormat(Format& format); 55 56 /* API11 audio codec interface */ CreateCodecByName(const std::string & name)57 virtual int32_t CreateCodecByName(const std::string &name) 58 { 59 (void)name; 60 return AVCODEC_ERROR_EXTEND_START; 61 } 62 Configure(const std::shared_ptr<Media::Meta> & meta)63 virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta) 64 { 65 (void)meta; 66 return AVCODEC_ERROR_EXTEND_START; 67 } 68 SetParameter(const std::shared_ptr<Media::Meta> & parameter)69 virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> ¶meter) 70 { 71 (void)parameter; 72 return AVCODEC_ERROR_EXTEND_START; 73 } 74 GetOutputFormat(std::shared_ptr<Media::Meta> & parameter)75 virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> ¶meter) 76 { 77 (void)parameter; 78 return AVCODEC_ERROR_EXTEND_START; 79 } 80 SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> & bufferQueueProducer)81 virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer) 82 { 83 (void)bufferQueueProducer; 84 return AVCODEC_ERROR_EXTEND_START; 85 } 86 Prepare()87 virtual int32_t Prepare() 88 { 89 return AVCODEC_ERROR_EXTEND_START; 90 } 91 GetInputBufferQueue()92 virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue() 93 { 94 return nullptr; 95 } 96 ProcessInputBuffer()97 virtual void ProcessInputBuffer() 98 { 99 return; 100 } 101 }; 102 } // namespace MediaAVCodec 103 } // namespace OHOS 104 #endif // CODECBASE_H