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 class C2Buffer; 26 27 namespace android { 28 29 struct ABuffer; 30 struct AMessage; 31 class MediaBufferBase; 32 33 /** 34 * Buffers used by MediaCodec. 35 */ 36 class MediaCodecBuffer : public RefBase { 37 public: 38 MediaCodecBuffer(const sp<AMessage> &format, const sp<ABuffer> &buffer); 39 40 /** 41 * MediaCodec will release all references to the buffer when it's done using 42 * it, so the destructor should return the buffer to the owner, such as OMX 43 * components, buffer allocators, surfaces, etc. 44 */ 45 virtual ~MediaCodecBuffer() = default; 46 47 // ABuffer-like interface 48 uint8_t *base(); 49 uint8_t *data(); 50 size_t capacity() const; 51 size_t size() const; 52 size_t offset() const; 53 // Default implementation calls ABuffer::setRange() and returns OK. 54 virtual status_t setRange(size_t offset, size_t size); 55 56 // TODO: Specify each field for meta/format. 57 sp<AMessage> meta(); 58 sp<AMessage> format(); 59 60 void setFormat(const sp<AMessage> &format); 61 62 /** 63 * \return C2Buffer object represents this buffer. 64 */ asC2Buffer()65 virtual std::shared_ptr<C2Buffer> asC2Buffer() { return nullptr; } 66 67 /** 68 * Test if we can copy the content of |buffer| into this object. 69 * 70 * \param buffer C2Buffer object to copy. 71 * \return true if the content of buffer can be copied over to this buffer 72 * false otherwise. 73 */ canCopy(const std::shared_ptr<C2Buffer> & buffer)74 virtual bool canCopy(const std::shared_ptr<C2Buffer> &buffer) const { 75 (void)buffer; 76 return false; 77 } 78 79 /** 80 * Copy the content of |buffer| into this object. This method assumes that 81 * canCopy() check already passed. 82 * 83 * \param buffer C2Buffer object to copy. 84 * \return true if successful 85 * false otherwise. 86 */ copy(const std::shared_ptr<C2Buffer> & buffer)87 virtual bool copy(const std::shared_ptr<C2Buffer> &buffer) { 88 (void)buffer; 89 return false; 90 } 91 92 private: 93 MediaCodecBuffer() = delete; 94 95 const sp<AMessage> mMeta; 96 sp<AMessage> mFormat; 97 const sp<ABuffer> mBuffer; 98 }; 99 100 } // namespace android 101 102 #endif // MEDIA_CODEC_BUFFER_H_ 103