blob: 697823f41bf7452dc15a33ad0b3c637ad821b3b8 [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>
24
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);
38}}}}}
39
Chong Zhang3fd200f2016-10-07 17:25:58 -070040class GraphicBuffer;
41class IMemory;
42class MediaCodecBuffer;
43class NativeHandle;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080044struct OMXNodeInstance;
Chong Zhang3fd200f2016-10-07 17:25:58 -070045
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080046// TODO: After complete HIDL transition, this class would be replaced by
47// CodecBuffer.
Chong Zhang3fd200f2016-10-07 17:25:58 -070048class OMXBuffer {
49public:
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
61 // Constructs a buffer of type kBufferTypeSharedMem.
Chong Zhangd02c0862016-10-13 14:32:32 -070062 OMXBuffer(const sp<IMemory> &mem);
Chong Zhang3fd200f2016-10-07 17:25:58 -070063
64 // Constructs a buffer of type kBufferTypeANWBuffer.
65 OMXBuffer(const sp<GraphicBuffer> &gbuf);
66
67 // Constructs a buffer of type kBufferTypeNativeHandle.
68 OMXBuffer(const sp<NativeHandle> &handle);
69
70 // Parcelling/Un-parcelling.
71 status_t writeToParcel(Parcel *parcel) const;
72 status_t readFromParcel(const Parcel *parcel);
73
74 ~OMXBuffer();
75
76private:
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080077 friend struct OMXNodeInstance;
78
79 // This is needed temporarily for OMX HIDL transition.
80 friend inline bool (::android::hardware::media::omx::V1_0::implementation::
81 wrapAs)(::android::hardware::media::omx::V1_0::CodecBuffer* t,
82 OMXBuffer const& l);
83 friend inline bool (::android::hardware::media::omx::V1_0::implementation::
84 convertTo)(OMXBuffer* l,
85 ::android::hardware::media::omx::V1_0::CodecBuffer const& t);
Chong Zhang3fd200f2016-10-07 17:25:58 -070086
87 enum BufferType {
88 kBufferTypeInvalid = 0,
89 kBufferTypePreset,
90 kBufferTypeSharedMem,
91 kBufferTypeANWBuffer,
92 kBufferTypeNativeHandle,
93 };
94
95 BufferType mBufferType;
96
97 // kBufferTypePreset
98 // If the port is operating in byte buffer mode, mRangeLength is the valid
99 // range length. Otherwise the range info should also be ignored.
Chong Zhang49b2b4d2017-01-11 17:19:42 -0800100 OMX_U32 mRangeOffset;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700101 OMX_U32 mRangeLength;
102
103 // kBufferTypeSharedMem
104 sp<IMemory> mMem;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700105
106 // kBufferTypeANWBuffer
107 sp<GraphicBuffer> mGraphicBuffer;
108
109 // kBufferTypeNativeHandle
110 sp<NativeHandle> mNativeHandle;
111
Pawin Vongmasa517b0e02016-12-02 05:15:17 -0800112 // Move assignment
113 OMXBuffer &operator=(OMXBuffer&&);
114
115 // Deleted copy constructor and assignment.
116 OMXBuffer(const OMXBuffer&) = delete;
117 OMXBuffer& operator=(const OMXBuffer&) = delete;
Chong Zhang3fd200f2016-10-07 17:25:58 -0700118};
119
120} // namespace android
121
122#endif // _OMXBUFFER_H_