• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
31 struct ABuffer : public RefBase {
32     explicit ABuffer(size_t capacity);
33     ABuffer(void *data, size_t capacity);
34 
baseABuffer35     uint8_t *base() { return (uint8_t *)mData; }
dataABuffer36     uint8_t *data() { return (uint8_t *)mData + mRangeOffset; }
capacityABuffer37     size_t capacity() const { return mCapacity; }
sizeABuffer38     size_t size() const { return mRangeLength; }
offsetABuffer39     size_t offset() const { return mRangeOffset; }
40 
41     void setRange(size_t offset, size_t size);
42 
43     // create buffer from dup of some memory block
44     static sp<ABuffer> CreateAsCopy(const void *data, size_t capacity);
45 
setInt32DataABuffer46     void setInt32Data(int32_t data) { mInt32Data = data; }
int32DataABuffer47     int32_t int32Data() const { return mInt32Data; }
48 
49     sp<AMessage> meta();
50 
51 protected:
52     virtual ~ABuffer();
53 
54 private:
55     sp<AMessage> mMeta;
56 
57     void *mData;
58     size_t mCapacity;
59     size_t mRangeOffset;
60     size_t mRangeLength;
61 
62     int32_t mInt32Data;
63 
64     bool mOwnsData;
65 
66     DISALLOW_EVIL_CONSTRUCTORS(ABuffer);
67 };
68 
69 }  // namespace android
70 
71 #endif  // A_BUFFER_H_
72