blob: b4b9284b6d7de2861e80360a56206b3d2531507c [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);
39}}}}}
40
Chong Zhang3fd200f2016-10-07 17:25:58 -070041class GraphicBuffer;
42class IMemory;
43class MediaCodecBuffer;
44class NativeHandle;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080045struct OMXNodeInstance;
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070046using hardware::hidl_memory;
Chong Zhang3fd200f2016-10-07 17:25:58 -070047
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080048// TODO: After complete HIDL transition, this class would be replaced by
49// CodecBuffer.
Chong Zhang3fd200f2016-10-07 17:25:58 -070050class OMXBuffer {
51public:
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 Vongmasaf62ea802016-12-20 04:24:47 +070059 // 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 Zhang3fd200f2016-10-07 17:25:58 -070062 OMXBuffer(const sp<MediaCodecBuffer> &codecBuffer);
63
Pawin Vongmasaf62ea802016-12-20 04:24:47 +070064 // Constructs a buffer of type kBufferTypePreset with specified mRangeOffset
65 // and mRangeLength.
66 OMXBuffer(OMX_U32 rangeOffset, OMX_U32 rangeLength);
67
Chong Zhang3fd200f2016-10-07 17:25:58 -070068 // Constructs a buffer of type kBufferTypeSharedMem.
Chong Zhangd02c0862016-10-13 14:32:32 -070069 OMXBuffer(const sp<IMemory> &mem);
Chong Zhang3fd200f2016-10-07 17:25:58 -070070
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 Vongmasaf62ea802016-12-20 04:24:47 +070077 // Constructs a buffer of type kBufferTypeHidlMemory.
78 OMXBuffer(const hidl_memory &hidlMemory);
79
Chong Zhang3fd200f2016-10-07 17:25:58 -070080 // Parcelling/Un-parcelling.
81 status_t writeToParcel(Parcel *parcel) const;
82 status_t readFromParcel(const Parcel *parcel);
83
84 ~OMXBuffer();
85
86private:
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080087 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 Zhang3fd200f2016-10-07 17:25:58 -070096
97 enum BufferType {
98 kBufferTypeInvalid = 0,
99 kBufferTypePreset,
100 kBufferTypeSharedMem,
Pawin Vongmasaf62ea802016-12-20 04:24:47 +0700101 kBufferTypeANWBuffer, // Use only for non-Treble
Chong Zhang3fd200f2016-10-07 17:25:58 -0700102 kBufferTypeNativeHandle,
Pawin Vongmasaf62ea802016-12-20 04:24:47 +0700103 kBufferTypeHidlMemory // Mapped to CodecBuffer::Type::SHARED_MEM.
Chong Zhang3fd200f2016-10-07 17:25:58 -0700104 };
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 Zhang49b2b4d2017-01-11 17:19:42 -0800111 OMX_U32 mRangeOffset;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700112 OMX_U32 mRangeLength;
113
114 // kBufferTypeSharedMem
115 sp<IMemory> mMem;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700116
117 // kBufferTypeANWBuffer
118 sp<GraphicBuffer> mGraphicBuffer;
119
120 // kBufferTypeNativeHandle
121 sp<NativeHandle> mNativeHandle;
122
Pawin Vongmasaf62ea802016-12-20 04:24:47 +0700123 // kBufferTypeHidlMemory
124 hidl_memory mHidlMemory;
125
Pawin Vongmasa517b0e02016-12-02 05:15:17 -0800126 // 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 Zhang3fd200f2016-10-07 17:25:58 -0700132};
133
134} // namespace android
135
136#endif // _OMXBUFFER_H_