MetaData.h revision 145bfe5eb3e08c9689c28f6bf3287a979438b04b
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    kKeyDuration          = 'dura',  // int64_t (usecs)
50    kKeyColorFormat       = 'colf',
51    kKeyPlatformPrivate   = 'priv',  // pointer
52    kKeyDecoderComponent  = 'decC',  // cstring
53    kKeyBufferID          = 'bfID',
54    kKeyMaxInputSize      = 'inpS',
55    kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
56
57    kKeyAlbum             = 'albu',  // cstring
58    kKeyArtist            = 'arti',  // cstring
59    kKeyAlbumArtist       = 'aart',  // cstring
60    kKeyComposer          = 'comp',  // cstring
61    kKeyGenre             = 'genr',  // cstring
62    kKeyTitle             = 'titl',  // cstring
63    kKeyYear              = 'year',  // cstring
64    kKeyAlbumArt          = 'albA',  // compressed image data
65    kKeyAlbumArtMIME      = 'alAM',  // cstring
66    kKeyAuthor            = 'auth',  // cstring
67    kKeyCDTrackNumber     = 'cdtr',  // cstring
68    kKeyDiscNumber        = 'dnum',  // cstring
69    kKeyDate              = 'date',  // cstring
70    kKeyWriter            = 'writ',  // cstring
71
72    // video profile and level
73    kKeyVideoProfile      = 'vprf',  // int32_t
74    kKeyVideoLevel        = 'vlev',  // int32_t
75
76    // Set this key to enable authoring files in 64-bit offset
77    kKey64BitFileOffset   = 'fobt',  // int32_t (bool)
78
79    // Identify the file output format for authoring
80    // Please see <media/mediarecorder.h> for the supported
81    // file output formats.
82    kKeyFileType          = 'ftyp',  // int32_t
83
84    // Track authoring progress status
85    // kKeyTrackTimeStatus is used to track progress in elapsed time
86    // kKeyTrackFrameStatus is used to track progress in authored frames
87    kKeyTrackFrameStatus  = 'tkfm',  // int32_t
88    kKeyTrackTimeStatus   = 'tktm',  // int64_t
89
90};
91
92enum {
93    kTypeESDS        = 'esds',
94    kTypeAVCC        = 'avcc',
95};
96
97class MetaData : public RefBase {
98public:
99    MetaData();
100    MetaData(const MetaData &from);
101
102    enum Type {
103        TYPE_NONE     = 'none',
104        TYPE_C_STRING = 'cstr',
105        TYPE_INT32    = 'in32',
106        TYPE_INT64    = 'in64',
107        TYPE_FLOAT    = 'floa',
108        TYPE_POINTER  = 'ptr ',
109    };
110
111    void clear();
112    bool remove(uint32_t key);
113
114    bool setCString(uint32_t key, const char *value);
115    bool setInt32(uint32_t key, int32_t value);
116    bool setInt64(uint32_t key, int64_t value);
117    bool setFloat(uint32_t key, float value);
118    bool setPointer(uint32_t key, void *value);
119
120    bool findCString(uint32_t key, const char **value);
121    bool findInt32(uint32_t key, int32_t *value);
122    bool findInt64(uint32_t key, int64_t *value);
123    bool findFloat(uint32_t key, float *value);
124    bool findPointer(uint32_t key, void **value);
125
126    bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
127
128    bool findData(uint32_t key, uint32_t *type,
129                  const void **data, size_t *size) const;
130
131protected:
132    virtual ~MetaData();
133
134private:
135    struct typed_data {
136        typed_data();
137        ~typed_data();
138
139        typed_data(const MetaData::typed_data &);
140        typed_data &operator=(const MetaData::typed_data &);
141
142        void clear();
143        void setData(uint32_t type, const void *data, size_t size);
144        void getData(uint32_t *type, const void **data, size_t *size) const;
145
146    private:
147        uint32_t mType;
148        size_t mSize;
149
150        union {
151            void *ext_data;
152            float reservoir;
153        } u;
154
155        bool usesReservoir() const {
156            return mSize <= sizeof(u.reservoir);
157        }
158
159        void allocateStorage(size_t size);
160        void freeStorage();
161
162        void *storage() {
163            return usesReservoir() ? &u.reservoir : u.ext_data;
164        }
165
166        const void *storage() const {
167            return usesReservoir() ? &u.reservoir : u.ext_data;
168        }
169    };
170
171    KeyedVector<uint32_t, typed_data> mItems;
172
173    // MetaData &operator=(const MetaData &);
174};
175
176}  // namespace android
177
178#endif  // META_DATA_H_
179