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 GetChannelId(int32_t &channelId) = 0; 51 virtual int32_t NotifyEos() = 0; 52 virtual sptr<Surface> CreateInputSurface() = 0; 53 virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0; 54 virtual int32_t SetLowPowerPlayerMode(bool isLpp) = 0; 55 virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; 56 virtual int32_t QueueInputBuffer(uint32_t index) = 0; 57 virtual int32_t QueueInputParameter(uint32_t index) = 0; 58 virtual int32_t GetOutputFormat(Format &format) = 0; 59 virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render = false) = 0; 60 virtual int32_t RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) = 0; 61 virtual int32_t SetParameter(const Format &format) = 0; 62 virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0; 63 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) = 0; 64 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) = 0; 65 virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterWithAttrCallback> &callback) = 0; 66 QueryInputBuffer(uint32_t & index,int64_t timeoutUs)67 virtual int32_t QueryInputBuffer(uint32_t &index, int64_t timeoutUs) 68 { 69 (void)index; 70 (void)timeoutUs; 71 return AVCODEC_ERROR_EXTEND_START; 72 } 73 QueryOutputBuffer(uint32_t & index,int64_t timeoutUs)74 virtual int32_t QueryOutputBuffer(uint32_t &index, int64_t timeoutUs) 75 { 76 (void)index; 77 (void)timeoutUs; 78 return AVCODEC_ERROR_EXTEND_START; 79 } 80 GetInputBuffer(uint32_t index)81 virtual std::shared_ptr<AVBuffer> GetInputBuffer(uint32_t index) 82 { 83 (void)index; 84 return nullptr; 85 } 86 GetOutputBuffer(uint32_t index)87 virtual std::shared_ptr<AVBuffer> GetOutputBuffer(uint32_t index) 88 { 89 (void)index; 90 return nullptr; 91 } 92 ChangePlugin(const std::string & mime,bool isEncoder,const std::shared_ptr<Media::Meta> & meta)93 virtual int32_t ChangePlugin(const std::string &mime, bool isEncoder, const std::shared_ptr<Media::Meta> &meta) 94 { 95 (void)mime; 96 (void)isEncoder; 97 (void)meta; 98 return AVCODEC_ERROR_EXTEND_START; 99 } 100 SetCodecCallback(const std::shared_ptr<MediaCodecCallback> & codecCallback)101 virtual int32_t SetCodecCallback(const std::shared_ptr<MediaCodecCallback> &codecCallback) 102 { 103 (void)codecCallback; 104 return AVCODEC_ERROR_EXTEND_START; 105 } 106 SetDumpInfo(bool isDump,uint64_t instanceId)107 virtual void SetDumpInfo(bool isDump, uint64_t instanceId) 108 { 109 (void)isDump; 110 (void)instanceId; 111 } 112 113 virtual int32_t GetInputFormat(Format &format) = 0; SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)114 virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, 115 const bool svpFlag) 116 { 117 (void)keySession; 118 (void)svpFlag; 119 return AVCODEC_ERROR_EXTEND_START; 120 } 121 122 /* API11 audio codec interface */ CreateCodecByName(const std::string & name)123 virtual int32_t CreateCodecByName(const std::string &name) 124 { 125 (void)name; 126 return AVCODEC_ERROR_EXTEND_START; 127 } 128 Configure(const std::shared_ptr<Media::Meta> & meta)129 virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta) 130 { 131 (void)meta; 132 return AVCODEC_ERROR_EXTEND_START; 133 } SetParameter(const std::shared_ptr<Media::Meta> & parameter)134 virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> ¶meter) 135 { 136 (void)parameter; 137 return AVCODEC_ERROR_EXTEND_START; 138 } GetOutputFormat(std::shared_ptr<Media::Meta> & parameter)139 virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> ¶meter) 140 { 141 (void)parameter; 142 return AVCODEC_ERROR_EXTEND_START; 143 } 144 SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> & bufferQueueProducer)145 virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer) 146 { 147 (void)bufferQueueProducer; 148 return AVCODEC_ERROR_EXTEND_START; 149 } Prepare()150 virtual int32_t Prepare() 151 { 152 return AVCODEC_ERROR_EXTEND_START; 153 } GetInputBufferQueue()154 virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue() 155 { 156 return nullptr; 157 } ProcessInputBuffer()158 virtual void ProcessInputBuffer() 159 { 160 return; 161 } CheckRunning()162 virtual bool CheckRunning() 163 { 164 return false; 165 } 166 167 /* API12 audio codec interface for drm */ SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)168 virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, 169 const bool svpFlag) 170 { 171 (void)keySession; 172 (void)svpFlag; 173 return AVCODEC_ERROR_EXTEND_START; 174 } 175 GetInputBufferQueueConsumer()176 virtual sptr<Media::AVBufferQueueConsumer> GetInputBufferQueueConsumer() 177 { 178 return nullptr; 179 } 180 GetOutputBufferQueueProducer()181 virtual sptr<Media::AVBufferQueueProducer> GetOutputBufferQueueProducer() 182 { 183 return nullptr; 184 } 185 ProcessInputBufferInner(bool isTriggeredByOutPort,bool isFlushed,uint32_t & bufferStatus)186 virtual void ProcessInputBufferInner(bool isTriggeredByOutPort, bool isFlushed, uint32_t &bufferStatus) 187 { 188 (void)isTriggeredByOutPort; 189 (void)isFlushed; 190 (void)bufferStatus; 191 } 192 193 virtual int32_t NotifyMemoryExchange(const bool exchangeFlag) = 0; 194 }; 195 } // namespace MediaAVCodec 196 } // namespace OHOS 197 #endif // I_CODEC_SERVICE_H