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