blob: 45e8388e4df6c6511dc3886e386d10073461bce9 [file] [log] [blame]
Wonsik Kim0b78afb2014-03-03 11:33:08 +09001/*
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
Wonsik Kim0b78afb2014-03-03 11:33:08 +090017#include <errno.h>
Elliott Hughes84b9ff82015-01-28 19:54:13 -080018#include <fcntl.h>
19#include <malloc.h>
Wonsik Kim0b78afb2014-03-03 11:33:08 +090020
21#include <cutils/log.h>
22#include <cutils/native_handle.h>
23
24#include <hardware/tv_input.h>
25
26/*****************************************************************************/
27
28typedef struct tv_input_private {
29 tv_input_device_t device;
30
31 // Callback related data
32 const tv_input_callback_ops_t* callback;
33 void* callback_data;
34} tv_input_private_t;
35
36static int tv_input_device_open(const struct hw_module_t* module,
37 const char* name, struct hw_device_t** device);
38
39static struct hw_module_methods_t tv_input_module_methods = {
Wonsik Kimd15399e2015-11-26 11:56:46 +090040 .open = tv_input_device_open
Wonsik Kim0b78afb2014-03-03 11:33:08 +090041};
42
43tv_input_module_t HAL_MODULE_INFO_SYM = {
Wonsik Kimd15399e2015-11-26 11:56:46 +090044 .common = {
45 .tag = HARDWARE_MODULE_TAG,
46 .version_major = 0,
47 .version_minor = 1,
48 .id = TV_INPUT_HARDWARE_MODULE_ID,
49 .name = "Sample TV input module",
50 .author = "The Android Open Source Project",
51 .methods = &tv_input_module_methods,
Wonsik Kim0b78afb2014-03-03 11:33:08 +090052 }
53};
54
55/*****************************************************************************/
56
57static int tv_input_initialize(struct tv_input_device* dev,
58 const tv_input_callback_ops_t* callback, void* data)
59{
60 if (dev == NULL || callback == NULL) {
61 return -EINVAL;
62 }
63 tv_input_private_t* priv = (tv_input_private_t*)dev;
64 if (priv->callback != NULL) {
65 return -EEXIST;
66 }
67
68 priv->callback = callback;
69 priv->callback_data = data;
70
71 return 0;
72}
73
74static int tv_input_get_stream_configurations(
Wonsik Kimd15399e2015-11-26 11:56:46 +090075 const struct tv_input_device*, int, int*,
76 const tv_stream_config_t**)
Wonsik Kim0b78afb2014-03-03 11:33:08 +090077{
78 return -EINVAL;
79}
80
81static int tv_input_open_stream(struct tv_input_device*, int, tv_stream_t*)
82{
83 return -EINVAL;
84}
85
86static int tv_input_close_stream(struct tv_input_device*, int, int)
87{
88 return -EINVAL;
89}
90
Wonsik Kimdce529a2014-04-01 11:34:33 +090091static int tv_input_request_capture(
92 struct tv_input_device*, int, int, buffer_handle_t, uint32_t)
93{
94 return -EINVAL;
95}
96
97static int tv_input_cancel_capture(struct tv_input_device*, int, int, uint32_t)
98{
99 return -EINVAL;
100}
101
Wonsik Kimd15399e2015-11-26 11:56:46 +0900102static int tv_input_get_stream_configurations_ext(
103 const struct tv_input_device*, int, int*,
104 const tv_stream_config_ext_t**)
105{
106 return -EINVAL;
107}
108
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900109/*****************************************************************************/
110
111static int tv_input_device_close(struct hw_device_t *dev)
112{
113 tv_input_private_t* priv = (tv_input_private_t*)dev;
114 if (priv) {
115 free(priv);
116 }
117 return 0;
118}
119
120/*****************************************************************************/
121
122static int tv_input_device_open(const struct hw_module_t* module,
123 const char* name, struct hw_device_t** device)
124{
125 int status = -EINVAL;
126 if (!strcmp(name, TV_INPUT_DEFAULT_DEVICE)) {
127 tv_input_private_t* dev = (tv_input_private_t*)malloc(sizeof(*dev));
128
129 /* initialize our state here */
130 memset(dev, 0, sizeof(*dev));
131
132 /* initialize the procs */
133 dev->device.common.tag = HARDWARE_DEVICE_TAG;
134 dev->device.common.version = TV_INPUT_DEVICE_API_VERSION_0_1;
135 dev->device.common.module = const_cast<hw_module_t*>(module);
136 dev->device.common.close = tv_input_device_close;
137
138 dev->device.initialize = tv_input_initialize;
139 dev->device.get_stream_configurations =
140 tv_input_get_stream_configurations;
141 dev->device.open_stream = tv_input_open_stream;
142 dev->device.close_stream = tv_input_close_stream;
Wonsik Kimdce529a2014-04-01 11:34:33 +0900143 dev->device.request_capture = tv_input_request_capture;
144 dev->device.cancel_capture = tv_input_cancel_capture;
Wonsik Kimd15399e2015-11-26 11:56:46 +0900145 dev->device.get_stream_configurations_ext =
146 tv_input_get_stream_configurations_ext;
Wonsik Kim0b78afb2014-03-03 11:33:08 +0900147
148 *device = &dev->device.common;
149 status = 0;
150 }
151 return status;
152}