• 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     kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
121 
122     // Identify the file output format for authoring
123     // Please see <media/mediarecorder.h> for the supported
124     // file output formats.
125     kKeyFileType          = 'ftyp',  // int32_t
126 
127     // Track authoring progress status
128     // kKeyTrackTimeStatus is used to track progress in elapsed time
129     kKeyTrackTimeStatus   = 'tktm',  // int64_t
130 
131     kKeyRealTimeRecording = 'rtrc',  // bool (int32_t)
132     kKeyBackgroundMode = 'bkmd',  // bool (int32_t)
133 
134     kKeyNumBuffers        = 'nbbf',  // int32_t
135 
136     // Ogg files can be tagged to be automatically looping...
137     kKeyAutoLoop          = 'autL',  // bool (int32_t)
138 
139     kKeyValidSamples      = 'valD',  // int32_t
140 
141     kKeyIsUnreadable      = 'unre',  // bool (int32_t)
142 
143     // An indication that a video buffer has been rendered.
144     kKeyRendered          = 'rend',  // bool (int32_t)
145 
146     // The language code for this media
147     kKeyMediaLanguage     = 'lang',  // cstring
148 
149     // The manufacturer code for this media
150     kKeyManufacturer  = 'manu',  // cstring
151 
152     // To store the timed text format data
153     kKeyTextFormatData    = 'text',  // raw data
154 
155     kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
156 
157     kKeyIsADTS            = 'adts',  // bool (int32_t)
158     kKeyAACAOT            = 'aaot',  // int32_t
159 
160     kKeyMpeghProfileLevelIndication = 'hpli', // int32_t
161     kKeyMpeghReferenceChannelLayout = 'hrcl', // int32_t
162     kKeyMpeghCompatibleSets         = 'hcos', // raw data
163 
164     // If a MediaBuffer's data represents (at least partially) encrypted
165     // data, the following fields aid in decryption.
166     // The data can be thought of as pairs of plain and encrypted data
167     // fragments, i.e. plain and encrypted data alternate.
168     // The first fragment is by convention plain data (if that's not the
169     // case, simply specify plain fragment size of 0).
170     // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of
171     // size_t values. The sum total of all size_t values of both arrays
172     // must equal the amount of data (i.e. MediaBuffer's range_length()).
173     // If both arrays are present, they must be of the same size.
174     // If only encrypted sizes are present it is assumed that all
175     // plain sizes are 0, i.e. all fragments are encrypted.
176     // To programmatically set these array, use the MetaDataBase::setData API, i.e.
177     // const size_t encSizes[];
178     // meta->setData(
179     //  kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes));
180     // A plain sizes array by itself makes no sense.
181     kKeyEncryptedSizes    = 'encr',  // size_t[]
182     kKeyPlainSizes        = 'plai',  // size_t[]
183     kKeyCryptoKey         = 'cryK',  // uint8_t[16]
184     kKeyCryptoIV          = 'cryI',  // uint8_t[16]
185     kKeyCryptoMode        = 'cryM',  // int32_t
186 
187     kKeyCryptoDefaultIVSize = 'cryS',  // int32_t
188 
189     kKeyPssh              = 'pssh',  // raw data
190     kKeyCASystemID        = 'caid',  // int32_t
191     kKeyCASessionID       = 'seid',  // raw data
192     kKeyCAPrivateData     = 'cadc',  // raw data
193 
194     kKeyEncryptedByteBlock = 'cblk',  // uint8_t
195     kKeySkipByteBlock     = 'sblk',  // uint8_t
196 
197     // Please see MediaFormat.KEY_IS_AUTOSELECT.
198     kKeyTrackIsAutoselect = 'auto', // bool (int32_t)
199     // Please see MediaFormat.KEY_IS_DEFAULT.
200     kKeyTrackIsDefault    = 'dflt', // bool (int32_t)
201     // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well.
202     kKeyTrackIsForced     = 'frcd', // bool (int32_t)
203 
204     // H264 supplemental enhancement information offsets/sizes
205     kKeySEI               = 'sei ', // raw data
206 
207     // MPEG user data offsets
208     kKeyMpegUserData      = 'mpud', // size_t[]
209 
210     // HDR related
211     kKeyHdrStaticInfo    = 'hdrS', // HDRStaticInfo
212     kKeyHdr10PlusInfo    = 'hdrD', // raw data
213 
214     // color aspects
215     kKeyColorRange       = 'cRng', // int32_t, color range, value defined by ColorAspects.Range
216     kKeyColorPrimaries   = 'cPrm', // int32_t,
217                                    // color Primaries, value defined by ColorAspects.Primaries
218     kKeyTransferFunction = 'tFun', // int32_t,
219                                    // transfer Function, value defined by ColorAspects.Transfer.
220     kKeyColorMatrix      = 'cMtx', // int32_t,
221                                    // color Matrix, value defined by ColorAspects.MatrixCoeffs.
222     kKeyTemporalLayerId  = 'iLyr', // int32_t, temporal layer-id. 0-based (0 => base layer)
223     kKeyTemporalLayerCount = 'cLyr', // int32_t, number of temporal layers encoded
224 
225     kKeyTileWidth        = 'tilW', // int32_t, HEIF tile width
226     kKeyTileHeight       = 'tilH', // int32_t, HEIF tile height
227     kKeyGridRows         = 'grdR', // int32_t, HEIF grid rows
228     kKeyGridCols         = 'grdC', // int32_t, HEIF grid columns
229     kKeyIccProfile       = 'prof', // raw data, ICC profile data
230     kKeyIsPrimaryImage   = 'prim', // bool (int32_t), image track is the primary image
231     kKeyFrameCount       = 'nfrm', // int32_t, total number of frame in video track
232     kKeyExifOffset       = 'exof', // int64_t, Exif data offset
233     kKeyExifSize         = 'exsz', // int64_t, Exif data size
234     kKeyExifTiffOffset   = 'thdr', // int32_t, if > 0, buffer contains exif data block with
235                                    // tiff hdr at specified offset
236     kKeyXmpOffset        = 'xmof', // int64_t, XMP data offset
237     kKeyXmpSize          = 'xmsz', // int64_t, XMP data size
238     kKeyPcmBigEndian     = 'pcmb', // bool (int32_t)
239 
240     // Key for ALAC Magic Cookie
241     kKeyAlacMagicCookie  = 'almc', // raw data
242 
243     // AC-4 AudioPresentationInfo
244     kKeyAudioPresentationInfo = 'audP',  // raw data
245 
246     // opaque codec specific data being passed from extractor to codec
247     kKeyOpaqueCSD0       = 'csd0',
248     kKeyOpaqueCSD1       = 'csd1',
249     kKeyOpaqueCSD2       = 'csd2',
250 
251     kKeyHapticChannelCount = 'hapC',
252 
253     /* MediaRecorder.h, error notifications can represent track ids with 4 bits only.
254      * | track id | reserved |     error or info type     |
255      * 31         28         16                           0
256      */
257     kKey4BitTrackIds = '4bid',
258 
259     // Treat empty track as malformed for MediaRecorder.
260     kKeyEmptyTrackMalFormed = 'nemt', // bool (int32_t)
261 
262     kKeyVps              = 'sVps', // int32_t, indicates that a buffer has vps.
263     kKeySps              = 'sSps', // int32_t, indicates that a buffer has sps.
264     kKeyPps              = 'sPps', // int32_t, indicates that a buffer has pps.
265     kKeySelfID           = 'sfid', // int32_t, source ID to identify itself on RTP protocol.
266     kKeyPayloadType      = 'pTyp', // int32_t, SDP negotiated payload type.
267     kKeyRtpExtMap        = 'extm', // int32_t, rtp extension ID for cvo on RTP protocol.
268     kKeyRtpCvoDegrees    = 'cvod', // int32_t, rtp cvo degrees as per 3GPP 26.114.
269     kKeyRtpDscp          = 'dscp', // int32_t, DSCP(Differentiated services codepoint) of RFC 2474.
270     kKeyRtpEcn           = 'sEcn', // int32_t, ECN (Explicit Congestion Notification) of RFC 3168
271     kKeySocketNetwork    = 'sNet', // int64_t, socket will be bound to network handle.
272 
273     // Slow-motion markers
274     kKeySlowMotionMarkers = 'slmo', // raw data, byte array following spec for
275                                     // MediaFormat#KEY_SLOW_MOTION_MARKERS
276 
277     kKeySampleFileOffset = 'sfof', // int64_t, sample's offset in a media file.
278     kKeyLastSampleIndexInChunk = 'lsic',  //int64_t, index of last sample in a chunk.
279     kKeySampleTimeBeforeAppend = 'lsba', // int64_t, timestamp of last sample of a track.
280 
281 };
282 
283 enum {
284     kTypeESDS        = 'esds',
285     kTypeAVCC        = 'avcc',
286     kTypeHVCC        = 'hvcc',
287     kTypeAV1C        = 'av1c',
288     kTypeDVCC        = 'dvcc',
289     kTypeDVVC        = 'dvvc',
290     kTypeDVWC        = 'dvwc',
291     kTypeD263        = 'd263',
292     kTypeHCOS        = 'hcos',
293 };
294 
295 enum {
296     kCryptoModeUnencrypted = 0,
297     kCryptoModeAesCtr      = 1,
298     kCryptoModeAesCbc      = 2,
299 };
300 
301 class Parcel;
302 
303 class MetaDataBase {
304 public:
305     MetaDataBase();
306     MetaDataBase(const MetaDataBase &from);
307     MetaDataBase& operator = (const MetaDataBase &);
308 
309     virtual ~MetaDataBase();
310 
311     enum Type {
312         TYPE_NONE     = 'none',
313         TYPE_C_STRING = 'cstr',
314         TYPE_INT32    = 'in32',
315         TYPE_INT64    = 'in64',
316         TYPE_FLOAT    = 'floa',
317         TYPE_POINTER  = 'ptr ',
318         TYPE_RECT     = 'rect',
319     };
320 
321     void clear();
322     bool remove(uint32_t key);
323 
324     bool setCString(uint32_t key, const char *value);
325     bool setInt32(uint32_t key, int32_t value);
326     bool setInt64(uint32_t key, int64_t value);
327     bool setFloat(uint32_t key, float value);
328     bool setPointer(uint32_t key, void *value);
329 
330     bool setRect(
331             uint32_t key,
332             int32_t left, int32_t top,
333             int32_t right, int32_t bottom);
334 
335     bool findCString(uint32_t key, const char **value) const;
336     bool findInt32(uint32_t key, int32_t *value) const;
337     bool findInt64(uint32_t key, int64_t *value) const;
338     bool findFloat(uint32_t key, float *value) const;
339     bool findPointer(uint32_t key, void **value) const;
340 
341     bool findRect(
342             uint32_t key,
343             int32_t *left, int32_t *top,
344             int32_t *right, int32_t *bottom) const;
345 
346     bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
347 
348     bool findData(uint32_t key, uint32_t *type,
349                   const void **data, size_t *size) const;
350 
351     bool hasData(uint32_t key) const;
352 
353     String8 toString() const;
354     void dumpToLog() const;
355 
356 private:
357     friend class BpMediaSource;
358     friend class BnMediaSource;
359     friend class BnMediaExtractor;
360     friend class MetaData;
361 
362     struct typed_data;
363     struct Rect;
364     struct MetaDataInternal;
365     MetaDataInternal *mInternalData;
366 #ifndef __ANDROID_VNDK__
367     status_t writeToParcel(Parcel &parcel);
368     status_t updateFromParcel(const Parcel &parcel);
369 #endif
370 };
371 
372 }  // namespace android
373 
374 #endif  // META_DATA_H_
375