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