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