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