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> |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 24 | #include <hidl/HidlSupport.h> |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
Pawin Vongmasa | 517b0e0 | 2016-12-02 05:15:17 -0800 | [diff] [blame] | 28 | class OMXBuffer; |
| 29 | |
| 30 | // This is needed temporarily for the OMX HIDL transition. |
| 31 | namespace hardware { namespace media { namespace omx { |
| 32 | namespace V1_0 { |
| 33 | struct CodecBuffer; |
| 34 | namespace implementation { |
| 35 | inline bool wrapAs(::android::hardware::media::omx::V1_0::CodecBuffer* t, |
| 36 | ::android::OMXBuffer const& l); |
| 37 | inline bool convertTo(::android::OMXBuffer* l, |
| 38 | ::android::hardware::media::omx::V1_0::CodecBuffer const& t); |
| 39 | }}}}} |
| 40 | |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 41 | class GraphicBuffer; |
| 42 | class IMemory; |
| 43 | class MediaCodecBuffer; |
| 44 | class NativeHandle; |
Pawin Vongmasa | 517b0e0 | 2016-12-02 05:15:17 -0800 | [diff] [blame] | 45 | struct OMXNodeInstance; |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 46 | using hardware::hidl_memory; |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 47 | |
Pawin Vongmasa | 517b0e0 | 2016-12-02 05:15:17 -0800 | [diff] [blame] | 48 | // TODO: After complete HIDL transition, this class would be replaced by |
| 49 | // CodecBuffer. |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 50 | class OMXBuffer { |
| 51 | public: |
| 52 | // sPreset is used in places where we are referring to a pre-registered |
| 53 | // buffer on a port. It has type kBufferTypePreset and mRangeLength of 0. |
| 54 | static OMXBuffer sPreset; |
| 55 | |
| 56 | // Default constructor, constructs a buffer of type kBufferTypeInvalid. |
| 57 | OMXBuffer(); |
| 58 | |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 59 | // Constructs a buffer of type kBufferTypePreset with mRangeOffset set to |
| 60 | // |codecBuffer|'s offset and mRangeLength set to |codecBuffer|'s size (or 0 |
| 61 | // if |codecBuffer| is NULL). |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 62 | OMXBuffer(const sp<MediaCodecBuffer> &codecBuffer); |
| 63 | |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 64 | // Constructs a buffer of type kBufferTypePreset with specified mRangeOffset |
| 65 | // and mRangeLength. |
| 66 | OMXBuffer(OMX_U32 rangeOffset, OMX_U32 rangeLength); |
| 67 | |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 68 | // Constructs a buffer of type kBufferTypeSharedMem. |
Chong Zhang | d02c086 | 2016-10-13 14:32:32 -0700 | [diff] [blame] | 69 | OMXBuffer(const sp<IMemory> &mem); |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 70 | |
| 71 | // Constructs a buffer of type kBufferTypeANWBuffer. |
| 72 | OMXBuffer(const sp<GraphicBuffer> &gbuf); |
| 73 | |
| 74 | // Constructs a buffer of type kBufferTypeNativeHandle. |
| 75 | OMXBuffer(const sp<NativeHandle> &handle); |
| 76 | |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 77 | // Constructs a buffer of type kBufferTypeHidlMemory. |
| 78 | OMXBuffer(const hidl_memory &hidlMemory); |
| 79 | |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 80 | // Parcelling/Un-parcelling. |
| 81 | status_t writeToParcel(Parcel *parcel) const; |
| 82 | status_t readFromParcel(const Parcel *parcel); |
| 83 | |
| 84 | ~OMXBuffer(); |
| 85 | |
| 86 | private: |
Pawin Vongmasa | 517b0e0 | 2016-12-02 05:15:17 -0800 | [diff] [blame] | 87 | friend struct OMXNodeInstance; |
| 88 | |
| 89 | // This is needed temporarily for OMX HIDL transition. |
| 90 | friend inline bool (::android::hardware::media::omx::V1_0::implementation:: |
| 91 | wrapAs)(::android::hardware::media::omx::V1_0::CodecBuffer* t, |
| 92 | OMXBuffer const& l); |
| 93 | friend inline bool (::android::hardware::media::omx::V1_0::implementation:: |
| 94 | convertTo)(OMXBuffer* l, |
| 95 | ::android::hardware::media::omx::V1_0::CodecBuffer const& t); |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 96 | |
| 97 | enum BufferType { |
| 98 | kBufferTypeInvalid = 0, |
| 99 | kBufferTypePreset, |
| 100 | kBufferTypeSharedMem, |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 101 | kBufferTypeANWBuffer, // Use only for non-Treble |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 102 | kBufferTypeNativeHandle, |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 103 | kBufferTypeHidlMemory // Mapped to CodecBuffer::Type::SHARED_MEM. |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | BufferType mBufferType; |
| 107 | |
| 108 | // kBufferTypePreset |
| 109 | // If the port is operating in byte buffer mode, mRangeLength is the valid |
| 110 | // range length. Otherwise the range info should also be ignored. |
Chong Zhang | 49b2b4d | 2017-01-11 17:19:42 -0800 | [diff] [blame] | 111 | OMX_U32 mRangeOffset; |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 112 | OMX_U32 mRangeLength; |
| 113 | |
| 114 | // kBufferTypeSharedMem |
| 115 | sp<IMemory> mMem; |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 116 | |
| 117 | // kBufferTypeANWBuffer |
| 118 | sp<GraphicBuffer> mGraphicBuffer; |
| 119 | |
| 120 | // kBufferTypeNativeHandle |
| 121 | sp<NativeHandle> mNativeHandle; |
| 122 | |
Pawin Vongmasa | f62ea80 | 2016-12-20 04:24:47 +0700 | [diff] [blame^] | 123 | // kBufferTypeHidlMemory |
| 124 | hidl_memory mHidlMemory; |
| 125 | |
Pawin Vongmasa | 517b0e0 | 2016-12-02 05:15:17 -0800 | [diff] [blame] | 126 | // Move assignment |
| 127 | OMXBuffer &operator=(OMXBuffer&&); |
| 128 | |
| 129 | // Deleted copy constructor and assignment. |
| 130 | OMXBuffer(const OMXBuffer&) = delete; |
| 131 | OMXBuffer& operator=(const OMXBuffer&) = delete; |
Chong Zhang | 3fd200f | 2016-10-07 17:25:58 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | } // namespace android |
| 135 | |
| 136 | #endif // _OMXBUFFER_H_ |