• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016, 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 MEDIA_CODEC_BUFFER_H_
18 
19 #define MEDIA_CODEC_BUFFER_H_
20 
21 #include <utils/Errors.h>
22 #include <utils/RefBase.h>
23 #include <utils/StrongPointer.h>
24 
25 namespace android {
26 
27 struct ABuffer;
28 struct AMessage;
29 class MediaBufferBase;
30 
31 /**
32  * Buffers used by MediaCodec.
33  */
34 class MediaCodecBuffer : public RefBase {
35 public:
36     MediaCodecBuffer(const sp<AMessage> &format, const sp<ABuffer> &buffer);
37 
38     /**
39      * MediaCodec will release all references to the buffer when it's done using
40      * it, so the destructor should return the buffer to the owner, such as OMX
41      * components, buffer allocators, surfaces, etc.
42      */
43     virtual ~MediaCodecBuffer() = default;
44 
45     // ABuffer-like interface
46     uint8_t *base();
47     uint8_t *data();
48     size_t capacity() const;
49     size_t size() const;
50     size_t offset() const;
51     // Default implementation calls ABuffer::setRange() and returns OK.
52     virtual status_t setRange(size_t offset, size_t size);
53 
54     // TODO: Specify each field for meta/format.
55     sp<AMessage> meta();
56     sp<AMessage> format();
57 
58     void setFormat(const sp<AMessage> &format);
59 
60 private:
61     MediaCodecBuffer() = delete;
62 
63     const sp<AMessage> mMeta;
64     sp<AMessage> mFormat;
65     const sp<ABuffer> mBuffer;
66 };
67 
68 }  // namespace android
69 
70 #endif  // MEDIA_CODEC_BUFFER_H_
71