• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef __cplusplus
32 }
33 #endif
34 namespace OHOS {
35 namespace MediaAVCodec {
36 class FFMpegConverter {
37 public:
38     static ColorPrimary ConvertFFMpegToOHColorPrimaries(AVColorPrimaries ffColorPrimaries);
39     static TransferCharacteristic ConvertFFMpegToOHColorTrans(AVColorTransferCharacteristic ffColorTrans);
40     static MatrixCoefficient ConvertFFMpegToOHColorMatrix(AVColorSpace ffColorSpace);
41     static int ConvertFFMpegToOHColorRange(AVColorRange ffColorRange);
42     static ChromaLocation ConvertFFMpegToOHChromaLocation(AVChromaLocation ffChromaLocation);
43     static HEVCProfile ConvertFFMpegToOHHEVCProfile(int ffHEVCProfile);
44     static HEVCLevel ConvertFFMpegToOHHEVCLevel(int ffHEVCLevel);
45     static AudioSampleFormat ConvertFFMpegAVCodecIdToOHAudioFormat(AVCodecID codecId);
46     static AudioSampleFormat ConvertFFMpegToOHAudioFormat(AVSampleFormat ffSampleFormat);
47     static AVSampleFormat ConvertOHAudioFormatToFFMpeg(AudioSampleFormat sampleFormat);
48     static AudioChannelLayout ConvertFFToOHAudioChannelLayout(uint64_t ffChannelLayout);
49     static AudioChannelLayout GetDefaultChannelLayout(int channels);
50     static AudioChannelLayout ConvertFFToOHAudioChannelLayoutV2(uint64_t ffChannelLayout, int channels);
51     static uint64_t ConvertOHAudioChannelLayoutToFFMpeg(AudioChannelLayout channelLayout);
52     static std::string_view ConvertOHAudioChannelLayoutToString(AudioChannelLayout layout);
53     static int64_t ConvertAudioPtsToUs(int64_t pts, AVRational base);
54     static std::string AVStrError(int errnum);
55 
56 private:
57     FFMpegConverter() = delete;
58     ~FFMpegConverter() = delete;
59 };
60 } // namespace MediaAVCodec
61 } // namespace OHOS
62 #endif