summaryrefslogtreecommitdiff
Diffstat
-rw-r--r--Android.mk9
-rw-r--r--[-rwxr-xr-x]CameraHal.cpp4
-rw-r--r--[-rwxr-xr-x]CameraHal_Module.cpp3
-rw-r--r--[-rwxr-xr-x]V4LCameraAdapter/V4LCameraAdapter.cpp142
-rwxr-xr-xinc/mjpeg/colorspaces.h288
-rw-r--r--inc/mjpeg/defs.h57
-rwxr-xr-xinc/mjpeg/huffman.h99
-rwxr-xr-xinc/mjpeg/jutils.h149
-rwxr-xr-xmjpeg/colorspaces.c2016
-rwxr-xr-xmjpeg/jpegdec.c1040
10 files changed, 128 insertions, 3679 deletions
diff --git a/V4LCameraAdapter/V4LCameraAdapter.cpp b/V4LCameraAdapter/V4LCameraAdapter.cpp
index 32528e0..09164f3 100755..100644
--- a/V4LCameraAdapter/V4LCameraAdapter.cpp
+++ b/V4LCameraAdapter/V4LCameraAdapter.cpp
@@ -52,8 +52,8 @@
#include "CameraHal.h"
extern "C"{
#include "usb_fmt.h"
- #include "jutils.h"
}
+#include "libyuv.h"
//for private_handle_t TODO move out of private header
#include <ion/ion.h>
@@ -1821,27 +1821,83 @@ int V4LCameraAdapter::previewThread()
uint8_t* src = (uint8_t*) fp;
#ifdef AMLOGIC_USB_CAMERA_SUPPORT
- if(mFailedCnt == 0)
- gettimeofday(&mStartTime, NULL);
+ if (mFailedCnt == 0)
+ gettimeofday(&mStartTime, NULL);
#endif
- if(mSensorFormat == V4L2_PIX_FMT_MJPEG){ //enable mjpeg
- if(jpeg_decode(&dest,src,width,height, ( CameraFrame::PIXEL_FMT_NV21 == mPixelFormat)?V4L2_PIX_FMT_NV21:V4L2_PIX_FMT_YVU420) != 0){ // output format is nv21
- fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)), CameraFrame::PREVIEW_FRAME_SYNC);
- CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x",src[0], src[1], src[2], src[3]);
+ if (mSensorFormat == V4L2_PIX_FMT_MJPEG) { //enable mjpeg
+ if (CameraFrame::PIXEL_FMT_YV12 == mPixelFormat) {
+ if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest, width,
+ dest + width * height + width * height / 4, (width + 1) / 2,
+ dest + width * height, (width + 1) / 2, 0, 0, width, height,
+ width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) {
+ fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)),
+ CameraFrame::PREVIEW_FRAME_SYNC);
+ CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x",
+ src[0], src[1], src[2], src[3]);
+
#ifdef AMLOGIC_USB_CAMERA_SUPPORT
- mFailedCnt++;
- gettimeofday(&mEndTime, NULL);
- int intreval = (mEndTime.tv_sec - mStartTime.tv_sec) * 1000000 + (mEndTime.tv_usec - mStartTime.tv_usec);
- if(intreval > (int)mResetTH){
- CAMHAL_LOGIA("MJPEG Stream error ! Restart Preview");
- force_reset_sensor();
- mFailedCnt = 0;
- mFirstBuff = true;
- }
+ mFailedCnt++;
+ gettimeofday(&mEndTime, NULL);
+ int intreval = (mEndTime.tv_sec - mStartTime.tv_sec) * 1000000 +
+ (mEndTime.tv_usec - mStartTime.tv_usec);
+ if (intreval > (int)mResetTH) {
+ CAMHAL_LOGIA("MJPEG Stream error ! Restart Preview");
+ force_reset_sensor();
+ mFailedCnt = 0;
+ mFirstBuff = true;
+ }
#endif
- return -1;
+ return -1;
+ }
+ } else if (CameraFrame::PIXEL_FMT_NV21 == mPixelFormat) {
+ if (ConvertMjpegToNV21(src, mVideoInfo->buf.bytesused, dest, width,
+ dest + width * height, (width + 1) / 2,
+ width, height, width, height, libyuv::FOURCC_MJPG) != 0) {
+ uint8_t *vBuffer = new uint8_t[width * height / 4];
+ if (vBuffer == NULL)
+ CAMHAL_LOGIA("alloc temperary v buffer failed\n");
+ uint8_t *uBuffer = new uint8_t[width * height / 4];
+ if (uBuffer == NULL)
+ CAMHAL_LOGIA("alloc temperary u buffer failed\n");
+
+ if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest,
+ width, uBuffer, (width + 1) / 2,
+ vBuffer, (width + 1) / 2, 0, 0, width, height,
+ width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) {
+ fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)),
+ CameraFrame::PREVIEW_FRAME_SYNC);
+ CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x",
+ src[0], src[1], src[2], src[3]);
+
+#ifdef AMLOGIC_USB_CAMERA_SUPPORT
+ mFailedCnt++;
+ gettimeofday(&mEndTime, NULL);
+ int intreval = (mEndTime.tv_sec - mStartTime.tv_sec) * 1000000 +
+ (mEndTime.tv_usec - mStartTime.tv_usec);
+ if (intreval > (int)mResetTH) {
+ CAMHAL_LOGIA("MJPEG Stream error ! Restart Preview");
+ force_reset_sensor();
+ mFailedCnt = 0;
+ mFirstBuff = true;
+ }
+#endif
+
+ delete vBuffer;
+ delete uBuffer;
+ return -1;
+ }
+
+ uint8_t *pUVBuffer = dest + width * height;
+ for (int i = 0; i < width * height / 4; i++) {
+ *pUVBuffer++ = *(vBuffer + i);
+ *pUVBuffer++ = *(uBuffer + i);
+ }
+
+ delete vBuffer;
+ delete uBuffer;
+ }
}
- mFailedCnt = 0;
+ mFailedCnt = 0;
frame.mLength = width*height*3/2;
}else{
if(DEFAULT_PREVIEW_PIXEL_FORMAT == V4L2_PIX_FMT_YUYV){ // 422I
@@ -2276,17 +2332,59 @@ int V4LCameraAdapter::pictureThread()
height = temp;
}
#endif
-
+
CAMHAL_LOGDB("mCaptureBuf=%p,dest=%p,fp=%p,index=%d\n"
"w=%d h=%d,len=%d,bytesused=%d\n",
mCaptureBuf, dest, fp,index, width, height,
mVideoInfo->buf.length, mVideoInfo->buf.bytesused);
if(mSensorFormat == V4L2_PIX_FMT_MJPEG){
- if(jpeg_decode(&dest,src,width,height,V4L2_PIX_FMT_NV21) != 0){ // output format is nv21
- //fillThisBuffer(mCaptureBuf, CameraFrame::IMAGE_FRAME);
- CAMHAL_LOGEA("jpeg decode failed");
+ if (CameraFrame::PIXEL_FMT_YV12 == mPixelFormat) {
+ if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest, width,
+ dest + width * height + width * height / 4, (width + 1) / 2,
+ dest + width * height, (width + 1) / 2, 0, 0, width, height,
+ width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) {
+ fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)),
+ CameraFrame::PREVIEW_FRAME_SYNC);
+ CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x",
+ src[0], src[1], src[2], src[3]);
+ return -1;
+ }
+ } else if (CameraFrame::PIXEL_FMT_NV21 == mPixelFormat) {
+ if(ConvertMjpegToNV21(src, mVideoInfo->buf.bytesused, dest,
+ width, dest + width * height, (width + 1) / 2,
+ width, height, width, height, libyuv::FOURCC_MJPG) != 0) {
+ uint8_t *vBuffer = new uint8_t[width * height / 4];
+ if (vBuffer == NULL)
+ CAMHAL_LOGIA("alloc temperary v buffer failed\n");
+ uint8_t *uBuffer = new uint8_t[width * height / 4];
+ if (uBuffer == NULL)
+ CAMHAL_LOGIA("alloc temperary u buffer failed\n");
+
+ if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest,
+ width, uBuffer, (width + 1) / 2,
+ vBuffer, (width + 1) / 2, 0, 0, width, height,
+ width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) {
+ fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)),
+ CameraFrame::PREVIEW_FRAME_SYNC);
+ CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x",
+ src[0], src[1], src[2], src[3]);
+ delete vBuffer;
+ delete uBuffer;
+ return -1;
+ }
+
+ uint8_t *pUVBuffer = dest + width * height;
+ for (int i = 0; i < width * height / 4; i++) {
+ *pUVBuffer++ = *(vBuffer + i);
+ *pUVBuffer++ = *(uBuffer + i);
+ }
+
+ delete vBuffer;
+ delete uBuffer;
+ }
}
+
frame.mLength = width*height*3/2;
frame.mQuirks = CameraFrame::ENCODE_RAW_YUV420SP_TO_JPEG | CameraFrame::HAS_EXIF_DATA;