summaryrefslogtreecommitdiff
path: root/tv_input.cpp (plain)
blob: ea709de6c6d89051a32673ef3c7aac7291bcc364
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#define LOG_TAG "TvInput"
18#include <fcntl.h>
19#include <errno.h>
20
21#include <cutils/log.h>
22#include <cutils/native_handle.h>
23
24#include <hardware/tv_input.h>
25
26/*****************************************************************************/
27
28#define ATV_DEV_ID 1
29#define DTV_DEV_ID 2
30#define AV_DEV_ID 3
31#define HDMI1_DEV_ID 4
32#define HDMI2_DEV_ID 5
33#define HDMI3_DEV_ID 6
34
35typedef struct tv_input_private
36{
37 tv_input_device_t device;
38
39 // Callback related data
40 const tv_input_callback_ops_t* callback;
41 void* callback_data;
42} tv_input_private_t;
43
44static int notify_ATV_device_available(tv_input_private_t* priv)
45{
46 tv_input_event_t event;
47 event.device_info.device_id =ATV_DEV_ID;
48 event.device_info.type = TV_INPUT_TYPE_TUNER;
49 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
50 event.device_info.audio_type = AUDIO_DEVICE_NONE;
51 priv->callback->notify(&priv->device, &event, priv->callback_data);
52 return 0;
53}
54
55static int notify_DTV_device_available(tv_input_private_t* priv)
56{
57 tv_input_event_t event;
58 event.device_info.device_id =DTV_DEV_ID;
59 event.device_info.type = TV_INPUT_TYPE_TUNER;
60 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
61 event.device_info.audio_type = AUDIO_DEVICE_NONE;
62 priv->callback->notify(&priv->device, &event, priv->callback_data);
63 return 0;
64}
65
66static int notify_AV_device_available(tv_input_private_t* priv)
67{
68 tv_input_event_t event;
69 event.device_info.device_id =AV_DEV_ID;
70 event.device_info.type = TV_INPUT_TYPE_COMPONENT;
71 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
72 event.device_info.audio_type = AUDIO_DEVICE_NONE;
73 priv->callback->notify(&priv->device, &event, priv->callback_data);
74 return 0;
75}
76
77static int notify_hdmi_device_available(tv_input_private_t* priv, int dev_id, uint32_t port_id)
78{
79 tv_input_event_t event;
80 event.device_info.device_id =dev_id;
81 event.device_info.type = TV_INPUT_TYPE_HDMI;
82 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
83 event.device_info.hdmi.port_id = port_id;
84 event.device_info.audio_type = AUDIO_DEVICE_NONE;
85 priv->callback->notify(&priv->device, &event, priv->callback_data);
86 return 0;
87}
88
89static int get_stream_configs(int dev_id, int* num_configurations, const tv_stream_config_t** configs)
90{
91 tv_stream_config_t* mconfig = (tv_stream_config_t*)malloc(sizeof(mconfig));
92 if (!mconfig) {
93 return -1;
94 }
95 switch (dev_id) {
96 case ATV_DEV_ID:
97 mconfig->stream_id=ATV_DEV_ID;
98 mconfig->type =TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
99 mconfig->max_video_width = 1920;
100 mconfig->max_video_height = 1080;
101 *num_configurations = 1;
102 *configs = mconfig;
103 break;
104 case DTV_DEV_ID:
105 mconfig->stream_id=DTV_DEV_ID;
106 mconfig->type =TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
107 mconfig->max_video_width = 1920;
108 mconfig->max_video_height = 1080;
109 *num_configurations = 1;
110 *configs = mconfig;
111 break;
112 case AV_DEV_ID:
113 mconfig->stream_id=AV_DEV_ID;
114 mconfig->type =TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
115 mconfig->max_video_width = 1920;
116 mconfig->max_video_height = 1080;
117 *num_configurations = 1;
118 *configs = mconfig;
119 break;
120 case HDMI1_DEV_ID:
121 mconfig->stream_id=HDMI1_DEV_ID;
122 mconfig->type =TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
123 mconfig->max_video_width = 1920;
124 mconfig->max_video_height = 1080;
125 *num_configurations = 1;
126 *configs = mconfig;
127 break;
128 case HDMI2_DEV_ID:
129 mconfig->stream_id=HDMI2_DEV_ID;
130 mconfig->type =TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
131 mconfig->max_video_width = 1920;
132 mconfig->max_video_height = 1080;
133 *num_configurations = 1;
134 *configs = mconfig;
135 break;
136 case HDMI3_DEV_ID:
137 mconfig->stream_id=HDMI3_DEV_ID;
138 mconfig->type =TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
139 mconfig->max_video_width = 1920;
140 mconfig->max_video_height = 1080;
141 *num_configurations = 1;
142 *configs = mconfig;
143 break;
144 default:
145 break;
146 }
147 return 0;
148}
149
150static int tv_input_device_open(const struct hw_module_t* module,
151 const char* name, struct hw_device_t** device);
152
153static struct hw_module_methods_t tv_input_module_methods = {
154 open: tv_input_device_open
155};
156
157tv_input_module_t HAL_MODULE_INFO_SYM = {
158 common: {
159 tag: HARDWARE_MODULE_TAG,
160 version_major: 0,
161 version_minor: 1,
162 id: TV_INPUT_HARDWARE_MODULE_ID,
163 name: "TVInput module",
164 author: "Amlogic",
165 methods: &tv_input_module_methods,
166 }
167};
168
169/*****************************************************************************/
170
171static int tv_input_initialize(struct tv_input_device* dev,
172 const tv_input_callback_ops_t* callback, void* data)
173{
174 if (dev == NULL || callback == NULL) {
175 return -EINVAL;
176 }
177 tv_input_private_t* priv = (tv_input_private_t*)dev;
178 if (priv->callback != NULL) {
179 return -EEXIST;
180 }
181
182 priv->callback = callback;
183 priv->callback_data = data;
184/* ATV_DEVICE_AVAILABLE */
185 notify_ATV_device_available(priv);
186/* DTV_DEVICE_AVAILABLE */
187 notify_DTV_device_available(priv);
188/* AV_DEVICE_AVAILABLE */
189 notify_AV_device_available(priv);
190/* HDMI1_DEVICE_AVAILABLE */
191 notify_hdmi_device_available(priv, HDMI1_DEV_ID, 1);
192/* HDMI2_DEVICE_AVAILABLE */
193 notify_hdmi_device_available(priv, HDMI2_DEV_ID, 2);
194/* HDMI3_DEVICE_AVAILABLE */
195 notify_hdmi_device_available(priv, HDMI3_DEV_ID, 3);
196
197 return 0;
198}
199
200static int tv_input_get_stream_configurations(const struct tv_input_device* dev,
201 int device_id, int* num_configurations,
202 const tv_stream_config_t** configs)
203{
204 if (get_stream_configs(device_id, num_configurations, configs) == 0) {
205 return 0;
206 }
207 return -EINVAL;
208}
209
210static int tv_input_open_stream(struct tv_input_device*, int, tv_stream_t*)
211{
212 return -EINVAL;
213}
214
215static int tv_input_close_stream(struct tv_input_device*, int, int)
216{
217 return -EINVAL;
218}
219
220static int tv_input_request_capture(
221 struct tv_input_device*, int, int, buffer_handle_t, uint32_t)
222{
223 return -EINVAL;
224}
225
226static int tv_input_cancel_capture(struct tv_input_device*, int, int, uint32_t)
227{
228 return -EINVAL;
229}
230
231/*****************************************************************************/
232
233static int tv_input_device_close(struct hw_device_t *dev)
234{
235 tv_input_private_t* priv = (tv_input_private_t*)dev;
236 if (priv) {
237 free(priv);
238 }
239 return 0;
240}
241
242/*****************************************************************************/
243
244static int tv_input_device_open(const struct hw_module_t* module,
245 const char* name, struct hw_device_t** device)
246{
247 int status = -EINVAL;
248 if (!strcmp(name, TV_INPUT_DEFAULT_DEVICE)) {
249 tv_input_private_t* dev = (tv_input_private_t*)malloc(sizeof(*dev));
250
251 /* initialize our state here */
252 memset(dev, 0, sizeof(*dev));
253
254 /* initialize the procs */
255 dev->device.common.tag = HARDWARE_DEVICE_TAG;
256 dev->device.common.version = TV_INPUT_DEVICE_API_VERSION_0_1;
257 dev->device.common.module = const_cast<hw_module_t*>(module);
258 dev->device.common.close = tv_input_device_close;
259
260 dev->device.initialize = tv_input_initialize;
261 dev->device.get_stream_configurations =
262 tv_input_get_stream_configurations;
263 dev->device.open_stream = tv_input_open_stream;
264 dev->device.close_stream = tv_input_close_stream;
265 dev->device.request_capture = tv_input_request_capture;
266 dev->device.cancel_capture = tv_input_cancel_capture;
267
268 *device = &dev->device.common;
269 status = 0;
270 }
271 return status;
272}
273