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