1 /* 2 * Copyright (C) 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 AUDIO_DECODER_ADAPTER_H 17 #define AUDIO_DECODER_ADAPTER_H 18 19 #include <shared_mutex> 20 #include "buffer/avbuffer.h" 21 #include "buffer/avbuffer_queue.h" 22 #include "buffer/avbuffer_queue_producer.h" 23 #include "osal/task/condition_variable.h" 24 #include "meta/format.h" 25 #include "avcodec_audio_codec.h" 26 #include "avcodec_common.h" 27 28 namespace OHOS { 29 namespace Media { 30 class AudioDecoderAdapter : public std::enable_shared_from_this<AudioDecoderAdapter> { 31 public: 32 AudioDecoderAdapter(); 33 virtual ~AudioDecoderAdapter(); 34 35 Status Configure(const std::shared_ptr<Meta> ¶meter); 36 37 Status Prepare(); 38 39 Status Start(); 40 41 Status Stop(); 42 43 Status Flush(); 44 45 Status Reset(); 46 47 Status Release(); 48 49 Status SetParameter(const std::shared_ptr<Meta> ¶meter); 50 51 Status SetOutputBufferQueue(const sptr<AVBufferQueueProducer> &bufferQueueProducer); 52 53 int32_t GetOutputFormat(std::shared_ptr<Meta> ¶meter); 54 55 sptr<Media::AVBufferQueueProducer> GetInputBufferQueue(); 56 57 sptr<Media::AVBufferQueueConsumer> GetInputBufferQueueConsumer(); 58 59 sptr<Media::AVBufferQueueProducer> GetOutputBufferQueueProducer(); 60 61 void ProcessInputBufferInner(bool isTriggeredByOutPort, bool isFlushed); 62 63 void ProcessInputBuffer(); 64 65 int32_t NotifyEos(); 66 67 Status Init(bool isMimeType, const std::string &name); 68 69 Status ChangePlugin(const std::string &mime, bool isEncoder, const std::shared_ptr<Meta> &meta); 70 71 void SetDumpInfo(bool isDump, uint64_t instanceId); 72 73 void OnDumpInfo(int32_t fd); 74 75 int32_t SetCodecCallback(const std::shared_ptr<MediaAVCodec::MediaCodecCallback> &codecCallback); 76 77 int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, 78 const bool svpFlag); 79 80 private: 81 82 std::shared_ptr<MediaAVCodec::AVCodecAudioCodec> audiocodec_{nullptr}; 83 84 sptr<Media::AVBufferQueueProducer> outputBufferQueueProducer_{nullptr}; 85 86 sptr<Media::AVBufferQueueProducer> inputBufferQueueProducer_{nullptr}; 87 88 std::atomic<bool> isRunning_{false}; 89 }; 90 } // namespace Media 91 } // namespace OHOS 92 #endif // AUDIO_DECODER_ADAPTER_H