blob: 4abe9e603f593acb688971abc4694ffe65e5e294 [file] [log] [blame]
Chong Zhang3fd200f2016-10-07 17:25:58 -07001/*
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>
Chong Zhang3fd200f2016-10-07 17:25:58 -070022#include <utils/StrongPointer.h>
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070023#include <hidl/HidlSupport.h>
Chong Zhang3fd200f2016-10-07 17:25:58 -070024
25namespace android {
26
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080027class OMXBuffer;
28
29// This is needed temporarily for the OMX HIDL transition.
30namespace hardware { namespace media { namespace omx {
31namespace V1_0 {
32 struct CodecBuffer;
33namespace 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);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080038}
39namespace utils {
40 inline bool wrapAs(::android::hardware::media::omx::V1_0::CodecBuffer* t,
41 ::android::OMXBuffer const& l);
42 inline bool convertTo(::android::OMXBuffer* l,
43 ::android::hardware::media::omx::V1_0::CodecBuffer const& t);
44}
45}}}}
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080046
Chong Zhang3fd200f2016-10-07 17:25:58 -070047class GraphicBuffer;
48class IMemory;
49class MediaCodecBuffer;
50class NativeHandle;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080051struct OMXNodeInstance;
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070052using hardware::hidl_memory;
Chong Zhang3fd200f2016-10-07 17:25:58 -070053
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080054// TODO: After complete HIDL transition, this class would be replaced by
55// CodecBuffer.
Chong Zhang3fd200f2016-10-07 17:25:58 -070056class OMXBuffer {
57public:
58 // sPreset is used in places where we are referring to a pre-registered
59 // buffer on a port. It has type kBufferTypePreset and mRangeLength of 0.
60 static OMXBuffer sPreset;
61
62 // Default constructor, constructs a buffer of type kBufferTypeInvalid.
63 OMXBuffer();
64
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070065 // Constructs a buffer of type kBufferTypePreset with mRangeOffset set to
66 // |codecBuffer|'s offset and mRangeLength set to |codecBuffer|'s size (or 0
67 // if |codecBuffer| is NULL).
Chong Zhang3fd200f2016-10-07 17:25:58 -070068 OMXBuffer(const sp<MediaCodecBuffer> &codecBuffer);
69
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070070 // Constructs a buffer of type kBufferTypePreset with specified mRangeOffset
71 // and mRangeLength.
72 OMXBuffer(OMX_U32 rangeOffset, OMX_U32 rangeLength);
73
Chong Zhang3fd200f2016-10-07 17:25:58 -070074 // Constructs a buffer of type kBufferTypeSharedMem.
Chong Zhangd02c0862016-10-13 14:32:32 -070075 OMXBuffer(const sp<IMemory> &mem);
Chong Zhang3fd200f2016-10-07 17:25:58 -070076
77 // Constructs a buffer of type kBufferTypeANWBuffer.
78 OMXBuffer(const sp<GraphicBuffer> &gbuf);
79
80 // Constructs a buffer of type kBufferTypeNativeHandle.
81 OMXBuffer(const sp<NativeHandle> &handle);
82
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070083 // Constructs a buffer of type kBufferTypeHidlMemory.
84 OMXBuffer(const hidl_memory &hidlMemory);
85
Chong Zhang3fd200f2016-10-07 17:25:58 -070086 // Parcelling/Un-parcelling.
87 status_t writeToParcel(Parcel *parcel) const;
88 status_t readFromParcel(const Parcel *parcel);
89
90 ~OMXBuffer();
91
92private:
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080093 friend struct OMXNodeInstance;
Wonsik Kimdc310172018-01-30 16:51:07 -080094 friend struct C2OMXNode;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080095
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 Vongmasaeeac97b2017-01-18 05:03:07 -0800103 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 Zhang3fd200f2016-10-07 17:25:58 -0700109
110 enum BufferType {
111 kBufferTypeInvalid = 0,
112 kBufferTypePreset,
113 kBufferTypeSharedMem,
Pawin Vongmasaf62ea802016-12-20 04:24:47 +0700114 kBufferTypeANWBuffer, // Use only for non-Treble
Chong Zhang3fd200f2016-10-07 17:25:58 -0700115 kBufferTypeNativeHandle,
Pawin Vongmasaf62ea802016-12-20 04:24:47 +0700116 kBufferTypeHidlMemory // Mapped to CodecBuffer::Type::SHARED_MEM.
Chong Zhang3fd200f2016-10-07 17:25:58 -0700117 };
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 Zhang49b2b4d2017-01-11 17:19:42 -0800124 OMX_U32 mRangeOffset;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700125 OMX_U32 mRangeLength;
126
127 // kBufferTypeSharedMem
128 sp<IMemory> mMem;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700129
130 // kBufferTypeANWBuffer
131 sp<GraphicBuffer> mGraphicBuffer;
132
133 // kBufferTypeNativeHandle
134 sp<NativeHandle> mNativeHandle;
135
Pawin Vongmasaf62ea802016-12-20 04:24:47 +0700136 // kBufferTypeHidlMemory
137 hidl_memory mHidlMemory;
138
Pawin Vongmasa517b0e02016-12-02 05:15:17 -0800139 // Move assignment
Chih-Hung Hsiehcf8d9b42018-09-25 14:02:02 -0700140 OMXBuffer &operator=(OMXBuffer&&) noexcept;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -0800141
142 // Deleted copy constructor and assignment.
143 OMXBuffer(const OMXBuffer&) = delete;
144 OMXBuffer& operator=(const OMXBuffer&) = delete;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700145};
146
147} // namespace android
148
149#endif // _OMXBUFFER_H_