• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <errno.h>
18 #include <fcntl.h>
19 #include <malloc.h>
20 
21 #include <cutils/native_handle.h>
22 #include <log/log.h>
23 
24 #include <hardware/tv_input.h>
25 
26 /*****************************************************************************/
27 
28 typedef 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 
36 static int tv_input_device_open(const struct hw_module_t* module,
37         const char* name, struct hw_device_t** device);
38 
39 static struct hw_module_methods_t tv_input_module_methods = {
40     .open = tv_input_device_open
41 };
42 
43 tv_input_module_t HAL_MODULE_INFO_SYM = {
44     .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,
52     }
53 };
54 
55 /*****************************************************************************/
56 
tv_input_initialize(struct tv_input_device * dev,const tv_input_callback_ops_t * callback,void * data)57 static 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 
tv_input_get_stream_configurations(const struct tv_input_device *,int,int *,const tv_stream_config_t **)74 static int tv_input_get_stream_configurations(
75         const struct tv_input_device*, int, int*, const tv_stream_config_t**)
76 {
77     return -EINVAL;
78 }
79 
tv_input_open_stream(struct tv_input_device *,int,tv_stream_t *)80 static int tv_input_open_stream(struct tv_input_device*, int, tv_stream_t*)
81 {
82     return -EINVAL;
83 }
84 
tv_input_close_stream(struct tv_input_device *,int,int)85 static int tv_input_close_stream(struct tv_input_device*, int, int)
86 {
87     return -EINVAL;
88 }
89 
tv_input_request_capture(struct tv_input_device *,int,int,buffer_handle_t,uint32_t)90 static int tv_input_request_capture(
91         struct tv_input_device*, int, int, buffer_handle_t, uint32_t)
92 {
93     return -EINVAL;
94 }
95 
tv_input_cancel_capture(struct tv_input_device *,int,int,uint32_t)96 static int tv_input_cancel_capture(struct tv_input_device*, int, int, uint32_t)
97 {
98     return -EINVAL;
99 }
100 
101 /*****************************************************************************/
102 
tv_input_device_close(struct hw_device_t * dev)103 static int tv_input_device_close(struct hw_device_t *dev)
104 {
105     tv_input_private_t* priv = (tv_input_private_t*)dev;
106     if (priv) {
107         free(priv);
108     }
109     return 0;
110 }
111 
112 /*****************************************************************************/
113 
tv_input_device_open(const struct hw_module_t * module,const char * name,struct hw_device_t ** device)114 static int tv_input_device_open(const struct hw_module_t* module,
115         const char* name, struct hw_device_t** device)
116 {
117     int status = -EINVAL;
118     if (!strcmp(name, TV_INPUT_DEFAULT_DEVICE)) {
119         tv_input_private_t* dev = (tv_input_private_t*)malloc(sizeof(*dev));
120 
121         /* initialize our state here */
122         memset(dev, 0, sizeof(*dev));
123 
124         /* initialize the procs */
125         dev->device.common.tag = HARDWARE_DEVICE_TAG;
126         dev->device.common.version = TV_INPUT_DEVICE_API_VERSION_0_1;
127         dev->device.common.module = const_cast<hw_module_t*>(module);
128         dev->device.common.close = tv_input_device_close;
129 
130         dev->device.initialize = tv_input_initialize;
131         dev->device.get_stream_configurations =
132                 tv_input_get_stream_configurations;
133         dev->device.open_stream = tv_input_open_stream;
134         dev->device.close_stream = tv_input_close_stream;
135         dev->device.request_capture = tv_input_request_capture;
136         dev->device.cancel_capture = tv_input_cancel_capture;
137 
138         *device = &dev->device.common;
139         status = 0;
140     }
141     return status;
142 }
143