• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_FORMAT_HELPER_H
17 #define FFMPEG_FORMAT_HELPER_H
18 
19 #include <cstdint>
20 #include "meta/meta.h"
21 #include "ffmpeg_utils.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 #include "libavformat/avformat.h"
27 #include "libavutil/channel_layout.h"
28 #include "libavcodec/av3a.h"
29 #include "libavutil/parseutils.h"
30 #ifdef __cplusplus
31 }
32 #endif
33 
34 namespace OHOS {
35 namespace Media {
36 namespace Plugins {
37 namespace Ffmpeg {
38 struct ParserSdtpInfo {
39     void *pb = nullptr;
40     int pbIsCopied = 0;
41     int ffindex = 0;
42     int nextChunk = 0;
43     unsigned int chunkCount = 0;
44     int64_t *chunkOffsets = nullptr;
45     unsigned int sttsCount = 0;
46     void *sttsData = nullptr;
47     unsigned int sdtpCount = 0;
48     uint8_t *sdtpData = nullptr;
49 };
50 
51 struct HevcParseFormat {
52     int32_t isHdrVivid = 0;
53     int32_t colorRange = 0;
54     uint8_t colorPrimaries = 0x02;
55     uint8_t colorTransfer = 0x02;
56     uint8_t colorMatrixCoeff = 0x02;
57     uint8_t profile = 0;
58     uint8_t level = 0;
59     uint32_t chromaLocation = 0;
60     uint32_t picWidInLumaSamples = 0;
61     uint32_t picHetInLumaSamples = 0;
62 };
63 
64 class FFmpegFormatHelper {
65 public:
66     static void ParseMediaInfo(const AVFormatContext& avFormatContext, Meta& format);
67     static void ParseTrackInfo(const AVStream& avStream, Meta& format, const AVFormatContext& avFormatContext);
68     static void ParseUserMeta(const AVFormatContext& avFormatContext, std::shared_ptr<Meta> format);
69     static void ParseHevcInfo(const AVFormatContext& avFormatContext, HevcParseFormat parse, Meta &format);
70     static FileType GetFileTypeByName(const AVFormatContext& avFormatContext);
71     static bool IsVideoCodecId(const AVCodecID &codecId);
72     static bool IsImageTrack(const AVStream &avStream);
73     static bool IsVideoType(const AVStream &avStream);
74     static bool IsAudioType(const AVStream &avStream);
75     static bool IsMpeg4File(FileType filetype);
76     static bool IsValidCodecId(const AVCodecID &codecId);
77 private:
78     FFmpegFormatHelper() = delete;
79     ~FFmpegFormatHelper() = delete;
80 
81     static void ParseBaseTrackInfo(const AVStream& avStream, Meta &format, const AVFormatContext& avFormatContext);
82     static void ParseAVTrackInfo(const AVStream& avStream, Meta &format);
83     static void ParseVideoTrackInfo(const AVStream& avStream, Meta &format, const AVFormatContext& avFormatContext);
84     static void ParseAudioTrackInfo(const AVStream& avStream, Meta &format, const AVFormatContext& avFormatContext);
85     static void ParseAudioApeTrackInfo(const AVStream& avStream, Meta &format, const AVFormatContext& avFormatContext);
86     static void ParseImageTrackInfo(const AVStream& avStream, Meta &format);
87     static void ParseTimedMetaTrackInfo(const AVStream& avStream, Meta &format);
88     static void ParseAuxiliaryTrackInfo(const AVStream& avStream, Meta &format);
89     static void ParseHvccBoxInfo(const AVStream& avStream, Meta &format);
90     static void ParseColorBoxInfo(const AVStream& avStream, Meta &format);
91     static void ParseColorBoxInfo(const AVFormatContext& avFormatContext, HevcParseFormat parse, Meta &format);
92 
93     static void ParseLocationInfo(const AVFormatContext& avFormatContext, Meta &format);
94 
95     static void ParseInfoFromMetadata(const AVDictionary* metadata, Meta &format);
96     static void ParseRotationFromMatrix(const AVStream& avStream, Meta &format);
97     static void ParseOrientationFromMatrix(const AVStream& avStream, Meta &format);
98     static void ParseTrackType(const AVFormatContext& avFormatContext, Meta& format);
99 
100     static void ParseAv3aInfo(const AVStream& avStream, Meta &format);
101     static void ConvertAv3aSampleFormat(const AVStream& avStream, Meta &format);
102 };
103 extern std::vector<TagType> g_supportSourceFormat;
104 } // namespace Ffmpeg
105 } // namespace Plugins
106 } // namespace Media
107 } // namespace OHOS
108 #endif // FFMPEG_FORMAT_HELPER_H