blob: 89b709cfd4a9f25612019a7996dc4b06744dde2f [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
27class GraphicBuffer;
28class IMemory;
29class MediaCodecBuffer;
30class NativeHandle;
31class OMXNodeInstance;
32
33class OMXBuffer {
34public:
35 // sPreset is used in places where we are referring to a pre-registered
36 // buffer on a port. It has type kBufferTypePreset and mRangeLength of 0.
37 static OMXBuffer sPreset;
38
39 // Default constructor, constructs a buffer of type kBufferTypeInvalid.
40 OMXBuffer();
41
42 // Constructs a buffer of type kBufferTypePreset with mRangeLength set to
43 // |codecBuffer|'s size (or 0 if |codecBuffer| is NULL).
44 OMXBuffer(const sp<MediaCodecBuffer> &codecBuffer);
45
46 // Constructs a buffer of type kBufferTypeSharedMem.
Chong Zhangd02c0862016-10-13 14:32:32 -070047 OMXBuffer(const sp<IMemory> &mem);
Chong Zhang3fd200f2016-10-07 17:25:58 -070048
49 // Constructs a buffer of type kBufferTypeANWBuffer.
50 OMXBuffer(const sp<GraphicBuffer> &gbuf);
51
52 // Constructs a buffer of type kBufferTypeNativeHandle.
53 OMXBuffer(const sp<NativeHandle> &handle);
54
55 // Parcelling/Un-parcelling.
56 status_t writeToParcel(Parcel *parcel) const;
57 status_t readFromParcel(const Parcel *parcel);
58
59 ~OMXBuffer();
60
61private:
62 friend class OMXNodeInstance;
63
64 enum BufferType {
65 kBufferTypeInvalid = 0,
66 kBufferTypePreset,
67 kBufferTypeSharedMem,
68 kBufferTypeANWBuffer,
69 kBufferTypeNativeHandle,
70 };
71
72 BufferType mBufferType;
73
74 // kBufferTypePreset
75 // If the port is operating in byte buffer mode, mRangeLength is the valid
76 // range length. Otherwise the range info should also be ignored.
77 OMX_U32 mRangeLength;
78
79 // kBufferTypeSharedMem
80 sp<IMemory> mMem;
Chong Zhang3fd200f2016-10-07 17:25:58 -070081
82 // kBufferTypeANWBuffer
83 sp<GraphicBuffer> mGraphicBuffer;
84
85 // kBufferTypeNativeHandle
86 sp<NativeHandle> mNativeHandle;
87
88 OMXBuffer(const OMXBuffer &);
89 OMXBuffer &operator=(const OMXBuffer &);
90};
91
92} // namespace android
93
94#endif // _OMXBUFFER_H_