MetaData.h revision ddcc4a66d848deef6fb4689e64e30cd9bd2684fe
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 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 73enum { 74 kTypeESDS = 'esds', 75 kTypeAVCC = 'avcc', 76}; 77 78class MetaData : public RefBase { 79public: 80 MetaData(); 81 MetaData(const MetaData &from); 82 83 enum Type { 84 TYPE_NONE = 'none', 85 TYPE_C_STRING = 'cstr', 86 TYPE_INT32 = 'in32', 87 TYPE_INT64 = 'in64', 88 TYPE_FLOAT = 'floa', 89 TYPE_POINTER = 'ptr ', 90 }; 91 92 void clear(); 93 bool remove(uint32_t key); 94 95 bool setCString(uint32_t key, const char *value); 96 bool setInt32(uint32_t key, int32_t value); 97 bool setInt64(uint32_t key, int64_t value); 98 bool setFloat(uint32_t key, float value); 99 bool setPointer(uint32_t key, void *value); 100 101 bool findCString(uint32_t key, const char **value); 102 bool findInt32(uint32_t key, int32_t *value); 103 bool findInt64(uint32_t key, int64_t *value); 104 bool findFloat(uint32_t key, float *value); 105 bool findPointer(uint32_t key, void **value); 106 107 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 108 109 bool findData(uint32_t key, uint32_t *type, 110 const void **data, size_t *size) const; 111 112protected: 113 virtual ~MetaData(); 114 115private: 116 struct typed_data { 117 typed_data(); 118 ~typed_data(); 119 120 typed_data(const MetaData::typed_data &); 121 typed_data &operator=(const MetaData::typed_data &); 122 123 void clear(); 124 void setData(uint32_t type, const void *data, size_t size); 125 void getData(uint32_t *type, const void **data, size_t *size) const; 126 127 private: 128 uint32_t mType; 129 size_t mSize; 130 131 union { 132 void *ext_data; 133 float reservoir; 134 } u; 135 136 bool usesReservoir() const { 137 return mSize <= sizeof(u.reservoir); 138 } 139 140 void allocateStorage(size_t size); 141 void freeStorage(); 142 143 void *storage() { 144 return usesReservoir() ? &u.reservoir : u.ext_data; 145 } 146 147 const void *storage() const { 148 return usesReservoir() ? &u.reservoir : u.ext_data; 149 } 150 }; 151 152 KeyedVector<uint32_t, typed_data> mItems; 153 154 // MetaData &operator=(const MetaData &); 155}; 156 157} // namespace android 158 159#endif // META_DATA_H_ 160