MetaData.h revision 4948818cb91176df74c972ac27b2f392b5d148bc
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
28namespace android {
29
30// The following keys map to int32_t data unless indicated otherwise.
31enum {
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
38    // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1)
39    kKeyCropRect          = 'crop',
40
41    kKeyRotation          = 'rotA',  // int32_t (angle in degrees)
42    kKeyIFramesInterval   = 'ifiv',  // int32_t
43    kKeyStride            = 'strd',  // int32_t
44    kKeySliceHeight       = 'slht',  // int32_t
45    kKeyChannelCount      = '#chn',  // int32_t
46    kKeySampleRate        = 'srte',  // int32_t (audio sampling rate Hz)
47    kKeyFrameRate         = 'frmR',  // int32_t (video frame rate fps)
48    kKeyBitRate           = 'brte',  // int32_t (bps)
49    kKeyESDS              = 'esds',  // raw data
50    kKeyAVCC              = 'avcc',  // raw data
51    kKeyD263              = 'd263',  // raw data
52    kKeyVorbisInfo        = 'vinf',  // raw data
53    kKeyVorbisBooks       = 'vboo',  // raw data
54    kKeyWantsNALFragments = 'NALf',
55    kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
56    kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
57    kKeyTime              = 'time',  // int64_t (usecs)
58    kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
59    kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
60    kKeyTargetTime        = 'tarT',  // int64_t (usecs)
61    kKeyDriftTime         = 'dftT',  // int64_t (usecs)
62    kKeyAnchorTime        = 'ancT',  // int64_t (usecs)
63    kKeyDuration          = 'dura',  // int64_t (usecs)
64    kKeyColorFormat       = 'colf',
65    kKeyPlatformPrivate   = 'priv',  // pointer
66    kKeyDecoderComponent  = 'decC',  // cstring
67    kKeyBufferID          = 'bfID',
68    kKeyMaxInputSize      = 'inpS',
69    kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
70    kKeyTrackID           = 'trID',
71    kKeyIsDRM             = 'idrm',  // int32_t (bool)
72
73    kKeyAlbum             = 'albu',  // cstring
74    kKeyArtist            = 'arti',  // cstring
75    kKeyAlbumArtist       = 'aart',  // cstring
76    kKeyComposer          = 'comp',  // cstring
77    kKeyGenre             = 'genr',  // cstring
78    kKeyTitle             = 'titl',  // cstring
79    kKeyYear              = 'year',  // cstring
80    kKeyAlbumArt          = 'albA',  // compressed image data
81    kKeyAlbumArtMIME      = 'alAM',  // cstring
82    kKeyAuthor            = 'auth',  // cstring
83    kKeyCDTrackNumber     = 'cdtr',  // cstring
84    kKeyDiscNumber        = 'dnum',  // cstring
85    kKeyDate              = 'date',  // cstring
86    kKeyWriter            = 'writ',  // cstring
87    kKeyCompilation       = 'cpil',  // cstring
88    kKeyLocation          = 'loc ',  // cstring
89    kKeyTimeScale         = 'tmsl',  // int32_t
90
91    // video profile and level
92    kKeyVideoProfile      = 'vprf',  // int32_t
93    kKeyVideoLevel        = 'vlev',  // int32_t
94
95    // Set this key to enable authoring files in 64-bit offset
96    kKey64BitFileOffset   = 'fobt',  // int32_t (bool)
97    kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
98
99    // Identify the file output format for authoring
100    // Please see <media/mediarecorder.h> for the supported
101    // file output formats.
102    kKeyFileType          = 'ftyp',  // int32_t
103
104    // Track authoring progress status
105    // kKeyTrackTimeStatus is used to track progress in elapsed time
106    kKeyTrackTimeStatus   = 'tktm',  // int64_t
107
108    kKeyNotRealTime       = 'ntrt',  // bool (int32_t)
109
110    // Ogg files can be tagged to be automatically looping...
111    kKeyAutoLoop          = 'autL',  // bool (int32_t)
112
113    kKeyValidSamples      = 'valD',  // int32_t
114
115    kKeyIsUnreadable      = 'unre',  // bool (int32_t)
116
117    // An indication that a video buffer has been rendered.
118    kKeyRendered          = 'rend',  // bool (int32_t)
119
120    // The language code for this media
121    kKeyMediaLanguage     = 'lang',  // cstring
122
123    // To store the timed text format data
124    kKeyTextFormatData    = 'text',  // raw data
125
126    kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
127};
128
129enum {
130    kTypeESDS        = 'esds',
131    kTypeAVCC        = 'avcc',
132    kTypeD263        = 'd263',
133};
134
135class MetaData : public RefBase {
136public:
137    MetaData();
138    MetaData(const MetaData &from);
139
140    enum Type {
141        TYPE_NONE     = 'none',
142        TYPE_C_STRING = 'cstr',
143        TYPE_INT32    = 'in32',
144        TYPE_INT64    = 'in64',
145        TYPE_FLOAT    = 'floa',
146        TYPE_POINTER  = 'ptr ',
147        TYPE_RECT     = 'rect',
148    };
149
150    void clear();
151    bool remove(uint32_t key);
152
153    bool setCString(uint32_t key, const char *value);
154    bool setInt32(uint32_t key, int32_t value);
155    bool setInt64(uint32_t key, int64_t value);
156    bool setFloat(uint32_t key, float value);
157    bool setPointer(uint32_t key, void *value);
158
159    bool setRect(
160            uint32_t key,
161            int32_t left, int32_t top,
162            int32_t right, int32_t bottom);
163
164    bool findCString(uint32_t key, const char **value);
165    bool findInt32(uint32_t key, int32_t *value);
166    bool findInt64(uint32_t key, int64_t *value);
167    bool findFloat(uint32_t key, float *value);
168    bool findPointer(uint32_t key, void **value);
169
170    bool findRect(
171            uint32_t key,
172            int32_t *left, int32_t *top,
173            int32_t *right, int32_t *bottom);
174
175    bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
176
177    bool findData(uint32_t key, uint32_t *type,
178                  const void **data, size_t *size) const;
179
180protected:
181    virtual ~MetaData();
182
183private:
184    struct typed_data {
185        typed_data();
186        ~typed_data();
187
188        typed_data(const MetaData::typed_data &);
189        typed_data &operator=(const MetaData::typed_data &);
190
191        void clear();
192        void setData(uint32_t type, const void *data, size_t size);
193        void getData(uint32_t *type, const void **data, size_t *size) const;
194
195    private:
196        uint32_t mType;
197        size_t mSize;
198
199        union {
200            void *ext_data;
201            float reservoir;
202        } u;
203
204        bool usesReservoir() const {
205            return mSize <= sizeof(u.reservoir);
206        }
207
208        void allocateStorage(size_t size);
209        void freeStorage();
210
211        void *storage() {
212            return usesReservoir() ? &u.reservoir : u.ext_data;
213        }
214
215        const void *storage() const {
216            return usesReservoir() ? &u.reservoir : u.ext_data;
217        }
218    };
219
220    struct Rect {
221        int32_t mLeft, mTop, mRight, mBottom;
222    };
223
224    KeyedVector<uint32_t, typed_data> mItems;
225
226    // MetaData &operator=(const MetaData &);
227};
228
229}  // namespace android
230
231#endif  // META_DATA_H_
232