• 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_H_
18 
19 #define META_DATA_H_
20 
21 #include <sys/types.h>
22 
23 #include <stdint.h>
24 
25 #include <utils/RefBase.h>
26 #include <utils/KeyedVector.h>
27 #include <utils/String8.h>
28 
29 namespace android {
30 
31 // The following keys map to int32_t data unless indicated otherwise.
32 enum {
33     kKeyMIMEType          = 'mime',  // cstring
34     kKeyWidth             = 'widt',  // int32_t, image pixel
35     kKeyHeight            = 'heig',  // int32_t, image pixel
36     kKeyDisplayWidth      = 'dWid',  // int32_t, display/presentation
37     kKeyDisplayHeight     = 'dHgt',  // int32_t, display/presentation
38 
39     // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1)
40     kKeyCropRect          = 'crop',
41 
42     kKeyRotation          = 'rotA',  // int32_t (angle in degrees)
43     kKeyIFramesInterval   = 'ifiv',  // int32_t
44     kKeyStride            = 'strd',  // int32_t
45     kKeySliceHeight       = 'slht',  // int32_t
46     kKeyChannelCount      = '#chn',  // int32_t
47     kKeyChannelMask       = 'chnm',  // int32_t
48     kKeySampleRate        = 'srte',  // int32_t (audio sampling rate Hz)
49     kKeyFrameRate         = 'frmR',  // int32_t (video frame rate fps)
50     kKeyBitRate           = 'brte',  // int32_t (bps)
51     kKeyESDS              = 'esds',  // raw data
52     kKeyAACProfile        = 'aacp',  // int32_t
53     kKeyAVCC              = 'avcc',  // raw data
54     kKeyD263              = 'd263',  // raw data
55     kKeyVorbisInfo        = 'vinf',  // raw data
56     kKeyVorbisBooks       = 'vboo',  // raw data
57     kKeyWantsNALFragments = 'NALf',
58     kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
59     kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
60     kKeyTime              = 'time',  // int64_t (usecs)
61     kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
62     kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
63     kKeyTargetTime        = 'tarT',  // int64_t (usecs)
64     kKeyDriftTime         = 'dftT',  // int64_t (usecs)
65     kKeyAnchorTime        = 'ancT',  // int64_t (usecs)
66     kKeyDuration          = 'dura',  // int64_t (usecs)
67     kKeyColorFormat       = 'colf',
68     kKeyPlatformPrivate   = 'priv',  // pointer
69     kKeyDecoderComponent  = 'decC',  // cstring
70     kKeyBufferID          = 'bfID',
71     kKeyMaxInputSize      = 'inpS',
72     kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
73     kKeyTrackID           = 'trID',
74     kKeyIsDRM             = 'idrm',  // int32_t (bool)
75     kKeyEncoderDelay      = 'encd',  // int32_t (frames)
76     kKeyEncoderPadding    = 'encp',  // int32_t (frames)
77 
78     kKeyAlbum             = 'albu',  // cstring
79     kKeyArtist            = 'arti',  // cstring
80     kKeyAlbumArtist       = 'aart',  // cstring
81     kKeyComposer          = 'comp',  // cstring
82     kKeyGenre             = 'genr',  // cstring
83     kKeyTitle             = 'titl',  // cstring
84     kKeyYear              = 'year',  // cstring
85     kKeyAlbumArt          = 'albA',  // compressed image data
86     kKeyAlbumArtMIME      = 'alAM',  // cstring
87     kKeyAuthor            = 'auth',  // cstring
88     kKeyCDTrackNumber     = 'cdtr',  // cstring
89     kKeyDiscNumber        = 'dnum',  // cstring
90     kKeyDate              = 'date',  // cstring
91     kKeyWriter            = 'writ',  // cstring
92     kKeyCompilation       = 'cpil',  // cstring
93     kKeyLocation          = 'loc ',  // cstring
94     kKeyTimeScale         = 'tmsl',  // int32_t
95 
96     // video profile and level
97     kKeyVideoProfile      = 'vprf',  // int32_t
98     kKeyVideoLevel        = 'vlev',  // int32_t
99 
100     // Set this key to enable authoring files in 64-bit offset
101     kKey64BitFileOffset   = 'fobt',  // int32_t (bool)
102     kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
103 
104     // Identify the file output format for authoring
105     // Please see <media/mediarecorder.h> for the supported
106     // file output formats.
107     kKeyFileType          = 'ftyp',  // int32_t
108 
109     // Track authoring progress status
110     // kKeyTrackTimeStatus is used to track progress in elapsed time
111     kKeyTrackTimeStatus   = 'tktm',  // int64_t
112 
113     kKeyNotRealTime       = 'ntrt',  // bool (int32_t)
114 
115     // Ogg files can be tagged to be automatically looping...
116     kKeyAutoLoop          = 'autL',  // bool (int32_t)
117 
118     kKeyValidSamples      = 'valD',  // int32_t
119 
120     kKeyIsUnreadable      = 'unre',  // bool (int32_t)
121 
122     // An indication that a video buffer has been rendered.
123     kKeyRendered          = 'rend',  // bool (int32_t)
124 
125     // The language code for this media
126     kKeyMediaLanguage     = 'lang',  // cstring
127 
128     // To store the timed text format data
129     kKeyTextFormatData    = 'text',  // raw data
130 
131     kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
132 
133     kKeyIsADTS            = 'adts',  // bool (int32_t)
134 
135     // If a MediaBuffer's data represents (at least partially) encrypted
136     // data, the following fields aid in decryption.
137     // The data can be thought of as pairs of plain and encrypted data
138     // fragments, i.e. plain and encrypted data alternate.
139     // The first fragment is by convention plain data (if that's not the
140     // case, simply specify plain fragment size of 0).
141     // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of
142     // size_t values. The sum total of all size_t values of both arrays
143     // must equal the amount of data (i.e. MediaBuffer's range_length()).
144     // If both arrays are present, they must be of the same size.
145     // If only encrypted sizes are present it is assumed that all
146     // plain sizes are 0, i.e. all fragments are encrypted.
147     // To programmatically set these array, use the MetaData::setData API, i.e.
148     // const size_t encSizes[];
149     // meta->setData(
150     //  kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes));
151     // A plain sizes array by itself makes no sense.
152     kKeyEncryptedSizes    = 'encr',  // size_t[]
153     kKeyPlainSizes        = 'plai',  // size_t[]
154     kKeyCryptoKey         = 'cryK',  // uint8_t[16]
155     kKeyCryptoIV          = 'cryI',  // uint8_t[16]
156     kKeyCryptoMode        = 'cryM',  // int32_t
157 };
158 
159 enum {
160     kTypeESDS        = 'esds',
161     kTypeAVCC        = 'avcc',
162     kTypeD263        = 'd263',
163 };
164 
165 class MetaData : public RefBase {
166 public:
167     MetaData();
168     MetaData(const MetaData &from);
169 
170     enum Type {
171         TYPE_NONE     = 'none',
172         TYPE_C_STRING = 'cstr',
173         TYPE_INT32    = 'in32',
174         TYPE_INT64    = 'in64',
175         TYPE_FLOAT    = 'floa',
176         TYPE_POINTER  = 'ptr ',
177         TYPE_RECT     = 'rect',
178     };
179 
180     void clear();
181     bool remove(uint32_t key);
182 
183     bool setCString(uint32_t key, const char *value);
184     bool setInt32(uint32_t key, int32_t value);
185     bool setInt64(uint32_t key, int64_t value);
186     bool setFloat(uint32_t key, float value);
187     bool setPointer(uint32_t key, void *value);
188 
189     bool setRect(
190             uint32_t key,
191             int32_t left, int32_t top,
192             int32_t right, int32_t bottom);
193 
194     bool findCString(uint32_t key, const char **value);
195     bool findInt32(uint32_t key, int32_t *value);
196     bool findInt64(uint32_t key, int64_t *value);
197     bool findFloat(uint32_t key, float *value);
198     bool findPointer(uint32_t key, void **value);
199 
200     bool findRect(
201             uint32_t key,
202             int32_t *left, int32_t *top,
203             int32_t *right, int32_t *bottom);
204 
205     bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
206 
207     bool findData(uint32_t key, uint32_t *type,
208                   const void **data, size_t *size) const;
209 
210     void dumpToLog() const;
211 
212 protected:
213     virtual ~MetaData();
214 
215 private:
216     struct typed_data {
217         typed_data();
218         ~typed_data();
219 
220         typed_data(const MetaData::typed_data &);
221         typed_data &operator=(const MetaData::typed_data &);
222 
223         void clear();
224         void setData(uint32_t type, const void *data, size_t size);
225         void getData(uint32_t *type, const void **data, size_t *size) const;
226         String8 asString() const;
227 
228     private:
229         uint32_t mType;
230         size_t mSize;
231 
232         union {
233             void *ext_data;
234             float reservoir;
235         } u;
236 
usesReservoirtyped_data237         bool usesReservoir() const {
238             return mSize <= sizeof(u.reservoir);
239         }
240 
241         void allocateStorage(size_t size);
242         void freeStorage();
243 
storagetyped_data244         void *storage() {
245             return usesReservoir() ? &u.reservoir : u.ext_data;
246         }
247 
storagetyped_data248         const void *storage() const {
249             return usesReservoir() ? &u.reservoir : u.ext_data;
250         }
251     };
252 
253     struct Rect {
254         int32_t mLeft, mTop, mRight, mBottom;
255     };
256 
257     KeyedVector<uint32_t, typed_data> mItems;
258 
259     // MetaData &operator=(const MetaData &);
260 };
261 
262 }  // namespace android
263 
264 #endif  // META_DATA_H_
265