• 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 class MediaBufferBase;
31 
32 struct ABuffer : public RefBase {
33     ABuffer(size_t capacity);
34     ABuffer(void *data, size_t capacity);
35 
baseABuffer36     uint8_t *base() { return (uint8_t *)mData; }
dataABuffer37     uint8_t *data() { return (uint8_t *)mData + mRangeOffset; }
capacityABuffer38     size_t capacity() const { return mCapacity; }
sizeABuffer39     size_t size() const { return mRangeLength; }
offsetABuffer40     size_t offset() const { return mRangeOffset; }
41 
42     void setRange(size_t offset, size_t size);
43 
44     // create buffer from dup of some memory block
45     static sp<ABuffer> CreateAsCopy(const void *data, size_t capacity);
46 
setInt32DataABuffer47     void setInt32Data(int32_t data) { mInt32Data = data; }
int32DataABuffer48     int32_t int32Data() const { return mInt32Data; }
49 
50     sp<AMessage> meta();
51 
52     MediaBufferBase *getMediaBufferBase();
53     void setMediaBufferBase(MediaBufferBase *mediaBuffer);
54 
55 protected:
56     virtual ~ABuffer();
57 
58 private:
59     sp<AMessage> mMeta;
60 
61     MediaBufferBase *mMediaBufferBase;
62 
63     void *mData;
64     size_t mCapacity;
65     size_t mRangeOffset;
66     size_t mRangeLength;
67 
68     int32_t mInt32Data;
69 
70     bool mOwnsData;
71 
72     DISALLOW_EVIL_CONSTRUCTORS(ABuffer);
73 };
74 
75 }  // namespace android
76 
77 #endif  // A_BUFFER_H_
78