1 /* 2 * Copyright (C) 2024 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 OH_VEF_AUDIO_DECODER_H 17 #define OH_VEF_AUDIO_DECODER_H 18 19 #include "codec/common/codec_decoder.h" 20 #include <cstdint> 21 #include "codec/audio/pcm_buffer_queue.h" 22 23 namespace OHOS { 24 namespace Media { 25 26 class AudioDecoder : public CodecDecoder { 27 public: 28 AudioDecoder(uint64_t id, const CodecOnInData& packetReadFunc, 29 const CodecOnDecodeFrame& onDecodeFrameCallback, const CodecOnDecodeResult& onDecodeResultCallback); 30 ~AudioDecoder(); 31 32 public: 33 VEFError Init(OH_AVFormat* format) override; 34 VEFError Start() override; 35 VEFError Stop() override; 36 void SetPcmOutputBufferQueue(std::shared_ptr<PcmBufferQueue>& queue); 37 38 protected: 39 void CodecOnErrorInner(OH_AVCodec* codec, int32_t errorCode) override; 40 41 private: 42 VEFError CreateDecoder(); 43 VEFError ConfigureDecoder(OH_AVFormat* format); 44 void CodecOnStreamChangedInner(OH_AVFormat* format) override; 45 void CodecOnNeedInputDataInner(OH_AVCodec* codec, uint32_t index, OH_AVMemory* data) override; 46 void CodecOnNewOutputDataInner(OH_AVCodec* codec, uint32_t index, OH_AVMemory* data, 47 OH_AVCodecBufferAttr* attr) override; 48 private: 49 CodecOnInData packetReadFunc_{ nullptr }; 50 CodecOnDecodeFrame onDecodeFrameCallback_{ nullptr }; 51 CodecOnDecodeResult onDecodeResultCallback_{ nullptr }; 52 std::shared_ptr<PcmBufferQueue> pcmInputBufferQueue_; 53 }; 54 } // namespace Media 55 } // namespace OHOS 56 57 #endif // OH_VEF_AUDIO_DECODER_H