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> |
| 25 | |
| 26 | __BEGIN_DECLS |
| 27 | |
| 28 | /* |
| 29 | * Module versioning information for the TV input hardware module, based on |
| 30 | * tv_input_module_t.common.module_api_version. |
| 31 | * |
| 32 | * Version History: |
| 33 | * |
| 34 | * TV_INPUT_MODULE_API_VERSION_0_1: |
| 35 | * Initial TV input hardware module API. |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | #define TV_INPUT_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 40 | |
| 41 | #define TV_INPUT_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1) |
| 42 | |
| 43 | /* |
| 44 | * The id of this module |
| 45 | */ |
| 46 | #define TV_INPUT_HARDWARE_MODULE_ID "tv_input" |
| 47 | |
| 48 | #define TV_INPUT_DEFAULT_DEVICE "default" |
| 49 | |
| 50 | /*****************************************************************************/ |
| 51 | |
| 52 | /* |
| 53 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 54 | * and the fields of this data structure must begin with hw_module_t |
| 55 | * followed by module specific information. |
| 56 | */ |
| 57 | typedef struct tv_input_module { |
| 58 | struct hw_module_t common; |
| 59 | } tv_input_module_t; |
| 60 | |
| 61 | /*****************************************************************************/ |
| 62 | |
| 63 | typedef enum tv_input_type { |
| 64 | /* HDMI */ |
| 65 | TV_INPUT_TYPE_HDMI = 1, |
| 66 | |
| 67 | /* Built-in tuners. */ |
| 68 | TV_INPUT_TYPE_BUILT_IN_TUNER = 2, |
| 69 | |
| 70 | /* Passthrough */ |
| 71 | TV_INPUT_TYPE_PASSTHROUGH = 3, |
| 72 | } tv_input_type_t; |
| 73 | |
| 74 | typedef struct tv_input_device_info { |
| 75 | /* Device ID */ |
| 76 | int device_id; |
| 77 | |
| 78 | /* Type of physical TV input. */ |
| 79 | tv_input_type_t type; |
| 80 | |
| 81 | /* |
| 82 | * TODO: A union of type specific information. For example, HDMI port |
| 83 | * identifier that HDMI hardware understands. |
| 84 | */ |
| 85 | |
| 86 | /* TODO: Add capability if necessary. */ |
| 87 | |
| 88 | /* TODO: Audio info */ |
| 89 | } tv_input_device_info_t; |
| 90 | |
| 91 | typedef enum { |
| 92 | /* |
| 93 | * Hardware notifies the framework that a device is available. |
| 94 | */ |
| 95 | TV_INPUT_EVENT_DEVICE_AVAILABLE = 1, |
| 96 | /* |
| 97 | * Hardware notifies the framework that a device is unavailable. |
| 98 | */ |
| 99 | TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2, |
| 100 | /* |
| 101 | * Stream configurations are changed. Client should regard all open streams |
| 102 | * at the specific device are closed, and should call |
| 103 | * get_stream_configurations() again, opening some of them if necessary. |
| 104 | */ |
| 105 | TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED = 3, |
| 106 | /* TODO: Buffer notifications, etc. */ |
| 107 | } tv_input_event_type_t; |
| 108 | |
| 109 | typedef struct tv_input_event { |
| 110 | tv_input_event_type_t type; |
| 111 | |
| 112 | union { |
| 113 | /* |
| 114 | * TV_INPUT_EVENT_DEVICE_AVAILABLE: all fields are relevant |
| 115 | * TV_INPUT_EVENT_DEVICE_UNAVAILABLE: only device_id is relevant |
| 116 | * TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED: only device_id is |
| 117 | * relevant |
| 118 | */ |
| 119 | tv_input_device_info_t device_info; |
| 120 | }; |
| 121 | } tv_input_event_t; |
| 122 | |
| 123 | typedef struct tv_input_callback_ops { |
| 124 | /* |
| 125 | * event contains the type of the event and additional data if necessary. |
| 126 | * The event object is guaranteed to be valid only for the duration of the |
| 127 | * call. |
| 128 | * |
| 129 | * data is an object supplied at device initialization, opaque to the |
| 130 | * hardware. |
| 131 | */ |
| 132 | void (*notify)(struct tv_input_device* dev, |
| 133 | tv_input_event_t* event, void* data); |
| 134 | } tv_input_callback_ops_t; |
| 135 | |
| 136 | typedef enum { |
| 137 | TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1, |
| 138 | /* TODO: TV_STREAM_TYPE_BUFFER_PRODUCER = 2, */ |
| 139 | } tv_stream_type_t; |
| 140 | |
| 141 | typedef struct tv_stream_config { |
| 142 | /* |
| 143 | * ID number of the stream. This value is used to identify the whole stream |
| 144 | * configuration. |
| 145 | */ |
| 146 | int stream_id; |
| 147 | |
| 148 | /* Type of the stream */ |
| 149 | tv_stream_type_t type; |
| 150 | |
| 151 | /* Max width/height of the stream. */ |
| 152 | uint32_t max_video_width; |
| 153 | uint32_t max_video_height; |
| 154 | } tv_stream_config_t; |
| 155 | |
| 156 | typedef struct tv_stream { |
| 157 | /* IN: ID in the stream configuration. */ |
| 158 | int stream_id; |
| 159 | |
| 160 | /* OUT: Type of the stream (for convenience) */ |
| 161 | tv_stream_type_t type; |
| 162 | |
| 163 | /* OUT: Data associated with the stream for client's use */ |
| 164 | union { |
| 165 | native_handle_t* sideband_stream_source_handle; |
| 166 | /* TODO: buffer_producer_stream_t buffer_producer; */ |
| 167 | }; |
| 168 | } tv_stream_t; |
| 169 | |
| 170 | /* |
| 171 | * Every device data structure must begin with hw_device_t |
| 172 | * followed by module specific public methods and attributes. |
| 173 | */ |
| 174 | typedef struct tv_input_device { |
| 175 | struct hw_device_t common; |
| 176 | |
| 177 | /* |
| 178 | * initialize: |
| 179 | * |
| 180 | * Provide callbacks to the device and start operation. At first, no device |
| 181 | * is available and after initialize() completes, currently available |
| 182 | * devices including static devices should notify via callback. |
| 183 | * |
| 184 | * Framework owns callbacks object. |
| 185 | * |
| 186 | * data is a framework-owned object which would be sent back to the |
| 187 | * framework for each callback notifications. |
| 188 | * |
| 189 | * Return 0 on success. |
| 190 | */ |
| 191 | int (*initialize)(struct tv_input_device* dev, |
| 192 | const tv_input_callback_ops_t* callback, void* data); |
| 193 | |
| 194 | /* |
| 195 | * get_stream_configurations: |
| 196 | * |
| 197 | * Get stream configurations for a specific device. An input device may have |
| 198 | * multiple configurations. |
| 199 | * |
| 200 | * The configs object is guaranteed to be valid only until the next call to |
| 201 | * get_stream_configurations() or STREAM_CONFIGURATIONS_CHANGED event. |
| 202 | * |
| 203 | * Return 0 on success. |
| 204 | */ |
| 205 | int (*get_stream_configurations)(const struct tv_input_device* dev, |
| 206 | int device_id, int* num_configurations, |
| 207 | const tv_stream_config_t** configs); |
| 208 | |
| 209 | /* |
| 210 | * open_stream: |
| 211 | * |
| 212 | * Open a stream with given stream ID. Caller owns stream object, and the |
| 213 | * populated data is only valid until the stream is closed. |
| 214 | * |
| 215 | * Return 0 on success; -EBUSY if the client should close other streams to |
| 216 | * open the stream; -EEXIST if the stream with the given ID is already open; |
| 217 | * -EINVAL if device_id and/or stream_id are invalid; other non-zero value |
| 218 | * denotes unknown error. |
| 219 | */ |
| 220 | int (*open_stream)(struct tv_input_device* dev, int device_id, |
| 221 | tv_stream_t* stream); |
| 222 | |
| 223 | /* |
| 224 | * close_stream: |
| 225 | * |
| 226 | * Close a stream to a device. data in tv_stream_t* object associated with |
| 227 | * the stream_id is obsolete once this call finishes. |
| 228 | * |
| 229 | * Return 0 on success; -ENOENT if the stream is not open; -EINVAL if |
| 230 | * device_id and/or stream_id are invalid. |
| 231 | */ |
| 232 | int (*close_stream)(struct tv_input_device* dev, int device_id, |
| 233 | int stream_id); |
| 234 | |
| 235 | /* |
| 236 | * TODO: Add more APIs such as buffer operations in case of buffer producer |
| 237 | * profile. |
| 238 | */ |
| 239 | |
| 240 | void* reserved[16]; |
| 241 | } tv_input_device_t; |
| 242 | |
| 243 | __END_DECLS |
| 244 | |
| 245 | #endif // ANDROID_TV_INPUT_INTERFACE_H |