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