summaryrefslogtreecommitdiff
path: root/aml_screen.cpp (plain)
blob: 33923c9f8e63efa269d17c4e6eebc61804d4ba87
1/*
2 * Copyright (C) 2013 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_NDEBUG 0
18#define LOG_TAG "screen_source"
19#include <hardware/hardware.h>
20#include <hardware/aml_screen.h>
21
22#include <signal.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <fcntl.h>
27#include <unistd.h>
28#include <errno.h>
29#include <sys/ioctl.h>
30#include <sys/mman.h>
31#include <sys/select.h>
32#include <linux/videodev.h>
33#include <sys/time.h>
34
35
36#include <errno.h>
37#include <cutils/log.h>
38#include <cutils/atomic.h>
39
40#include "v4l2_vdin.h"
41
42#ifndef LOGD
43#define LOGD ALOGD
44#endif
45#ifndef LOGV
46#define LOGV ALOGV
47#endif
48#ifndef LOGE
49#define LOGE ALOGE
50#endif
51#ifndef LOGI
52#define LOGI ALOGI
53#endif
54
55static unsigned int gAmlScreenOpen = 0;
56static android::Mutex gAmlScreenLock;
57
58
59/*****************************************************************************/
60
61static int aml_screen_device_open(const struct hw_module_t* module, const char* name,
62 struct hw_device_t** device);
63
64static struct hw_module_methods_t aml_screen_module_methods = {
65 open: aml_screen_device_open
66};
67
68aml_screen_module_t HAL_MODULE_INFO_SYM = {
69 common: {
70 tag: HARDWARE_MODULE_TAG,
71 version_major: 1,
72 version_minor: 0,
73 id: AML_SCREEN_HARDWARE_MODULE_ID,
74 name: "aml screen source module",
75 author: "Amlogic",
76 methods: &aml_screen_module_methods,
77 dso : NULL,
78 reserved : {0},
79 }
80};
81
82/*****************************************************************************/
83
84static int aml_screen_device_close(struct hw_device_t *dev)
85{
86 android::vdin_screen_source* source = NULL;
87 aml_screen_device_t* ctx = (aml_screen_device_t*)dev;
88
89 android::Mutex::Autolock lock(gAmlScreenLock);
90 if (ctx) {
91 if (ctx->priv){
92 source = (android::vdin_screen_source*)ctx->priv;
93 delete source;
94 source = NULL;
95 }
96 free(ctx);
97 }
98 gAmlScreenOpen--;
99 return 0;
100}
101
102int screen_source_start(struct aml_screen_device* dev)
103{
104 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
105 LOGV("screen_source_start");
106 return source->start();
107}
108int screen_source_stop(struct aml_screen_device* dev)
109{
110 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
111 return source->stop();
112}
113int screen_source_pause(struct aml_screen_device* dev)
114{
115 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
116 return source->pause();
117}
118
119int screen_source_get_format(struct aml_screen_device* dev)
120{
121 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
122 return source->get_format();
123}
124int screen_source_set_format(struct aml_screen_device* dev, int width, int height, int pix_format)
125{
126 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
127
128 if ((width > 0) && (height > 0) && ((pix_format == V4L2_PIX_FMT_NV21) || (pix_format == V4L2_PIX_FMT_YUV420)))
129 {
130 return source->set_format(width, height, pix_format);
131 }
132 else
133 {
134 return source->set_format();
135 }
136}
137
138int screen_source_set_rotation(struct aml_screen_device* dev, int degree)
139{
140 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
141 return source->set_rotation(degree);
142}
143
144int screen_source_set_crop(struct aml_screen_device* dev, int x, int y, int width, int height)
145{
146 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
147
148 if ((x >= 0) && (y >= 0) && (width > 0) && (height > 0))
149 return source->set_crop(x, y, width, height);
150
151 return android::BAD_VALUE;
152}
153
154int screen_source_aquire_buffer(struct aml_screen_device* dev, int* buff_info)
155{
156 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
157
158 return source->aquire_buffer(buff_info);
159}
160
161int screen_source_release_buffer(struct aml_screen_device* dev, int* ptr)
162{
163 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
164 return source->release_buffer(ptr);
165}
166int screen_source_set_state_callback(struct aml_screen_device* dev, olStateCB callback)
167{
168 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
169 return source->set_state_callback(callback);
170}
171int screen_source_set_preview_window(struct aml_screen_device* dev, ANativeWindow* window)
172{
173 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
174 return source->set_preview_window(window);
175}
176int screen_source_set_data_callback(struct aml_screen_device* dev, app_data_callback callback, void* user)
177{
178 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
179 return source->set_data_callback(callback, user);
180}
181
182int screen_source_set_frame_rate(struct aml_screen_device* dev, int frameRate)
183{
184 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
185 return source->set_frame_rate(frameRate);
186}
187
188int screen_source_set_source_type(struct aml_screen_device* dev, SOURCETYPE sourceType)
189{
190 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
191 return source->set_source_type(sourceType);
192}
193
194int screen_source_get_source_type(struct aml_screen_device* dev)
195{
196 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
197 return source->get_source_type();
198}
199
200/* int screen_source_inc_buffer_refcount(struct aml_screen_device* dev, int* ptr)
201{
202 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
203 return source->inc_buffer_refcount(ptr);
204} */
205
206
207/*****************************************************************************/
208
209static int aml_screen_device_open(const struct hw_module_t* module, const char* name,
210 struct hw_device_t** device)
211{
212 int status = -EINVAL;
213 android::vdin_screen_source* source = NULL;
214
215 android::Mutex::Autolock lock(gAmlScreenLock);
216
217 LOGV("aml_screen_device_open");
218
219 if (!strcmp(name, AML_SCREEN_SOURCE)) {
220
221 if(gAmlScreenOpen > 1){
222 ALOGD("aml screen device already open");
223 *device = NULL;
224 return -EINVAL;
225 }
226
227 aml_screen_device_t *dev = (aml_screen_device_t*)malloc(sizeof(aml_screen_device_t));
228
229 if (!dev)
230 {
231 LOGE("no memory for the screen source device");
232 return -ENOMEM;
233 }
234 /* initialize handle here */
235 memset(dev, 0, sizeof(*dev));
236
237 source = new android::vdin_screen_source;
238 if (!source)
239 {
240 LOGE("no memory for class of vdin_screen_source");
241 free (dev);
242 return -ENOMEM;
243 }
244 dev->priv = (void*)source;
245
246 /* initialize the procs */
247 dev->common.tag = HARDWARE_DEVICE_TAG;
248 dev->common.version = 0;
249 dev->common.module = const_cast<hw_module_t*>(module);
250 dev->common.close = aml_screen_device_close;
251
252 dev->ops.start = screen_source_start;
253 dev->ops.stop = screen_source_stop;
254 dev->ops.pause = screen_source_pause;
255 dev->ops.get_format = screen_source_get_format;
256 dev->ops.set_format = screen_source_set_format;
257 dev->ops.set_rotation = screen_source_set_rotation;
258 dev->ops.set_crop = screen_source_set_crop;
259 dev->ops.aquire_buffer = screen_source_aquire_buffer;
260 dev->ops.release_buffer = screen_source_release_buffer;
261 dev->ops.setStateCallBack = screen_source_set_state_callback;
262 dev->ops.setPreviewWindow = screen_source_set_preview_window;
263 dev->ops.setDataCallBack = screen_source_set_data_callback;
264 dev->ops.set_frame_rate = screen_source_set_frame_rate;
265 dev->ops.set_source_type = screen_source_set_source_type;
266 dev->ops.get_source_type = screen_source_get_source_type;
267 // dev->ops.inc_buffer_refcount = screen_source_inc_buffer_refcount;
268 *device = &dev->common;
269
270 status = 0;
271 gAmlScreenOpen++;
272 }
273 return status;
274}
275