Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 1 | /* |
| 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 Kim | 8b5714f | 2014-05-23 17:22:04 +0900 | [diff] [blame] | 25 | #include <system/audio.h> |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 26 | #include <system/window.h> |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 27 | |
| 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 | */ |
| 59 | typedef struct tv_input_module { |
| 60 | struct hw_module_t common; |
| 61 | } tv_input_module_t; |
| 62 | |
| 63 | /*****************************************************************************/ |
| 64 | |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 65 | enum { |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 66 | /* HDMI */ |
| 67 | TV_INPUT_TYPE_HDMI = 1, |
| 68 | |
| 69 | /* Built-in tuners. */ |
| 70 | TV_INPUT_TYPE_BUILT_IN_TUNER = 2, |
| 71 | |
| 72 | /* Passthrough */ |
| 73 | TV_INPUT_TYPE_PASSTHROUGH = 3, |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 74 | }; |
| 75 | typedef uint32_t tv_input_type_t; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 76 | |
| 77 | typedef struct tv_input_device_info { |
| 78 | /* Device ID */ |
| 79 | int device_id; |
| 80 | |
| 81 | /* Type of physical TV input. */ |
| 82 | tv_input_type_t type; |
| 83 | |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 84 | union { |
| 85 | struct { |
| 86 | /* HDMI port ID number */ |
| 87 | uint32_t port_id; |
| 88 | } hdmi; |
| 89 | |
| 90 | /* TODO: add other type specific information. */ |
| 91 | |
| 92 | int32_t type_info_reserved[16]; |
| 93 | }; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 94 | |
| 95 | /* TODO: Add capability if necessary. */ |
| 96 | |
Wonsik Kim | 8b5714f | 2014-05-23 17:22:04 +0900 | [diff] [blame] | 97 | /* |
| 98 | * Audio info |
| 99 | * |
| 100 | * audio_type == AUDIO_DEVICE_NONE if this input has no audio. |
| 101 | */ |
| 102 | audio_devices_t audio_type; |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 103 | const char* audio_address; |
| 104 | |
| 105 | int32_t reserved[16]; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 106 | } tv_input_device_info_t; |
| 107 | |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 108 | enum { |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 109 | /* |
| 110 | * Hardware notifies the framework that a device is available. |
| 111 | */ |
| 112 | TV_INPUT_EVENT_DEVICE_AVAILABLE = 1, |
| 113 | /* |
| 114 | * Hardware notifies the framework that a device is unavailable. |
| 115 | */ |
| 116 | TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2, |
| 117 | /* |
| 118 | * Stream configurations are changed. Client should regard all open streams |
| 119 | * at the specific device are closed, and should call |
| 120 | * get_stream_configurations() again, opening some of them if necessary. |
| 121 | */ |
| 122 | TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED = 3, |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 123 | /* |
| 124 | * Hardware is done with capture request with the buffer. Client can assume |
| 125 | * ownership of the buffer again. |
| 126 | */ |
| 127 | TV_INPUT_EVENT_CAPTURE_SUCCEEDED = 4, |
| 128 | /* |
| 129 | * Hardware met a failure while processing a capture request or client |
| 130 | * canceled the request. Client can assume ownership of the buffer again. |
| 131 | */ |
| 132 | TV_INPUT_EVENT_CAPTURE_FAILED = 5, |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 133 | }; |
| 134 | typedef uint32_t tv_input_event_type_t; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 135 | |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 136 | typedef struct tv_input_capture_result { |
| 137 | /* Device ID */ |
| 138 | int device_id; |
| 139 | |
| 140 | /* Stream ID */ |
| 141 | int stream_id; |
| 142 | |
| 143 | /* Sequence number of the request */ |
| 144 | uint32_t seq; |
| 145 | |
| 146 | /* |
| 147 | * The buffer passed to hardware in request_capture(). The content of |
| 148 | * buffer is undefined (although buffer itself is valid) for |
| 149 | * TV_INPUT_CAPTURE_FAILED event. |
| 150 | */ |
| 151 | buffer_handle_t buffer; |
| 152 | |
| 153 | /* |
| 154 | * Error code for the request. -ECANCELED if request is cancelled; other |
| 155 | * error codes are unknown errors. |
| 156 | */ |
| 157 | int error_code; |
| 158 | } tv_input_capture_result_t; |
| 159 | |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 160 | typedef struct tv_input_event { |
| 161 | tv_input_event_type_t type; |
| 162 | |
| 163 | union { |
| 164 | /* |
| 165 | * TV_INPUT_EVENT_DEVICE_AVAILABLE: all fields are relevant |
| 166 | * TV_INPUT_EVENT_DEVICE_UNAVAILABLE: only device_id is relevant |
| 167 | * TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED: only device_id is |
| 168 | * relevant |
| 169 | */ |
| 170 | tv_input_device_info_t device_info; |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 171 | /* |
| 172 | * TV_INPUT_EVENT_CAPTURE_SUCCEEDED: error_code is not relevant |
| 173 | * TV_INPUT_EVENT_CAPTURE_FAILED: all fields are relevant |
| 174 | */ |
| 175 | tv_input_capture_result_t capture_result; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 176 | }; |
| 177 | } tv_input_event_t; |
| 178 | |
| 179 | typedef struct tv_input_callback_ops { |
| 180 | /* |
| 181 | * event contains the type of the event and additional data if necessary. |
| 182 | * The event object is guaranteed to be valid only for the duration of the |
| 183 | * call. |
| 184 | * |
| 185 | * data is an object supplied at device initialization, opaque to the |
| 186 | * hardware. |
| 187 | */ |
| 188 | void (*notify)(struct tv_input_device* dev, |
| 189 | tv_input_event_t* event, void* data); |
| 190 | } tv_input_callback_ops_t; |
| 191 | |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 192 | enum { |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 193 | TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1, |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 194 | TV_STREAM_TYPE_BUFFER_PRODUCER = 2, |
Wonsik Kim | 45849fb | 2014-06-12 14:52:39 +0900 | [diff] [blame^] | 195 | }; |
| 196 | typedef uint32_t tv_stream_type_t; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 197 | |
| 198 | typedef struct tv_stream_config { |
| 199 | /* |
| 200 | * ID number of the stream. This value is used to identify the whole stream |
| 201 | * configuration. |
| 202 | */ |
| 203 | int stream_id; |
| 204 | |
| 205 | /* Type of the stream */ |
| 206 | tv_stream_type_t type; |
| 207 | |
| 208 | /* Max width/height of the stream. */ |
| 209 | uint32_t max_video_width; |
| 210 | uint32_t max_video_height; |
| 211 | } tv_stream_config_t; |
| 212 | |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 213 | typedef struct buffer_producer_stream { |
| 214 | /* |
| 215 | * IN/OUT: Width / height of the stream. Client may request for specific |
| 216 | * size but hardware may change it. Client must allocate buffers with |
| 217 | * specified width and height. |
| 218 | */ |
| 219 | uint32_t width; |
| 220 | uint32_t height; |
| 221 | |
| 222 | /* OUT: Client must set this usage when allocating buffer. */ |
| 223 | uint32_t usage; |
| 224 | |
| 225 | /* OUT: Client must allocate a buffer with this format. */ |
| 226 | uint32_t format; |
| 227 | } buffer_producer_stream_t; |
| 228 | |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 229 | typedef struct tv_stream { |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 230 | /* IN: ID in the stream configuration */ |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 231 | int stream_id; |
| 232 | |
| 233 | /* OUT: Type of the stream (for convenience) */ |
| 234 | tv_stream_type_t type; |
| 235 | |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 236 | /* Data associated with the stream for client's use */ |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 237 | union { |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 238 | /* OUT: A native handle describing the sideband stream source */ |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 239 | native_handle_t* sideband_stream_source_handle; |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 240 | |
| 241 | /* IN/OUT: Details are in buffer_producer_stream_t */ |
| 242 | buffer_producer_stream_t buffer_producer; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 243 | }; |
| 244 | } tv_stream_t; |
| 245 | |
| 246 | /* |
| 247 | * Every device data structure must begin with hw_device_t |
| 248 | * followed by module specific public methods and attributes. |
| 249 | */ |
| 250 | typedef struct tv_input_device { |
| 251 | struct hw_device_t common; |
| 252 | |
| 253 | /* |
| 254 | * initialize: |
| 255 | * |
| 256 | * Provide callbacks to the device and start operation. At first, no device |
| 257 | * is available and after initialize() completes, currently available |
| 258 | * devices including static devices should notify via callback. |
| 259 | * |
| 260 | * Framework owns callbacks object. |
| 261 | * |
| 262 | * data is a framework-owned object which would be sent back to the |
| 263 | * framework for each callback notifications. |
| 264 | * |
| 265 | * Return 0 on success. |
| 266 | */ |
| 267 | int (*initialize)(struct tv_input_device* dev, |
| 268 | const tv_input_callback_ops_t* callback, void* data); |
| 269 | |
| 270 | /* |
| 271 | * get_stream_configurations: |
| 272 | * |
| 273 | * Get stream configurations for a specific device. An input device may have |
| 274 | * multiple configurations. |
| 275 | * |
| 276 | * The configs object is guaranteed to be valid only until the next call to |
| 277 | * get_stream_configurations() or STREAM_CONFIGURATIONS_CHANGED event. |
| 278 | * |
| 279 | * Return 0 on success. |
| 280 | */ |
| 281 | int (*get_stream_configurations)(const struct tv_input_device* dev, |
| 282 | int device_id, int* num_configurations, |
| 283 | const tv_stream_config_t** configs); |
| 284 | |
| 285 | /* |
| 286 | * open_stream: |
| 287 | * |
| 288 | * Open a stream with given stream ID. Caller owns stream object, and the |
| 289 | * populated data is only valid until the stream is closed. |
| 290 | * |
| 291 | * Return 0 on success; -EBUSY if the client should close other streams to |
| 292 | * open the stream; -EEXIST if the stream with the given ID is already open; |
| 293 | * -EINVAL if device_id and/or stream_id are invalid; other non-zero value |
| 294 | * denotes unknown error. |
| 295 | */ |
| 296 | int (*open_stream)(struct tv_input_device* dev, int device_id, |
| 297 | tv_stream_t* stream); |
| 298 | |
| 299 | /* |
| 300 | * close_stream: |
| 301 | * |
| 302 | * Close a stream to a device. data in tv_stream_t* object associated with |
| 303 | * the stream_id is obsolete once this call finishes. |
| 304 | * |
| 305 | * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if |
| 306 | * device_id and/or stream_id are invalid. |
| 307 | */ |
| 308 | int (*close_stream)(struct tv_input_device* dev, int device_id, |
| 309 | int stream_id); |
| 310 | |
| 311 | /* |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 312 | * request_capture: |
| 313 | * |
| 314 | * Request buffer capture for a stream. This is only valid for buffer |
| 315 | * producer streams. The buffer should be created with size, format and |
| 316 | * usage specified in the stream. Framework provides seq in an |
| 317 | * increasing sequence per each stream. Hardware should provide the picture |
| 318 | * in a chronological order according to seq. For example, if two |
| 319 | * requests are being processed at the same time, the request with the |
| 320 | * smaller seq should get an earlier frame. |
| 321 | * |
| 322 | * The framework releases the ownership of the buffer upon calling this |
| 323 | * function. When the buffer is filled, hardware notifies the framework |
| 324 | * via TV_INPUT_EVENT_CAPTURE_FINISHED callback, and the ownership is |
| 325 | * transferred back to framework at that time. |
| 326 | * |
| 327 | * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if |
| 328 | * device_id and/or stream_id are invalid; -EWOULDBLOCK if HAL cannot take |
| 329 | * additional requests until it releases a buffer. |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 330 | */ |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 331 | int (*request_capture)(struct tv_input_device* dev, int device_id, |
| 332 | int stream_id, buffer_handle_t buffer, uint32_t seq); |
| 333 | |
| 334 | /* |
| 335 | * cancel_capture: |
| 336 | * |
| 337 | * Cancel an ongoing capture. Hardware should release the buffer as soon as |
| 338 | * possible via TV_INPUT_EVENT_CAPTURE_FAILED callback. |
| 339 | * |
| 340 | * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if |
| 341 | * device_id, stream_id, and/or seq are invalid. |
| 342 | */ |
| 343 | int (*cancel_capture)(struct tv_input_device* dev, int device_id, |
| 344 | int stream_id, uint32_t seq); |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 345 | |
| 346 | void* reserved[16]; |
| 347 | } tv_input_device_t; |
| 348 | |
| 349 | __END_DECLS |
| 350 | |
| 351 | #endif // ANDROID_TV_INPUT_INTERFACE_H |