• 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     kKeyDVVC              = 'dvvc',  // raw data
64     kKeyDVWC              = 'dvwc',  // raw data
65     kKeyAV1C              = 'av1c',  // raw data
66     kKeyThumbnailHVCC     = 'thvc',  // raw data
67     kKeyThumbnailAV1C     = 'tav1',  // raw data
68     kKeyD263              = 'd263',  // raw data
69     kKeyOpusHeader        = 'ohdr',  // raw data
70     kKeyOpusCodecDelay    = 'ocod',  // uint64_t (codec delay in ns)
71     kKeyOpusSeekPreRoll   = 'ospr',  // uint64_t (seek preroll in ns)
72     kKeyVp9CodecPrivate   = 'vp9p',  // raw data (vp9 csd information)
73     kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
74     kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
75     kKeyIsMuxerData       = 'muxd',  // int32_t (bool)
76     kKeyIsEndOfStream     = 'feos',  // int32_t (bool)
77     kKeyTime              = 'time',  // int64_t (usecs)
78     kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
79     kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
80     kKeyTargetTime        = 'tarT',  // int64_t (usecs)
81     kKeyDriftTime         = 'dftT',  // int64_t (usecs)
82     kKeyAnchorTime        = 'ancT',  // int64_t (usecs)
83     kKeyDuration          = 'dura',  // int64_t (usecs)
84     kKeyPixelFormat       = 'pixf',  // int32_t
85     kKeyColorFormat       = 'colf',  // int32_t
86     kKeyColorSpace        = 'cols',  // int32_t
87     kKeyPlatformPrivate   = 'priv',  // pointer
88     kKeyDecoderComponent  = 'decC',  // cstring
89     kKeyBufferID          = 'bfID',
90     kKeyMaxInputSize      = 'inpS',
91     kKeyMaxWidth          = 'maxW',
92     kKeyMaxHeight         = 'maxH',
93     kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
94     kKeyTrackID           = 'trID',
95     kKeyEncoderDelay      = 'encd',  // int32_t (frames)
96     kKeyEncoderPadding    = 'encp',  // int32_t (frames)
97 
98     kKeyAlbum             = 'albu',  // cstring
99     kKeyArtist            = 'arti',  // cstring
100     kKeyAlbumArtist       = 'aart',  // cstring
101     kKeyComposer          = 'comp',  // cstring
102     kKeyGenre             = 'genr',  // cstring
103     kKeyTitle             = 'titl',  // cstring
104     kKeyYear              = 'year',  // cstring
105     kKeyAlbumArt          = 'albA',  // compressed image data
106     kKeyAuthor            = 'auth',  // cstring
107     kKeyCDTrackNumber     = 'cdtr',  // cstring
108     kKeyDiscNumber        = 'dnum',  // cstring
109     kKeyDate              = 'date',  // cstring
110     kKeyWriter            = 'writ',  // cstring
111     kKeyCompilation       = 'cpil',  // cstring
112     kKeyLocation          = 'loc ',  // cstring
113     kKeyTimeScale         = 'tmsl',  // int32_t
114     kKeyCaptureFramerate  = 'capF',  // float (capture fps)
115 
116     // video profile and level
117     kKeyVideoProfile      = 'vprf',  // int32_t
118     kKeyVideoLevel        = 'vlev',  // int32_t
119 
120     // audio profile and level
121     // The codec framework doesn't distinguish between video and audio profiles,
122     // so there is no need to define a separate key
123     kKeyAudioProfile      = 'vprf',  // int32_t
124     kKeyAudioLevel        = 'vlev',  // int32_t
125 
126     kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
127 
128     // Identify the file output format for authoring
129     // Please see <media/mediarecorder.h> for the supported
130     // file output formats.
131     kKeyFileType          = 'ftyp',  // int32_t
132 
133     // Track authoring progress status
134     // kKeyTrackTimeStatus is used to track progress in elapsed time
135     kKeyTrackTimeStatus   = 'tktm',  // int64_t
136 
137     kKeyRealTimeRecording = 'rtrc',  // bool (int32_t)
138     kKeyBackgroundMode = 'bkmd',  // bool (int32_t)
139 
140     kKeyNumBuffers        = 'nbbf',  // int32_t
141 
142     // Ogg files can be tagged to be automatically looping...
143     kKeyAutoLoop          = 'autL',  // bool (int32_t)
144 
145     kKeyValidSamples      = 'valD',  // int32_t
146 
147     kKeyIsUnreadable      = 'unre',  // bool (int32_t)
148 
149     // An indication that a video buffer has been rendered.
150     kKeyRendered          = 'rend',  // bool (int32_t)
151 
152     // The language code for this media
153     kKeyMediaLanguage     = 'lang',  // cstring
154 
155     // The manufacturer code for this media
156     kKeyManufacturer  = 'manu',  // cstring
157 
158     // To store the timed text format data
159     kKeyTextFormatData    = 'text',  // raw data
160 
161     kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
162 
163     kKeyIsADTS            = 'adts',  // bool (int32_t)
164     kKeyAACAOT            = 'aaot',  // int32_t
165 
166     kKeyMpeghProfileLevelIndication = 'hpli', // int32_t
167     kKeyMpeghReferenceChannelLayout = 'hrcl', // int32_t
168     kKeyMpeghCompatibleSets         = 'hcos', // raw data
169 
170     // If a MediaBuffer's data represents (at least partially) encrypted
171     // data, the following fields aid in decryption.
172     // The data can be thought of as pairs of plain and encrypted data
173     // fragments, i.e. plain and encrypted data alternate.
174     // The first fragment is by convention plain data (if that's not the
175     // case, simply specify plain fragment size of 0).
176     // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of
177     // size_t values. The sum total of all size_t values of both arrays
178     // must equal the amount of data (i.e. MediaBuffer's range_length()).
179     // If both arrays are present, they must be of the same size.
180     // If only encrypted sizes are present it is assumed that all
181     // plain sizes are 0, i.e. all fragments are encrypted.
182     // To programmatically set these array, use the MetaDataBase::setData API, i.e.
183     // const size_t encSizes[];
184     // meta->setData(
185     //  kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes));
186     // A plain sizes array by itself makes no sense.
187     kKeyEncryptedSizes    = 'encr',  // size_t[]
188     kKeyPlainSizes        = 'plai',  // size_t[]
189     kKeyCryptoKey         = 'cryK',  // uint8_t[16]
190     kKeyCryptoIV          = 'cryI',  // uint8_t[16]
191     kKeyCryptoMode        = 'cryM',  // int32_t
192 
193     kKeyCryptoDefaultIVSize = 'cryS',  // int32_t
194 
195     kKeyPssh              = 'pssh',  // raw data
196     kKeyCASystemID        = 'caid',  // int32_t
197     kKeyCASessionID       = 'seid',  // raw data
198     kKeyCAPrivateData     = 'cadc',  // raw data
199 
200     kKeyEncryptedByteBlock = 'cblk',  // uint8_t
201     kKeySkipByteBlock     = 'sblk',  // uint8_t
202 
203     // Please see MediaFormat.KEY_IS_AUTOSELECT.
204     kKeyTrackIsAutoselect = 'auto', // bool (int32_t)
205     // Please see MediaFormat.KEY_IS_DEFAULT.
206     kKeyTrackIsDefault    = 'dflt', // bool (int32_t)
207     // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well.
208     kKeyTrackIsForced     = 'frcd', // bool (int32_t)
209 
210     // H264 supplemental enhancement information offsets/sizes
211     kKeySEI               = 'sei ', // raw data
212 
213     // MPEG user data offsets
214     kKeyMpegUserData      = 'mpud', // size_t[]
215 
216     // HDR related
217     kKeyHdrStaticInfo    = 'hdrS', // HDRStaticInfo
218     kKeyHdr10PlusInfo    = 'hdrD', // raw data
219 
220     // color aspects
221     kKeyColorRange       = 'cRng', // int32_t, color range, value defined by ColorAspects.Range
222     kKeyColorPrimaries   = 'cPrm', // int32_t,
223                                    // color Primaries, value defined by ColorAspects.Primaries
224     kKeyTransferFunction = 'tFun', // int32_t,
225                                    // transfer Function, value defined by ColorAspects.Transfer.
226     kKeyColorMatrix      = 'cMtx', // int32_t,
227                                    // color Matrix, value defined by ColorAspects.MatrixCoeffs.
228     kKeyTemporalLayerId  = 'iLyr', // int32_t, temporal layer-id. 0-based (0 => base layer)
229     kKeyTemporalLayerCount = 'cLyr', // int32_t, number of temporal layers encoded
230 
231     kKeyTileWidth        = 'tilW', // int32_t, HEIF tile width
232     kKeyTileHeight       = 'tilH', // int32_t, HEIF tile height
233     kKeyGridRows         = 'grdR', // int32_t, HEIF grid rows
234     kKeyGridCols         = 'grdC', // int32_t, HEIF grid columns
235     kKeyIccProfile       = 'prof', // raw data, ICC profile data
236     kKeyIsPrimaryImage   = 'prim', // bool (int32_t), image track is the primary image
237     kKeyFrameCount       = 'nfrm', // int32_t, total number of frame in video track
238     kKeyExifOffset       = 'exof', // int64_t, Exif data offset
239     kKeyExifSize         = 'exsz', // int64_t, Exif data size
240     kKeyExifTiffOffset   = 'thdr', // int32_t, if > 0, buffer contains exif data block with
241                                    // tiff hdr at specified offset
242     kKeyXmpOffset        = 'xmof', // int64_t, XMP data offset
243     kKeyXmpSize          = 'xmsz', // int64_t, XMP data size
244     kKeyPcmBigEndian     = 'pcmb', // bool (int32_t)
245 
246     // Key for ALAC Magic Cookie
247     kKeyAlacMagicCookie  = 'almc', // raw data
248 
249     // AC-4 AudioPresentationInfo
250     kKeyAudioPresentationInfo = 'audP',  // raw data
251 
252     // opaque codec specific data being passed from extractor to codec
253     kKeyOpaqueCSD0       = 'csd0',
254     kKeyOpaqueCSD1       = 'csd1',
255     kKeyOpaqueCSD2       = 'csd2',
256 
257     kKeyHapticChannelCount = 'hapC',
258 
259     /* MediaRecorder.h, error notifications can represent track ids with 4 bits only.
260      * | track id | reserved |     error or info type     |
261      * 31         28         16                           0
262      */
263     kKey4BitTrackIds = '4bid',
264 
265     // Treat empty track as malformed for MediaRecorder.
266     kKeyEmptyTrackMalFormed = 'nemt', // bool (int32_t)
267 
268     kKeyVps              = 'sVps', // int32_t, indicates that a buffer has vps.
269     kKeySps              = 'sSps', // int32_t, indicates that a buffer has sps.
270     kKeyPps              = 'sPps', // int32_t, indicates that a buffer has pps.
271     kKeySelfID           = 'sfid', // int32_t, source ID to identify itself on RTP protocol.
272     kKeyPayloadType      = 'pTyp', // int32_t, SDP negotiated payload type.
273     kKeyRtpExtMap        = 'extm', // int32_t, rtp extension ID for cvo on RTP protocol.
274     kKeyRtpCvoDegrees    = 'cvod', // int32_t, rtp cvo degrees as per 3GPP 26.114.
275     kKeyRtpDscp          = 'dscp', // int32_t, DSCP(Differentiated services codepoint) of RFC 2474.
276     kKeyRtpEcn           = 'sEcn', // int32_t, ECN (Explicit Congestion Notification) of RFC 3168
277     kKeySocketNetwork    = 'sNet', // int64_t, socket will be bound to network handle.
278 
279     // Slow-motion markers
280     kKeySlowMotionMarkers = 'slmo', // raw data, byte array following spec for
281                                     // MediaFormat#KEY_SLOW_MOTION_MARKERS
282 
283     kKeySampleFileOffset = 'sfof', // int64_t, sample's offset in a media file.
284     kKeyLastSampleIndexInChunk = 'lsic',  //int64_t, index of last sample in a chunk.
285     kKeySampleTimeBeforeAppend = 'lsba', // int64_t, timestamp of last sample of a track.
286 
287     // DVB component tag
288     kKeyDvbComponentTag = 'copt', // int32_t, component tag for DVB video/audio/subtitle
289 
290     // DVB audio description
291     kKeyDvbAudioDescription = 'addt', // bool (int32_t), DVB audio description only defined for
292                                       // audio component
293 
294     // DVB teletext magazine number
295     kKeyDvbTeletextMagazineNumber = 'ttxm', // int32_t, DVB teletext magazine number
296 
297     // DVB teletext page number
298     kKeyDvbTeletextPageNumber = 'ttxp', // int32_t, DVB teletext page number
299 };
300 
301 enum {
302     kTypeESDS        = 'esds',
303     kTypeAVCC        = 'avcc',
304     kTypeHVCC        = 'hvcc',
305     kTypeAV1C        = 'av1c',
306     kTypeDVCC        = 'dvcc',
307     kTypeDVVC        = 'dvvc',
308     kTypeDVWC        = 'dvwc',
309     kTypeD263        = 'd263',
310     kTypeHCOS        = 'hcos',
311 };
312 
313 enum {
314     kCryptoModeUnencrypted = 0,
315     kCryptoModeAesCtr      = 1,
316     kCryptoModeAesCbc      = 2,
317 };
318 
319 class Parcel;
320 
321 class MetaDataBase {
322 public:
323     MetaDataBase();
324     MetaDataBase(const MetaDataBase &from);
325     MetaDataBase& operator = (const MetaDataBase &);
326 
327     virtual ~MetaDataBase();
328 
329     enum Type {
330         TYPE_NONE     = 'none',
331         TYPE_C_STRING = 'cstr',
332         TYPE_INT32    = 'in32',
333         TYPE_INT64    = 'in64',
334         TYPE_FLOAT    = 'floa',
335         TYPE_POINTER  = 'ptr ',
336         TYPE_RECT     = 'rect',
337     };
338 
339     void clear();
340     bool remove(uint32_t key);
341 
342     bool setCString(uint32_t key, const char *value);
343     bool setInt32(uint32_t key, int32_t value);
344     bool setInt64(uint32_t key, int64_t value);
345     bool setFloat(uint32_t key, float value);
346     bool setPointer(uint32_t key, void *value);
347 
348     bool setRect(
349             uint32_t key,
350             int32_t left, int32_t top,
351             int32_t right, int32_t bottom);
352 
353     bool findCString(uint32_t key, const char **value) const;
354     bool findInt32(uint32_t key, int32_t *value) const;
355     bool findInt64(uint32_t key, int64_t *value) const;
356     bool findFloat(uint32_t key, float *value) const;
357     bool findPointer(uint32_t key, void **value) const;
358 
359     bool findRect(
360             uint32_t key,
361             int32_t *left, int32_t *top,
362             int32_t *right, int32_t *bottom) const;
363 
364     bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
365 
366     bool findData(uint32_t key, uint32_t *type,
367                   const void **data, size_t *size) const;
368 
369     bool hasData(uint32_t key) const;
370 
371     String8 toString() const;
372     void dumpToLog() const;
373 
374 private:
375     friend class BpMediaSource;
376     friend class BnMediaSource;
377     friend class BnMediaExtractor;
378     friend class MetaData;
379 
380     struct typed_data;
381     struct Rect;
382     struct MetaDataInternal;
383     MetaDataInternal *mInternalData;
384 #ifndef __ANDROID_VNDK__
385     status_t writeToParcel(Parcel &parcel);
386     status_t updateFromParcel(const Parcel &parcel);
387 #endif
388 };
389 
390 }  // namespace android
391 
392 #endif  // META_DATA_H_
393