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