ABuffer.h revision 90b16fbdef406d95a6fb2f9395719dd7b7ca6adb
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 27namespace android { 28 29struct AMessage; 30 31struct ABuffer : public RefBase { 32 ABuffer(size_t capacity); 33 ABuffer(void *data, size_t capacity); 34 35 void setFarewellMessage(const sp<AMessage> msg); 36 37 uint8_t *base() { return (uint8_t *)mData; } 38 uint8_t *data() { return (uint8_t *)mData + mRangeOffset; } 39 size_t capacity() const { return mCapacity; } 40 size_t size() const { return mRangeLength; } 41 size_t offset() const { return mRangeOffset; } 42 43 void setRange(size_t offset, size_t size); 44 45 // create buffer from dup of some memory block 46 static sp<ABuffer> CreateAsCopy(const void *data, size_t capacity); 47 48 void setInt32Data(int32_t data) { mInt32Data = data; } 49 int32_t int32Data() const { return mInt32Data; } 50 51 sp<AMessage> meta(); 52 53protected: 54 virtual ~ABuffer(); 55 56private: 57 sp<AMessage> mFarewell; 58 sp<AMessage> mMeta; 59 60 void *mData; 61 size_t mCapacity; 62 size_t mRangeOffset; 63 size_t mRangeLength; 64 65 int32_t mInt32Data; 66 67 bool mOwnsData; 68 69 DISALLOW_EVIL_CONSTRUCTORS(ABuffer); 70}; 71 72} // namespace android 73 74#endif // A_BUFFER_H_ 75