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 28 namespace android { 29 30 // The following keys map to int32_t data unless indicated otherwise. 31 enum { 32 kKeyMIMEType = 'mime', // cstring 33 kKeyWidth = 'widt', 34 kKeyHeight = 'heig', 35 kKeyChannelCount = '#chn', 36 kKeySampleRate = 'srte', 37 kKeyBitRate = 'brte', // int32_t (bps) 38 kKeyESDS = 'esds', // raw data 39 kKeyAVCC = 'avcc', // raw data 40 kKeyVorbisInfo = 'vinf', // raw data 41 kKeyVorbisBooks = 'vboo', // raw data 42 kKeyWantsNALFragments = 'NALf', 43 kKeyIsSyncFrame = 'sync', // int32_t (bool) 44 kKeyIsCodecConfig = 'conf', // int32_t (bool) 45 kKeyTime = 'time', // int64_t (usecs) 46 kKeyDuration = 'dura', // int64_t (usecs) 47 kKeyColorFormat = 'colf', 48 kKeyPlatformPrivate = 'priv', // pointer 49 kKeyDecoderComponent = 'decC', // cstring 50 kKeyBufferID = 'bfID', 51 kKeyMaxInputSize = 'inpS', 52 kKeyThumbnailTime = 'thbT', // int64_t (usecs) 53 54 kKeyAlbum = 'albu', // cstring 55 kKeyArtist = 'arti', // cstring 56 kKeyAlbumArtist = 'aart', // cstring 57 kKeyComposer = 'comp', // cstring 58 kKeyGenre = 'genr', // cstring 59 kKeyTitle = 'titl', // cstring 60 kKeyYear = 'year', // cstring 61 kKeyAlbumArt = 'albA', // compressed image data 62 kKeyAlbumArtMIME = 'alAM', // cstring 63 kKeyAuthor = 'auth', // cstring 64 kKeyCDTrackNumber = 'cdtr', // cstring 65 kKeyDiscNumber = 'dnum', // cstring 66 kKeyDate = 'date', // cstring 67 kKeyWriter = 'writ', // cstring 68 }; 69 70 enum { 71 kTypeESDS = 'esds', 72 kTypeAVCC = 'avcc', 73 }; 74 75 class MetaData : public RefBase { 76 public: 77 MetaData(); 78 MetaData(const MetaData &from); 79 80 enum Type { 81 TYPE_NONE = 'none', 82 TYPE_C_STRING = 'cstr', 83 TYPE_INT32 = 'in32', 84 TYPE_INT64 = 'in64', 85 TYPE_FLOAT = 'floa', 86 TYPE_POINTER = 'ptr ', 87 }; 88 89 void clear(); 90 bool remove(uint32_t key); 91 92 bool setCString(uint32_t key, const char *value); 93 bool setInt32(uint32_t key, int32_t value); 94 bool setInt64(uint32_t key, int64_t value); 95 bool setFloat(uint32_t key, float value); 96 bool setPointer(uint32_t key, void *value); 97 98 bool findCString(uint32_t key, const char **value); 99 bool findInt32(uint32_t key, int32_t *value); 100 bool findInt64(uint32_t key, int64_t *value); 101 bool findFloat(uint32_t key, float *value); 102 bool findPointer(uint32_t key, void **value); 103 104 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 105 106 bool findData(uint32_t key, uint32_t *type, 107 const void **data, size_t *size) const; 108 109 protected: 110 virtual ~MetaData(); 111 112 private: 113 struct typed_data { 114 typed_data(); 115 ~typed_data(); 116 117 typed_data(const MetaData::typed_data &); 118 typed_data &operator=(const MetaData::typed_data &); 119 120 void clear(); 121 void setData(uint32_t type, const void *data, size_t size); 122 void getData(uint32_t *type, const void **data, size_t *size) const; 123 124 private: 125 uint32_t mType; 126 size_t mSize; 127 128 union { 129 void *ext_data; 130 float reservoir; 131 } u; 132 133 bool usesReservoir() const { 134 return mSize <= sizeof(u.reservoir); 135 } 136 137 void allocateStorage(size_t size); 138 void freeStorage(); 139 140 void *storage() { 141 return usesReservoir() ? &u.reservoir : u.ext_data; 142 } 143 144 const void *storage() const { 145 return usesReservoir() ? &u.reservoir : u.ext_data; 146 } 147 }; 148 149 KeyedVector<uint32_t, typed_data> mItems; 150 151 // MetaData &operator=(const MetaData &); 152 }; 153 154 } // namespace android 155 156 #endif // META_DATA_H_ 157