author | jiyu.yang <jiyu.yang@amlogic.com> | 2012-08-31 13:06:21 (GMT) |
---|---|---|
committer | jiyu.yang <jiyu.yang@amlogic.com> | 2012-09-03 01:39:32 (GMT) |
commit | 5249946c75243d89a0e96f2d54fe1a3df12f9d4e (patch) | |
tree | 0fca8b0c3efa2ee69b617858fc6d36c429c9e317 | |
parent | ed5b5b18237476df588f09d2c8fdace75fada158 (diff) | |
download | camera-5249946c75243d89a0e96f2d54fe1a3df12f9d4e.zip camera-5249946c75243d89a0e96f2d54fe1a3df12f9d4e.tar.gz camera-5249946c75243d89a0e96f2d54fe1a3df12f9d4e.tar.bz2 |
add hflip,zoom,rotation by Brian
-rwxr-xr-x | AppCallbackNotifier.cpp | 6 | ||||
-rwxr-xr-x | V4LCameraAdapter/V4LCameraAdapter.cpp | 110 | ||||
-rwxr-xr-x | inc/V4LCameraAdapter/V4LCameraAdapter.h | 4 |
3 files changed, 108 insertions, 12 deletions
diff --git a/AppCallbackNotifier.cpp b/AppCallbackNotifier.cpp index 43a837e..7f6f949 100755 --- a/AppCallbackNotifier.cpp +++ b/AppCallbackNotifier.cpp @@ -916,6 +916,12 @@ void AppCallbackNotifier::notifyFrame() #else tn_width = parameters.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH); tn_height = parameters.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT); + + if(frame->mHeight>frame->mWidth){ + int temp = tn_width; + tn_width = tn_height; + tn_height = tn_width; + } if ((tn_width > 0) && (tn_height > 0)) { tn_jpeg = (Encoder_libjpeg::params*) diff --git a/V4LCameraAdapter/V4LCameraAdapter.cpp b/V4LCameraAdapter/V4LCameraAdapter.cpp index 026c9bb..e98398b 100755 --- a/V4LCameraAdapter/V4LCameraAdapter.cpp +++ b/V4LCameraAdapter/V4LCameraAdapter.cpp @@ -92,6 +92,8 @@ namespace android { //frames skipped before recalculating the framerate #define FPS_PERIOD 30 +#define V4L2_ROTATE_ID 0x980922 //V4L2_CID_ROTATE + Mutex gAdapterLock; extern "C" int set_banding(int camera_fd,const char *snm); @@ -109,6 +111,7 @@ static int set_hflip_mode(int camera_fd, bool mode); static int get_hflip_mode(int camera_fd); static int get_supported_zoom(int camera_fd, char * zoom_str); static int set_zoom_level(int camera_fd, int zoom); +static int set_rotate_value(int camera_fd, int value); #endif #ifdef AMLOGIC_USB_CAMERA_SUPPORT @@ -245,18 +248,31 @@ status_t V4LCameraAdapter::initialize(CameraProperties::Properties* caps) #ifndef AMLOGIC_USB_CAMERA_SUPPORT // --------- if(get_hflip_mode(mCameraHandle)==0) - mhflip_supported = true; + mIoctlSupport |= IOCTL_MASK_HFLIP; else - mhflip_supported = false; + mIoctlSupport &= ~IOCTL_MASK_HFLIP; { struct v4l2_queryctrl qc; int i_ret = 0; + memset(&qc, 0, sizeof(struct v4l2_queryctrl)); qc.id = V4L2_CID_ZOOM_ABSOLUTE; i_ret = ioctl (mCameraHandle, VIDIOC_QUERYCTRL, &qc); if((qc.flags == V4L2_CTRL_FLAG_DISABLED) ||( i_ret < 0) || (qc.type != V4L2_CTRL_TYPE_INTEGER)) - mZoomMode = false; + mIoctlSupport &= ~IOCTL_MASK_ZOOM; else - mZoomMode = true; + mIoctlSupport |= IOCTL_MASK_ZOOM; + + memset(&qc, 0, sizeof(struct v4l2_queryctrl)); + qc.id = V4L2_ROTATE_ID; + i_ret = ioctl (mCameraHandle, VIDIOC_QUERYCTRL, &qc); + if((qc.flags == V4L2_CTRL_FLAG_DISABLED) ||( i_ret < 0) || (qc.type != V4L2_CTRL_TYPE_INTEGER)) + mIoctlSupport &= ~IOCTL_MASK_ROTATE; + else + mIoctlSupport |= IOCTL_MASK_ROTATE; + + if(mIoctlSupport & IOCTL_MASK_ROTATE) + CAMHAL_LOGDB("camera %d support capture rotate",mSensorIndex); + mRotateValue = 0; } writefile((char*)SYSFILE_CAMERA_SET_PARA, (char*)"1"); //mirror set at here will not work. @@ -354,7 +370,7 @@ status_t V4LCameraAdapter::setParameters(const CameraParameters ¶ms) CAMHAL_LOGDB("Change the zoom level---old:%d,new:%d",mZoomlevel,zoom); mZoomlevel = zoom; #ifndef AMLOGIC_USB_CAMERA_SUPPORT - if(mZoomMode) + if(mIoctlSupport & IOCTL_MASK_ZOOM) set_zoom_level(mCameraHandle,z); else SYS_set_zoom(z); @@ -759,6 +775,17 @@ status_t V4LCameraAdapter::UseBuffersCapture(void* bufArr, int num) #ifdef AMLOGIC_USB_CAMERA_SUPPORT setBuffersFormat(width, height, V4L2_PIX_FMT_YUYV); #else + if(mIoctlSupport & IOCTL_MASK_ROTATE){ + int temp = 0; + mRotateValue = mParams.getInt(CameraParameters::KEY_ROTATION); + if((mRotateValue!=0)&&(mRotateValue!=90)&&(mRotateValue!=180)&&(mRotateValue!=270)) + mRotateValue = 0; + if((mRotateValue==90)||(mRotateValue==270)){ + temp = width; + width = height; + height = temp; + } + } setBuffersFormat(width, height, DEFAULT_IMAGE_CAPTURE_PIXEL_FORMAT); #endif @@ -927,12 +954,18 @@ status_t V4LCameraAdapter::startPreview() } #ifndef AMLOGIC_USB_CAMERA_SUPPORT - if(mhflip_supported){ + + if(mIoctlSupport & IOCTL_MASK_HFLIP){ if(set_hflip_mode(mCameraHandle,mbFrontCamera?true:false)) writefile((char *)SYSFILE_CAMERA_SET_MIRROR,(char*)(mbFrontCamera?"1":"0")); }else{ writefile((char *)SYSFILE_CAMERA_SET_MIRROR,(char*)(mbFrontCamera?"1":"0")); } + + if(mIoctlSupport & IOCTL_MASK_ROTATE){ + set_rotate_value(mCameraHandle,0); + mRotateValue = 0; + } #endif nQueued = 0; @@ -1351,13 +1384,26 @@ int V4LCameraAdapter::GenExif(ExifElementsTable* exiftable) orientation = 3; else if(orientation == 270) orientation = 8; - sprintf(exifcontent,"%d",orientation); - LOGD("exifcontent %s",exifcontent); - exiftable->insertElement("Orientation",(const char*)exifcontent); + //Image width,height int width,height; mParams.getPictureSize(&width,&height); +#ifndef AMLOGIC_USB_CAMERA_SUPPORT + if(mIoctlSupport & IOCTL_MASK_ROTATE){ + orientation = 1; + if((mRotateValue==90)||(mRotateValue==270)){ + int temp = width; + width = height; + height = temp; + } + } +#endif + + sprintf(exifcontent,"%d",orientation); + //LOGD("exifcontent %s",exifcontent); + exiftable->insertElement("Orientation",(const char*)exifcontent); + sprintf(exifcontent,"%d",width); exiftable->insertElement("ImageWidth",(const char*)exifcontent); sprintf(exifcontent,"%d",height); @@ -1492,7 +1538,7 @@ int V4LCameraAdapter::pictureThread() CameraFrame frame; #ifndef AMLOGIC_USB_CAMERA_SUPPORT - if(mhflip_supported){ + if(mIoctlSupport & IOCTL_MASK_HFLIP){ if(set_hflip_mode(mCameraHandle,mbFrontCamera?true:false)) writefile((char *)SYSFILE_CAMERA_SET_MIRROR,(char*)(mbFrontCamera?"1":"0")); }else{ @@ -1522,6 +1568,12 @@ int V4LCameraAdapter::pictureThread() CAMHAL_LOGEA("VIDIOC_QBUF Failed"); return -EINVAL; } + +#ifndef AMLOGIC_USB_CAMERA_SUPPORT + if(mIoctlSupport & IOCTL_MASK_ROTATE){ + set_rotate_value(mCameraHandle,mRotateValue); + } +#endif enum v4l2_buf_type bufType; if (!mVideoInfo->isStreaming) @@ -1553,6 +1605,16 @@ int V4LCameraAdapter::pictureThread() uint8_t* dest = (uint8_t*)mCaptureBuf->data; uint8_t* src = (uint8_t*) fp; mParams.getPictureSize(&width, &height); + +#ifndef AMLOGIC_USB_CAMERA_SUPPORT + if((mRotateValue==90)||(mRotateValue==270)){ + int temp = 0; + temp = width; + width = height; + height = temp; + } +#endif + LOGD("pictureThread mCaptureBuf=%#x dest=%#x fp=%#x width=%d height=%d", (uint32_t)mCaptureBuf, (uint32_t)dest, (uint32_t)fp, width, height); LOGD("length=%d bytesused=%d index=%d", mVideoInfo->buf.length, mVideoInfo->buf.bytesused, index); @@ -1633,6 +1695,12 @@ int V4LCameraAdapter::pictureThread() &&(FLASHLIGHT_ON == mFlashMode)){ set_flash_mode( mCameraHandle, "off"); } +#ifndef AMLOGIC_USB_CAMERA_SUPPORT + if(mIoctlSupport & IOCTL_MASK_ROTATE){ + set_rotate_value(mCameraHandle,0); + mRotateValue = 0; + } +#endif // start preview thread again after stopping it in UseBuffersCapture { @@ -2919,6 +2987,28 @@ static int set_zoom_level(int camera_fd, int zoom) CAMHAL_LOGEB("Set zoom level fail: %s. ret=%d", strerror(errno),ret); return ret ; } +static int set_rotate_value(int camera_fd, int value) +{ + int ret = 0; + struct v4l2_control ctl; + if(camera_fd<0) + return -1; + + if((value!=0)&&(value!=90)&&(value!=180)&&(value!=270)){ + CAMHAL_LOGEB("Set rotate value invalid: %d.", value); + return -1; + } + + ctl.value=value; + + ctl.id = V4L2_ROTATE_ID; + + ret = ioctl(camera_fd, VIDIOC_S_CTRL, &ctl); + if(ret<0) + CAMHAL_LOGEB("Set rotate value fail: %s. ret=%d", strerror(errno),ret); + return ret ; +} + #endif }; diff --git a/inc/V4LCameraAdapter/V4LCameraAdapter.h b/inc/V4LCameraAdapter/V4LCameraAdapter.h index 8938df5..56f942d 100755 --- a/inc/V4LCameraAdapter/V4LCameraAdapter.h +++ b/inc/V4LCameraAdapter/V4LCameraAdapter.h @@ -214,6 +214,7 @@ typedef enum camera_focus_mode_e { #define IOCTL_MASK_EXPOSURE (1<<5) #define IOCTL_MASK_EFFECT (1<<6) #define IOCTL_MASK_BANDING (1<<7) +#define IOCTL_MASK_ROTATE (1<<8) /** * Class which completely abstracts the camera hardware interaction from camera hal @@ -371,8 +372,7 @@ private: struct timeval ppm_now; bool first_time; #ifndef AMLOGIC_USB_CAMERA_SUPPORT - bool mhflip_supported; - bool mZoomMode; + int mRotateValue; #endif }; }; //// namespace |