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 AUDIO_FFMPEG_OPUS_DECODER_PLUGIN_H 17 #define AUDIO_FFMPEG_OPUS_DECODER_PLUGIN_H 18 19 #include <mutex> 20 #include "audio_base_codec.h" 21 #include "avcodec_codec_name.h" 22 #include "audio_base_codec.h" 23 #include "nocopyable.h" 24 #include "audio_base_codec_ext.h" 25 26 namespace OHOS { 27 namespace MediaAVCodec { 28 enum ParaType : int32_t { 29 CHANNEL = 0, 30 SAMPLE_RATE = 1, 31 }; 32 33 class AudioOpusDecoderPlugin : public AudioBaseCodec::CodecRegister<AudioOpusDecoderPlugin> { 34 public: 35 AudioOpusDecoderPlugin(); 36 ~AudioOpusDecoderPlugin() override; 37 38 int32_t Init(const Format &format) override; 39 int32_t ProcessSendData(const std::shared_ptr<AudioBufferInfo> &inputBuffer) override; 40 int32_t ProcessRecieveData(std::shared_ptr<AudioBufferInfo> &outBuffer) override; 41 int32_t Reset() override; 42 int32_t Release() override; 43 int32_t Flush() override; 44 int32_t GetInputBufferSize() const override; 45 int32_t GetOutputBufferSize() const override; 46 Format GetFormat() const noexcept override; 47 std::string_view GetCodecType() const noexcept override; 48 Identify()49 const static std::string Identify() 50 { 51 return std::string(AVCodecCodecName::AUDIO_DECODER_OPUS_NAME); 52 } 53 54 private: 55 Format format_; 56 mutable std::mutex avMutext_; 57 int32_t CheckSampleFormat(); 58 OHOS::MediaAVCodec::AudioBaseCodecExt *PluginCodecPtr; 59 int32_t ret; 60 unsigned char *fbytes; 61 int32_t len; 62 unsigned char *codeData; 63 64 int32_t channels; 65 int32_t sampleRate; 66 void *handle = nullptr; 67 }; 68 } // namespace MediaAVCodec 69 } // namespace OHOS 70 #endif