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