IOMX.h revision e0f0b08aa692d15f3bfa19e10abfc84803c099b4
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
28namespace android {
29
30class IMemory;
31class IOMXObserver;
32class IOMXRenderer;
33class ISurface;
34class Surface;
35
36class IOMX : public IInterface {
37public:
38    DECLARE_META_INTERFACE(OMX);
39
40    typedef void *buffer_id;
41    typedef void *node_id;
42
43    virtual status_t list_nodes(List<String8> *list) = 0;
44
45    virtual status_t allocate_node(const char *name, node_id *node) = 0;
46    virtual status_t free_node(node_id node) = 0;
47
48    virtual status_t send_command(
49            node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
50
51    virtual status_t get_parameter(
52            node_id node, OMX_INDEXTYPE index,
53            void *params, size_t size) = 0;
54
55    virtual status_t set_parameter(
56            node_id node, OMX_INDEXTYPE index,
57            const void *params, size_t size) = 0;
58
59    virtual status_t get_config(
60            node_id node, OMX_INDEXTYPE index,
61            void *params, size_t size) = 0;
62
63    virtual status_t set_config(
64            node_id node, OMX_INDEXTYPE index,
65            const void *params, size_t size) = 0;
66
67    virtual status_t use_buffer(
68            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
69            buffer_id *buffer) = 0;
70
71    virtual status_t allocate_buffer(
72            node_id node, OMX_U32 port_index, size_t size,
73            buffer_id *buffer) = 0;
74
75    virtual status_t allocate_buffer_with_backup(
76            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
77            buffer_id *buffer) = 0;
78
79    virtual status_t free_buffer(
80            node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
81
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
93    virtual status_t get_extension_index(
94            node_id node,
95            const char *parameter_name,
96            OMX_INDEXTYPE *index) = 0;
97
98    virtual sp<IOMXRenderer> createRenderer(
99            const sp<ISurface> &surface,
100            const char *componentName,
101            OMX_COLOR_FORMATTYPE colorFormat,
102            size_t encodedWidth, size_t encodedHeight,
103            size_t displayWidth, size_t displayHeight) = 0;
104
105    // Note: This method is _not_ virtual, it exists as a wrapper around
106    // the virtual "createRenderer" method above facilitating extraction
107    // of the ISurface from a regular Surface.
108    sp<IOMXRenderer> createRenderer(
109            const sp<Surface> &surface,
110            const char *componentName,
111            OMX_COLOR_FORMATTYPE colorFormat,
112            size_t encodedWidth, size_t encodedHeight,
113            size_t displayWidth, size_t displayHeight);
114};
115
116struct omx_message {
117    enum {
118        EVENT,
119        EMPTY_BUFFER_DONE,
120        FILL_BUFFER_DONE,
121
122    } type;
123
124    IOMX::node_id node;
125
126    union {
127        // if type == EVENT
128        struct {
129            OMX_EVENTTYPE event;
130            OMX_U32 data1;
131            OMX_U32 data2;
132        } event_data;
133
134        // if type == EMPTY_BUFFER_DONE
135        struct {
136            IOMX::buffer_id buffer;
137        } buffer_data;
138
139        // if type == FILL_BUFFER_DONE
140        struct {
141            IOMX::buffer_id buffer;
142            OMX_U32 range_offset;
143            OMX_U32 range_length;
144            OMX_U32 flags;
145            OMX_TICKS timestamp;
146            OMX_PTR platform_private;
147        } extended_buffer_data;
148
149    } u;
150};
151
152class IOMXObserver : public IInterface {
153public:
154    DECLARE_META_INTERFACE(OMXObserver);
155
156    virtual void on_message(const omx_message &msg) = 0;
157};
158
159class IOMXRenderer : public IInterface {
160public:
161    DECLARE_META_INTERFACE(OMXRenderer);
162
163    virtual void render(IOMX::buffer_id buffer) = 0;
164};
165
166////////////////////////////////////////////////////////////////////////////////
167
168class BnOMX : public BnInterface<IOMX> {
169public:
170    virtual status_t onTransact(
171            uint32_t code, const Parcel &data, Parcel *reply,
172            uint32_t flags = 0);
173};
174
175class BnOMXObserver : public BnInterface<IOMXObserver> {
176public:
177    virtual status_t onTransact(
178            uint32_t code, const Parcel &data, Parcel *reply,
179            uint32_t flags = 0);
180};
181
182class BnOMXRenderer : public BnInterface<IOMXRenderer> {
183public:
184    virtual status_t onTransact(
185            uint32_t code, const Parcel &data, Parcel *reply,
186            uint32_t flags = 0);
187};
188
189}  // namespace android
190
191#endif  // ANDROID_IOMX_H_
192