• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 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 HISTREAMER_PLUGIN_COMMON_TAGS_H
17 #define HISTREAMER_PLUGIN_COMMON_TAGS_H
18 
19 #include <map> // NOLINT
20 #include <string>
21 #include <vector> // NOLINT
22 #include "any.h" // NOLINT
23 
24 namespace OHOS {
25 namespace Media {
26 namespace Plugin {
27 enum struct TagSection : uint8_t {
28     REGULAR = 1,
29     MEDIA = 2,
30     AUDIO_UNIVERSAL = 3,
31     AUDIO_SPECIFIC = 4,
32     VIDEO_UNIVERSAL = 5,
33     VIDEO_SPECIFIC = 6,
34     MAX_SECTION = 64
35 };
36 
37 enum struct AudioFormat : uint8_t {
38     MPEG = 1,
39     AAC,
40 };
41 
42 enum struct VideoFormat : uint8_t {
43     UNKNOWN = 0,
44     H264 = 1,
45     MPEG4 = 2,
46 };
47 
48 enum class MediaType : uint32_t {
49     UNKNOWN = 0,    ///< Usually treated as DATA
50     AUDIO,
51     VIDEO,
52     SUBTITLE,
53     ATTACHMENT,     ///< Opaque data information usually sparse
54     DATA            ///< Opaque data information usually continuous
55 };
56 
57 #define MAKE_AUDIO_SPECIFIC_START(format) (SECTION_AUDIO_SPECIFIC_START | (static_cast<uint8_t>(format) << 8U))
58 
59 #define MAKE_VIDEO_SPECIFIC_START(format) (SECTION_VIDEO_SPECIFIC_START | (static_cast<uint8_t>(format) << 8U))
60 
61 /**
62  * @brief Tag is a key-value pair used to settings or transfer information.
63  *
64  * The "key" member:An uint32_t index, defined as an enumerated type.
65  *   Tag Index consisting of the following fragments:
66  *   - reserved field
67  *   - vendor extensions
68  *   - section (regular, audio, video ...)
69  *   - addition index
70  *
71  *   layout:
72  *          +----------+---------+--------+----------------+
73  *          | reserved | section | vendor | addition index |
74  *          +----------+---------+--------+----------------+
75  *    bit:   31 ... 22  21 ... 16    15    14 ............ 0
76  *
77  * The "value" member: Different tag have different value types,
78  *                     which is defined in the plug-in interface.
79  *
80  * @since 1.0
81  * @version 1.0
82  */
83 enum struct Tag : uint32_t {
84     INVALID = 0,
85     SECTION_REGULAR_START = static_cast<uint8_t>(TagSection::REGULAR) << 16U,                 // regular tag
86     SECTION_MEDIA_START = static_cast<uint8_t>(TagSection::MEDIA) << 16U,                     // media tag
87     SECTION_AUDIO_UNIVERSAL_START = static_cast<uint8_t>(TagSection::AUDIO_UNIVERSAL) << 16U, // audio universal tag
88     SECTION_AUDIO_SPECIFIC_START = static_cast<uint8_t>(TagSection::AUDIO_SPECIFIC) << 16U,   // audio specific tag
89     SECTION_VIDEO_UNIVERSAL_START = static_cast<uint8_t>(TagSection::VIDEO_UNIVERSAL) << 16U, // video universal tag
90     SECTION_VIDEO_SPECIFIC_START = static_cast<uint8_t>(TagSection::VIDEO_SPECIFIC) << 16U,   // video specific tag
91 
92     /* -------------------- regular tag -------------------- */
93     MIME = SECTION_REGULAR_START + 1, ///< std::string
94     TRACK_ID,                         ///< uint32_t, track id
95     REQUIRED_OUT_BUFFER_CNT,          ///< uint32_t, required buffer count of plugin; read only tag
96     REQUIRED_OUT_BUFFER_SIZE,         ///< uint32_t, required buffer size of plugin; read only tag
97     BUFFER_ALLOCATOR,                 ///< Allocator, allocator to alloc buffers
98     BUFFERING_SIZE,                   ///< uint32_t, download buffer size
99     WATERLINE_HIGH,                   ///< uint32_t, high waterline
100     WATERLINE_LOW,                    ///< uint32_t, low waterline
101     SRC_INPUT_TYPE,                   ///< @see SrcInputType
102     BITS_PER_CODED_SAMPLE,            ///< uint32_t, bits per coded sample
103     APP_TOKEN_ID,                     ///< uint32_t, app token id
104     APP_UID,                          ///< int32_t, app uid
105     APP_PID,                          ///< int32_t, app pid
106     AUDIO_RENDER_INFO,                ///< AudioRenderInfo, audio render info
107     AUDIO_INTERRUPT_MODE,             ///< AudioInterruptMode, audio interrupt mode
108 
109     /* -------------------- media tag -------------------- */
110     MEDIA_TITLE = SECTION_MEDIA_START + 1, ///< string
111     MEDIA_ARTIST,                          ///< std::string, artist
112     MEDIA_LYRICIST,                        ///< std::string, lyricist
113     MEDIA_ALBUM,                           ///< std::string, album
114     MEDIA_ALBUM_ARTIST,                    ///< std::string, album artist
115     MEDIA_DATE,                            ///< std::string, media date, format:YYYY-MM-DD
116     MEDIA_COMMENT,                         ///< std::string, comment
117     MEDIA_GENRE,                           ///< std::string, genre
118     MEDIA_COPYRIGHT,                       ///< std::string, copyright
119     MEDIA_LANGUAGE,                        ///< std::string, language
120     MEDIA_DESCRIPTION,                     ///< std::string, description
121     MEDIA_LYRICS,                          ///< std::string, cyrics
122     MEDIA_DURATION,                        ///< int64_t, duration based on {@link HST_TIME_BASE}
123     MEDIA_FILE_SIZE,                       ///< uint64_t, file size
124     MEDIA_BITRATE,                         ///< int64_t, bite rate
125     MEDIA_FILE_EXTENSION,                  ///< std::string, file extension
126     MEDIA_CODEC_CONFIG,                    ///< std::vector<uint8_t>, codec config. e.g. AudioSpecificConfig for mp4
127     MEDIA_POSITION,                        ///< uint64_t : The byte position within media stream/file
128     MEDIA_START_TIME,                      ///< int64_t: The start time of one track
129     MEDIA_SEEKABLE,                        ///< enum Seekable: Seekable status of the media
130     MEDIA_PLAYBACK_SPEED,                  ///< double, playback speed
131     MEDIA_TYPE,                            ///< enum MediaType: Auido Video Subtitle...
132 
133     /* -------------------- audio universal tag -------------------- */
134     AUDIO_CHANNELS = SECTION_AUDIO_UNIVERSAL_START + 1, ///< uint32_t, stream channel num
135     AUDIO_CHANNEL_LAYOUT,                               ///< @see AudioChannelLayout, stream channel layout
136     AUDIO_SAMPLE_RATE,                                  ///< uint32_t, sample rate
137     AUDIO_SAMPLE_FORMAT,                                ///< @see AudioSampleFormat
138     AUDIO_SAMPLE_PER_FRAME,                             ///< uint32_t, sample per frame
139     AUDIO_OUTPUT_CHANNELS,                              ///< uint32_t, sink output channel num
140     AUDIO_OUTPUT_CHANNEL_LAYOUT,                        ///< @see AudioChannelLayout, sink output channel layout
141 
142     /* -------------------- audio specific tag -------------------- */
143     AUDIO_SPECIFIC_MPEG_START = MAKE_AUDIO_SPECIFIC_START(AudioFormat::MPEG),
144     AUDIO_MPEG_VERSION, ///< uint32_t, mpeg version
145     AUDIO_MPEG_LAYER,   ///< uint32_t, mpeg layer
146 
147     AUDIO_SPECIFIC_AAC_START = MAKE_AUDIO_SPECIFIC_START(AudioFormat::AAC),
148     AUDIO_AAC_PROFILE,       ///< @see AudioAacProfile
149     AUDIO_AAC_LEVEL,         ///< uint32_t, acc level
150     AUDIO_AAC_STREAM_FORMAT, ///< @see AudioAacStreamFormat
151 
152     /* -------------------- video universal tag -------------------- */
153     VIDEO_WIDTH = SECTION_VIDEO_UNIVERSAL_START + 1, ///< uint32_t, video width
154     VIDEO_HEIGHT,                                    ///< uint32_t, video height
155     VIDEO_PIXEL_FORMAT,                              ///< @see VideoPixelFormat
156     VIDEO_FRAME_RATE,                                ///< uint32_t, video frame rate
157     VIDEO_SURFACE,                                   ///< @see class Surface
158     VIDEO_MAX_SURFACE_NUM,                           ///< uint32_t, max video surface num
159     VIDEO_CAPTURE_RATE,                              ///< double, video capture rate
160     VIDEO_BIT_STREAM_FORMAT,                         ///< @see VideoBitStreamFormat
161 
162     /* -------------------- video specific tag -------------------- */
163     VIDEO_SPECIFIC_H264_START = MAKE_VIDEO_SPECIFIC_START(VideoFormat::H264),
164     VIDEO_H264_PROFILE,      ///< @see VideoH264Profile
165     VIDEO_H264_LEVEL,        ///< uint32_t, h264 level
166 };
167 /**
168  * @enum Media protocol type.
169  *
170  * @since 1.0
171  * @version 1.0
172  */
173 enum struct ProtocolType : uint32_t {
174     UNKNOWN, ///< Unknown protocol
175     FILE,    ///< File protocol, uri prefix: "file://"
176     FD,      ///< File descriptor protocol, uri prefix: "fd://"
177     STREAM,  ///< Stream protocol, uri prefix: "stream://"
178     HTTP,    ///< Http protocol, uri prefix: "http://"
179     HTTPS,   ///< Https protocol, uri prefix: "https://"
180     HLS,     ///< Http live streaming protocol, uri prefix: "https://" or "https://" or "file://", suffix: ".m3u8"
181     DASH,    ///< Dynamic adaptive streaming over Http protocol, uri prefix: "https://" or "https://", suffix: ".mpd"
182     RTSP,    ///< Real time streaming protocol, uri prefix: "rtsp://"
183     RTP,     ///< Real-time transport protocol, uri prefix: "rtp://"
184     RTMP,    ///< RTMP protocol, uri prefix: "rtmp://"
185     FTP,     ///< FTP protocol, uri prefix: "ftp://"
186     UDP,     ///< User datagram protocol, uri prefix: "udp://"
187 };
188 
189 using ValueType = Any;
190 
191 /**
192  * The tag content is stored in key-value format.
193  */
194 using CodecConfig = std::vector<uint8_t>;
195 } // namespace Plugin
196 } // namespace Media
197 } // namespace OHOS
198 #endif // HISTREAMER_PLUGIN_COMMON_TAGS_H
199