blob: 8c7c562234c1fd80d46d28114a8a0bf35f82b58b [file] [log] [blame]
Andreas Huber784202e2009-10-15 13:46:54 -07001/*
2 * Copyright (C) 2009 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 OMX_NODE_INSTANCE_H_
18
19#define OMX_NODE_INSTANCE_H_
20
21#include "OMX.h"
22
23#include <utils/RefBase.h>
24#include <utils/threads.h>
25
26namespace android {
27
28class IOMXObserver;
Andreas Huberfef64352009-12-04 12:52:40 -080029struct OMXMaster;
Andreas Huber784202e2009-10-15 13:46:54 -070030
31struct OMXNodeInstance {
32 OMXNodeInstance(
33 OMX *owner, const sp<IOMXObserver> &observer);
34
35 void setHandle(OMX::node_id node_id, OMX_HANDLETYPE handle);
36
37 OMX *owner();
38 sp<IOMXObserver> observer();
39 OMX::node_id nodeID();
40
Andreas Huberfef64352009-12-04 12:52:40 -080041 status_t freeNode(OMXMaster *master);
Andreas Huber784202e2009-10-15 13:46:54 -070042
43 status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param);
44 status_t getParameter(OMX_INDEXTYPE index, void *params, size_t size);
45
46 status_t setParameter(
47 OMX_INDEXTYPE index, const void *params, size_t size);
48
49 status_t getConfig(OMX_INDEXTYPE index, void *params, size_t size);
50 status_t setConfig(OMX_INDEXTYPE index, const void *params, size_t size);
51
Jamie Gennis33a78142010-08-30 16:48:38 -070052 status_t enableGraphicBuffers(OMX_U32 portIndex, OMX_BOOL enable);
53
Andreas Huber784202e2009-10-15 13:46:54 -070054 status_t useBuffer(
55 OMX_U32 portIndex, const sp<IMemory> &params,
56 OMX::buffer_id *buffer);
57
Jamie Gennis33a78142010-08-30 16:48:38 -070058 status_t useGraphicBuffer(
59 OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer,
60 OMX::buffer_id *buffer);
61
Andreas Huber784202e2009-10-15 13:46:54 -070062 status_t allocateBuffer(
Andreas Huberc712b9f2010-01-20 15:05:46 -080063 OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer,
64 void **buffer_data);
Andreas Huber784202e2009-10-15 13:46:54 -070065
66 status_t allocateBufferWithBackup(
67 OMX_U32 portIndex, const sp<IMemory> &params,
68 OMX::buffer_id *buffer);
69
70 status_t freeBuffer(OMX_U32 portIndex, OMX::buffer_id buffer);
71
72 status_t fillBuffer(OMX::buffer_id buffer);
73
74 status_t emptyBuffer(
75 OMX::buffer_id buffer,
76 OMX_U32 rangeOffset, OMX_U32 rangeLength,
77 OMX_U32 flags, OMX_TICKS timestamp);
78
79 status_t getExtensionIndex(
80 const char *parameterName, OMX_INDEXTYPE *index);
81
82 void onMessage(const omx_message &msg);
Andreas Huberfef64352009-12-04 12:52:40 -080083 void onObserverDied(OMXMaster *master);
Andreas Huber784202e2009-10-15 13:46:54 -070084 void onGetHandleFailed();
85
86 static OMX_CALLBACKTYPE kCallbacks;
87
88private:
89 Mutex mLock;
90
91 OMX *mOwner;
92 OMX::node_id mNodeID;
93 OMX_HANDLETYPE mHandle;
94 sp<IOMXObserver> mObserver;
Andreas Huber2ea14e22009-12-16 09:30:55 -080095 bool mDying;
Andreas Huber784202e2009-10-15 13:46:54 -070096
Andreas Huber3085c832009-10-26 16:11:54 -070097 struct ActiveBuffer {
98 OMX_U32 mPortIndex;
99 OMX::buffer_id mID;
100 };
101 Vector<ActiveBuffer> mActiveBuffers;
102
Andreas Huber784202e2009-10-15 13:46:54 -0700103 ~OMXNodeInstance();
104
Andreas Huber3085c832009-10-26 16:11:54 -0700105 void addActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id);
106 void removeActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id);
107 void freeActiveBuffers();
108
Andreas Huber784202e2009-10-15 13:46:54 -0700109 static OMX_ERRORTYPE OnEvent(
110 OMX_IN OMX_HANDLETYPE hComponent,
111 OMX_IN OMX_PTR pAppData,
112 OMX_IN OMX_EVENTTYPE eEvent,
113 OMX_IN OMX_U32 nData1,
114 OMX_IN OMX_U32 nData2,
115 OMX_IN OMX_PTR pEventData);
116
117 static OMX_ERRORTYPE OnEmptyBufferDone(
118 OMX_IN OMX_HANDLETYPE hComponent,
119 OMX_IN OMX_PTR pAppData,
120 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);
121
122 static OMX_ERRORTYPE OnFillBufferDone(
123 OMX_IN OMX_HANDLETYPE hComponent,
124 OMX_IN OMX_PTR pAppData,
125 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);
126
127 OMXNodeInstance(const OMXNodeInstance &);
128 OMXNodeInstance &operator=(const OMXNodeInstance &);
129};
130
131} // namespace android
132
133#endif // OMX_NODE_INSTANCE_H_