1 /* 2 * Copyright (C) 2010 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 A_BUFFER_H_ 18 19 #define A_BUFFER_H_ 20 21 #include <sys/types.h> 22 #include <stdint.h> 23 24 #include <media/stagefright/foundation/ABase.h> 25 #include <utils/RefBase.h> 26 27 namespace android { 28 29 struct AMessage; 30 class MediaBufferBase; 31 32 struct ABuffer : public RefBase { 33 ABuffer(size_t capacity); 34 ABuffer(void *data, size_t capacity); 35 36 void setFarewellMessage(const sp<AMessage> msg); 37 baseABuffer38 uint8_t *base() { return (uint8_t *)mData; } dataABuffer39 uint8_t *data() { return (uint8_t *)mData + mRangeOffset; } capacityABuffer40 size_t capacity() const { return mCapacity; } sizeABuffer41 size_t size() const { return mRangeLength; } offsetABuffer42 size_t offset() const { return mRangeOffset; } 43 44 void setRange(size_t offset, size_t size); 45 46 // create buffer from dup of some memory block 47 static sp<ABuffer> CreateAsCopy(const void *data, size_t capacity); 48 setInt32DataABuffer49 void setInt32Data(int32_t data) { mInt32Data = data; } int32DataABuffer50 int32_t int32Data() const { return mInt32Data; } 51 52 sp<AMessage> meta(); 53 54 MediaBufferBase *getMediaBufferBase(); 55 void setMediaBufferBase(MediaBufferBase *mediaBuffer); 56 57 protected: 58 virtual ~ABuffer(); 59 60 private: 61 sp<AMessage> mFarewell; 62 sp<AMessage> mMeta; 63 64 MediaBufferBase *mMediaBufferBase; 65 66 void *mData; 67 size_t mCapacity; 68 size_t mRangeOffset; 69 size_t mRangeLength; 70 71 int32_t mInt32Data; 72 73 bool mOwnsData; 74 75 DISALLOW_EVIL_CONSTRUCTORS(ABuffer); 76 }; 77 78 } // namespace android 79 80 #endif // A_BUFFER_H_ 81