Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [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 _OMXBUFFER_H_ |
| 18 | #define _OMXBUFFER_H_ |
| 19 | |
| 20 | #include <cutils/native_handle.h> |
| 21 | #include <media/IOMX.h> |
| 22 | #include <system/window.h> |
| 23 | #include <utils/StrongPointer.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | class GraphicBuffer; |
| 28 | class IMemory; |
| 29 | class MediaCodecBuffer; |
| 30 | class NativeHandle; |
| 31 | class OMXNodeInstance; |
| 32 | |
| 33 | class OMXBuffer { |
| 34 | public: |
| 35 | // sPreset is used in places where we are referring to a pre-registered |
| 36 | // buffer on a port. It has type kBufferTypePreset and mRangeLength of 0. |
| 37 | static OMXBuffer sPreset; |
| 38 | |
| 39 | // Default constructor, constructs a buffer of type kBufferTypeInvalid. |
| 40 | OMXBuffer(); |
| 41 | |
| 42 | // Constructs a buffer of type kBufferTypePreset with mRangeLength set to |
| 43 | // |codecBuffer|'s size (or 0 if |codecBuffer| is NULL). |
| 44 | OMXBuffer(const sp<MediaCodecBuffer> &codecBuffer); |
| 45 | |
| 46 | // Constructs a buffer of type kBufferTypeSharedMem. |
| 47 | OMXBuffer(const sp<IMemory> &mem, size_t allottedSize = 0); |
| 48 | |
| 49 | // Constructs a buffer of type kBufferTypeANWBuffer. |
| 50 | OMXBuffer(const sp<GraphicBuffer> &gbuf); |
| 51 | |
| 52 | // Constructs a buffer of type kBufferTypeNativeHandle. |
| 53 | OMXBuffer(const sp<NativeHandle> &handle); |
| 54 | |
| 55 | // Parcelling/Un-parcelling. |
| 56 | status_t writeToParcel(Parcel *parcel) const; |
| 57 | status_t readFromParcel(const Parcel *parcel); |
| 58 | |
| 59 | ~OMXBuffer(); |
| 60 | |
| 61 | private: |
| 62 | friend class OMXNodeInstance; |
| 63 | |
| 64 | enum BufferType { |
| 65 | kBufferTypeInvalid = 0, |
| 66 | kBufferTypePreset, |
| 67 | kBufferTypeSharedMem, |
| 68 | kBufferTypeANWBuffer, |
| 69 | kBufferTypeNativeHandle, |
| 70 | }; |
| 71 | |
| 72 | BufferType mBufferType; |
| 73 | |
| 74 | // kBufferTypePreset |
| 75 | // If the port is operating in byte buffer mode, mRangeLength is the valid |
| 76 | // range length. Otherwise the range info should also be ignored. |
| 77 | OMX_U32 mRangeLength; |
| 78 | |
| 79 | // kBufferTypeSharedMem |
| 80 | sp<IMemory> mMem; |
| 81 | OMX_U32 mAllottedSize; |
| 82 | |
| 83 | // kBufferTypeANWBuffer |
| 84 | sp<GraphicBuffer> mGraphicBuffer; |
| 85 | |
| 86 | // kBufferTypeNativeHandle |
| 87 | sp<NativeHandle> mNativeHandle; |
| 88 | |
| 89 | OMXBuffer(const OMXBuffer &); |
| 90 | OMXBuffer &operator=(const OMXBuffer &); |
| 91 | }; |
| 92 | |
| 93 | } // namespace android |
| 94 | |
| 95 | #endif // _OMXBUFFER_H_ |