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
25namespace android {
26
27struct ABuffer;
28struct AMessage;
29class MediaBufferBase;
30
31/**
32 * Buffers used by MediaCodec.
33 */
34class MediaCodecBuffer : public RefBase {
35public:
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    // TODO: These can be removed if we finish replacing all MediaBuffer's.
54    MediaBufferBase *getMediaBufferBase();
55    void setMediaBufferBase(MediaBufferBase *mediaBuffer);
56
57    // TODO: Specify each field for meta/format.
58    sp<AMessage> meta();
59    sp<AMessage> format();
60
61    void setFormat(const sp<AMessage> &format);
62
63private:
64    MediaCodecBuffer() = delete;
65
66    const sp<AMessage> mMeta;
67    sp<AMessage> mFormat;
68    const sp<ABuffer> mBuffer;
69    MediaBufferBase *mMediaBufferBase;
70};
71
72}  // namespace android
73
74#endif  // MEDIA_CODEC_BUFFER_H_
75