From b16271acf212cfa28a29bf912f26801458e8b40a Mon Sep 17 00:00:00 2001 From: Guosong Zhou Date: Thu, 29 Jan 2015 03:30:24 +0000 Subject: PD #102342: fix usb camera MJEGP and YUYV format JPEG compress fail. Change-Id: Ib1dafe301cc9eaf3014e799be17957af6e8f705a --- diff --git a/v3/fake-pipeline2/Sensor.cpp b/v3/fake-pipeline2/Sensor.cpp index 422c26b..09818d6 100755 --- a/v3/fake-pipeline2/Sensor.cpp +++ b/v3/fake-pipeline2/Sensor.cpp @@ -1748,38 +1748,43 @@ void Sensor::captureRGB(uint8_t *img, uint32_t gain, uint32_t stride) { { src = (uint8_t *)get_picture(vinfo); if (NULL != src) { - break; - } - - usleep(5000); - } - ALOGD("get picture success !"); - - if (vinfo->picture.format.fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG){ - uint8_t *tmp_buffer = new uint8_t[width * height * 3 / 2]; - if ( tmp_buffer == NULL) { - ALOGE("new buffer failed!\n"); - return; - } - if (ConvertMjpegToNV21(src, vinfo->picture.buf.bytesused, tmp_buffer, + if (vinfo->picture.format.fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { + uint8_t *tmp_buffer = new uint8_t[width * height * 3 / 2]; + if ( tmp_buffer == NULL) { + ALOGE("new buffer failed!\n"); + return; + } + if (ConvertMjpegToNV21(src, vinfo->picture.buf.bytesused, tmp_buffer, width, tmp_buffer + width * height, (width + 1) / 2, width, height, width, height, libyuv::FOURCC_MJPG) != 0) { - DBG_LOGA("Decode MJPEG frame failed\n"); - } - nv21_to_rgb24(tmp_buffer,img,width,height); - if (tmp_buffer != NULL) - delete [] tmp_buffer; - } else if (vinfo->picture.format.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) { - yuyv422_to_rgb24(src,img,width,height); - } - - if (vinfo->picture.format.fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24){ - if (vinfo->picture.buf.length == width*height*3) { - memcpy(img, src, vinfo->picture.buf.length); - } else { - rgb24_memcpy( img, src, width, height); + DBG_LOGA("Decode MJPEG frame failed\n"); + putback_picture_frame(vinfo); + usleep(5000); + } else { + nv21_to_rgb24(tmp_buffer,img,width,height); + if (tmp_buffer != NULL) + delete [] tmp_buffer; + break; + } + } else if (vinfo->picture.format.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) { + if (vinfo->picture.buf.length == vinfo->picture.buf.bytesused) { + yuyv422_to_rgb24(src,img,width,height); + break; + } else { + putback_picture_frame(vinfo); + usleep(5000); + } + } else if (vinfo->picture.format.fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24) { + if (vinfo->picture.buf.length == width * height * 3) { + memcpy(img, src, vinfo->picture.buf.length); + } else { + rgb24_memcpy(img, src, width, height); + } + break; + } } } + ALOGD("get picture success !"); if (mSensorType == SENSOR_USB) { releasebuf_and_stop_picture(vinfo); diff --git a/v3/fake-pipeline2/camera_hw.cpp b/v3/fake-pipeline2/camera_hw.cpp index c98f154..4234f69 100755 --- a/v3/fake-pipeline2/camera_hw.cpp +++ b/v3/fake-pipeline2/camera_hw.cpp @@ -286,6 +286,15 @@ int putback_frame(struct VideoInfo *vinfo) return 0; } +int putback_picture_frame(struct VideoInfo *vinfo) +{ + + if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &vinfo->picture.buf)) + DBG_LOGB("QBUF failed error=%d\n", errno); + + return 0; +} + int start_picture(struct VideoInfo *vinfo, int rotate) { int ret = 0; diff --git a/v3/fake-pipeline2/camera_hw.h b/v3/fake-pipeline2/camera_hw.h index 6ed581d..30a1fb4 100755 --- a/v3/fake-pipeline2/camera_hw.h +++ b/v3/fake-pipeline2/camera_hw.h @@ -69,4 +69,5 @@ extern uintptr_t get_frame_phys(struct VideoInfo *vinfo); extern void *get_frame(struct VideoInfo *vinfo); extern void *get_picture(struct VideoInfo *vinfo); extern int putback_frame(struct VideoInfo *vinfo); +extern int putback_picture_frame(struct VideoInfo *vinfo); #endif -- cgit