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