blob: f7f2235eee089ddf1a940c2ac60e2531f248ccde [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)
Andreas Hubere46b7be2009-07-14 16:56:47 -0700117};
118
119enum {
120 kTypeESDS = 'esds',
121 kTypeAVCC = 'avcc',
James Dongfe84cf12011-02-11 15:21:45 -0800122 kTypeD263 = 'd263',
Andreas Hubere46b7be2009-07-14 16:56:47 -0700123};
124
125class MetaData : public RefBase {
126public:
127 MetaData();
128 MetaData(const MetaData &from);
129
130 enum Type {
131 TYPE_NONE = 'none',
132 TYPE_C_STRING = 'cstr',
133 TYPE_INT32 = 'in32',
Andreas Huberfa8de752009-10-08 10:07:49 -0700134 TYPE_INT64 = 'in64',
Andreas Hubere46b7be2009-07-14 16:56:47 -0700135 TYPE_FLOAT = 'floa',
136 TYPE_POINTER = 'ptr ',
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800137 TYPE_RECT = 'rect',
Andreas Hubere46b7be2009-07-14 16:56:47 -0700138 };
139
140 void clear();
141 bool remove(uint32_t key);
142
143 bool setCString(uint32_t key, const char *value);
144 bool setInt32(uint32_t key, int32_t value);
Andreas Huberfa8de752009-10-08 10:07:49 -0700145 bool setInt64(uint32_t key, int64_t value);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700146 bool setFloat(uint32_t key, float value);
147 bool setPointer(uint32_t key, void *value);
148
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800149 bool setRect(
150 uint32_t key,
151 int32_t left, int32_t top,
152 int32_t right, int32_t bottom);
153
Andreas Hubere46b7be2009-07-14 16:56:47 -0700154 bool findCString(uint32_t key, const char **value);
155 bool findInt32(uint32_t key, int32_t *value);
Andreas Huberfa8de752009-10-08 10:07:49 -0700156 bool findInt64(uint32_t key, int64_t *value);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700157 bool findFloat(uint32_t key, float *value);
158 bool findPointer(uint32_t key, void **value);
159
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800160 bool findRect(
161 uint32_t key,
162 int32_t *left, int32_t *top,
163 int32_t *right, int32_t *bottom);
164
Andreas Hubere46b7be2009-07-14 16:56:47 -0700165 bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
166
167 bool findData(uint32_t key, uint32_t *type,
168 const void **data, size_t *size) const;
169
170protected:
171 virtual ~MetaData();
172
173private:
174 struct typed_data {
175 typed_data();
176 ~typed_data();
177
178 typed_data(const MetaData::typed_data &);
179 typed_data &operator=(const MetaData::typed_data &);
180
181 void clear();
182 void setData(uint32_t type, const void *data, size_t size);
183 void getData(uint32_t *type, const void **data, size_t *size) const;
184
185 private:
186 uint32_t mType;
187 size_t mSize;
188
189 union {
190 void *ext_data;
191 float reservoir;
192 } u;
193
194 bool usesReservoir() const {
195 return mSize <= sizeof(u.reservoir);
196 }
197
198 void allocateStorage(size_t size);
199 void freeStorage();
200
201 void *storage() {
202 return usesReservoir() ? &u.reservoir : u.ext_data;
203 }
204
205 const void *storage() const {
206 return usesReservoir() ? &u.reservoir : u.ext_data;
207 }
208 };
209
Andreas Huber1bb0ffd2010-11-22 13:06:35 -0800210 struct Rect {
211 int32_t mLeft, mTop, mRight, mBottom;
212 };
213
Andreas Hubere46b7be2009-07-14 16:56:47 -0700214 KeyedVector<uint32_t, typed_data> mItems;
215
216 // MetaData &operator=(const MetaData &);
217};
218
219} // namespace android
220
221#endif // META_DATA_H_