• 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_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/parseutils.h"
28 #ifdef __cplusplus
29 }
30 #endif
31 
32 namespace OHOS {
33 namespace Media {
34 namespace Plugins {
35 namespace Ffmpeg {
36 struct ParserSdtpInfo {
37     void *pb = nullptr;
38     int pbIsCopied = 0;
39     int ffindex = 0;
40     int nextChunk = 0;
41     unsigned int chunkCount = 0;
42     int64_t *chunkOffsets = nullptr;
43     unsigned int sttsCount = 0;
44     void *sttsData = nullptr;
45     unsigned int sdtpCount = 0;
46     uint8_t *sdtpData = nullptr;
47 };
48 
49 struct HevcParseFormat {
50     int32_t isHdrVivid = 0;
51     int32_t colorRange = 0;
52     uint8_t colorPrimaries = 0x02;
53     uint8_t colorTransfer = 0x02;
54     uint8_t colorMatrixCoeff = 0x02;
55     uint8_t profile = 0;
56     uint8_t level = 0;
57     uint32_t chromaLocation = 0;
58     uint32_t picWidInLumaSamples = 0;
59     uint32_t picHetInLumaSamples = 0;
60 };
61 
62 class FFmpegFormatHelper {
63 public:
64     static void ParseMediaInfo(const AVFormatContext& avFormatContext, Meta& format);
65     static void ParseTrackInfo(const AVStream& avStream, Meta& format, const AVFormatContext& avFormatContext);
66     static void ParseUserMeta(const AVFormatContext& avFormatContext, std::shared_ptr<Meta> format);
67     static void ParseHevcInfo(const AVFormatContext& avFormatContext, HevcParseFormat parse, Meta &format);
68     static FileType GetFileTypeByName(const AVFormatContext& avFormatContext);
69 private:
70     FFmpegFormatHelper() = delete;
71     ~FFmpegFormatHelper() = delete;
72 
73     static void ParseBaseTrackInfo(const AVStream& avStream, Meta &format, const AVFormatContext& avFormatContext);
74     static void ParseAVTrackInfo(const AVStream& avStream, Meta &format);
75     static void ParseVideoTrackInfo(const AVStream& avStream, Meta &format, const AVFormatContext& avFormatContext);
76     static void ParseAudioTrackInfo(const AVStream& avStream, Meta &format);
77     static void ParseImageTrackInfo(const AVStream& avStream, Meta &format);
78     static void ParseTimedMetaTrackInfo(const AVStream& avStream, Meta &format);
79     static void ParseHvccBoxInfo(const AVStream& avStream, Meta &format);
80     static void ParseColorBoxInfo(const AVStream& avStream, Meta &format);
81 
82     static void ParseLocationInfo(const AVFormatContext& avFormatContext, Meta &format);
83 
84     static void ParseInfoFromMetadata(const AVDictionary* metadata, const TagType key, Meta &format);
85     static void PutInfoToFormat(const Tag key, int32_t value, Meta &format);
86     static void PutInfoToFormat(const Tag key, int64_t value, Meta &format);
87     static void PutInfoToFormat(const Tag key, float value, Meta &format);
88     static void PutInfoToFormat(const Tag key, double value, Meta &format);
89     static void PutInfoToFormat(const Tag key, const std::string_view &value, Meta &format);
90     static void PutBufferToFormat(const Tag key, const uint8_t *addr, size_t size, Meta &format);
91     static void ParseRotationFromMatrix(const AVStream& avStream, Meta &format);
92     static void ParseOrientationFromMatrix(const AVStream& avStream, Meta &format);
93     static void ParseTrackType(const AVFormatContext& avFormatContext, Meta& format);
94 };
95 extern std::vector<TagType> g_supportSourceFormat;
96 } // namespace Ffmpeg
97 } // namespace Plugins
98 } // namespace Media
99 } // namespace OHOS
100 #endif // FFMPEG_FORMAT_HELPER_H