IOMX.h revision 8b938cdab5bd3d074d9b41bc2915fcfc11e47f27
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 <utils/List.h>
23#include <utils/String8.h>
24
25#include <OMX_Core.h>
26#include <OMX_Video.h>
27
28#define IOMX_USES_SOCKETS       0
29
30namespace android {
31
32class IMemory;
33class IOMXObserver;
34class IOMXRenderer;
35class ISurface;
36
37class IOMX : public IInterface {
38public:
39    DECLARE_META_INTERFACE(OMX);
40
41    typedef void *buffer_id;
42    typedef void *node_id;
43
44#if IOMX_USES_SOCKETS
45    // If successful, returns a socket descriptor used for further
46    // communication. Caller assumes ownership of "*sd".
47    virtual status_t connect(int *sd) = 0;
48#endif
49
50    virtual status_t list_nodes(List<String8> *list) = 0;
51
52    virtual status_t allocate_node(const char *name, node_id *node) = 0;
53    virtual status_t free_node(node_id node) = 0;
54
55    virtual status_t send_command(
56            node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
57
58    virtual status_t get_parameter(
59            node_id node, OMX_INDEXTYPE index,
60            void *params, size_t size) = 0;
61
62    virtual status_t set_parameter(
63            node_id node, OMX_INDEXTYPE index,
64            const void *params, size_t size) = 0;
65
66    virtual status_t use_buffer(
67            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
68            buffer_id *buffer) = 0;
69
70    virtual status_t allocate_buffer(
71            node_id node, OMX_U32 port_index, size_t size,
72            buffer_id *buffer) = 0;
73
74    virtual status_t allocate_buffer_with_backup(
75            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
76            buffer_id *buffer) = 0;
77
78    virtual status_t free_buffer(
79            node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
80
81#if !IOMX_USES_SOCKETS
82    virtual status_t observe_node(
83            node_id node, const sp<IOMXObserver> &observer) = 0;
84
85    virtual void fill_buffer(node_id node, buffer_id buffer) = 0;
86
87    virtual void empty_buffer(
88            node_id node,
89            buffer_id buffer,
90            OMX_U32 range_offset, OMX_U32 range_length,
91            OMX_U32 flags, OMX_TICKS timestamp) = 0;
92#endif
93
94    virtual sp<IOMXRenderer> createRenderer(
95            const sp<ISurface> &surface,
96            const char *componentName,
97            OMX_COLOR_FORMATTYPE colorFormat,
98            size_t encodedWidth, size_t encodedHeight,
99            size_t displayWidth, size_t displayHeight) = 0;
100};
101
102struct omx_message {
103    enum {
104        EVENT,
105        EMPTY_BUFFER_DONE,
106        FILL_BUFFER_DONE,
107
108#if IOMX_USES_SOCKETS
109        EMPTY_BUFFER,
110        FILL_BUFFER,
111        SEND_COMMAND,
112        DISCONNECT,
113        DISCONNECTED,
114#endif
115
116        // reserved for OMXDecoder use.
117        START,
118        INITIAL_FILL_BUFFER,
119
120        // reserved for OMXObserver use.
121        QUIT_OBSERVER,
122    } type;
123
124    union {
125        // if type == EVENT
126        struct {
127            IOMX::node_id node;
128            OMX_EVENTTYPE event;
129            OMX_U32 data1;
130            OMX_U32 data2;
131        } event_data;
132
133        // if type == EMPTY_BUFFER_DONE || type == FILL_BUFFER
134        //    || type == INITIAL_FILL_BUFFER
135        struct {
136            IOMX::node_id node;
137            IOMX::buffer_id buffer;
138        } buffer_data;
139
140        // if type == EMPTY_BUFFER || type == FILL_BUFFER_DONE
141        struct {
142            IOMX::node_id node;
143            IOMX::buffer_id buffer;
144            OMX_U32 range_offset;
145            OMX_U32 range_length;
146            OMX_U32 flags;
147            OMX_TICKS timestamp;
148            OMX_PTR platform_private;  // ignored if type == EMPTY_BUFFER
149        } extended_buffer_data;
150
151        // if type == SEND_COMMAND
152        struct {
153            IOMX::node_id node;
154            OMX_COMMANDTYPE cmd;
155            OMX_S32 param;
156        } send_command_data;
157
158    } u;
159};
160
161class IOMXObserver : public IInterface {
162public:
163    DECLARE_META_INTERFACE(OMXObserver);
164
165    virtual void on_message(const omx_message &msg) = 0;
166};
167
168class IOMXRenderer : public IInterface {
169public:
170    DECLARE_META_INTERFACE(OMXRenderer);
171
172    virtual void render(IOMX::buffer_id buffer) = 0;
173};
174
175////////////////////////////////////////////////////////////////////////////////
176
177class BnOMX : public BnInterface<IOMX> {
178public:
179    virtual status_t onTransact(
180            uint32_t code, const Parcel &data, Parcel *reply,
181            uint32_t flags = 0);
182};
183
184class BnOMXObserver : public BnInterface<IOMXObserver> {
185public:
186    virtual status_t onTransact(
187            uint32_t code, const Parcel &data, Parcel *reply,
188            uint32_t flags = 0);
189};
190
191class BnOMXRenderer : public BnInterface<IOMXRenderer> {
192public:
193    virtual status_t onTransact(
194            uint32_t code, const Parcel &data, Parcel *reply,
195            uint32_t flags = 0);
196};
197
198}  // namespace android
199
200#endif  // ANDROID_IOMX_H_
201