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