From 7f391a443597f078d7614e0aa9472481c90b2611 Mon Sep 17 00:00:00 2001 From: Junliang Zhou Date: Wed, 05 Aug 2015 08:18:40 +0000 Subject: PD#110605 add screencatch for l-amlogic Change-Id: I1a1f7670e6e764e37ceb71e02c5d5c59d13e3b5a --- diff --git a/aml_screen.cpp b/aml_screen.cpp index 5baee05..640389e 100644 --- a/aml_screen.cpp +++ b/aml_screen.cpp @@ -55,7 +55,6 @@ static unsigned int gAmlScreenOpen = 0; static android::Mutex gAmlScreenLock; - /*****************************************************************************/ static int aml_screen_device_open(const struct hw_module_t* module, const char* name, @@ -104,11 +103,13 @@ int screen_source_start(struct aml_screen_device* dev) android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; return source->start(); } + int screen_source_stop(struct aml_screen_device* dev) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; return source->stop(); } + int screen_source_pause(struct aml_screen_device* dev) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; @@ -120,16 +121,14 @@ int screen_source_get_format(struct aml_screen_device* dev) android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; return source->get_format(); } + int screen_source_set_format(struct aml_screen_device* dev, int width, int height, int pix_format) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; - - if ((width > 0) && (height > 0) && ((pix_format == V4L2_PIX_FMT_NV21) || (pix_format == V4L2_PIX_FMT_YUV420))) - { + + if ((width > 0) && (height > 0) && ((pix_format == V4L2_PIX_FMT_NV21) || (pix_format == V4L2_PIX_FMT_YUV420))) { return source->set_format(width, height, pix_format); - } - else - { + } else { return source->set_format(); } } @@ -150,6 +149,16 @@ int screen_source_set_crop(struct aml_screen_device* dev, int x, int y, int widt return android::BAD_VALUE; } +int screen_source_set_amlvideo2_crop(struct aml_screen_device* dev, int x, int y, int width, int height) +{ + android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; + + if ((x >= 0) && (y >= 0) && (width > 0) && (height > 0)) + return source->set_amlvideo2_crop(x, y, width, height); + + return android::BAD_VALUE; +} + int screen_source_aquire_buffer(struct aml_screen_device* dev, aml_screen_buffer_info_t* buff_info) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; @@ -162,16 +171,19 @@ int screen_source_release_buffer(struct aml_screen_device* dev, void* ptr) android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; return source->release_buffer(ptr); } + int screen_source_set_state_callback(struct aml_screen_device* dev, olStateCB callback) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; return source->set_state_callback(callback); } + int screen_source_set_preview_window(struct aml_screen_device* dev, ANativeWindow* window) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; return source->set_preview_window(window); } + int screen_source_set_data_callback(struct aml_screen_device* dev, app_data_callback callback, void* user) { android::vdin_screen_source* source = (android::vdin_screen_source*)dev->priv; @@ -202,7 +214,6 @@ int screen_source_get_source_type(struct aml_screen_device* dev) return source->inc_buffer_refcount(ptr); } */ - /*****************************************************************************/ static int aml_screen_device_open(const struct hw_module_t* module, const char* name, @@ -211,46 +222,46 @@ static int aml_screen_device_open(const struct hw_module_t* module, const char* int status = -EINVAL; android::vdin_screen_source* source = NULL; android::Mutex::Autolock lock(gAmlScreenLock); - + LOGV("aml_screen_device_open"); - + if (!strcmp(name, AML_SCREEN_SOURCE)) { if(gAmlScreenOpen > 1){ ALOGD("aml screen device already open"); *device = NULL; return -EINVAL; } - + aml_screen_device_t *dev = (aml_screen_device_t*)malloc(sizeof(aml_screen_device_t)); - - if (!dev){ + + if (!dev) { LOGE("no memory for the screen source device"); return -ENOMEM; } /* initialize handle here */ memset(dev, 0, sizeof(*dev)); - + source = new android::vdin_screen_source; - if (!source){ + if (!source) { LOGE("no memory for class of vdin_screen_source"); free (dev); return -ENOMEM; } - if(source->init()!=0){ + if (source->init()!= 0) { LOGE("open vdin_screen_source failed!"); - free (dev); + free (dev); return -1; } dev->priv = (void*)source; - + /* initialize the procs */ dev->common.tag = HARDWARE_DEVICE_TAG; dev->common.version = 0; dev->common.module = const_cast(module); dev->common.close = aml_screen_device_close; - + dev->ops.start = screen_source_start; dev->ops.stop = screen_source_stop; dev->ops.pause = screen_source_pause; @@ -258,6 +269,7 @@ static int aml_screen_device_open(const struct hw_module_t* module, const char* dev->ops.set_format = screen_source_set_format; dev->ops.set_rotation = screen_source_set_rotation; dev->ops.set_crop = screen_source_set_crop; + dev->ops.set_amlvideo2_crop = screen_source_set_amlvideo2_crop; dev->ops.aquire_buffer = screen_source_aquire_buffer; dev->ops.release_buffer = screen_source_release_buffer; dev->ops.setStateCallBack = screen_source_set_state_callback; diff --git a/test/Android.mk b/test/Android.mk deleted file mode 100755 index a17fdd5..0000000 --- a/test/Android.mk +++ b/dev/null @@ -1,16 +0,0 @@ -# Build the unit tests. -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := screen_source_test - -LOCAL_MODULE_TAGS := tests - -LOCAL_SRC_FILES := screen_source_test.cpp - -LOCAL_SHARED_LIBRARIES := libutils\ - libhardware - -#LOCAL_C_INCLUDES := - -include $(BUILD_EXECUTABLE) \ No newline at end of file diff --git a/test/screen_source_test.cpp b/test/screen_source_test.cpp deleted file mode 100755 index fa38337..0000000 --- a/test/screen_source_test.cpp +++ b/dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_NDEBUG 0 -#define LOG_TAG "screen_source_test" -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - - -#ifndef LOGD -#define LOGD ALOGD -#endif -#ifndef LOGV -#define LOGV ALOGV -#endif -#ifndef LOGE -#define LOGE ALOGE -#endif -#ifndef LOGI -#define LOGI ALOGI -#endif -/*****************************************************************************/ -int main(int argc, char **argv) { - aml_screen_module_t* mModule; - aml_screen_device_t* mDev; - int ret = 0; - int dumpfd; - char * pSrcBufffer; - int i = 100; - - if (hw_get_module(AML_SCREEN_HARDWARE_MODULE_ID, - (const hw_module_t **)&mModule) < 0) - { - LOGE("can not get screen source module"); - ret = -1; - } - else - { - LOGV("succeed to get screen source module"); - mModule->common.methods->open((const hw_module_t *)mModule, - AML_SCREEN_SOURCE, (struct hw_device_t**)&mDev); - //do test here, we can use ops of mDev to operate vdin source - } - - mDev->ops.start(mDev); - - dumpfd = open("/tmp/yuvsource", O_CREAT | O_RDWR | O_TRUNC, 0644); - LOGV("dumpfd:%d\n"); - - while(i--) - { - pSrcBufffer = mDev->ops.aquire_buffer(mDev); - - write(dumpfd, pSrcBufffer, 640*480*3/2); - - //usleep(100000); - LOGV("release_buffer %x pSrcBufffer:%x", mDev->ops.release_buffer, pSrcBufffer); - mDev->ops.release_buffer(mDev); - } - - mDev->ops.stop(mDev); - - return ret; -} -/*****************************************************************************/ diff --git a/v4l2_vdin.cpp b/v4l2_vdin.cpp index 9e2283f..fbbe6e2 100644 --- a/v4l2_vdin.cpp +++ b/v4l2_vdin.cpp @@ -423,23 +423,44 @@ int vdin_screen_source::set_frame_rate(int frameRate) ALOGV("[%s %d]", __FUNCTION__, __LINE__); int ret = 0; struct v4l2_control ctl; - + if(mCameraHandle<0) return -1; - - struct v4l2_streamparm sparm; - memset(&sparm, 0, sizeof( sparm )); - sparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;//stream_flag; - sparm.parm.output.timeperframe.denominator = frameRate; - sparm.parm.output.timeperframe.numerator = 1; - - ret = ioctl(mCameraHandle, VIDIOC_S_PARM, &sparm); + + struct v4l2_streamparm sparm; + memset(&sparm, 0, sizeof( sparm )); + sparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;//stream_flag; + sparm.parm.output.timeperframe.denominator = frameRate; + sparm.parm.output.timeperframe.numerator = 1; + + ret = ioctl(mCameraHandle, VIDIOC_S_PARM, &sparm); if(ret < 0){ ALOGE("Set frame rate fail: %s. ret=%d", strerror(errno),ret); } return ret ; } +int vdin_screen_source::set_amlvideo2_crop(int x, int y, int width, int height) +{ + ALOGV("[%s %d]", __FUNCTION__, __LINE__); + int ret = 0; + + struct v4l2_crop crop; + memset(&crop, 0, sizeof(struct v4l2_crop)); + + crop.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; + crop.c.left = x; + crop.c.top = y; + crop.c.width = width; + crop.c.height = height; + ret = ioctl(mCameraHandle, VIDIOC_S_CROP, &crop); + if (ret) { + ALOGE("Set frame rate fail: %s. ret=%d", strerror(errno),ret); + } + + return ret ; +} + int vdin_screen_source::set_source_type(int sourceType) { ALOGV("[%s %d]", __FUNCTION__, __LINE__); diff --git a/v4l2_vdin.h b/v4l2_vdin.h index 0db756e..e299d8e 100644 --- a/v4l2_vdin.h +++ b/v4l2_vdin.h @@ -87,6 +87,7 @@ class vdin_screen_source { int set_format(int width = 640, int height = 480, int color_format = V4L2_PIX_FMT_NV21); int set_rotation(int degree); int set_crop(int x, int y, int width, int height); + int set_amlvideo2_crop(int x, int y, int width, int height); int aquire_buffer(aml_screen_buffer_info_t *buff_info); // int inc_buffer_refcount(int* ptr); int release_buffer(void* ptr); -- cgit