blob: f2d03f1762a18c4ae45df8c7ca0032098d5e4c53 [file] [log] [blame]
Wonsik Kim0b78afb2014-03-03 11:33:08 +09001/*
2 * Copyright 2014 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_TV_INPUT_INTERFACE_H
18#define ANDROID_TV_INPUT_INTERFACE_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
Wonsik Kimdce529a2014-04-01 11:34:33 +090025#include <system/window.h>
Wonsik Kim0b78afb2014-03-03 11:33:08 +090026
27__BEGIN_DECLS
28
29/*
30 * Module versioning information for the TV input hardware module, based on
31 * tv_input_module_t.common.module_api_version.
32 *
33 * Version History:
34 *
35 * TV_INPUT_MODULE_API_VERSION_0_1:
36 * Initial TV input hardware module API.
37 *
38 */
39
40#define TV_INPUT_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
41
42#define TV_INPUT_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
43
44/*
45 * The id of this module
46 */
47#define TV_INPUT_HARDWARE_MODULE_ID "tv_input"
48
49#define TV_INPUT_DEFAULT_DEVICE "default"
50
51/*****************************************************************************/
52
53/*
54 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
55 * and the fields of this data structure must begin with hw_module_t
56 * followed by module specific information.
57 */
58typedef struct tv_input_module {
59 struct hw_module_t common;
60} tv_input_module_t;
61
62/*****************************************************************************/
63
64typedef enum tv_input_type {
65 /* HDMI */
66 TV_INPUT_TYPE_HDMI = 1,
67
68 /* Built-in tuners. */
69 TV_INPUT_TYPE_BUILT_IN_TUNER = 2,
70
71 /* Passthrough */
72 TV_INPUT_TYPE_PASSTHROUGH = 3,
73} tv_input_type_t;
74
75typedef struct tv_input_device_info {
76 /* Device ID */
77 int device_id;
78
79 /* Type of physical TV input. */
80 tv_input_type_t type;
81
82 /*
83 * TODO: A union of type specific information. For example, HDMI port
84 * identifier that HDMI hardware understands.
85 */
86
87 /* TODO: Add capability if necessary. */
88
89 /* TODO: Audio info */
90} tv_input_device_info_t;
91
92typedef enum {
93 /*
94 * Hardware notifies the framework that a device is available.
95 */
96 TV_INPUT_EVENT_DEVICE_AVAILABLE = 1,
97 /*
98 * Hardware notifies the framework that a device is unavailable.
99 */
100 TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2,
101 /*
102 * Stream configurations are changed. Client should regard all open streams
103 * at the specific device are closed, and should call
104 * get_stream_configurations() again, opening some of them if necessary.
105 */
106 TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED = 3,
Wonsik Kimdce529a2014-04-01 11:34:33 +0900107 /*
108 * Hardware is done with capture request with the buffer. Client can assume
109 * ownership of the buffer again.
110 */
111 TV_INPUT_EVENT_CAPTURE_SUCCEEDED = 4,
112 /*
113 * Hardware met a failure while processing a capture request or client
114 * canceled the request. Client can assume ownership of the buffer again.
115 */
116 TV_INPUT_EVENT_CAPTURE_FAILED = 5,
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900117} tv_input_event_type_t;
118
Wonsik Kimdce529a2014-04-01 11:34:33 +0900119typedef struct tv_input_capture_result {
120 /* Device ID */
121 int device_id;
122
123 /* Stream ID */
124 int stream_id;
125
126 /* Sequence number of the request */
127 uint32_t seq;
128
129 /*
130 * The buffer passed to hardware in request_capture(). The content of
131 * buffer is undefined (although buffer itself is valid) for
132 * TV_INPUT_CAPTURE_FAILED event.
133 */
134 buffer_handle_t buffer;
135
136 /*
137 * Error code for the request. -ECANCELED if request is cancelled; other
138 * error codes are unknown errors.
139 */
140 int error_code;
141} tv_input_capture_result_t;
142
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900143typedef struct tv_input_event {
144 tv_input_event_type_t type;
145
146 union {
147 /*
148 * TV_INPUT_EVENT_DEVICE_AVAILABLE: all fields are relevant
149 * TV_INPUT_EVENT_DEVICE_UNAVAILABLE: only device_id is relevant
150 * TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED: only device_id is
151 * relevant
152 */
153 tv_input_device_info_t device_info;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900154 /*
155 * TV_INPUT_EVENT_CAPTURE_SUCCEEDED: error_code is not relevant
156 * TV_INPUT_EVENT_CAPTURE_FAILED: all fields are relevant
157 */
158 tv_input_capture_result_t capture_result;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900159 };
160} tv_input_event_t;
161
162typedef struct tv_input_callback_ops {
163 /*
164 * event contains the type of the event and additional data if necessary.
165 * The event object is guaranteed to be valid only for the duration of the
166 * call.
167 *
168 * data is an object supplied at device initialization, opaque to the
169 * hardware.
170     */
171 void (*notify)(struct tv_input_device* dev,
172 tv_input_event_t* event, void* data);
173} tv_input_callback_ops_t;
174
175typedef enum {
176 TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1,
Wonsik Kimdce529a2014-04-01 11:34:33 +0900177 TV_STREAM_TYPE_BUFFER_PRODUCER = 2,
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900178} tv_stream_type_t;
179
180typedef struct tv_stream_config {
181 /*
182 * ID number of the stream. This value is used to identify the whole stream
183 * configuration.
184 */
185 int stream_id;
186
187 /* Type of the stream */
188 tv_stream_type_t type;
189
190 /* Max width/height of the stream. */
191 uint32_t max_video_width;
192 uint32_t max_video_height;
193} tv_stream_config_t;
194
Wonsik Kimdce529a2014-04-01 11:34:33 +0900195typedef struct buffer_producer_stream {
196 /*
197 * IN/OUT: Width / height of the stream. Client may request for specific
198 * size but hardware may change it. Client must allocate buffers with
199 * specified width and height.
200 */
201 uint32_t width;
202 uint32_t height;
203
204 /* OUT: Client must set this usage when allocating buffer. */
205 uint32_t usage;
206
207 /* OUT: Client must allocate a buffer with this format. */
208 uint32_t format;
209} buffer_producer_stream_t;
210
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900211typedef struct tv_stream {
Wonsik Kimdce529a2014-04-01 11:34:33 +0900212 /* IN: ID in the stream configuration */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900213 int stream_id;
214
215 /* OUT: Type of the stream (for convenience) */
216 tv_stream_type_t type;
217
Wonsik Kimdce529a2014-04-01 11:34:33 +0900218 /* Data associated with the stream for client's use */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900219 union {
Wonsik Kimdce529a2014-04-01 11:34:33 +0900220 /* OUT: A native handle describing the sideband stream source */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900221 native_handle_t* sideband_stream_source_handle;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900222
223 /* IN/OUT: Details are in buffer_producer_stream_t */
224 buffer_producer_stream_t buffer_producer;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900225 };
226} tv_stream_t;
227
228/*
229 * Every device data structure must begin with hw_device_t
230 * followed by module specific public methods and attributes.
231 */
232typedef struct tv_input_device {
233 struct hw_device_t common;
234
235 /*
236 * initialize:
237 *
238 * Provide callbacks to the device and start operation. At first, no device
239 * is available and after initialize() completes, currently available
240 * devices including static devices should notify via callback.
241 *
242 * Framework owns callbacks object.
243 *
244 * data is a framework-owned object which would be sent back to the
245 * framework for each callback notifications.
246 *
247 * Return 0 on success.
248 */
249 int (*initialize)(struct tv_input_device* dev,
250 const tv_input_callback_ops_t* callback, void* data);
251
252 /*
253 * get_stream_configurations:
254 *
255 * Get stream configurations for a specific device. An input device may have
256 * multiple configurations.
257 *
258 * The configs object is guaranteed to be valid only until the next call to
259 * get_stream_configurations() or STREAM_CONFIGURATIONS_CHANGED event.
260 *
261 * Return 0 on success.
262 */
263 int (*get_stream_configurations)(const struct tv_input_device* dev,
264 int device_id, int* num_configurations,
265 const tv_stream_config_t** configs);
266
267 /*
268 * open_stream:
269 *
270 * Open a stream with given stream ID. Caller owns stream object, and the
271 * populated data is only valid until the stream is closed.
272 *
273 * Return 0 on success; -EBUSY if the client should close other streams to
274 * open the stream; -EEXIST if the stream with the given ID is already open;
275 * -EINVAL if device_id and/or stream_id are invalid; other non-zero value
276 * denotes unknown error.
277 */
278 int (*open_stream)(struct tv_input_device* dev, int device_id,
279 tv_stream_t* stream);
280
281 /*
282 * close_stream:
283 *
284 * Close a stream to a device. data in tv_stream_t* object associated with
285 * the stream_id is obsolete once this call finishes.
286 *
287 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
288 * device_id and/or stream_id are invalid.
289 */
290 int (*close_stream)(struct tv_input_device* dev, int device_id,
291 int stream_id);
292
293 /*
Wonsik Kimdce529a2014-04-01 11:34:33 +0900294 * request_capture:
295 *
296 * Request buffer capture for a stream. This is only valid for buffer
297 * producer streams. The buffer should be created with size, format and
298 * usage specified in the stream. Framework provides seq in an
299 * increasing sequence per each stream. Hardware should provide the picture
300 * in a chronological order according to seq. For example, if two
301 * requests are being processed at the same time, the request with the
302 * smaller seq should get an earlier frame.
303 *
304 * The framework releases the ownership of the buffer upon calling this
305 * function. When the buffer is filled, hardware notifies the framework
306 * via TV_INPUT_EVENT_CAPTURE_FINISHED callback, and the ownership is
307 * transferred back to framework at that time.
308 *
309 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
310 * device_id and/or stream_id are invalid; -EWOULDBLOCK if HAL cannot take
311 * additional requests until it releases a buffer.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900312 */
Wonsik Kimdce529a2014-04-01 11:34:33 +0900313 int (*request_capture)(struct tv_input_device* dev, int device_id,
314 int stream_id, buffer_handle_t buffer, uint32_t seq);
315
316 /*
317 * cancel_capture:
318 *
319 * Cancel an ongoing capture. Hardware should release the buffer as soon as
320 * possible via TV_INPUT_EVENT_CAPTURE_FAILED callback.
321 *
322 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
323 * device_id, stream_id, and/or seq are invalid.
324 */
325 int (*cancel_capture)(struct tv_input_device* dev, int device_id,
326 int stream_id, uint32_t seq);
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900327
328 void* reserved[16];
329} tv_input_device_t;
330
331__END_DECLS
332
333#endif // ANDROID_TV_INPUT_INTERFACE_H