IOMX.h revision abf471f9d25f7a3104c5723657e3c6c329f3f08c
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 ANDROID_IOMX_H_
18
19#define ANDROID_IOMX_H_
20
21#include <binder/IInterface.h>
22#include <ui/GraphicBuffer.h>
23#include <utils/List.h>
24#include <utils/String8.h>
25
26#include <OMX_Core.h>
27#include <OMX_Video.h>
28
29#include "jni.h"
30
31namespace android {
32
33class IMemory;
34class IOMXObserver;
35class IOMXRenderer;
36class Surface;
37
38class IOMX : public IInterface {
39public:
40    DECLARE_META_INTERFACE(OMX);
41
42    typedef void *buffer_id;
43    typedef void *node_id;
44
45    // Given the calling process' pid, returns true iff
46    // the implementation of the OMX interface lives in the same
47    // process.
48    virtual bool livesLocally(pid_t pid) = 0;
49
50    struct ComponentInfo {
51        String8 mName;
52        List<String8> mRoles;
53    };
54    virtual status_t listNodes(List<ComponentInfo> *list) = 0;
55
56    virtual status_t allocateNode(
57            const char *name, const sp<IOMXObserver> &observer,
58            node_id *node) = 0;
59
60    virtual status_t freeNode(node_id node) = 0;
61
62    virtual status_t sendCommand(
63            node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
64
65    virtual status_t getParameter(
66            node_id node, OMX_INDEXTYPE index,
67            void *params, size_t size) = 0;
68
69    virtual status_t setParameter(
70            node_id node, OMX_INDEXTYPE index,
71            const void *params, size_t size) = 0;
72
73    virtual status_t getConfig(
74            node_id node, OMX_INDEXTYPE index,
75            void *params, size_t size) = 0;
76
77    virtual status_t setConfig(
78            node_id node, OMX_INDEXTYPE index,
79            const void *params, size_t size) = 0;
80
81    virtual status_t storeMetaDataInBuffers(
82            node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
83
84    virtual status_t enableGraphicBuffers(
85            node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
86
87    virtual status_t getGraphicBufferUsage(
88            node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
89
90    virtual status_t useBuffer(
91            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
92            buffer_id *buffer) = 0;
93
94    virtual status_t useGraphicBuffer(
95            node_id node, OMX_U32 port_index,
96            const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
97
98    // This API clearly only makes sense if the caller lives in the
99    // same process as the callee, i.e. is the media_server, as the
100    // returned "buffer_data" pointer is just that, a pointer into local
101    // address space.
102    virtual status_t allocateBuffer(
103            node_id node, OMX_U32 port_index, size_t size,
104            buffer_id *buffer, void **buffer_data) = 0;
105
106    virtual status_t allocateBufferWithBackup(
107            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
108            buffer_id *buffer) = 0;
109
110    virtual status_t freeBuffer(
111            node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
112
113    virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
114
115    virtual status_t emptyBuffer(
116            node_id node,
117            buffer_id buffer,
118            OMX_U32 range_offset, OMX_U32 range_length,
119            OMX_U32 flags, OMX_TICKS timestamp) = 0;
120
121    virtual status_t getExtensionIndex(
122            node_id node,
123            const char *parameter_name,
124            OMX_INDEXTYPE *index) = 0;
125};
126
127struct omx_message {
128    enum {
129        EVENT,
130        EMPTY_BUFFER_DONE,
131        FILL_BUFFER_DONE,
132
133    } type;
134
135    IOMX::node_id node;
136
137    union {
138        // if type == EVENT
139        struct {
140            OMX_EVENTTYPE event;
141            OMX_U32 data1;
142            OMX_U32 data2;
143        } event_data;
144
145        // if type == EMPTY_BUFFER_DONE
146        struct {
147            IOMX::buffer_id buffer;
148        } buffer_data;
149
150        // if type == FILL_BUFFER_DONE
151        struct {
152            IOMX::buffer_id buffer;
153            OMX_U32 range_offset;
154            OMX_U32 range_length;
155            OMX_U32 flags;
156            OMX_TICKS timestamp;
157            OMX_PTR platform_private;
158            OMX_PTR data_ptr;
159        } extended_buffer_data;
160
161    } u;
162};
163
164class IOMXObserver : public IInterface {
165public:
166    DECLARE_META_INTERFACE(OMXObserver);
167
168    virtual void onMessage(const omx_message &msg) = 0;
169};
170
171////////////////////////////////////////////////////////////////////////////////
172
173class BnOMX : public BnInterface<IOMX> {
174public:
175    virtual status_t onTransact(
176            uint32_t code, const Parcel &data, Parcel *reply,
177            uint32_t flags = 0);
178};
179
180class BnOMXObserver : public BnInterface<IOMXObserver> {
181public:
182    virtual status_t onTransact(
183            uint32_t code, const Parcel &data, Parcel *reply,
184            uint32_t flags = 0);
185};
186
187}  // namespace android
188
189#endif  // ANDROID_IOMX_H_
190