blob: a300f0e03929d53bd49574a510bb5b6eb3fdfc18 [file] [log] [blame]
Andreas Hubere46b7be2009-07-14 16:56:47 -07001/*
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
Andreas Huberfa8de752009-10-08 10:07:49 -070030// The following keys map to int32_t data unless indicated otherwise.
Andreas Hubere46b7be2009-07-14 16:56:47 -070031enum {
Andreas Huberfa8de752009-10-08 10:07:49 -070032 kKeyMIMEType = 'mime', // cstring
James Dong08adfd22011-01-16 11:30:13 -080033 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
Andreas Huber1bb0ffd2010-11-22 13:06:35 -080037
38 // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1)
39 kKeyCropRect = 'crop',
40
James Dong2bff8392010-11-08 20:01:12 -080041 kKeyRotation = 'rotA', // int32_t (angle in degrees)
James Dong1244eab2010-06-08 11:58:53 -070042 kKeyIFramesInterval = 'ifiv', // int32_t
43 kKeyStride = 'strd', // int32_t
44 kKeySliceHeight = 'slht', // int32_t
45 kKeyChannelCount = '#chn', // int32_t
James Dongaac193c2010-11-10 20:43:53 -080046 kKeySampleRate = 'srte', // int32_t (audio sampling rate Hz)
47 kKeyFrameRate = 'frmR', // int32_t (video frame rate fps)
Andreas Huberd49b526dd2009-12-11 15:07:25 -080048 kKeyBitRate = 'brte', // int32_t (bps)
Andreas Huberfa8de752009-10-08 10:07:49 -070049 kKeyESDS = 'esds', // raw data
50 kKeyAVCC = 'avcc', // raw data
James Dongfe84cf12011-02-11 15:21:45 -080051 kKeyD263 = 'd263', // raw data
Andreas Huber388379f2010-05-07 10:35:13 -070052 kKeyVorbisInfo = 'vinf', // raw data
53 kKeyVorbisBooks = 'vboo', // raw data
Andreas Huber4f5e6022009-08-19 09:29:34 -070054 kKeyWantsNALFragments = 'NALf',
Andreas Huberea6a38c2009-11-16 15:43:38 -080055 kKeyIsSyncFrame = 'sync', // int32_t (bool)
56 kKeyIsCodecConfig = 'conf', // int32_t (bool)
Andreas Huberfa8de752009-10-08 10:07:49 -070057 kKeyTime = 'time', // int64_t (usecs)
Andreas Huber57648e42010-08-04 10:14:30 -070058 kKeyNTPTime = 'ntpT', // uint64_t (ntp-timestamp)
Andreas Huber6624c9f2010-07-20 15:04:28 -070059 kKeyTargetTime = 'tarT', // int64_t (usecs)
James Dong4c238152010-09-01 18:48:35 -070060 kKeyDriftTime = 'dftT', // int64_t (usecs)
James Dongd015ccf2010-09-08 15:07:21 -070061 kKeyAnchorTime = 'ancT', // int64_t (usecs)
Andreas Huberfa8de752009-10-08 10:07:49 -070062 kKeyDuration = 'dura', // int64_t (usecs)
Andreas Huber4f5e6022009-08-19 09:29:34 -070063 kKeyColorFormat = 'colf',
Andreas Huberfa8de752009-10-08 10:07:49 -070064 kKeyPlatformPrivate = 'priv', // pointer
65 kKeyDecoderComponent = 'decC', // cstring
Andreas Huber4f5e6022009-08-19 09:29:34 -070066 kKeyBufferID = 'bfID',
Andreas Huberda050cf22009-09-02 14:01:43 -070067 kKeyMaxInputSize = 'inpS',
Andreas Hubere981c332009-10-22 13:49:30 -070068 kKeyThumbnailTime = 'thbT', // int64_t (usecs)
Gloria Wangd5770912010-06-22 13:55:38 -070069 kKeyTrackID = 'trID',
70 kKeyIsDRM = 'idrm', // int32_t (bool)
Andreas Huberaee3c632010-01-11 15:35:19 -080071
72 kKeyAlbum = 'albu', // cstring
73 kKeyArtist = 'arti', // cstring
Marco Nelissenc5d5ee32010-02-11 13:31:44 -080074 kKeyAlbumArtist = 'aart', // cstring
Andreas Huberaee3c632010-01-11 15:35:19 -080075 kKeyComposer = 'comp', // cstring
76 kKeyGenre = 'genr', // cstring
77 kKeyTitle = 'titl', // cstring
78 kKeyYear = 'year', // cstring
79 kKeyAlbumArt = 'albA', // compressed image data
80 kKeyAlbumArtMIME = 'alAM', // cstring
Andreas Huber3a3656c2010-01-13 10:45:49 -080081 kKeyAuthor = 'auth', // cstring
82 kKeyCDTrackNumber = 'cdtr', // cstring
Marco Nelissen655306f2010-02-08 14:50:19 -080083 kKeyDiscNumber = 'dnum', // cstring
Andreas Huber3a3656c2010-01-13 10:45:49 -080084 kKeyDate = 'date', // cstring
Andreas Huberc2c9dd32010-01-19 16:43:53 -080085 kKeyWriter = 'writ', // cstring
Marco Nelissenee35aff2011-01-06 11:12:17 -080086 kKeyCompilation = 'cpil', // cstring
James Dong52d13f02010-07-02 11:39:06 -070087 kKeyTimeScale = 'tmsl', // int32_t
James Dong09936ed2010-06-24 19:04:27 -070088
James Dong81c929a2010-07-01 15:02:14 -070089 // video profile and level
90 kKeyVideoProfile = 'vprf', // int32_t
91 kKeyVideoLevel = 'vlev', // int32_t
92
James Dong09936ed2010-06-24 19:04:27 -070093 // Set this key to enable authoring files in 64-bit offset
94 kKey64BitFileOffset = 'fobt', // int32_t (bool)
James Dong7755cdd2010-09-02 10:49:55 -070095 kKey2ByteNalLength = '2NAL', // int32_t (bool)
James Dong09936ed2010-06-24 19:04:27 -070096
97 // Identify the file output format for authoring
98 // Please see <media/mediarecorder.h> for the supported
99 // file output formats.
100 kKeyFileType = 'ftyp', // int32_t
101
102 // Track authoring progress status
103 // kKeyTrackTimeStatus is used to track progress in elapsed time
James Dong09936ed2010-06-24 19:04:27 -0700104 kKeyTrackTimeStatus = 'tktm', // int64_t
105
James Dongb7208192010-08-02 19:13:40 -0700106 kKeyNotRealTime = 'ntrt', // bool (int32_t)
107
Andreas Huber9fee0b22010-09-03 14:09:21 -0700108 // Ogg files can be tagged to be automatically looping...
109 kKeyAutoLoop = 'autL', // bool (int32_t)
Andreas Huber38ae2202010-09-28 09:16:21 -0700110
111 kKeyValidSamples = 'valD', // int32_t
Andreas Huber1e194162010-10-06 16:43:57 -0700112
113 kKeyIsUnreadable = 'unre', // bool (int32_t)
Jamie Gennis58a36ad2010-10-07 14:08:38 -0700114
115 // An indication that a video buffer has been rendered.
116 kKeyRendered = 'rend', // bool (int32_t)
Gloria Wangc6091dd2011-05-03 15:59:03 -0700117
118 // The language code for this media
119 kKeyMediaLanguage = 'lang', // cstring
Andreas Hubere46b7be2009-07-14 16:56:47 -0700120};
121
122enum {
123 kTypeESDS = 'esds',
124 kTypeAVCC = 'avcc',
James Dongfe84cf12011-02-11 15:21:45 -0800125 kTypeD263 = 'd263',
Andreas Hubere46b7be2009-07-14 16:56:47 -0700126};
127
128class MetaData : public RefBase {
129public:
130 MetaData();
131 MetaData(const MetaData &from);
132
133 enum Type {
134 TYPE_NONE = 'none',
135 TYPE_C_STRING = 'cstr',
136 TYPE_INT32 = 'in32',
Andreas Huberfa8de752009-10-08 10:07:49 -0700137 TYPE_INT64 = 'in64',
Andreas Hubere46b7be2009-07-14 16:56:47 -0700138 TYPE_FLOAT = 'floa',
139 TYPE_POINTER = 'ptr ',
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800140 TYPE_RECT = 'rect',
Andreas Hubere46b7be2009-07-14 16:56:47 -0700141 };
142
143 void clear();
144 bool remove(uint32_t key);
145
146 bool setCString(uint32_t key, const char *value);
147 bool setInt32(uint32_t key, int32_t value);
Andreas Huberfa8de752009-10-08 10:07:49 -0700148 bool setInt64(uint32_t key, int64_t value);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700149 bool setFloat(uint32_t key, float value);
150 bool setPointer(uint32_t key, void *value);
151
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800152 bool setRect(
153 uint32_t key,
154 int32_t left, int32_t top,
155 int32_t right, int32_t bottom);
156
James Dong78fed1712011-05-09 11:36:53 -0700157 bool findCString(uint32_t key, const char **value) const;
158 bool findInt32(uint32_t key, int32_t *value) const;
159 bool findInt64(uint32_t key, int64_t *value) const;
160 bool findFloat(uint32_t key, float *value) const;
161 bool findPointer(uint32_t key, void **value) const;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700162
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800163 bool findRect(
164 uint32_t key,
165 int32_t *left, int32_t *top,
James Dong78fed1712011-05-09 11:36:53 -0700166 int32_t *right, int32_t *bottom) const;
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800167
Andreas Hubere46b7be2009-07-14 16:56:47 -0700168 bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
169
170 bool findData(uint32_t key, uint32_t *type,
171 const void **data, size_t *size) const;
172
173protected:
174 virtual ~MetaData();
175
176private:
177 struct typed_data {
178 typed_data();
179 ~typed_data();
180
181 typed_data(const MetaData::typed_data &);
182 typed_data &operator=(const MetaData::typed_data &);
183
184 void clear();
185 void setData(uint32_t type, const void *data, size_t size);
186 void getData(uint32_t *type, const void **data, size_t *size) const;
187
188 private:
189 uint32_t mType;
190 size_t mSize;
191
192 union {
193 void *ext_data;
194 float reservoir;
195 } u;
196
197 bool usesReservoir() const {
198 return mSize <= sizeof(u.reservoir);
199 }
200
201 void allocateStorage(size_t size);
202 void freeStorage();
203
204 void *storage() {
205 return usesReservoir() ? &u.reservoir : u.ext_data;
206 }
207
208 const void *storage() const {
209 return usesReservoir() ? &u.reservoir : u.ext_data;
210 }
211 };
212
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800213 struct Rect {
214 int32_t mLeft, mTop, mRight, mBottom;
215 };
216
Andreas Hubere46b7be2009-07-14 16:56:47 -0700217 KeyedVector<uint32_t, typed_data> mItems;
218
219 // MetaData &operator=(const MetaData &);
220};
221
222} // namespace android
223
224#endif // META_DATA_H_