Wonsik Kim | 7e34bf5 | 2016-08-23 00:09:18 +0900 | [diff] [blame] | 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 | // 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 | private: |
| 62 | MediaCodecBuffer() = delete; |
| 63 | |
| 64 | const sp<AMessage> mMeta; |
| 65 | const sp<AMessage> mFormat; |
| 66 | const sp<ABuffer> mBuffer; |
| 67 | MediaBufferBase *mMediaBufferBase; |
| 68 | }; |
| 69 | |
| 70 | } // namespace android |
| 71 | |
| 72 | #endif // MEDIA_CODEC_BUFFER_H_ |