blob: 3bb986260db657d98b9b060630796db1636ddd0b [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 Kim8b5714f2014-05-23 17:22:04 +090025#include <system/audio.h>
Wonsik Kimdce529a2014-04-01 11:34:33 +090026#include <system/window.h>
Wonsik Kim0b78afb2014-03-03 11:33:08 +090027
28__BEGIN_DECLS
29
30/*
31 * Module versioning information for the TV input hardware module, based on
32 * tv_input_module_t.common.module_api_version.
33 *
34 * Version History:
35 *
Wonsik Kimd15399e2015-11-26 11:56:46 +090036 * TV_INPUT_DEVICE_API_VERSION_0_1:
37 * Initial TV input hardware device API.
38 *
39 * TV_INPUT_DEVICE_API_VERSION_0_2:
40 * Minor revision --- add video detection flag in stream configs.
Wonsik Kim0b78afb2014-03-03 11:33:08 +090041 *
42 */
43
44#define TV_INPUT_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
45
46#define TV_INPUT_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
Wonsik Kimd15399e2015-11-26 11:56:46 +090047#define TV_INPUT_DEVICE_API_VERSION_0_2 HARDWARE_DEVICE_API_VERSION(0, 2)
Wonsik Kim0b78afb2014-03-03 11:33:08 +090048
49/*
50 * The id of this module
51 */
52#define TV_INPUT_HARDWARE_MODULE_ID "tv_input"
53
54#define TV_INPUT_DEFAULT_DEVICE "default"
55
56/*****************************************************************************/
57
58/*
59 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
60 * and the fields of this data structure must begin with hw_module_t
61 * followed by module specific information.
62 */
63typedef struct tv_input_module {
64 struct hw_module_t common;
65} tv_input_module_t;
66
67/*****************************************************************************/
68
Wonsik Kim45849fb2014-06-12 14:52:39 +090069enum {
Wonsik Kim962e9ad2014-07-19 16:01:57 +090070 /* Generic hardware. */
71 TV_INPUT_TYPE_OTHER_HARDWARE = 1,
72 /* Tuner. (e.g. built-in terrestrial tuner) */
73 TV_INPUT_TYPE_TUNER = 2,
74 TV_INPUT_TYPE_COMPOSITE = 3,
75 TV_INPUT_TYPE_SVIDEO = 4,
76 TV_INPUT_TYPE_SCART = 5,
77 TV_INPUT_TYPE_COMPONENT = 6,
78 TV_INPUT_TYPE_VGA = 7,
79 TV_INPUT_TYPE_DVI = 8,
80 /* Physical HDMI port. (e.g. HDMI 1) */
81 TV_INPUT_TYPE_HDMI = 9,
82 TV_INPUT_TYPE_DISPLAY_PORT = 10,
Wonsik Kim45849fb2014-06-12 14:52:39 +090083};
84typedef uint32_t tv_input_type_t;
Wonsik Kim0b78afb2014-03-03 11:33:08 +090085
86typedef struct tv_input_device_info {
87 /* Device ID */
88 int device_id;
89
90 /* Type of physical TV input. */
91 tv_input_type_t type;
92
Wonsik Kim45849fb2014-06-12 14:52:39 +090093 union {
94 struct {
95 /* HDMI port ID number */
96 uint32_t port_id;
97 } hdmi;
98
99 /* TODO: add other type specific information. */
100
101 int32_t type_info_reserved[16];
102 };
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900103
104 /* TODO: Add capability if necessary. */
105
Wonsik Kim8b5714f2014-05-23 17:22:04 +0900106 /*
107 * Audio info
108 *
109 * audio_type == AUDIO_DEVICE_NONE if this input has no audio.
110 */
111 audio_devices_t audio_type;
Wonsik Kim45849fb2014-06-12 14:52:39 +0900112 const char* audio_address;
113
114 int32_t reserved[16];
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900115} tv_input_device_info_t;
116
Wonsik Kimfbb44122014-10-20 16:15:15 +0900117/* See tv_input_event_t for more details. */
Wonsik Kim45849fb2014-06-12 14:52:39 +0900118enum {
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900119 /*
120 * Hardware notifies the framework that a device is available.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900121 *
122 * Note that DEVICE_AVAILABLE and DEVICE_UNAVAILABLE events do not represent
123 * hotplug events (i.e. plugging cable into or out of the physical port).
124 * These events notify the framework whether the port is available or not.
125 * For a concrete example, when a user plugs in or pulls out the HDMI cable
126 * from a HDMI port, it does not generate DEVICE_AVAILABLE and/or
127 * DEVICE_UNAVAILABLE events. However, if a user inserts a pluggable USB
128 * tuner into the Android device, it will generate a DEVICE_AVAILABLE event
129 * and when the port is removed, it should generate a DEVICE_UNAVAILABLE
130 * event.
131 *
132 * For hotplug events, please see STREAM_CONFIGURATION_CHANGED for more
133 * details.
134 *
135 * HAL implementation should register devices by using this event when the
136 * device boots up. The framework will recognize device reported via this
137 * event only. In addition, the implementation could use this event to
138 * notify the framework that a removable TV input device (such as USB tuner
139 * as stated in the example above) is attached.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900140 */
141 TV_INPUT_EVENT_DEVICE_AVAILABLE = 1,
142 /*
143 * Hardware notifies the framework that a device is unavailable.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900144 *
145 * HAL implementation should generate this event when a device registered
146 * by TV_INPUT_EVENT_DEVICE_AVAILABLE is no longer available. For example,
147 * the event can indicate that a USB tuner is plugged out from the Android
148 * device.
149 *
150 * Note that this event is not for indicating cable plugged out of the port;
151 * for that purpose, the implementation should use
152 * STREAM_CONFIGURATION_CHANGED event. This event represents the port itself
153 * being no longer available.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900154 */
155 TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2,
156 /*
157 * Stream configurations are changed. Client should regard all open streams
158 * at the specific device are closed, and should call
159 * get_stream_configurations() again, opening some of them if necessary.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900160 *
161 * HAL implementation should generate this event when the available stream
162 * configurations change for any reason. A typical use case of this event
163 * would be to notify the framework that the input signal has changed
164 * resolution, or that the cable is plugged out so that the number of
165 * available streams is 0.
166 *
167 * The implementation may use this event to indicate hotplug status of the
168 * port. the framework regards input devices with no available streams as
169 * disconnected, so the implementation can generate this event with no
170 * available streams to indicate that this device is disconnected, and vice
Wonsik Kimd15399e2015-11-26 11:56:46 +0900171 * versa. In addition, streams have signal detection flag to denote if
172 * signal is detected for sure.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900173 */
174 TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED = 3,
Wonsik Kimdce529a2014-04-01 11:34:33 +0900175 /*
176 * Hardware is done with capture request with the buffer. Client can assume
177 * ownership of the buffer again.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900178 *
179 * HAL implementation should generate this event after request_capture() if
180 * it succeeded. The event shall have the buffer with the captured image.
Wonsik Kimdce529a2014-04-01 11:34:33 +0900181 */
182 TV_INPUT_EVENT_CAPTURE_SUCCEEDED = 4,
183 /*
184 * Hardware met a failure while processing a capture request or client
185 * canceled the request. Client can assume ownership of the buffer again.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900186 *
187 * The event is similar to TV_INPUT_EVENT_CAPTURE_SUCCEEDED, but HAL
188 * implementation generates this event upon a failure to process
189 * request_capture(), or a request cancellation.
Wonsik Kimdce529a2014-04-01 11:34:33 +0900190 */
191 TV_INPUT_EVENT_CAPTURE_FAILED = 5,
Wonsik Kim45849fb2014-06-12 14:52:39 +0900192};
193typedef uint32_t tv_input_event_type_t;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900194
Wonsik Kimdce529a2014-04-01 11:34:33 +0900195typedef struct tv_input_capture_result {
196 /* Device ID */
197 int device_id;
198
199 /* Stream ID */
200 int stream_id;
201
202 /* Sequence number of the request */
203 uint32_t seq;
204
205 /*
206 * The buffer passed to hardware in request_capture(). The content of
207 * buffer is undefined (although buffer itself is valid) for
208 * TV_INPUT_CAPTURE_FAILED event.
209 */
210 buffer_handle_t buffer;
211
212 /*
213 * Error code for the request. -ECANCELED if request is cancelled; other
214 * error codes are unknown errors.
215 */
216 int error_code;
217} tv_input_capture_result_t;
218
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900219typedef struct tv_input_event {
220 tv_input_event_type_t type;
221
222 union {
223 /*
224 * TV_INPUT_EVENT_DEVICE_AVAILABLE: all fields are relevant
225 * TV_INPUT_EVENT_DEVICE_UNAVAILABLE: only device_id is relevant
226 * TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED: only device_id is
227 * relevant
228 */
229 tv_input_device_info_t device_info;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900230 /*
231 * TV_INPUT_EVENT_CAPTURE_SUCCEEDED: error_code is not relevant
232 * TV_INPUT_EVENT_CAPTURE_FAILED: all fields are relevant
233 */
234 tv_input_capture_result_t capture_result;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900235 };
236} tv_input_event_t;
237
238typedef struct tv_input_callback_ops {
239 /*
240 * event contains the type of the event and additional data if necessary.
241 * The event object is guaranteed to be valid only for the duration of the
242 * call.
243 *
244 * data is an object supplied at device initialization, opaque to the
245 * hardware.
246     */
247 void (*notify)(struct tv_input_device* dev,
248 tv_input_event_t* event, void* data);
249} tv_input_callback_ops_t;
250
Wonsik Kim45849fb2014-06-12 14:52:39 +0900251enum {
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900252 TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1,
Wonsik Kimdce529a2014-04-01 11:34:33 +0900253 TV_STREAM_TYPE_BUFFER_PRODUCER = 2,
Wonsik Kim45849fb2014-06-12 14:52:39 +0900254};
255typedef uint32_t tv_stream_type_t;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900256
257typedef struct tv_stream_config {
258 /*
259 * ID number of the stream. This value is used to identify the whole stream
260 * configuration.
261 */
262 int stream_id;
263
264 /* Type of the stream */
265 tv_stream_type_t type;
266
267 /* Max width/height of the stream. */
268 uint32_t max_video_width;
269 uint32_t max_video_height;
270} tv_stream_config_t;
271
Wonsik Kimd15399e2015-11-26 11:56:46 +0900272enum {
273 /*
274 * Set if signal is detected on this stream. Note that even if this mask is
275 * unset it does not necessarily mean no signal --- it denotes that HAL is
276 * unsure of the signal status.
277 */
278 TV_STREAM_FLAG_MASK_SIGNAL_DETECTION = 0x1,
279};
280
281/*
282 * >= TV_INPUT_DEVICE_API_VERSION_0_2
283 *
284 * tv_stream_config_t extended in a way that allows extension without breaking
285 * binary compatibility
286 */
287typedef struct tv_stream_config_ext {
288 tv_stream_config_t config;
289
290 /*
291 * Flags to show the status of this stream. See TV_STREAM_FLAG_* for
292 * details.
293 */
294 uint32_t flags;
295
296 int32_t reserved[16 - 1];
297} tv_stream_config_ext_t;
298
Wonsik Kimdce529a2014-04-01 11:34:33 +0900299typedef struct buffer_producer_stream {
300 /*
301 * IN/OUT: Width / height of the stream. Client may request for specific
302 * size but hardware may change it. Client must allocate buffers with
303 * specified width and height.
304 */
305 uint32_t width;
306 uint32_t height;
307
308 /* OUT: Client must set this usage when allocating buffer. */
309 uint32_t usage;
310
311 /* OUT: Client must allocate a buffer with this format. */
312 uint32_t format;
313} buffer_producer_stream_t;
314
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900315typedef struct tv_stream {
Wonsik Kimdce529a2014-04-01 11:34:33 +0900316 /* IN: ID in the stream configuration */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900317 int stream_id;
318
319 /* OUT: Type of the stream (for convenience) */
320 tv_stream_type_t type;
321
Wonsik Kimdce529a2014-04-01 11:34:33 +0900322 /* Data associated with the stream for client's use */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900323 union {
Wonsik Kimdce529a2014-04-01 11:34:33 +0900324 /* OUT: A native handle describing the sideband stream source */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900325 native_handle_t* sideband_stream_source_handle;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900326
327 /* IN/OUT: Details are in buffer_producer_stream_t */
328 buffer_producer_stream_t buffer_producer;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900329 };
330} tv_stream_t;
331
332/*
333 * Every device data structure must begin with hw_device_t
334 * followed by module specific public methods and attributes.
335 */
336typedef struct tv_input_device {
337 struct hw_device_t common;
338
339 /*
340 * initialize:
341 *
342 * Provide callbacks to the device and start operation. At first, no device
343 * is available and after initialize() completes, currently available
344 * devices including static devices should notify via callback.
345 *
346 * Framework owns callbacks object.
347 *
348 * data is a framework-owned object which would be sent back to the
349 * framework for each callback notifications.
350 *
351 * Return 0 on success.
352 */
353 int (*initialize)(struct tv_input_device* dev,
354 const tv_input_callback_ops_t* callback, void* data);
355
356 /*
357 * get_stream_configurations:
358 *
359 * Get stream configurations for a specific device. An input device may have
360 * multiple configurations.
361 *
362 * The configs object is guaranteed to be valid only until the next call to
363 * get_stream_configurations() or STREAM_CONFIGURATIONS_CHANGED event.
364 *
365 * Return 0 on success.
366 */
367 int (*get_stream_configurations)(const struct tv_input_device* dev,
368 int device_id, int* num_configurations,
369 const tv_stream_config_t** configs);
370
371 /*
372 * open_stream:
373 *
374 * Open a stream with given stream ID. Caller owns stream object, and the
375 * populated data is only valid until the stream is closed.
376 *
377 * Return 0 on success; -EBUSY if the client should close other streams to
378 * open the stream; -EEXIST if the stream with the given ID is already open;
379 * -EINVAL if device_id and/or stream_id are invalid; other non-zero value
380 * denotes unknown error.
381 */
382 int (*open_stream)(struct tv_input_device* dev, int device_id,
383 tv_stream_t* stream);
384
385 /*
386 * close_stream:
387 *
388 * Close a stream to a device. data in tv_stream_t* object associated with
389 * the stream_id is obsolete once this call finishes.
390 *
391 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
392 * device_id and/or stream_id are invalid.
393 */
394 int (*close_stream)(struct tv_input_device* dev, int device_id,
395 int stream_id);
396
397 /*
Wonsik Kimdce529a2014-04-01 11:34:33 +0900398 * request_capture:
399 *
400 * Request buffer capture for a stream. This is only valid for buffer
401 * producer streams. The buffer should be created with size, format and
402 * usage specified in the stream. Framework provides seq in an
403 * increasing sequence per each stream. Hardware should provide the picture
404 * in a chronological order according to seq. For example, if two
405 * requests are being processed at the same time, the request with the
406 * smaller seq should get an earlier frame.
407 *
408 * The framework releases the ownership of the buffer upon calling this
409 * function. When the buffer is filled, hardware notifies the framework
410 * via TV_INPUT_EVENT_CAPTURE_FINISHED callback, and the ownership is
411 * transferred back to framework at that time.
412 *
413 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
414 * device_id and/or stream_id are invalid; -EWOULDBLOCK if HAL cannot take
415 * additional requests until it releases a buffer.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900416 */
Wonsik Kimdce529a2014-04-01 11:34:33 +0900417 int (*request_capture)(struct tv_input_device* dev, int device_id,
418 int stream_id, buffer_handle_t buffer, uint32_t seq);
419
420 /*
421 * cancel_capture:
422 *
423 * Cancel an ongoing capture. Hardware should release the buffer as soon as
424 * possible via TV_INPUT_EVENT_CAPTURE_FAILED callback.
425 *
426 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
427 * device_id, stream_id, and/or seq are invalid.
428 */
429 int (*cancel_capture)(struct tv_input_device* dev, int device_id,
430 int stream_id, uint32_t seq);
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900431
Wonsik Kimd15399e2015-11-26 11:56:46 +0900432 /*
433 * get_stream_configurations_ext:
434 *
435 * Get stream configurations for a specific device. An input device may have
436 * multiple configurations.
437 *
438 * The configs object is guaranteed to be valid only until the next call to
439 * get_stream_configurations_ext() or STREAM_CONFIGURATIONS_CHANGED event.
440 *
441 * Return 0 on success.
442 */
443 int (*get_stream_configurations_ext)(const struct tv_input_device* dev,
444 int device_id, int* num_configurations,
445 const tv_stream_config_ext_t** configs);
446
447 void* reserved[16 - 1];
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900448} tv_input_device_t;
449
450__END_DECLS
451
452#endif // ANDROID_TV_INPUT_INTERFACE_H