• 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 MEDIA_AVCODEC_FFMPEG_FORMAT_HELPER
17 #define MEDIA_AVCODEC_FFMPEG_FORMAT_HELPER
18 
19 #include <cstdint>
20 #include "meta/format.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 #include "libavformat/avformat.h"
26 #include "libavutil/parseutils.h"
27 #ifdef __cplusplus
28 }
29 #endif
30 
31 namespace OHOS {
32 namespace MediaAVCodec {
33 namespace Plugin {
34 struct HevcParseFormat {
35     int32_t isHdrVivid = 0;
36     int32_t colorRange = 0;
37     uint8_t colorPrimaries = 0x02;
38     uint8_t colorTransfer = 0x02;
39     uint8_t colorMatrixCoeff = 0x02;
40     uint8_t profile = 0;
41     uint8_t level = 0;
42     uint32_t chromaLocation = 0;
43     uint32_t picWidInLumaSamples = 0;
44     uint32_t picHetInLumaSamples = 0;
45 };
46 
47 class FFmpegFormatHelper {
48 public:
49     static void ParseMediaInfo(const AVFormatContext &avFormatContext, Media::Format &format);
50     static void ParseTrackInfo(const AVStream &avStream, Media::Format &format);
51     static void ParseHevcInfo(const AVFormatContext &avFormatContext, HevcParseFormat parse, Media::Format &format);
52 
53 private:
54     FFmpegFormatHelper() = delete;
55     ~FFmpegFormatHelper() = delete;
56 
57     static void ParseBaseTrackInfo(const AVStream &avStream, Media::Format &format);
58     static void ParseAVTrackInfo(const AVStream& avStream, Media::Format &format);
59     static void ParseVideoTrackInfo(const AVStream& avStream, Media::Format &format);
60     static void ParseAudioTrackInfo(const AVStream& avStream, Media::Format &format);
61     static void ParseImageTrackInfo(const AVStream& avStream, Media::Format &format);
62     static void ParseHvccBoxInfo(const AVStream& avStream, Media::Format &format);
63     static void ParseColorBoxInfo(const AVStream& avStream, Media::Format &format);
64 
65     static void ParseInfoFromMetadata(const AVDictionary* metadata, const std::string_view key, Media::Format &format);
66     static void PutInfoToFormat(const std::string_view &key, int32_t value, Media::Format& format);
67     static void PutInfoToFormat(const std::string_view &key, int64_t value, Media::Format& format);
68     static void PutInfoToFormat(const std::string_view &key, float value, Media::Format& format);
69     static void PutInfoToFormat(const std::string_view &key, double value, Media::Format& format);
70     static void PutInfoToFormat(const std::string_view &key, const std::string_view &value, Media::Format& format);
71     static void PutBufferToFormat(const std::string_view &key, const uint8_t *addr, size_t size, Media::Format &format);
72 };
73 } // namespace Plugin
74 } // namespace MediaAVCodec
75 } // namespace OHOS
76 #endif // MEDIA_AVCODEC_FFMPEG_FORMAT_HELPER