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