blob: 456b06e1fdebc94fb356d713dc5dbe90836e875c [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 *
36 * TV_INPUT_MODULE_API_VERSION_0_1:
37 * Initial TV input hardware module API.
38 *
39 */
40
41#define TV_INPUT_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
42
43#define TV_INPUT_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
44
45/*
46 * The id of this module
47 */
48#define TV_INPUT_HARDWARE_MODULE_ID "tv_input"
49
50#define TV_INPUT_DEFAULT_DEVICE "default"
51
52/*****************************************************************************/
53
54/*
55 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
56 * and the fields of this data structure must begin with hw_module_t
57 * followed by module specific information.
58 */
59typedef struct tv_input_module {
60 struct hw_module_t common;
61} tv_input_module_t;
62
63/*****************************************************************************/
64
Wonsik Kim45849fb2014-06-12 14:52:39 +090065enum {
Wonsik Kim962e9ad2014-07-19 16:01:57 +090066 /* Generic hardware. */
67 TV_INPUT_TYPE_OTHER_HARDWARE = 1,
68 /* Tuner. (e.g. built-in terrestrial tuner) */
69 TV_INPUT_TYPE_TUNER = 2,
70 TV_INPUT_TYPE_COMPOSITE = 3,
71 TV_INPUT_TYPE_SVIDEO = 4,
72 TV_INPUT_TYPE_SCART = 5,
73 TV_INPUT_TYPE_COMPONENT = 6,
74 TV_INPUT_TYPE_VGA = 7,
75 TV_INPUT_TYPE_DVI = 8,
76 /* Physical HDMI port. (e.g. HDMI 1) */
77 TV_INPUT_TYPE_HDMI = 9,
78 TV_INPUT_TYPE_DISPLAY_PORT = 10,
Wonsik Kim45849fb2014-06-12 14:52:39 +090079};
80typedef uint32_t tv_input_type_t;
Wonsik Kim0b78afb2014-03-03 11:33:08 +090081
82typedef struct tv_input_device_info {
83 /* Device ID */
84 int device_id;
85
86 /* Type of physical TV input. */
87 tv_input_type_t type;
88
Wonsik Kim45849fb2014-06-12 14:52:39 +090089 union {
90 struct {
91 /* HDMI port ID number */
92 uint32_t port_id;
93 } hdmi;
94
95 /* TODO: add other type specific information. */
96
97 int32_t type_info_reserved[16];
98 };
Wonsik Kim0b78afb2014-03-03 11:33:08 +090099
100 /* TODO: Add capability if necessary. */
101
Wonsik Kim8b5714f2014-05-23 17:22:04 +0900102 /*
103 * Audio info
104 *
105 * audio_type == AUDIO_DEVICE_NONE if this input has no audio.
106 */
107 audio_devices_t audio_type;
Wonsik Kim45849fb2014-06-12 14:52:39 +0900108 const char* audio_address;
109
110 int32_t reserved[16];
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900111} tv_input_device_info_t;
112
Wonsik Kimfbb44122014-10-20 16:15:15 +0900113/* See tv_input_event_t for more details. */
Wonsik Kim45849fb2014-06-12 14:52:39 +0900114enum {
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900115 /*
116 * Hardware notifies the framework that a device is available.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900117 *
118 * Note that DEVICE_AVAILABLE and DEVICE_UNAVAILABLE events do not represent
119 * hotplug events (i.e. plugging cable into or out of the physical port).
120 * These events notify the framework whether the port is available or not.
121 * For a concrete example, when a user plugs in or pulls out the HDMI cable
122 * from a HDMI port, it does not generate DEVICE_AVAILABLE and/or
123 * DEVICE_UNAVAILABLE events. However, if a user inserts a pluggable USB
124 * tuner into the Android device, it will generate a DEVICE_AVAILABLE event
125 * and when the port is removed, it should generate a DEVICE_UNAVAILABLE
126 * event.
127 *
128 * For hotplug events, please see STREAM_CONFIGURATION_CHANGED for more
129 * details.
130 *
131 * HAL implementation should register devices by using this event when the
132 * device boots up. The framework will recognize device reported via this
133 * event only. In addition, the implementation could use this event to
134 * notify the framework that a removable TV input device (such as USB tuner
135 * as stated in the example above) is attached.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900136 */
137 TV_INPUT_EVENT_DEVICE_AVAILABLE = 1,
138 /*
139 * Hardware notifies the framework that a device is unavailable.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900140 *
141 * HAL implementation should generate this event when a device registered
142 * by TV_INPUT_EVENT_DEVICE_AVAILABLE is no longer available. For example,
143 * the event can indicate that a USB tuner is plugged out from the Android
144 * device.
145 *
146 * Note that this event is not for indicating cable plugged out of the port;
147 * for that purpose, the implementation should use
148 * STREAM_CONFIGURATION_CHANGED event. This event represents the port itself
149 * being no longer available.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900150 */
151 TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2,
152 /*
153 * Stream configurations are changed. Client should regard all open streams
154 * at the specific device are closed, and should call
155 * get_stream_configurations() again, opening some of them if necessary.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900156 *
157 * HAL implementation should generate this event when the available stream
158 * configurations change for any reason. A typical use case of this event
159 * would be to notify the framework that the input signal has changed
160 * resolution, or that the cable is plugged out so that the number of
161 * available streams is 0.
162 *
163 * The implementation may use this event to indicate hotplug status of the
164 * port. the framework regards input devices with no available streams as
165 * disconnected, so the implementation can generate this event with no
166 * available streams to indicate that this device is disconnected, and vice
167 * versa.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900168 */
169 TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED = 3,
Wonsik Kimdce529a2014-04-01 11:34:33 +0900170 /*
171 * Hardware is done with capture request with the buffer. Client can assume
172 * ownership of the buffer again.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900173 *
174 * HAL implementation should generate this event after request_capture() if
175 * it succeeded. The event shall have the buffer with the captured image.
Wonsik Kimdce529a2014-04-01 11:34:33 +0900176 */
177 TV_INPUT_EVENT_CAPTURE_SUCCEEDED = 4,
178 /*
179 * Hardware met a failure while processing a capture request or client
180 * canceled the request. Client can assume ownership of the buffer again.
Wonsik Kimfbb44122014-10-20 16:15:15 +0900181 *
182 * The event is similar to TV_INPUT_EVENT_CAPTURE_SUCCEEDED, but HAL
183 * implementation generates this event upon a failure to process
184 * request_capture(), or a request cancellation.
Wonsik Kimdce529a2014-04-01 11:34:33 +0900185 */
186 TV_INPUT_EVENT_CAPTURE_FAILED = 5,
Wonsik Kim45849fb2014-06-12 14:52:39 +0900187};
188typedef uint32_t tv_input_event_type_t;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900189
Wonsik Kimdce529a2014-04-01 11:34:33 +0900190typedef struct tv_input_capture_result {
191 /* Device ID */
192 int device_id;
193
194 /* Stream ID */
195 int stream_id;
196
197 /* Sequence number of the request */
198 uint32_t seq;
199
200 /*
201 * The buffer passed to hardware in request_capture(). The content of
202 * buffer is undefined (although buffer itself is valid) for
203 * TV_INPUT_CAPTURE_FAILED event.
204 */
205 buffer_handle_t buffer;
206
207 /*
208 * Error code for the request. -ECANCELED if request is cancelled; other
209 * error codes are unknown errors.
210 */
211 int error_code;
212} tv_input_capture_result_t;
213
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900214typedef struct tv_input_event {
215 tv_input_event_type_t type;
216
217 union {
218 /*
219 * TV_INPUT_EVENT_DEVICE_AVAILABLE: all fields are relevant
220 * TV_INPUT_EVENT_DEVICE_UNAVAILABLE: only device_id is relevant
221 * TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED: only device_id is
222 * relevant
223 */
224 tv_input_device_info_t device_info;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900225 /*
226 * TV_INPUT_EVENT_CAPTURE_SUCCEEDED: error_code is not relevant
227 * TV_INPUT_EVENT_CAPTURE_FAILED: all fields are relevant
228 */
229 tv_input_capture_result_t capture_result;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900230 };
231} tv_input_event_t;
232
233typedef struct tv_input_callback_ops {
234 /*
235 * event contains the type of the event and additional data if necessary.
236 * The event object is guaranteed to be valid only for the duration of the
237 * call.
238 *
239 * data is an object supplied at device initialization, opaque to the
240 * hardware.
241     */
242 void (*notify)(struct tv_input_device* dev,
243 tv_input_event_t* event, void* data);
244} tv_input_callback_ops_t;
245
Wonsik Kim45849fb2014-06-12 14:52:39 +0900246enum {
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900247 TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1,
Wonsik Kimdce529a2014-04-01 11:34:33 +0900248 TV_STREAM_TYPE_BUFFER_PRODUCER = 2,
Wonsik Kim45849fb2014-06-12 14:52:39 +0900249};
250typedef uint32_t tv_stream_type_t;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900251
252typedef struct tv_stream_config {
253 /*
254 * ID number of the stream. This value is used to identify the whole stream
255 * configuration.
256 */
257 int stream_id;
258
259 /* Type of the stream */
260 tv_stream_type_t type;
261
262 /* Max width/height of the stream. */
263 uint32_t max_video_width;
264 uint32_t max_video_height;
265} tv_stream_config_t;
266
Wonsik Kimdce529a2014-04-01 11:34:33 +0900267typedef struct buffer_producer_stream {
268 /*
269 * IN/OUT: Width / height of the stream. Client may request for specific
270 * size but hardware may change it. Client must allocate buffers with
271 * specified width and height.
272 */
273 uint32_t width;
274 uint32_t height;
275
276 /* OUT: Client must set this usage when allocating buffer. */
277 uint32_t usage;
278
279 /* OUT: Client must allocate a buffer with this format. */
280 uint32_t format;
Domi Papoi3ef9fa62015-10-05 16:08:08 -0400281
282 /* OUT: Client must allocate buffers based on this count. */
283 uint32_t buffer_count;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900284} buffer_producer_stream_t;
285
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900286typedef struct tv_stream {
Wonsik Kimdce529a2014-04-01 11:34:33 +0900287 /* IN: ID in the stream configuration */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900288 int stream_id;
289
290 /* OUT: Type of the stream (for convenience) */
291 tv_stream_type_t type;
292
Wonsik Kimdce529a2014-04-01 11:34:33 +0900293 /* Data associated with the stream for client's use */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900294 union {
Wonsik Kimdce529a2014-04-01 11:34:33 +0900295 /* OUT: A native handle describing the sideband stream source */
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900296 native_handle_t* sideband_stream_source_handle;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900297
298 /* IN/OUT: Details are in buffer_producer_stream_t */
299 buffer_producer_stream_t buffer_producer;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900300 };
301} tv_stream_t;
302
303/*
304 * Every device data structure must begin with hw_device_t
305 * followed by module specific public methods and attributes.
306 */
307typedef struct tv_input_device {
308 struct hw_device_t common;
309
310 /*
311 * initialize:
312 *
313 * Provide callbacks to the device and start operation. At first, no device
314 * is available and after initialize() completes, currently available
315 * devices including static devices should notify via callback.
316 *
317 * Framework owns callbacks object.
318 *
319 * data is a framework-owned object which would be sent back to the
320 * framework for each callback notifications.
321 *
322 * Return 0 on success.
323 */
324 int (*initialize)(struct tv_input_device* dev,
325 const tv_input_callback_ops_t* callback, void* data);
326
327 /*
328 * get_stream_configurations:
329 *
330 * Get stream configurations for a specific device. An input device may have
331 * multiple configurations.
332 *
333 * The configs object is guaranteed to be valid only until the next call to
334 * get_stream_configurations() or STREAM_CONFIGURATIONS_CHANGED event.
335 *
336 * Return 0 on success.
337 */
338 int (*get_stream_configurations)(const struct tv_input_device* dev,
339 int device_id, int* num_configurations,
340 const tv_stream_config_t** configs);
341
342 /*
343 * open_stream:
344 *
345 * Open a stream with given stream ID. Caller owns stream object, and the
346 * populated data is only valid until the stream is closed.
347 *
348 * Return 0 on success; -EBUSY if the client should close other streams to
349 * open the stream; -EEXIST if the stream with the given ID is already open;
350 * -EINVAL if device_id and/or stream_id are invalid; other non-zero value
351 * denotes unknown error.
352 */
353 int (*open_stream)(struct tv_input_device* dev, int device_id,
354 tv_stream_t* stream);
355
356 /*
357 * close_stream:
358 *
359 * Close a stream to a device. data in tv_stream_t* object associated with
360 * the stream_id is obsolete once this call finishes.
361 *
362 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
363 * device_id and/or stream_id are invalid.
364 */
365 int (*close_stream)(struct tv_input_device* dev, int device_id,
366 int stream_id);
367
368 /*
Wonsik Kimdce529a2014-04-01 11:34:33 +0900369 * request_capture:
370 *
371 * Request buffer capture for a stream. This is only valid for buffer
372 * producer streams. The buffer should be created with size, format and
373 * usage specified in the stream. Framework provides seq in an
374 * increasing sequence per each stream. Hardware should provide the picture
375 * in a chronological order according to seq. For example, if two
376 * requests are being processed at the same time, the request with the
377 * smaller seq should get an earlier frame.
378 *
379 * The framework releases the ownership of the buffer upon calling this
380 * function. When the buffer is filled, hardware notifies the framework
381 * via TV_INPUT_EVENT_CAPTURE_FINISHED callback, and the ownership is
382 * transferred back to framework at that time.
383 *
384 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
385 * device_id and/or stream_id are invalid; -EWOULDBLOCK if HAL cannot take
386 * additional requests until it releases a buffer.
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900387 */
Wonsik Kimdce529a2014-04-01 11:34:33 +0900388 int (*request_capture)(struct tv_input_device* dev, int device_id,
389 int stream_id, buffer_handle_t buffer, uint32_t seq);
390
391 /*
392 * cancel_capture:
393 *
394 * Cancel an ongoing capture. Hardware should release the buffer as soon as
395 * possible via TV_INPUT_EVENT_CAPTURE_FAILED callback.
396 *
397 * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
398 * device_id, stream_id, and/or seq are invalid.
399 */
400 int (*cancel_capture)(struct tv_input_device* dev, int device_id,
401 int stream_id, uint32_t seq);
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900402
403 void* reserved[16];
404} tv_input_device_t;
405
406__END_DECLS
407
408#endif // ANDROID_TV_INPUT_INTERFACE_H