MetaData.h revision 3b573f7bf1c5736d500e39013b8d32478a1429e6
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    // To store the timed text format data
123    kKeyTextFormatData    = 'text',  // raw data
124};
125
126enum {
127    kTypeESDS        = 'esds',
128    kTypeAVCC        = 'avcc',
129    kTypeD263        = 'd263',
130};
131
132class MetaData : public RefBase {
133public:
134    MetaData();
135    MetaData(const MetaData &from);
136
137    enum Type {
138        TYPE_NONE     = 'none',
139        TYPE_C_STRING = 'cstr',
140        TYPE_INT32    = 'in32',
141        TYPE_INT64    = 'in64',
142        TYPE_FLOAT    = 'floa',
143        TYPE_POINTER  = 'ptr ',
144        TYPE_RECT     = 'rect',
145    };
146
147    void clear();
148    bool remove(uint32_t key);
149
150    bool setCString(uint32_t key, const char *value);
151    bool setInt32(uint32_t key, int32_t value);
152    bool setInt64(uint32_t key, int64_t value);
153    bool setFloat(uint32_t key, float value);
154    bool setPointer(uint32_t key, void *value);
155
156    bool setRect(
157            uint32_t key,
158            int32_t left, int32_t top,
159            int32_t right, int32_t bottom);
160
161    bool findCString(uint32_t key, const char **value);
162    bool findInt32(uint32_t key, int32_t *value);
163    bool findInt64(uint32_t key, int64_t *value);
164    bool findFloat(uint32_t key, float *value);
165    bool findPointer(uint32_t key, void **value);
166
167    bool findRect(
168            uint32_t key,
169            int32_t *left, int32_t *top,
170            int32_t *right, int32_t *bottom);
171
172    bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
173
174    bool findData(uint32_t key, uint32_t *type,
175                  const void **data, size_t *size) const;
176
177protected:
178    virtual ~MetaData();
179
180private:
181    struct typed_data {
182        typed_data();
183        ~typed_data();
184
185        typed_data(const MetaData::typed_data &);
186        typed_data &operator=(const MetaData::typed_data &);
187
188        void clear();
189        void setData(uint32_t type, const void *data, size_t size);
190        void getData(uint32_t *type, const void **data, size_t *size) const;
191
192    private:
193        uint32_t mType;
194        size_t mSize;
195
196        union {
197            void *ext_data;
198            float reservoir;
199        } u;
200
201        bool usesReservoir() const {
202            return mSize <= sizeof(u.reservoir);
203        }
204
205        void allocateStorage(size_t size);
206        void freeStorage();
207
208        void *storage() {
209            return usesReservoir() ? &u.reservoir : u.ext_data;
210        }
211
212        const void *storage() const {
213            return usesReservoir() ? &u.reservoir : u.ext_data;
214        }
215    };
216
217    struct Rect {
218        int32_t mLeft, mTop, mRight, mBottom;
219    };
220
221    KeyedVector<uint32_t, typed_data> mItems;
222
223    // MetaData &operator=(const MetaData &);
224};
225
226}  // namespace android
227
228#endif  // META_DATA_H_
229