OMXNodeInstance.h revision 9f2d258645826c999a93a4206df157fec2e3b0f2
1/*
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;
29struct OMXMaster;
30
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
41    status_t freeNode(OMXMaster *master);
42
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
52    status_t useBuffer(
53            OMX_U32 portIndex, const sp<IMemory> &params,
54            OMX::buffer_id *buffer);
55
56    status_t allocateBuffer(
57            OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer,
58            void **buffer_data);
59
60    status_t allocateBufferWithBackup(
61            OMX_U32 portIndex, const sp<IMemory> &params,
62            OMX::buffer_id *buffer);
63
64    status_t freeBuffer(OMX_U32 portIndex, OMX::buffer_id buffer);
65
66    status_t fillBuffer(OMX::buffer_id buffer);
67
68    status_t emptyBuffer(
69            OMX::buffer_id buffer,
70            OMX_U32 rangeOffset, OMX_U32 rangeLength,
71            OMX_U32 flags, OMX_TICKS timestamp);
72
73    status_t getExtensionIndex(
74            const char *parameterName, OMX_INDEXTYPE *index);
75
76    void onMessage(const omx_message &msg);
77    void onObserverDied(OMXMaster *master);
78    void onGetHandleFailed();
79
80    static OMX_CALLBACKTYPE kCallbacks;
81
82private:
83    Mutex mLock;
84
85    OMX *mOwner;
86    OMX::node_id mNodeID;
87    OMX_HANDLETYPE mHandle;
88    sp<IOMXObserver> mObserver;
89    bool mDying;
90
91    struct ActiveBuffer {
92        OMX_U32 mPortIndex;
93        OMX::buffer_id mID;
94    };
95    Vector<ActiveBuffer> mActiveBuffers;
96
97    ~OMXNodeInstance();
98
99    void addActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id);
100    void removeActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id);
101    void freeActiveBuffers();
102
103    static OMX_ERRORTYPE OnEvent(
104            OMX_IN OMX_HANDLETYPE hComponent,
105            OMX_IN OMX_PTR pAppData,
106            OMX_IN OMX_EVENTTYPE eEvent,
107            OMX_IN OMX_U32 nData1,
108            OMX_IN OMX_U32 nData2,
109            OMX_IN OMX_PTR pEventData);
110
111    static OMX_ERRORTYPE OnEmptyBufferDone(
112            OMX_IN OMX_HANDLETYPE hComponent,
113            OMX_IN OMX_PTR pAppData,
114            OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);
115
116    static OMX_ERRORTYPE OnFillBufferDone(
117            OMX_IN OMX_HANDLETYPE hComponent,
118            OMX_IN OMX_PTR pAppData,
119            OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);
120
121    OMXNodeInstance(const OMXNodeInstance &);
122    OMXNodeInstance &operator=(const OMXNodeInstance &);
123};
124
125}  // namespace android
126
127#endif  // OMX_NODE_INSTANCE_H_
128
129