summaryrefslogtreecommitdiff
path: root/aml_screen.cpp (plain)
blob: 48acbd601fd8f3dbfaa43427578bd49a5aac3bb9
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 return source->start();
106}
107int screen_source_stop(struct aml_screen_device* dev)
108{
109 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
110 return source->stop();
111}
112int screen_source_pause(struct aml_screen_device* dev)
113{
114 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
115 return source->pause();
116}
117
118int screen_source_get_format(struct aml_screen_device* dev)
119{
120 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
121 return source->get_format();
122}
123int screen_source_set_format(struct aml_screen_device* dev, int width, int height, int pix_format)
124{
125 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
126
127 if ((width > 0) && (height > 0) && ((pix_format == V4L2_PIX_FMT_NV21) || (pix_format == V4L2_PIX_FMT_YUV420)))
128 {
129 return source->set_format(width, height, pix_format);
130 }
131 else
132 {
133 return source->set_format();
134 }
135}
136
137int screen_source_set_rotation(struct aml_screen_device* dev, int degree)
138{
139 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
140 return source->set_rotation(degree);
141}
142
143int screen_source_set_crop(struct aml_screen_device* dev, int x, int y, int width, int height)
144{
145 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
146
147 if ((x >= 0) && (y >= 0) && (width > 0) && (height > 0))
148 return source->set_crop(x, y, width, height);
149
150 return android::BAD_VALUE;
151}
152
153int screen_source_aquire_buffer(struct aml_screen_device* dev, int* buff_info)
154{
155 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
156
157 return source->aquire_buffer(buff_info);
158}
159
160int screen_source_release_buffer(struct aml_screen_device* dev, int* ptr)
161{
162 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
163 return source->release_buffer(ptr);
164}
165int screen_source_set_state_callback(struct aml_screen_device* dev, olStateCB callback)
166{
167 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
168 return source->set_state_callback(callback);
169}
170int screen_source_set_preview_window(struct aml_screen_device* dev, ANativeWindow* window)
171{
172 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
173 return source->set_preview_window(window);
174}
175int screen_source_set_data_callback(struct aml_screen_device* dev, app_data_callback callback, void* user)
176{
177 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
178 return source->set_data_callback(callback, user);
179}
180
181int screen_source_set_frame_rate(struct aml_screen_device* dev, int frameRate)
182{
183 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
184 return source->set_frame_rate(frameRate);
185}
186
187int screen_source_set_source_type(struct aml_screen_device* dev, SOURCETYPE sourceType)
188{
189 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
190 return source->set_source_type(sourceType);
191}
192
193int screen_source_get_source_type(struct aml_screen_device* dev)
194{
195 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
196 return source->get_source_type();
197}
198
199/* int screen_source_inc_buffer_refcount(struct aml_screen_device* dev, int* ptr)
200{
201 android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv;
202 return source->inc_buffer_refcount(ptr);
203} */
204
205
206/*****************************************************************************/
207
208static int aml_screen_device_open(const struct hw_module_t* module, const char* name,
209 struct hw_device_t** device)
210{
211 int status = -EINVAL;
212 android::vdin_screen_source* source = NULL;
213 android::Mutex::Autolock lock(gAmlScreenLock);
214
215 LOGV("aml_screen_device_open");
216
217 if (!strcmp(name, AML_SCREEN_SOURCE)) {
218 if(gAmlScreenOpen > 1){
219 ALOGD("aml screen device already open");
220 *device = NULL;
221 return -EINVAL;
222 }
223
224 aml_screen_device_t *dev = (aml_screen_device_t*)malloc(sizeof(aml_screen_device_t));
225
226 if (!dev){
227 LOGE("no memory for the screen source device");
228 return -ENOMEM;
229 }
230 /* initialize handle here */
231 memset(dev, 0, sizeof(*dev));
232
233 source = new android::vdin_screen_source;
234 if (!source){
235 LOGE("no memory for class of vdin_screen_source");
236 free (dev);
237 return -ENOMEM;
238 }
239
240 if(source->init()!=0){
241 LOGE("open vdin_screen_source failed!");
242 free (dev);
243 return -1;
244 }
245
246 dev->priv = (void*)source;
247
248 /* initialize the procs */
249 dev->common.tag = HARDWARE_DEVICE_TAG;
250 dev->common.version = 0;
251 dev->common.module = const_cast<hw_module_t*>(module);
252 dev->common.close = aml_screen_device_close;
253
254 dev->ops.start = screen_source_start;
255 dev->ops.stop = screen_source_stop;
256 dev->ops.pause = screen_source_pause;
257 dev->ops.get_format = screen_source_get_format;
258 dev->ops.set_format = screen_source_set_format;
259 dev->ops.set_rotation = screen_source_set_rotation;
260 dev->ops.set_crop = screen_source_set_crop;
261 dev->ops.aquire_buffer = screen_source_aquire_buffer;
262 dev->ops.release_buffer = screen_source_release_buffer;
263 dev->ops.setStateCallBack = screen_source_set_state_callback;
264 dev->ops.setPreviewWindow = screen_source_set_preview_window;
265 dev->ops.setDataCallBack = screen_source_set_data_callback;
266 dev->ops.set_frame_rate = screen_source_set_frame_rate;
267 dev->ops.set_source_type = screen_source_set_source_type;
268 dev->ops.get_source_type = screen_source_get_source_type;
269 // dev->ops.inc_buffer_refcount = screen_source_inc_buffer_refcount;
270 *device = &dev->common;
271 status = 0;
272 gAmlScreenOpen++;
273 }
274 return status;
275}
276