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