• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef META_DATA_BASE_H_
18 
19 #define META_DATA_BASE_H_
20 
21 #include <sys/types.h>
22 
23 #include <stdint.h>
24 
25 #include <utils/RefBase.h>
26 #include <utils/String8.h>
27 
28 namespace android {
29 
30 // The following keys map to int32_t data unless indicated otherwise.
31 enum {
32     kKeyMIMEType          = 'mime',  // cstring
33     kKeyWidth             = 'widt',  // int32_t, image pixel
34     kKeyHeight            = 'heig',  // int32_t, image pixel
35     kKeyDisplayWidth      = 'dWid',  // int32_t, display/presentation
36     kKeyDisplayHeight     = 'dHgt',  // int32_t, display/presentation
37     kKeySARWidth          = 'sarW',  // int32_t, sampleAspectRatio width
38     kKeySARHeight         = 'sarH',  // int32_t, sampleAspectRatio height
39     kKeyThumbnailWidth    = 'thbW',  // int32_t, thumbnail width
40     kKeyThumbnailHeight   = 'thbH',  // int32_t, thumbnail height
41 
42     // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1)
43     kKeyCropRect          = 'crop',
44 
45     kKeyRotation          = 'rotA',  // int32_t (angle in degrees)
46     kKeyIFramesInterval   = 'ifiv',  // int32_t
47     kKeyStride            = 'strd',  // int32_t
48     kKeySliceHeight       = 'slht',  // int32_t
49     kKeyChannelCount      = '#chn',  // int32_t
50     kKeyChannelMask       = 'chnm',  // int32_t
51     kKeySampleRate        = 'srte',  // int32_t (audio sampling rate Hz)
52     kKeyPcmEncoding       = 'PCMe',  // int32_t (audio encoding enum)
53     kKeyFrameRate         = 'frmR',  // int32_t (video frame rate fps)
54     kKeyBitRate           = 'brte',  // int32_t (bps)
55     kKeyMaxBitRate        = 'mxBr',  // int32_t (bps)
56     kKeyBitsPerSample     = 'bits',  // int32_t (bits per sample)
57     kKeyStreamHeader      = 'stHd',  // raw data
58     kKeyESDS              = 'esds',  // raw data
59     kKeyAACProfile        = 'aacp',  // int32_t
60     kKeyAVCC              = 'avcc',  // raw data
61     kKeyHVCC              = 'hvcc',  // raw data
62     kKeyDVCC              = 'dvcc',  // raw data
63     kKeyAV1C              = 'av1c',  // raw data
64     kKeyThumbnailHVCC     = 'thvc',  // raw data
65     kKeyThumbnailAV1C     = 'tav1',  // raw data
66     kKeyD263              = 'd263',  // raw data
67     kKeyOpusHeader        = 'ohdr',  // raw data
68     kKeyOpusCodecDelay    = 'ocod',  // uint64_t (codec delay in ns)
69     kKeyOpusSeekPreRoll   = 'ospr',  // uint64_t (seek preroll in ns)
70     kKeyVp9CodecPrivate   = 'vp9p',  // raw data (vp9 csd information)
71     kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
72     kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
73     kKeyIsMuxerData       = 'muxd',  // int32_t (bool)
74     kKeyIsEndOfStream     = 'feos',  // int32_t (bool)
75     kKeyTime              = 'time',  // int64_t (usecs)
76     kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
77     kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
78     kKeyTargetTime        = 'tarT',  // int64_t (usecs)
79     kKeyDriftTime         = 'dftT',  // int64_t (usecs)
80     kKeyAnchorTime        = 'ancT',  // int64_t (usecs)
81     kKeyDuration          = 'dura',  // int64_t (usecs)
82     kKeyPixelFormat       = 'pixf',  // int32_t
83     kKeyColorFormat       = 'colf',  // int32_t
84     kKeyColorSpace        = 'cols',  // int32_t
85     kKeyPlatformPrivate   = 'priv',  // pointer
86     kKeyDecoderComponent  = 'decC',  // cstring
87     kKeyBufferID          = 'bfID',
88     kKeyMaxInputSize      = 'inpS',
89     kKeyMaxWidth          = 'maxW',
90     kKeyMaxHeight         = 'maxH',
91     kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
92     kKeyTrackID           = 'trID',
93     kKeyEncoderDelay      = 'encd',  // int32_t (frames)
94     kKeyEncoderPadding    = 'encp',  // int32_t (frames)
95 
96     kKeyAlbum             = 'albu',  // cstring
97     kKeyArtist            = 'arti',  // cstring
98     kKeyAlbumArtist       = 'aart',  // cstring
99     kKeyComposer          = 'comp',  // cstring
100     kKeyGenre             = 'genr',  // cstring
101     kKeyTitle             = 'titl',  // cstring
102     kKeyYear              = 'year',  // cstring
103     kKeyAlbumArt          = 'albA',  // compressed image data
104     kKeyAuthor            = 'auth',  // cstring
105     kKeyCDTrackNumber     = 'cdtr',  // cstring
106     kKeyDiscNumber        = 'dnum',  // cstring
107     kKeyDate              = 'date',  // cstring
108     kKeyWriter            = 'writ',  // cstring
109     kKeyCompilation       = 'cpil',  // cstring
110     kKeyLocation          = 'loc ',  // cstring
111     kKeyTimeScale         = 'tmsl',  // int32_t
112     kKeyCaptureFramerate  = 'capF',  // float (capture fps)
113 
114     // video profile and level
115     kKeyVideoProfile      = 'vprf',  // int32_t
116     kKeyVideoLevel        = 'vlev',  // int32_t
117 
118     kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
119 
120     // Identify the file output format for authoring
121     // Please see <media/mediarecorder.h> for the supported
122     // file output formats.
123     kKeyFileType          = 'ftyp',  // int32_t
124 
125     // Track authoring progress status
126     // kKeyTrackTimeStatus is used to track progress in elapsed time
127     kKeyTrackTimeStatus   = 'tktm',  // int64_t
128 
129     kKeyRealTimeRecording = 'rtrc',  // bool (int32_t)
130     kKeyBackgroundMode = 'bkmd',  // bool (int32_t)
131 
132     kKeyNumBuffers        = 'nbbf',  // int32_t
133 
134     // Ogg files can be tagged to be automatically looping...
135     kKeyAutoLoop          = 'autL',  // bool (int32_t)
136 
137     kKeyValidSamples      = 'valD',  // int32_t
138 
139     kKeyIsUnreadable      = 'unre',  // bool (int32_t)
140 
141     // An indication that a video buffer has been rendered.
142     kKeyRendered          = 'rend',  // bool (int32_t)
143 
144     // The language code for this media
145     kKeyMediaLanguage     = 'lang',  // cstring
146 
147     // The manufacturer code for this media
148     kKeyManufacturer  = 'manu',  // cstring
149 
150     // To store the timed text format data
151     kKeyTextFormatData    = 'text',  // raw data
152 
153     kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
154 
155     kKeyIsADTS            = 'adts',  // bool (int32_t)
156     kKeyAACAOT            = 'aaot',  // int32_t
157 
158     kKeyMpeghProfileLevelIndication = 'hpli', // int32_t
159     kKeyMpeghReferenceChannelLayout = 'hrcl', // int32_t
160     kKeyMpeghCompatibleSets         = 'hcos', // raw data
161 
162     // If a MediaBuffer's data represents (at least partially) encrypted
163     // data, the following fields aid in decryption.
164     // The data can be thought of as pairs of plain and encrypted data
165     // fragments, i.e. plain and encrypted data alternate.
166     // The first fragment is by convention plain data (if that's not the
167     // case, simply specify plain fragment size of 0).
168     // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of
169     // size_t values. The sum total of all size_t values of both arrays
170     // must equal the amount of data (i.e. MediaBuffer's range_length()).
171     // If both arrays are present, they must be of the same size.
172     // If only encrypted sizes are present it is assumed that all
173     // plain sizes are 0, i.e. all fragments are encrypted.
174     // To programmatically set these array, use the MetaDataBase::setData API, i.e.
175     // const size_t encSizes[];
176     // meta->setData(
177     //  kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes));
178     // A plain sizes array by itself makes no sense.
179     kKeyEncryptedSizes    = 'encr',  // size_t[]
180     kKeyPlainSizes        = 'plai',  // size_t[]
181     kKeyCryptoKey         = 'cryK',  // uint8_t[16]
182     kKeyCryptoIV          = 'cryI',  // uint8_t[16]
183     kKeyCryptoMode        = 'cryM',  // int32_t
184 
185     kKeyCryptoDefaultIVSize = 'cryS',  // int32_t
186 
187     kKeyPssh              = 'pssh',  // raw data
188     kKeyCASystemID        = 'caid',  // int32_t
189     kKeyCASessionID       = 'seid',  // raw data
190     kKeyCAPrivateData     = 'cadc',  // raw data
191 
192     kKeyEncryptedByteBlock = 'cblk',  // uint8_t
193     kKeySkipByteBlock     = 'sblk',  // uint8_t
194 
195     // Please see MediaFormat.KEY_IS_AUTOSELECT.
196     kKeyTrackIsAutoselect = 'auto', // bool (int32_t)
197     // Please see MediaFormat.KEY_IS_DEFAULT.
198     kKeyTrackIsDefault    = 'dflt', // bool (int32_t)
199     // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well.
200     kKeyTrackIsForced     = 'frcd', // bool (int32_t)
201 
202     // H264 supplemental enhancement information offsets/sizes
203     kKeySEI               = 'sei ', // raw data
204 
205     // MPEG user data offsets
206     kKeyMpegUserData      = 'mpud', // size_t[]
207 
208     // HDR related
209     kKeyHdrStaticInfo    = 'hdrS', // HDRStaticInfo
210     kKeyHdr10PlusInfo    = 'hdrD', // raw data
211 
212     // color aspects
213     kKeyColorRange       = 'cRng', // int32_t, color range, value defined by ColorAspects.Range
214     kKeyColorPrimaries   = 'cPrm', // int32_t,
215                                    // color Primaries, value defined by ColorAspects.Primaries
216     kKeyTransferFunction = 'tFun', // int32_t,
217                                    // transfer Function, value defined by ColorAspects.Transfer.
218     kKeyColorMatrix      = 'cMtx', // int32_t,
219                                    // color Matrix, value defined by ColorAspects.MatrixCoeffs.
220     kKeyTemporalLayerId  = 'iLyr', // int32_t, temporal layer-id. 0-based (0 => base layer)
221     kKeyTemporalLayerCount = 'cLyr', // int32_t, number of temporal layers encoded
222 
223     kKeyTileWidth        = 'tilW', // int32_t, HEIF tile width
224     kKeyTileHeight       = 'tilH', // int32_t, HEIF tile height
225     kKeyGridRows         = 'grdR', // int32_t, HEIF grid rows
226     kKeyGridCols         = 'grdC', // int32_t, HEIF grid columns
227     kKeyIccProfile       = 'prof', // raw data, ICC profile data
228     kKeyIsPrimaryImage   = 'prim', // bool (int32_t), image track is the primary image
229     kKeyFrameCount       = 'nfrm', // int32_t, total number of frame in video track
230     kKeyExifOffset       = 'exof', // int64_t, Exif data offset
231     kKeyExifSize         = 'exsz', // int64_t, Exif data size
232     kKeyExifTiffOffset   = 'thdr', // int32_t, if > 0, buffer contains exif data block with
233                                    // tiff hdr at specified offset
234     kKeyXmpOffset        = 'xmof', // int64_t, XMP data offset
235     kKeyXmpSize          = 'xmsz', // int64_t, XMP data size
236     kKeyPcmBigEndian     = 'pcmb', // bool (int32_t)
237 
238     // Key for ALAC Magic Cookie
239     kKeyAlacMagicCookie  = 'almc', // raw data
240 
241     // AC-4 AudioPresentationInfo
242     kKeyAudioPresentationInfo = 'audP',  // raw data
243 
244     // opaque codec specific data being passed from extractor to codec
245     kKeyOpaqueCSD0       = 'csd0',
246     kKeyOpaqueCSD1       = 'csd1',
247     kKeyOpaqueCSD2       = 'csd2',
248 
249     kKeyHapticChannelCount = 'hapC',
250 
251     /* MediaRecorder.h, error notifications can represent track ids with 4 bits only.
252      * | track id | reserved |     error or info type     |
253      * 31         28         16                           0
254      */
255     kKey4BitTrackIds = '4bid',
256 
257     // Treat empty track as malformed for MediaRecorder.
258     kKeyEmptyTrackMalFormed = 'nemt', // bool (int32_t)
259 
260     kKeyVps              = 'sVps', // int32_t, indicates that a buffer has vps.
261     kKeySps              = 'sSps', // int32_t, indicates that a buffer has sps.
262     kKeyPps              = 'sPps', // int32_t, indicates that a buffer has pps.
263     kKeySelfID           = 'sfid', // int32_t, source ID to identify itself on RTP protocol.
264     kKeyPayloadType      = 'pTyp', // int32_t, SDP negotiated payload type.
265     kKeyRtpExtMap        = 'extm', // int32_t, rtp extension ID for cvo on RTP protocol.
266     kKeyRtpCvoDegrees    = 'cvod', // int32_t, rtp cvo degrees as per 3GPP 26.114.
267     kKeyRtpDscp          = 'dscp', // int32_t, DSCP(Differentiated services codepoint) of RFC 2474.
268     kKeySocketNetwork    = 'sNet', // int64_t, socket will be bound to network handle.
269 
270     // Slow-motion markers
271     kKeySlowMotionMarkers = 'slmo', // raw data, byte array following spec for
272                                     // MediaFormat#KEY_SLOW_MOTION_MARKERS
273 
274     kKeySampleFileOffset = 'sfof', // int64_t, sample's offset in a media file.
275     kKeyLastSampleIndexInChunk = 'lsic',  //int64_t, index of last sample in a chunk.
276     kKeySampleTimeBeforeAppend = 'lsba', // int64_t, timestamp of last sample of a track.
277 
278 };
279 
280 enum {
281     kTypeESDS        = 'esds',
282     kTypeAVCC        = 'avcc',
283     kTypeHVCC        = 'hvcc',
284     kTypeAV1C        = 'av1c',
285     kTypeDVCC        = 'dvcc',
286     kTypeD263        = 'd263',
287     kTypeHCOS        = 'hcos',
288 };
289 
290 enum {
291     kCryptoModeUnencrypted = 0,
292     kCryptoModeAesCtr      = 1,
293     kCryptoModeAesCbc      = 2,
294 };
295 
296 class Parcel;
297 
298 class MetaDataBase {
299 public:
300     MetaDataBase();
301     MetaDataBase(const MetaDataBase &from);
302     MetaDataBase& operator = (const MetaDataBase &);
303 
304     virtual ~MetaDataBase();
305 
306     enum Type {
307         TYPE_NONE     = 'none',
308         TYPE_C_STRING = 'cstr',
309         TYPE_INT32    = 'in32',
310         TYPE_INT64    = 'in64',
311         TYPE_FLOAT    = 'floa',
312         TYPE_POINTER  = 'ptr ',
313         TYPE_RECT     = 'rect',
314     };
315 
316     void clear();
317     bool remove(uint32_t key);
318 
319     bool setCString(uint32_t key, const char *value);
320     bool setInt32(uint32_t key, int32_t value);
321     bool setInt64(uint32_t key, int64_t value);
322     bool setFloat(uint32_t key, float value);
323     bool setPointer(uint32_t key, void *value);
324 
325     bool setRect(
326             uint32_t key,
327             int32_t left, int32_t top,
328             int32_t right, int32_t bottom);
329 
330     bool findCString(uint32_t key, const char **value) const;
331     bool findInt32(uint32_t key, int32_t *value) const;
332     bool findInt64(uint32_t key, int64_t *value) const;
333     bool findFloat(uint32_t key, float *value) const;
334     bool findPointer(uint32_t key, void **value) const;
335 
336     bool findRect(
337             uint32_t key,
338             int32_t *left, int32_t *top,
339             int32_t *right, int32_t *bottom) const;
340 
341     bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
342 
343     bool findData(uint32_t key, uint32_t *type,
344                   const void **data, size_t *size) const;
345 
346     bool hasData(uint32_t key) const;
347 
348     String8 toString() const;
349     void dumpToLog() const;
350 
351 private:
352     friend class BpMediaSource;
353     friend class BnMediaSource;
354     friend class BnMediaExtractor;
355     friend class MetaData;
356 
357     struct typed_data;
358     struct Rect;
359     struct MetaDataInternal;
360     MetaDataInternal *mInternalData;
361 #ifndef __ANDROID_VNDK__
362     status_t writeToParcel(Parcel &parcel);
363     status_t updateFromParcel(const Parcel &parcel);
364 #endif
365 };
366 
367 }  // namespace android
368 
369 #endif  // META_DATA_H_
370