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 AVCODEC_AUDIO_AVBUFFER_LBVC_DECODER_INNER_DEMO_H 17 #define AVCODEC_AUDIO_AVBUFFER_LBVC_DECODER_INNER_DEMO_H 18 19 #include <atomic> 20 #include <fstream> 21 #include <thread> 22 #include <queue> 23 #include <string> 24 #include "avcodec_common.h" 25 #include "avcodec_audio_codec.h" 26 #include "buffer/avbuffer.h" 27 #include "buffer/avbuffer_queue.h" 28 #include "buffer/avbuffer_queue_consumer.h" 29 #include "buffer/avbuffer_queue_define.h" 30 #include "nocopyable.h" 31 32 namespace OHOS { 33 namespace MediaAVCodec { 34 namespace InnerAudioDecoderLbvcDemo { 35 36 class AudioDecInnerAvBufferLbvcDemo { 37 public: 38 AudioDecInnerAvBufferLbvcDemo() = default; 39 virtual ~AudioDecInnerAvBufferLbvcDemo() = default; 40 void RunCase(); 41 void InputFunc(); 42 void OutputFunc(); 43 44 private: 45 int32_t GetInputBufferSize(); 46 int32_t fileSize_ = 0; 47 std::atomic<int32_t> bufferConsumerAvailableCount_ = 0; 48 std::atomic<bool> isRunning_ = false; 49 std::unique_ptr<std::ifstream> testFile_; 50 std::shared_ptr<AVCodecAudioCodec> audiocodec_; 51 std::shared_ptr<Media::AVBufferQueue> innerBufferQueue_; 52 sptr<Media::AVBufferQueueConsumer> implConsumer_; 53 sptr<Media::AVBufferQueueProducer> mediaCodecProducer_; 54 std::unique_ptr<std::ifstream> inputFile_; 55 std::unique_ptr<std::ofstream> outputFile_; 56 }; 57 58 class AudioCodecConsumerListener : public OHOS::Media::IConsumerListener { 59 public: 60 explicit AudioCodecConsumerListener(AudioDecInnerAvBufferLbvcDemo *demo); 61 62 void OnBufferAvailable() override; 63 64 private: 65 AudioDecInnerAvBufferLbvcDemo *demo_; 66 }; 67 68 } // namespace InnerAudioDecoderLbvcDemo 69 } // namespace MediaAVCodec 70 } // namespace OHOS 71 #endif // AVCODEC_AUDIO_AVBUFFER_LBVC_DECODER_INNER_DEMO_H