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