blob: 6f79182afd19f68ae523ffbbefc2dd988b7c9923 [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>
22#include <system/window.h>
23#include <utils/StrongPointer.h>
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070024#include <hidl/HidlSupport.h>
Chong Zhang3fd200f2016-10-07 17:25:58 -070025
26namespace android {
27
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080028class OMXBuffer;
29
30// This is needed temporarily for the OMX HIDL transition.
31namespace hardware { namespace media { namespace omx {
32namespace V1_0 {
33 struct CodecBuffer;
34namespace 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 Vongmasaeeac97b2017-01-18 05:03:07 -080039}
40namespace 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 Vongmasa517b0e02016-12-02 05:15:17 -080047
Chong Zhang3fd200f2016-10-07 17:25:58 -070048class GraphicBuffer;
49class IMemory;
50class MediaCodecBuffer;
51class NativeHandle;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080052struct OMXNodeInstance;
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070053using hardware::hidl_memory;
Chong Zhang3fd200f2016-10-07 17:25:58 -070054
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080055// TODO: After complete HIDL transition, this class would be replaced by
56// CodecBuffer.
Chong Zhang3fd200f2016-10-07 17:25:58 -070057class OMXBuffer {
58public:
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 Vongmasaf62ea802016-12-20 04:24:47 +070066 // 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 Zhang3fd200f2016-10-07 17:25:58 -070069 OMXBuffer(const sp<MediaCodecBuffer> &codecBuffer);
70
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070071 // Constructs a buffer of type kBufferTypePreset with specified mRangeOffset
72 // and mRangeLength.
73 OMXBuffer(OMX_U32 rangeOffset, OMX_U32 rangeLength);
74
Chong Zhang3fd200f2016-10-07 17:25:58 -070075 // Constructs a buffer of type kBufferTypeSharedMem.
Chong Zhangd02c0862016-10-13 14:32:32 -070076 OMXBuffer(const sp<IMemory> &mem);
Chong Zhang3fd200f2016-10-07 17:25:58 -070077
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 Vongmasaf62ea802016-12-20 04:24:47 +070084 // Constructs a buffer of type kBufferTypeHidlMemory.
85 OMXBuffer(const hidl_memory &hidlMemory);
86
Chong Zhang3fd200f2016-10-07 17:25:58 -070087 // Parcelling/Un-parcelling.
88 status_t writeToParcel(Parcel *parcel) const;
89 status_t readFromParcel(const Parcel *parcel);
90
91 ~OMXBuffer();
92
93private:
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080094 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 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
140 OMXBuffer &operator=(OMXBuffer&&);
141
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_