summaryrefslogtreecommitdiff
path: root/tv_input.cpp (plain)
blob: b67e359eaa96c8d0c1d5a0e96144a3becc485230
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 <tvin/CTvin.h>
27#include <tvserver/TvService.h>
28/*****************************************************************************/
29
30typedef struct tv_input_private {
31 tv_input_device_t device;
32
33 // Callback related data
34 const tv_input_callback_ops_t *callback;
35 void *callback_data;
36 //TvService* pTvService;
37 CTv *pTv;
38} tv_input_private_t;
39
40static int notify_ATV_device_available(tv_input_private_t *priv)
41{
42 tv_input_event_t event;
43 event.device_info.device_id = SOURCE_TV;
44 event.device_info.type = TV_INPUT_TYPE_TUNER;
45 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
46 event.device_info.audio_type = AUDIO_DEVICE_NONE;
47 priv->callback->notify(&priv->device, &event, priv->callback_data);
48 return 0;
49}
50
51static int notify_DTV_device_available(tv_input_private_t *priv)
52{
53 tv_input_event_t event;
54 event.device_info.device_id = SOURCE_DTV;
55 event.device_info.type = TV_INPUT_TYPE_TUNER;
56 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
57 event.device_info.audio_type = AUDIO_DEVICE_NONE;
58 priv->callback->notify(&priv->device, &event, priv->callback_data);
59 return 0;
60}
61
62static int notify_AV_device_available(tv_input_private_t *priv)
63{
64 tv_input_event_t event;
65 event.device_info.device_id = SOURCE_AV1;
66 event.device_info.type = TV_INPUT_TYPE_COMPONENT;
67 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
68 event.device_info.audio_type = AUDIO_DEVICE_NONE;
69 priv->callback->notify(&priv->device, &event, priv->callback_data);
70 return 0;
71}
72
73static int notify_hdmi_device_available(tv_input_private_t *priv, int dev_id, uint32_t port_id)
74{
75 tv_input_event_t event;
76 event.device_info.device_id = dev_id;
77 event.device_info.type = TV_INPUT_TYPE_HDMI;
78 event.type = TV_INPUT_EVENT_DEVICE_AVAILABLE;
79 event.device_info.hdmi.port_id = port_id;
80 event.device_info.audio_type = AUDIO_DEVICE_NONE;
81 priv->callback->notify(&priv->device, &event, priv->callback_data);
82 return 0;
83}
84
85static int get_stream_configs(int dev_id, int *num_configurations, const tv_stream_config_t **configs)
86{
87 tv_stream_config_t *mconfig = (tv_stream_config_t *)malloc(sizeof(mconfig));
88 if (!mconfig) {
89 return -1;
90 }
91 switch (dev_id) {
92 case SOURCE_TV:
93 mconfig->stream_id = SOURCE_TV;
94 mconfig->type = TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
95 mconfig->max_video_width = 1920;
96 mconfig->max_video_height = 1080;
97 *num_configurations = 1;
98 *configs = mconfig;
99 break;
100 case SOURCE_DTV:
101 mconfig->stream_id = SOURCE_DTV;
102 mconfig->type = TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
103 mconfig->max_video_width = 1920;
104 mconfig->max_video_height = 1080;
105 *num_configurations = 1;
106 *configs = mconfig;
107 break;
108 case SOURCE_AV1:
109 mconfig->stream_id = SOURCE_AV1;
110 mconfig->type = TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
111 mconfig->max_video_width = 1920;
112 mconfig->max_video_height = 1080;
113 *num_configurations = 1;
114 *configs = mconfig;
115 break;
116 case SOURCE_HDMI1:
117 mconfig->stream_id = SOURCE_HDMI1;
118 mconfig->type = TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
119 mconfig->max_video_width = 1920;
120 mconfig->max_video_height = 1080;
121 *num_configurations = 1;
122 *configs = mconfig;
123 break;
124 case SOURCE_HDMI2:
125 mconfig->stream_id = SOURCE_HDMI2;
126 mconfig->type = TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
127 mconfig->max_video_width = 1920;
128 mconfig->max_video_height = 1080;
129 *num_configurations = 1;
130 *configs = mconfig;
131 break;
132 case SOURCE_HDMI3:
133 mconfig->stream_id = SOURCE_HDMI3;
134 mconfig->type = TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE ;
135 mconfig->max_video_width = 1920;
136 mconfig->max_video_height = 1080;
137 *num_configurations = 1;
138 *configs = mconfig;
139 break;
140 default:
141 break;
142 }
143 return 0;
144}
145
146static int tv_input_device_open(const struct hw_module_t *module,
147 const char *name, struct hw_device_t **device);
148
149static struct hw_module_methods_t tv_input_module_methods = {
150open:
151 tv_input_device_open
152};
153
154tv_input_module_t HAL_MODULE_INFO_SYM = {
155common:
156 {
157tag:
158 HARDWARE_MODULE_TAG,
159 version_major: 0,
160 version_minor: 1,
161id:
162 TV_INPUT_HARDWARE_MODULE_ID,
163name: "TVInput module"
164 ,
165author: "Amlogic"
166 ,
167methods:
168 &tv_input_module_methods,
169 }
170};
171
172/*****************************************************************************/
173
174static int tv_input_initialize(struct tv_input_device *dev,
175 const tv_input_callback_ops_t *callback, void *data)
176{
177 if (dev == NULL || callback == NULL) {
178 return -EINVAL;
179 }
180 tv_input_private_t *priv = (tv_input_private_t *)dev;
181 if (priv->callback != NULL) {
182 return -EEXIST;
183 }
184
185 priv->callback = callback;
186 priv->callback_data = data;
187 /* ATV_DEVICE_AVAILABLE */
188 notify_ATV_device_available(priv);
189 /* DTV_DEVICE_AVAILABLE */
190 notify_DTV_device_available(priv);
191 /* AV_DEVICE_AVAILABLE */
192 notify_AV_device_available(priv);
193 /* HDMI1_DEVICE_AVAILABLE */
194 notify_hdmi_device_available(priv, SOURCE_HDMI1, 1);
195 /* HDMI2_DEVICE_AVAILABLE */
196 notify_hdmi_device_available(priv, SOURCE_HDMI2, 2);
197 /* HDMI3_DEVICE_AVAILABLE */
198 notify_hdmi_device_available(priv, SOURCE_HDMI3, 3);
199
200 return 0;
201}
202
203static int tv_input_get_stream_configurations(const struct tv_input_device *dev,
204 int device_id, int *num_configurations,
205 const tv_stream_config_t **configs)
206{
207 if (get_stream_configs(device_id, num_configurations, configs) == 0) {
208 return 0;
209 }
210 return -EINVAL;
211}
212
213static int tv_input_open_stream(struct tv_input_device* dev, int device_id,
214 tv_stream_t* stream)
215{
216 tv_input_private_t *priv = (tv_input_private_t *)dev;
217 priv->pTv->SetSourceSwitchInput((tv_source_input_t) device_id);
218 return -EINVAL;
219}
220
221static int tv_input_close_stream(struct tv_input_device* dev, int device_id,
222 int stream_id)
223{
224 tv_input_private_t *priv = (tv_input_private_t *)dev;
225 priv->pTv->StopTvLock();
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