blob: aeb17651e4543daba47defc4613de51998eb5b4e [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
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080061 // Constructs a buffer of type kBufferTypePreset with a specified
62 // mRangeLength.
63 explicit OMXBuffer(OMX_U32 rangeLength);
64
Chong Zhang3fd200f2016-10-07 17:25:58 -070065 // Constructs a buffer of type kBufferTypeSharedMem.
Chong Zhangd02c0862016-10-13 14:32:32 -070066 OMXBuffer(const sp<IMemory> &mem);
Chong Zhang3fd200f2016-10-07 17:25:58 -070067
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
80private:
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080081 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 Zhang3fd200f2016-10-07 17:25:58 -070090
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 Zhang3fd200f2016-10-07 17:25:58 -0700108
109 // kBufferTypeANWBuffer
110 sp<GraphicBuffer> mGraphicBuffer;
111
112 // kBufferTypeNativeHandle
113 sp<NativeHandle> mNativeHandle;
114
Pawin Vongmasa517b0e02016-12-02 05:15:17 -0800115 // 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 Zhang3fd200f2016-10-07 17:25:58 -0700121};
122
123} // namespace android
124
125#endif // _OMXBUFFER_H_