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