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 16 #ifndef MEDIA_AVCODEC_AUDIO_CODEC_H 17 #define MEDIA_AVCODEC_AUDIO_CODEC_H 18 19 #include "avcodec_common.h" 20 #include "meta/format.h" 21 #include "meta/meta.h" 22 #include "buffer/avbuffer_queue_producer.h" 23 24 namespace OHOS { 25 namespace MediaAVCodec { 26 class AVCodecAudioCodec { 27 public: 28 virtual ~AVCodecAudioCodec() = default; 29 30 virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta); 31 32 virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer); 33 34 virtual int32_t Prepare(); 35 36 virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue(); 37 38 virtual int32_t Start(); 39 40 virtual int32_t Stop(); 41 42 virtual int32_t Flush(); 43 44 virtual int32_t Reset(); 45 46 virtual int32_t Release(); 47 48 virtual int32_t NotifyEos(); 49 50 virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> ¶meter); 51 52 virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> ¶meter); 53 54 virtual void ProcessInputBuffer(); 55 }; 56 57 class __attribute__((visibility("default"))) AudioCodecFactory { 58 public: 59 #ifdef UNSUPPORT_CODEC CreateByMime(const std::string & mime,bool isEncoder)60 static std::shared_ptr<AVCodecAudioCodec> CreateByMime(const std::string &mime, bool isEncoder) 61 { 62 (void)mime; 63 return nullptr; 64 } 65 CreateByName(const std::string & name)66 static std::shared_ptr<AVCodecAudioCodec> CreateByName(const std::string &name) 67 { 68 (void)name; 69 return nullptr; 70 } 71 #else 72 /** 73 * @brief Instantiate the preferred decoder of the given mime type. 74 * @param mime The mime type. 75 * @return Returns the preferred decoder. 76 * @since 4.1 77 */ 78 static std::shared_ptr<AVCodecAudioCodec> CreateByMime(const std::string &mime, bool isEncoder); 79 80 /** 81 * @brief Instantiates the designated decoder. 82 * @param name The codec's name. 83 * @return Returns the designated decoder. 84 * @since 4.1 85 */ 86 static std::shared_ptr<AVCodecAudioCodec> CreateByName(const std::string &name); 87 #endif 88 private: 89 AudioCodecFactory() = default; 90 ~AudioCodecFactory() = default; 91 }; 92 93 } // namespace MediaAVCodec 94 } // namespace OHOS 95 #endif // MEDIA_AVCODEC_AUDIO_CODEC_H