Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 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 | |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 17 | #include <errno.h> |
Elliott Hughes | 84b9ff8 | 2015-01-28 19:54:13 -0800 | [diff] [blame] | 18 | #include <fcntl.h> |
| 19 | #include <malloc.h> |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 20 | |
| 21 | #include <cutils/log.h> |
| 22 | #include <cutils/native_handle.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 = { |
Wonsik Kim | d15399e | 2015-11-26 11:56:46 +0900 | [diff] [blame] | 40 | .open = tv_input_device_open |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | tv_input_module_t HAL_MODULE_INFO_SYM = { |
Wonsik Kim | d15399e | 2015-11-26 11:56:46 +0900 | [diff] [blame] | 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, |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 52 | } |
| 53 | }; |
| 54 | |
| 55 | /*****************************************************************************/ |
| 56 | |
| 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 | |
| 74 | static int tv_input_get_stream_configurations( |
Wonsik Kim | d15399e | 2015-11-26 11:56:46 +0900 | [diff] [blame] | 75 | const struct tv_input_device*, int, int*, |
| 76 | const tv_stream_config_t**) |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 77 | { |
| 78 | return -EINVAL; |
| 79 | } |
| 80 | |
| 81 | static int tv_input_open_stream(struct tv_input_device*, int, tv_stream_t*) |
| 82 | { |
| 83 | return -EINVAL; |
| 84 | } |
| 85 | |
| 86 | static int tv_input_close_stream(struct tv_input_device*, int, int) |
| 87 | { |
| 88 | return -EINVAL; |
| 89 | } |
| 90 | |
Wonsik Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 91 | static int tv_input_request_capture( |
| 92 | struct tv_input_device*, int, int, buffer_handle_t, uint32_t) |
| 93 | { |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | |
| 97 | static int tv_input_cancel_capture(struct tv_input_device*, int, int, uint32_t) |
| 98 | { |
| 99 | return -EINVAL; |
| 100 | } |
| 101 | |
Wonsik Kim | d15399e | 2015-11-26 11:56:46 +0900 | [diff] [blame] | 102 | static 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 Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 109 | /*****************************************************************************/ |
| 110 | |
| 111 | static 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 | |
| 122 | static 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 Kim | dce529a | 2014-04-01 11:34:33 +0900 | [diff] [blame] | 143 | dev->device.request_capture = tv_input_request_capture; |
| 144 | dev->device.cancel_capture = tv_input_cancel_capture; |
Wonsik Kim | d15399e | 2015-11-26 11:56:46 +0900 | [diff] [blame] | 145 | dev->device.get_stream_configurations_ext = |
| 146 | tv_input_get_stream_configurations_ext; |
Wonsik Kim | 0b78afb | 2014-03-03 11:33:08 +0900 | [diff] [blame] | 147 | |
| 148 | *device = &dev->device.common; |
| 149 | status = 0; |
| 150 | } |
| 151 | return status; |
| 152 | } |