MetaData.h revision 965e4239ca1cf6c824c1f8ce23116f9ba8cf6ebd
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    kKeyTimeScale         = 'tmsl',  // int32_t
89
90    // video profile and level
91    kKeyVideoProfile      = 'vprf',  // int32_t
92    kKeyVideoLevel        = 'vlev',  // int32_t
93
94    // Set this key to enable authoring files in 64-bit offset
95    kKey64BitFileOffset   = 'fobt',  // int32_t (bool)
96    kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
97
98    // Identify the file output format for authoring
99    // Please see <media/mediarecorder.h> for the supported
100    // file output formats.
101    kKeyFileType          = 'ftyp',  // int32_t
102
103    // Track authoring progress status
104    // kKeyTrackTimeStatus is used to track progress in elapsed time
105    kKeyTrackTimeStatus   = 'tktm',  // int64_t
106
107    kKeyNotRealTime       = 'ntrt',  // bool (int32_t)
108
109    // Ogg files can be tagged to be automatically looping...
110    kKeyAutoLoop          = 'autL',  // bool (int32_t)
111
112    kKeyValidSamples      = 'valD',  // int32_t
113
114    kKeyIsUnreadable      = 'unre',  // bool (int32_t)
115
116    // An indication that a video buffer has been rendered.
117    kKeyRendered          = 'rend',  // bool (int32_t)
118
119    // The language code for this media
120    kKeyMediaLanguage     = 'lang',  // cstring
121};
122
123enum {
124    kTypeESDS        = 'esds',
125    kTypeAVCC        = 'avcc',
126    kTypeD263        = 'd263',
127};
128
129class MetaData : public RefBase {
130public:
131    MetaData();
132    MetaData(const MetaData &from);
133
134    enum Type {
135        TYPE_NONE     = 'none',
136        TYPE_C_STRING = 'cstr',
137        TYPE_INT32    = 'in32',
138        TYPE_INT64    = 'in64',
139        TYPE_FLOAT    = 'floa',
140        TYPE_POINTER  = 'ptr ',
141        TYPE_RECT     = 'rect',
142    };
143
144    void clear();
145    bool remove(uint32_t key);
146
147    bool setCString(uint32_t key, const char *value);
148    bool setInt32(uint32_t key, int32_t value);
149    bool setInt64(uint32_t key, int64_t value);
150    bool setFloat(uint32_t key, float value);
151    bool setPointer(uint32_t key, void *value);
152
153    bool setRect(
154            uint32_t key,
155            int32_t left, int32_t top,
156            int32_t right, int32_t bottom);
157
158    bool findCString(uint32_t key, const char **value);
159    bool findInt32(uint32_t key, int32_t *value);
160    bool findInt64(uint32_t key, int64_t *value);
161    bool findFloat(uint32_t key, float *value);
162    bool findPointer(uint32_t key, void **value);
163
164    bool findRect(
165            uint32_t key,
166            int32_t *left, int32_t *top,
167            int32_t *right, int32_t *bottom);
168
169    bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
170
171    bool findData(uint32_t key, uint32_t *type,
172                  const void **data, size_t *size) const;
173
174protected:
175    virtual ~MetaData();
176
177private:
178    struct typed_data {
179        typed_data();
180        ~typed_data();
181
182        typed_data(const MetaData::typed_data &);
183        typed_data &operator=(const MetaData::typed_data &);
184
185        void clear();
186        void setData(uint32_t type, const void *data, size_t size);
187        void getData(uint32_t *type, const void **data, size_t *size) const;
188
189    private:
190        uint32_t mType;
191        size_t mSize;
192
193        union {
194            void *ext_data;
195            float reservoir;
196        } u;
197
198        bool usesReservoir() const {
199            return mSize <= sizeof(u.reservoir);
200        }
201
202        void allocateStorage(size_t size);
203        void freeStorage();
204
205        void *storage() {
206            return usesReservoir() ? &u.reservoir : u.ext_data;
207        }
208
209        const void *storage() const {
210            return usesReservoir() ? &u.reservoir : u.ext_data;
211        }
212    };
213
214    struct Rect {
215        int32_t mLeft, mTop, mRight, mBottom;
216    };
217
218    KeyedVector<uint32_t, typed_data> mItems;
219
220    // MetaData &operator=(const MetaData &);
221};
222
223}  // namespace android
224
225#endif  // META_DATA_H_
226