MetaData.h revision e5adbeee3401915ff8e1a983396ce3554436b11c
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 30enum { 31 kKeyMIMEType = 'mime', 32 kKeyWidth = 'widt', 33 kKeyHeight = 'heig', 34 kKeyChannelCount = '#chn', 35 kKeySampleRate = 'srte', 36 kKeyBitRate = 'brte', 37 kKeyESDS = 'esds', 38 kKeyAVCC = 'avcc', 39 kKeyTimeUnits = '#tim', 40 kKeyTimeScale = 'scal', 41 kKeyWantsNALFragments = 'NALf', 42 kKeyIsSyncFrame = 'sync', 43 kKeyDuration = 'dura', 44 kKeyColorFormat = 'colf', 45 kKeyPlatformPrivate = 'priv', 46 kKeyDecoderComponent = 'decC', 47 kKeyBufferID = 'bfID', 48 kKeyMaxInputSize = 'inpS', 49}; 50 51enum { 52 kTypeESDS = 'esds', 53 kTypeAVCC = 'avcc', 54}; 55 56class MetaData : public RefBase { 57public: 58 MetaData(); 59 MetaData(const MetaData &from); 60 61 enum Type { 62 TYPE_NONE = 'none', 63 TYPE_C_STRING = 'cstr', 64 TYPE_INT32 = 'in32', 65 TYPE_FLOAT = 'floa', 66 TYPE_POINTER = 'ptr ', 67 }; 68 69 void clear(); 70 bool remove(uint32_t key); 71 72 bool setCString(uint32_t key, const char *value); 73 bool setInt32(uint32_t key, int32_t value); 74 bool setFloat(uint32_t key, float value); 75 bool setPointer(uint32_t key, void *value); 76 77 bool findCString(uint32_t key, const char **value); 78 bool findInt32(uint32_t key, int32_t *value); 79 bool findFloat(uint32_t key, float *value); 80 bool findPointer(uint32_t key, void **value); 81 82 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 83 84 bool findData(uint32_t key, uint32_t *type, 85 const void **data, size_t *size) const; 86 87protected: 88 virtual ~MetaData(); 89 90private: 91 struct typed_data { 92 typed_data(); 93 ~typed_data(); 94 95 typed_data(const MetaData::typed_data &); 96 typed_data &operator=(const MetaData::typed_data &); 97 98 void clear(); 99 void setData(uint32_t type, const void *data, size_t size); 100 void getData(uint32_t *type, const void **data, size_t *size) const; 101 102 private: 103 uint32_t mType; 104 size_t mSize; 105 106 union { 107 void *ext_data; 108 float reservoir; 109 } u; 110 111 bool usesReservoir() const { 112 return mSize <= sizeof(u.reservoir); 113 } 114 115 void allocateStorage(size_t size); 116 void freeStorage(); 117 118 void *storage() { 119 return usesReservoir() ? &u.reservoir : u.ext_data; 120 } 121 122 const void *storage() const { 123 return usesReservoir() ? &u.reservoir : u.ext_data; 124 } 125 }; 126 127 KeyedVector<uint32_t, typed_data> mItems; 128 129 // MetaData &operator=(const MetaData &); 130}; 131 132} // namespace android 133 134#endif // META_DATA_H_ 135