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 FFMPEG_CONVERTER_H 17 #define FFMPEG_CONVERTER_H 18 19 #include <string_view> 20 #include <string> 21 #include "avcodec_audio_common.h" 22 #include "avcodec_audio_channel_layout.h" 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 #include "libavcodec/avcodec.h" 27 #ifdef __cplusplus 28 } 29 #endif 30 namespace OHOS { 31 namespace MediaAVCodec { 32 class FFMpegConverter { 33 public: 34 static AudioSampleFormat ConvertFFMpegToOHAudioFormat(AVSampleFormat ffSampleFormat); 35 static AVSampleFormat ConvertOHAudioFormatToFFMpeg(AudioSampleFormat sampleFormat); 36 static AudioSampleFormat ConvertFFMpegAVCodecIdToOHAudioFormat(AVCodecID codecId); 37 static AudioChannelLayout ConvertFFToOHAudioChannelLayout(uint64_t ffChannelLayout); 38 static uint64_t ConvertOHAudioChannelLayoutToFFMpeg(AudioChannelLayout channelLayout); 39 static std::string_view ConvertOHAudioChannelLayoutToString(AudioChannelLayout layout); 40 static int64_t ConvertAudioPtsToUs(int64_t pts, AVRational base); 41 static std::string AVStrError(int errnum); 42 43 private: 44 FFMpegConverter() = delete; 45 ~FFMpegConverter() = delete; 46 }; 47 } // namespace MediaAVCodec 48 } // namespace OHOS 49 #endif