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_info.h"
22 #include "avcodec_common.h"
23 #include "avcodec_audio_common.h"
24 #include "avcodec_audio_channel_layout.h"
25 #include "media_description.h"
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 #include "libavcodec/avcodec.h"
30 #include "libavutil/pixfmt.h"
31 #include "libavcodec/bsf.h"
32 #include "libavutil/channel_layout.h"
33 #ifdef __cplusplus
34 }
35 #endif
36 namespace OHOS {
37 namespace MediaAVCodec {
38 class FFMpegConverter {
39 public:
40     static ColorPrimary ConvertFFMpegToOHColorPrimaries(AVColorPrimaries ffColorPrimaries);
41     static TransferCharacteristic ConvertFFMpegToOHColorTrans(AVColorTransferCharacteristic ffColorTrans);
42     static MatrixCoefficient ConvertFFMpegToOHColorMatrix(AVColorSpace ffColorSpace);
43     static int ConvertFFMpegToOHColorRange(AVColorRange ffColorRange);
44     static ChromaLocation ConvertFFMpegToOHChromaLocation(AVChromaLocation ffChromaLocation);
45     static HEVCProfile ConvertFFMpegToOHHEVCProfile(int ffHEVCProfile);
46     static HEVCLevel ConvertFFMpegToOHHEVCLevel(int ffHEVCLevel);
47     static AudioSampleFormat ConvertFFMpegAVCodecIdToOHAudioFormat(AVCodecID codecId);
48     static AudioSampleFormat ConvertFFMpegToOHAudioFormat(AVSampleFormat ffSampleFormat);
49     static AVSampleFormat ConvertOHAudioFormatToFFMpeg(AudioSampleFormat sampleFormat);
50     static AudioChannelLayout ConvertFFToOHAudioChannelLayout(uint64_t ffChannelLayout);
51     static AudioChannelLayout GetDefaultChannelLayout(int channels);
52     static AudioChannelLayout ConvertFFToOHAudioChannelLayoutV2(uint64_t ffChannelLayout, int channels);
53     static uint64_t ConvertOHAudioChannelLayoutToFFMpeg(AudioChannelLayout channelLayout);
54     static std::string_view ConvertOHAudioChannelLayoutToString(AudioChannelLayout layout);
55     static int64_t ConvertAudioPtsToUs(int64_t pts, AVRational base);
56     static std::string AVStrError(int errnum);
57 
58 private:
59     FFMpegConverter() = delete;
60     ~FFMpegConverter() = delete;
61 };
62 } // namespace MediaAVCodec
63 } // namespace OHOS
64 #endif