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_VORBIS_DECODER_PLUGIN_H 17 #define AUDIO_FFMPEG_VORBIS_DECODER_PLUGIN_H 18 19 #include "audio_base_codec.h" 20 #include "audio_ffmpeg_decoder_plugin.h" 21 #include "avcodec_codec_name.h" 22 23 namespace OHOS { 24 namespace MediaAVCodec { 25 class AudioFFMpegVorbisDecoderPlugin : public AudioBaseCodec::CodecRegister<AudioFFMpegVorbisDecoderPlugin> { 26 public: 27 AudioFFMpegVorbisDecoderPlugin(); 28 ~AudioFFMpegVorbisDecoderPlugin() override; 29 30 int32_t Init(const Format &format) override; 31 int32_t ProcessSendData(const std::shared_ptr<AudioBufferInfo> &inputBuffer) override; 32 int32_t ProcessRecieveData(std::shared_ptr<AudioBufferInfo> &outBuffer) override; 33 int32_t Reset() override; 34 int32_t Release() override; 35 int32_t Flush() override; 36 int32_t GetInputBufferSize() const override; 37 int32_t GetOutputBufferSize() const override; 38 Format GetFormat() const noexcept override; 39 std::string_view GetCodecType() const noexcept override; 40 Identify()41 const static std::string Identify() 42 { 43 return std::string(AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME); 44 } 45 46 private: 47 bool CheckFormat(const Format &format); 48 void GetExtradataSize(size_t idSize, size_t setupSize) const; 49 int PutHeaderLength(uint8_t *p, size_t value) const; 50 void PutCommentHeader(int offset) const; 51 int32_t GenExtradata(const Format &format) const; 52 bool CheckSampleFormat(const Format &format); 53 bool CheckChannelCount(const Format &format); 54 bool CheckSampleRate(const Format &format) const; 55 56 std::unique_ptr<AudioFfmpegDecoderPlugin> basePlugin; 57 int32_t channels_; 58 }; 59 } // namespace MediaAVCodec 60 } // namespace OHOS 61 #endif