1 /* 2 * Copyright (C) 2023-2025 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 I_CODEC_SERVICE_H 17 #define I_CODEC_SERVICE_H 18 19 #include <string> 20 #include "avcodec_dfx_component.h" 21 #include "avcodec_common.h" 22 #include "avcodec_info.h" 23 #include "buffer/avsharedmemory.h" 24 #include "refbase.h" 25 #include "surface.h" 26 #include "meta/meta.h" 27 #include "meta/format.h" 28 #include "buffer/avbuffer.h" 29 #include "buffer/avbuffer_queue.h" 30 #include "buffer/avbuffer_queue_consumer.h" 31 #include "buffer/avbuffer_queue_define.h" 32 #include "buffer/avbuffer_queue_producer.h" 33 #include "drm_i_keysession_service.h" 34 35 namespace OHOS { 36 namespace MediaAVCodec { 37 class ICodecService : public AVCodecDfxComponent { 38 public: 39 virtual ~ICodecService() = default; 40 41 virtual int32_t Init(AVCodecType type, bool isMimeType, 42 const std::string &name, Media::Meta &callerInfo, API_VERSION apiVersion = API_VERSION::API_VERSION_10) = 0; 43 virtual int32_t Configure(const Format &format) = 0; 44 virtual int32_t SetCustomBuffer(std::shared_ptr<AVBuffer> buffer) = 0; 45 virtual int32_t Start() = 0; 46 virtual int32_t Stop() = 0; 47 virtual int32_t Flush() = 0; 48 virtual int32_t Reset() = 0; 49 virtual int32_t Release() = 0; 50 virtual int32_t NotifyEos() = 0; 51 virtual sptr<Surface> CreateInputSurface() = 0; 52 virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0; 53 virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; 54 virtual int32_t QueueInputBuffer(uint32_t index) = 0; 55 virtual int32_t QueueInputParameter(uint32_t index) = 0; 56 virtual int32_t GetOutputFormat(Format &format) = 0; 57 virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render = false) = 0; 58 virtual int32_t RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) = 0; 59 virtual int32_t SetParameter(const Format &format) = 0; 60 virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0; 61 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) = 0; 62 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) = 0; 63 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterWithAttrCallback> &callback) = 0; ChangePlugin(const std::string & mime,bool isEncoder,const std::shared_ptr<Media::Meta> & meta)64 virtual int32_t ChangePlugin(const std::string &mime, bool isEncoder, const std::shared_ptr<Media::Meta> &meta) 65 { 66 (void)mime; 67 (void)isEncoder; 68 (void)meta; 69 return AVCODEC_ERROR_EXTEND_START; 70 } 71 SetCodecCallback(const std::shared_ptr<MediaCodecCallback> & codecCallback)72 virtual int32_t SetCodecCallback(const std::shared_ptr<MediaCodecCallback> &codecCallback) 73 { 74 (void)codecCallback; 75 return AVCODEC_ERROR_EXTEND_START; 76 } 77 SetDumpInfo(bool isDump,uint64_t instanceId)78 virtual void SetDumpInfo(bool isDump, uint64_t instanceId) 79 { 80 (void)isDump; 81 (void)instanceId; 82 } 83 84 virtual int32_t GetInputFormat(Format &format) = 0; SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)85 virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, 86 const bool svpFlag) 87 { 88 (void)keySession; 89 (void)svpFlag; 90 return AVCODEC_ERROR_EXTEND_START; 91 } 92 93 /* API11 audio codec interface */ CreateCodecByName(const std::string & name)94 virtual int32_t CreateCodecByName(const std::string &name) 95 { 96 (void)name; 97 return AVCODEC_ERROR_EXTEND_START; 98 } 99 Configure(const std::shared_ptr<Media::Meta> & meta)100 virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta) 101 { 102 (void)meta; 103 return AVCODEC_ERROR_EXTEND_START; 104 } SetParameter(const std::shared_ptr<Media::Meta> & parameter)105 virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> ¶meter) 106 { 107 (void)parameter; 108 return AVCODEC_ERROR_EXTEND_START; 109 } GetOutputFormat(std::shared_ptr<Media::Meta> & parameter)110 virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> ¶meter) 111 { 112 (void)parameter; 113 return AVCODEC_ERROR_EXTEND_START; 114 } 115 SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> & bufferQueueProducer)116 virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer) 117 { 118 (void)bufferQueueProducer; 119 return AVCODEC_ERROR_EXTEND_START; 120 } Prepare()121 virtual int32_t Prepare() 122 { 123 return AVCODEC_ERROR_EXTEND_START; 124 } GetInputBufferQueue()125 virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue() 126 { 127 return nullptr; 128 } ProcessInputBuffer()129 virtual void ProcessInputBuffer() 130 { 131 return; 132 } CheckRunning()133 virtual bool CheckRunning() 134 { 135 return false; 136 } 137 138 /* API12 audio codec interface for drm */ SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)139 virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, 140 const bool svpFlag) 141 { 142 (void)keySession; 143 (void)svpFlag; 144 return AVCODEC_ERROR_EXTEND_START; 145 } 146 GetInputBufferQueueConsumer()147 virtual sptr<Media::AVBufferQueueConsumer> GetInputBufferQueueConsumer() 148 { 149 return nullptr; 150 } 151 GetOutputBufferQueueProducer()152 virtual sptr<Media::AVBufferQueueProducer> GetOutputBufferQueueProducer() 153 { 154 return nullptr; 155 } 156 ProcessInputBufferInner(bool isTriggeredByOutPort,bool isFlushed)157 virtual void ProcessInputBufferInner(bool isTriggeredByOutPort, bool isFlushed) 158 { 159 (void)isTriggeredByOutPort; 160 (void)isFlushed; 161 } 162 }; 163 } // namespace MediaAVCodec 164 } // namespace OHOS 165 #endif // I_CODEC_SERVICE_H