author | Lawrence Mok <lawrence.mok@amlogic.com> | 2011-11-28 06:36:27 (GMT) |
---|---|---|
committer | Lawrence Mok <lawrence.mok@amlogic.com> | 2011-11-28 06:36:27 (GMT) |
commit | 41f116a83f0dbe403d269ced2cce58adb7c9a0a4 (patch) | |
tree | eb4359ec853fd5a2180c984bf0d764654b1571a0 | |
parent | 0f7a637e95233bfcb9fcdd443f645e70e9e31fe6 (diff) | |
download | camera-41f116a83f0dbe403d269ced2cce58adb7c9a0a4.zip camera-41f116a83f0dbe403d269ced2cce58adb7c9a0a4.tar.gz camera-41f116a83f0dbe403d269ced2cce58adb7c9a0a4.tar.bz2 |
fix image capture and jpeg encoding
still some problem with stop/start preview after taking picture
-rw-r--r-- | AppCallbackNotifier.cpp | 16 | ||||
-rw-r--r-- | CameraHal.cpp | 1 | ||||
-rw-r--r-- | CameraParameters.cpp | 2 | ||||
-rw-r--r-- | Encoder_libjpeg.cpp | 41 | ||||
-rw-r--r-- | V4LCameraAdapter/V4LCameraAdapter.cpp | 259 | ||||
-rw-r--r-- | inc/CameraHal.h | 3 | ||||
-rw-r--r-- | inc/CameraProperties.h | 2 | ||||
-rwxr-xr-x | inc/Encoder_libjpeg.h | 7 | ||||
-rw-r--r-- | inc/V4LCameraAdapter/V4LCameraAdapter.h | 6 |
9 files changed, 275 insertions, 62 deletions
diff --git a/AppCallbackNotifier.cpp b/AppCallbackNotifier.cpp index fce658a..207bce7 100644 --- a/AppCallbackNotifier.cpp +++ b/AppCallbackNotifier.cpp @@ -17,7 +17,7 @@ -#define LOG_TAG "CameraHAL" +#define LOG_TAG "AppCallbackNotif" #include "CameraHal.h" @@ -809,9 +809,11 @@ void AppCallbackNotifier::notifyFrame() else if ( (CameraFrame::IMAGE_FRAME == frame->mFrameType) && (NULL != mCameraHal) && (NULL != mDataCb) && - (CameraFrame::ENCODE_RAW_YUV422I_TO_JPEG & frame->mQuirks) ) + ((CameraFrame::ENCODE_RAW_YUV422I_TO_JPEG & frame->mQuirks) || + (CameraFrame::ENCODE_RAW_RGB24_TO_JPEG & frame->mQuirks)) ) { + LOGD("IMAGE_FRAME ENCODE_RAW.. %d", __LINE__); int encode_quality = 100, tn_quality = 100; int tn_width, tn_height; unsigned int current_snapshot = 0; @@ -854,9 +856,15 @@ void AppCallbackNotifier::notifyFrame() main_jpeg->in_height = frame->mHeight; main_jpeg->out_width = frame->mWidth; main_jpeg->out_height = frame->mHeight; - main_jpeg->format = CameraParameters::PIXEL_FORMAT_YUV422I; + if ((CameraFrame::ENCODE_RAW_RGB24_TO_JPEG & frame->mQuirks)) + main_jpeg->format = CameraProperties::PIXEL_FORMAT_RGB24; + else + main_jpeg->format = CameraParameters::PIXEL_FORMAT_YUV422I; } +// disable thumbnail for now. preview was stopped and mPreviewBufs was +// cleared, so this won't work. +#if 0 tn_width = parameters.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH); tn_height = parameters.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT); @@ -884,7 +892,9 @@ void AppCallbackNotifier::notifyFrame() tn_jpeg->out_height = tn_height; tn_jpeg->format = CameraParameters::PIXEL_FORMAT_YUV420SP;; } +#endif + LOGD("IMAGE_FRAME ENCODE_RAW.. %d", __LINE__); sp<Encoder_libjpeg> encoder = new Encoder_libjpeg(main_jpeg, tn_jpeg, AppCallbackNotifierEncoderCallback, diff --git a/CameraHal.cpp b/CameraHal.cpp index 7f1df0b..d306ea4 100644 --- a/CameraHal.cpp +++ b/CameraHal.cpp @@ -2514,6 +2514,7 @@ status_t CameraHal::takePicture( ) ret = mDisplayAdapter->pauseDisplay(mDisplayPaused); // since preview is paused we should stop sending preview frames too if(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) { + LOGD("disable MSG_PREVIEW_FRAME"); mAppCallbackNotifier->disableMsgType (CAMERA_MSG_PREVIEW_FRAME); } } diff --git a/CameraParameters.cpp b/CameraParameters.cpp index 2ab47a0..855b9b1 100644 --- a/CameraParameters.cpp +++ b/CameraParameters.cpp @@ -113,6 +113,8 @@ const char CameraProperties::VIDEO_SIZE[] = "video-size"; const char CameraProperties::SUPPORTED_VIDEO_SIZES[] = "video-size-values"; const char CameraProperties::PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = "preferred-preview-size-for-video"; +const char CameraProperties::PIXEL_FORMAT_RGB24[] = "rgb24"; + const char CameraProperties::DEFAULT_VALUE[] = ""; diff --git a/Encoder_libjpeg.cpp b/Encoder_libjpeg.cpp index 0240fb0..b4ccf4a 100644 --- a/Encoder_libjpeg.cpp +++ b/Encoder_libjpeg.cpp @@ -354,9 +354,11 @@ size_t Encoder_libjpeg::encode(params* input) { uint8_t* row_tmp = NULL; uint8_t* row_src = NULL; uint8_t* row_uv = NULL; // used only for NV12 + int row_stride; int out_width = 0, in_width = 0; int out_height = 0, in_height = 0; int bpp = 2; // for uyvy + Encoder_libjpeg::format informat = Encoder_libjpeg::YUV422I; if (!input) { return 0; @@ -379,12 +381,16 @@ size_t Encoder_libjpeg::encode(params* input) { } if (strcmp(input->format, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { + informat = Encoder_libjpeg::YUV420SP; bpp = 1; if ((in_width != out_width) || (in_height != out_height)) { resize_src = (uint8_t*) malloc(input->dst_size); resize_nv12(input, resize_src); if (resize_src) src = resize_src; } + } else if (strcmp(input->format, CameraProperties::PIXEL_FORMAT_RGB24) == 0) { + informat = Encoder_libjpeg::RGB24; + bpp = 1; } else if ((in_width != out_width) || (in_height != out_height)) { CAMHAL_LOGEB("Encoder: resizing is not supported for this format: %s", input->format); goto exit; @@ -411,7 +417,10 @@ size_t Encoder_libjpeg::encode(params* input) { cinfo.image_width = out_width; cinfo.image_height = out_height; cinfo.input_components = 3; - cinfo.in_color_space = JCS_YCbCr; + if (informat == Encoder_libjpeg::RGB24) + cinfo.in_color_space = JCS_RGB; + else + cinfo.in_color_space = JCS_YCbCr; cinfo.input_gamma = 1; jpeg_set_defaults(&cinfo); @@ -423,25 +432,31 @@ size_t Encoder_libjpeg::encode(params* input) { row_tmp = (uint8_t*)malloc(out_width * 3); row_src = src; row_uv = src + out_width * out_height * bpp; + row_stride = out_width * 3; while ((cinfo.next_scanline < cinfo.image_height) && !mCancelEncoding) { JSAMPROW row[1]; /* pointer to JSAMPLE row[s] */ - // convert input yuv format to yuv444 - if (strcmp(input->format, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { - nv21_to_yuv(row_tmp, row_src, row_uv, out_width); + if (informat == Encoder_libjpeg::RGB24) { + row[0] = &src[cinfo.next_scanline * row_stride]; + (void) jpeg_write_scanlines(&cinfo, row, 1); } else { - uyvy_to_yuv(row_tmp, (uint32_t*)row_src, out_width); - } + // convert input yuv format to yuv444 + if (informat == Encoder_libjpeg::YUV420SP) { + nv21_to_yuv(row_tmp, row_src, row_uv, out_width); + } else if (informat == Encoder_libjpeg::YUV422I) { + uyvy_to_yuv(row_tmp, (uint32_t*)row_src, out_width); + } - row[0] = row_tmp; - jpeg_write_scanlines(&cinfo, row, 1); - row_src = row_src + out_width*bpp; + row[0] = row_tmp; + jpeg_write_scanlines(&cinfo, row, 1); + row_src = row_src + out_width*bpp; - // move uv row if input format needs it - if (strcmp(input->format, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { - if (!(cinfo.next_scanline % 2)) - row_uv = row_uv + out_width * bpp; + // move uv row if input format needs it + if (informat == Encoder_libjpeg::YUV420SP) { + if (!(cinfo.next_scanline % 2)) + row_uv = row_uv + out_width * bpp; + } } } diff --git a/V4LCameraAdapter/V4LCameraAdapter.cpp b/V4LCameraAdapter/V4LCameraAdapter.cpp index 82d0672..e4d209c 100644 --- a/V4LCameraAdapter/V4LCameraAdapter.cpp +++ b/V4LCameraAdapter/V4LCameraAdapter.cpp @@ -157,6 +157,13 @@ status_t V4LCameraAdapter::fillThisBuffer(void* frameBuf, CameraFrame::FrameType status_t ret = NO_ERROR; + //LOGD("fillThisBuffer frameType=%d", frameType); + if (CameraFrame::IMAGE_FRAME == frameType) + { + if (NULL != mEndImageCaptureCallback) + mEndImageCaptureCallback(mEndCaptureData); + return NO_ERROR; + } if ( !mVideoInfo->isStreaming ) { return NO_ERROR; @@ -190,30 +197,6 @@ status_t V4LCameraAdapter::setParameters(const CameraParameters ¶ms) status_t ret = NO_ERROR; - int width, height; - - params.getPreviewSize(&width, &height); - - CAMHAL_LOGDB("Width * Height %d x %d format 0x%x", width, height, DEFAULT_PIXEL_FORMAT); - - mVideoInfo->width = width; - mVideoInfo->height = height; - mVideoInfo->framesizeIn = (width * height << 1); - mVideoInfo->formatIn = DEFAULT_PIXEL_FORMAT; - - mVideoInfo->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - mVideoInfo->format.fmt.pix.width = width; - mVideoInfo->format.fmt.pix.height = height; - mVideoInfo->format.fmt.pix.pixelformat = DEFAULT_PIXEL_FORMAT; - - ret = ioctl(mCameraHandle, VIDIOC_S_FMT, &mVideoInfo->format); - if (ret < 0) { - CAMHAL_LOGEB("Open: VIDIOC_S_FMT Failed: %s", strerror(errno)); - LOGD("ret=%d", ret); - ret = NO_ERROR; //TODO - //return ret; - } - // Udpate the current parameter set mParams = params; @@ -265,6 +248,31 @@ status_t V4LCameraAdapter::useBuffers(CameraMode mode, void* bufArr, int num, si return ret; } +status_t V4LCameraAdapter::setBuffersFormat(int width, int height, int pixelformat) +{ + int ret = NO_ERROR; + CAMHAL_LOGDB("Width * Height %d x %d format 0x%x", width, height, pixelformat); + + mVideoInfo->width = width; + mVideoInfo->height = height; + mVideoInfo->framesizeIn = (width * height << 1); + mVideoInfo->formatIn = pixelformat; + + mVideoInfo->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + mVideoInfo->format.fmt.pix.width = width; + mVideoInfo->format.fmt.pix.height = height; + mVideoInfo->format.fmt.pix.pixelformat = pixelformat; + + ret = ioctl(mCameraHandle, VIDIOC_S_FMT, &mVideoInfo->format); + if (ret < 0) { + CAMHAL_LOGEB("Open: VIDIOC_S_FMT Failed: %s", strerror(errno)); + LOGD("ret=%d", ret); + return ret; + } + + return ret; +} + status_t V4LCameraAdapter::UseBuffersPreview(void* bufArr, int num) { int ret = NO_ERROR; @@ -274,6 +282,10 @@ status_t V4LCameraAdapter::UseBuffersPreview(void* bufArr, int num) return BAD_VALUE; } + int width, height; + mParams.getPreviewSize(&width, &height); + setBuffersFormat(width, height, DEFAULT_PREVIEW_PIXEL_FORMAT); + //First allocate adapter internal buffers at V4L level for USB Cam //These are the buffers from which we will copy the data into overlay buffers /* Check if camera can handle NB_BUFFER buffers */ @@ -336,15 +348,65 @@ status_t V4LCameraAdapter::UseBuffersCapture(void* bufArr, int num) return BAD_VALUE; } - if (num > 1) + if (num != 1) { LOGD("----------------- UseBuffersCapture num=%d", num); } - uint32_t *ptr = (uint32_t*) bufArr; - LOGV("UseBuffersCapture %#x", ptr[0]); - mCaptureBuf = (camera_memory_t*)ptr[0]; + /* This will only be called right before taking a picture, so + * stop preview now so that we can set buffer format here. + */ + LOGD("UseBuffersCapture stopPreview.."); + stopPreview(); + + LOGD("UseBuffersCapture setBuffersFormat.."); + int width, height; + mParams.getPictureSize(&width, &height); + setBuffersFormat(width, height, DEFAULT_IMAGE_CAPTURE_PIXEL_FORMAT); + + //First allocate adapter internal buffers at V4L level for Cam + //These are the buffers from which we will copy the data into display buffers + /* Check if camera can handle NB_BUFFER buffers */ + mVideoInfo->rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + mVideoInfo->rb.memory = V4L2_MEMORY_MMAP; + mVideoInfo->rb.count = num; + + ret = ioctl(mCameraHandle, VIDIOC_REQBUFS, &mVideoInfo->rb); + if (ret < 0) { + CAMHAL_LOGEB("VIDIOC_REQBUFS failed: %s", strerror(errno)); + return ret; + } + + for (int i = 0; i < num; i++) { + + memset (&mVideoInfo->buf, 0, sizeof (struct v4l2_buffer)); + mVideoInfo->buf.index = i; + mVideoInfo->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + mVideoInfo->buf.memory = V4L2_MEMORY_MMAP; + + ret = ioctl (mCameraHandle, VIDIOC_QUERYBUF, &mVideoInfo->buf); + if (ret < 0) { + CAMHAL_LOGEB("Unable to query buffer (%s)", strerror(errno)); + return ret; + } + + mVideoInfo->mem[i] = mmap (0, + mVideoInfo->buf.length, + PROT_READ | PROT_WRITE, + MAP_SHARED, + mCameraHandle, + mVideoInfo->buf.m.offset); + + if (mVideoInfo->mem[i] == MAP_FAILED) { + CAMHAL_LOGEB("Unable to map buffer (%s)", strerror(errno)); + return -1; + } + + uint32_t *ptr = (uint32_t*) bufArr; + LOGV("UseBuffersCapture %#x", ptr[0]); + mCaptureBuf = (camera_memory_t*)ptr[0]; + } return ret; } @@ -379,6 +441,7 @@ status_t V4LCameraAdapter::startPreview() CAMHAL_LOGEA("VIDIOC_QBUF Failed"); return -EINVAL; } + LOGD("startPreview .length=%d", mVideoInfo->buf.length); nQueued++; } @@ -421,6 +484,11 @@ status_t V4LCameraAdapter::stopPreview() return NO_INIT; } + mPreviewThread->requestExitAndWait(); + mPreviewThread.clear(); + + + LOGD("stopPreview streamoff.."); if (mVideoInfo->isStreaming) { bufType = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -439,15 +507,15 @@ status_t V4LCameraAdapter::stopPreview() nQueued = 0; nDequeued = 0; + LOGD("stopPreview unmap.."); /* Unmap buffers */ for (int i = 0; i < mPreviewBufferCount; i++) if (munmap(mVideoInfo->mem[i], mVideoInfo->buf.length) < 0) CAMHAL_LOGEA("Unmap failed"); + LOGD("stopPreview clearexit.."); mPreviewBufs.clear(); - - mPreviewThread->requestExitAndWait(); - mPreviewThread.clear(); + mPreviewing = false; return ret; @@ -498,7 +566,7 @@ status_t V4LCameraAdapter::getPictureBufferSize(size_t &length, size_t bufferCou { int width, height; mParams.getPictureSize(&width, &height); - length = width * height * 2; //wild guess + length = width * height * 3; //rgb24 return NO_ERROR; } @@ -670,6 +738,29 @@ int V4LCameraAdapter::pictureThread() if (true) { + mVideoInfo->buf.index = 0; + mVideoInfo->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + mVideoInfo->buf.memory = V4L2_MEMORY_MMAP; + + ret = ioctl(mCameraHandle, VIDIOC_QBUF, &mVideoInfo->buf); + if (ret < 0) { + CAMHAL_LOGEA("VIDIOC_QBUF Failed"); + return -EINVAL; + } + + enum v4l2_buf_type bufType; + if (!mVideoInfo->isStreaming) { + bufType = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + ret = ioctl (mCameraHandle, VIDIOC_STREAMON, &bufType); + if (ret < 0) { + CAMHAL_LOGEB("StartStreaming: Unable to start capture: %s", strerror(errno)); + return ret; + } + + mVideoInfo->isStreaming = true; + } + int index = 0; char *fp = this->GetFrame(index); if(!fp) @@ -686,23 +777,35 @@ int V4LCameraAdapter::pictureThread() uint16_t* dest = (uint16_t*)mCaptureBuf->data; uint16_t* src = (uint16_t*) fp; mParams.getPictureSize(&width, &height); - //LOGD("pictureThread mCaptureBuf=%#x dest=%#x fp=%#x width=%d height=%d", mCaptureBuf, dest, fp, width, height); + LOGD("pictureThread mCaptureBuf=%#x dest=%#x fp=%#x width=%d height=%d", mCaptureBuf, dest, fp, width, height); + LOGD("length=%d bytesused=%d index=%d", mVideoInfo->buf.length, mVideoInfo->buf.bytesused, index); +#if 0 //frame size? + int zzz = 0; for(int i=0;i<height;i++) { for(int j=0;j<width;j++) { + if ((src - (uint16_t*)fp) > mVideoInfo->buf.length) { + LOGD("i j %d %d i*j*2 %d", i, j, i*j); + break; + } + zzz += *src; *dest = *src; src++; dest++; } //dest += 4096/2-width; } + LOGD("zzz %d", zzz); +#else + memcpy(dest, src, mVideoInfo->buf.length); +#endif frame.mFrameMask = CameraFrame::IMAGE_FRAME; frame.mFrameType = CameraFrame::IMAGE_FRAME; - frame.mQuirks = CameraFrame::ENCODE_RAW_YUV422I_TO_JPEG; - frame.mBuffer = mCaptureBuf; + frame.mQuirks = CameraFrame::ENCODE_RAW_RGB24_TO_JPEG; + frame.mBuffer = mCaptureBuf->data; frame.mLength = width*height*2; frame.mAlignment = width*2; frame.mOffset = 0; @@ -718,11 +821,36 @@ int V4LCameraAdapter::pictureThread() ret = sendFrameToSubscribers(&frame); //LOGD("pictureThread /sendFrameToSubscribers ret=%d", ret); + + if (mVideoInfo->isStreaming) { + bufType = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + ret = ioctl (mCameraHandle, VIDIOC_STREAMOFF, &bufType); + if (ret < 0) { + CAMHAL_LOGEB("StopStreaming: Unable to stop capture: %s", strerror(errno)); + return ret; + } + + mVideoInfo->isStreaming = false; + } + + mVideoInfo->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + mVideoInfo->buf.memory = V4L2_MEMORY_MMAP; + + nQueued = 0; + nDequeued = 0; + + /* Unmap buffers */ + if (munmap(mVideoInfo->mem[0], mVideoInfo->buf.length) < 0) + CAMHAL_LOGEA("Unmap failed"); + } return ret; } + +// --------------------------------------------------------------------------- extern "C" CameraAdapter* CameraAdapter_Factory() { CameraAdapter *adapter = NULL; @@ -759,11 +887,11 @@ extern "C" int CameraAdapter_Capabilities(CameraProperties::Properties* properti if (starting_camera + num_cameras_supported < max_camera) { num_cameras_supported++; properties = properties_array + starting_camera; - properties->set(CameraProperties::CAMERA_NAME, "USBCamera"); + properties->set(CameraProperties::CAMERA_NAME, "Camera"); + //TODO move + extern void loadCaps(int camera_id, CameraProperties::Properties* params); + loadCaps(0, properties); } - //TODO move - extern void loadCaps(CameraProperties::Properties* params); - loadCaps(properties); //------------------------ @@ -773,8 +901,44 @@ extern "C" int CameraAdapter_Capabilities(CameraProperties::Properties* properti return num_cameras_supported; } +extern "C" int getValidFrameSize(int camera_id, int pixel_format, char *framesize) +{ + struct v4l2_frmsizeenum frmsize; + int fd, i=0; + char tempsize[12]; + framesize[0] = '\0'; + fd = open(device, O_RDWR); + if (fd >= 0) { + LOGD("getValidFrameSize %d", __LINE__); + memset(&frmsize,0,sizeof(v4l2_frmsizeenum)); + for(i=0;;i++){ + frmsize.index = i; + frmsize.pixel_format = pixel_format; + LOGD("getValidFrameSize %d", __LINE__); + if(ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) == 0){ + if(frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE){ //only support this type + snprintf(tempsize, sizeof(tempsize), "%dx%d,", + frmsize.discrete.width, frmsize.discrete.height); + strcat(framesize, tempsize); + LOGD("getValidFrameSize %d tempsize framesize %s %s", __LINE__, tempsize, framesize); + } + else + break; + } + else + break; + } + close(fd); + } + LOGD("getValidFrameSize %d %s", __LINE__, framesize); + if(framesize[0] == '\0') + return -1; + else + return 0; +} + //TODO move -extern "C" void loadCaps(CameraProperties::Properties* params) { +extern "C" void loadCaps(int camera_id, CameraProperties::Properties* params) { const char DEFAULT_ANTIBANDING[] = "auto"; const char DEFAULT_BRIGHTNESS[] = "50"; const char DEFAULT_CONTRAST[] = "100"; @@ -794,7 +958,7 @@ extern "C" void loadCaps(CameraProperties::Properties* params) { const char DEFAULT_THUMBNAIL_QUALITY[] = "60"; const char DEFAULT_THUMBNAIL_SIZE[] = "160x120"; const char DEFAULT_PICTURE_FORMAT[] = "jpeg"; - const char DEFAULT_PICTURE_SIZE[] = "320x240"; + const char DEFAULT_PICTURE_SIZE[] = "640x480"; const char DEFAULT_PREVIEW_FORMAT[] = "yuv420sp"; const char DEFAULT_FRAMERATE[] = "30"; const char DEFAULT_PREVIEW_SIZE[] = "640x480"; @@ -872,8 +1036,17 @@ extern "C" void loadCaps(CameraProperties::Properties* params) { params->set(CameraProperties::VIDEO_SIZE, DEFAULT_VIDEO_SIZE); params->set(CameraProperties::PREFERRED_PREVIEW_SIZE_FOR_VIDEO, DEFAULT_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); - params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, "320x240"); - params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, "640x480"); + char sizes[64]; + if (!getValidFrameSize(camera_id, DEFAULT_PREVIEW_PIXEL_FORMAT, sizes)) { + params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, sizes); + } else + params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, "640x480"); + + if (!getValidFrameSize(camera_id, DEFAULT_IMAGE_CAPTURE_PIXEL_FORMAT, sizes)) { + params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, sizes); + } else + params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, "640x480"); + params->set(CameraProperties::SUPPORTED_THUMBNAIL_SIZES, "0x0"); params->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS, CameraParameters::PIXEL_FORMAT_YUV420SP); diff --git a/inc/CameraHal.h b/inc/CameraHal.h index c157fd7..ddc2506 100644 --- a/inc/CameraHal.h +++ b/inc/CameraHal.h @@ -247,7 +247,8 @@ class CameraFrame enum FrameQuirks { ENCODE_RAW_YUV422I_TO_JPEG = 0x1 << 0, - HAS_EXIF_DATA = 0x1 << 1, + ENCODE_RAW_RGB24_TO_JPEG = 0x1 << 1, + HAS_EXIF_DATA = 0x1 << 2, }; //default contrustor diff --git a/inc/CameraProperties.h b/inc/CameraProperties.h index c13edf7..ef3b459 100644 --- a/inc/CameraProperties.h +++ b/inc/CameraProperties.h @@ -141,6 +141,8 @@ public: static const char SUPPORTED_VIDEO_SIZES[];
static const char PREFERRED_PREVIEW_SIZE_FOR_VIDEO[];
+ static const char PIXEL_FORMAT_RGB24[];
+
CameraProperties();
~CameraProperties();
diff --git a/inc/Encoder_libjpeg.h b/inc/Encoder_libjpeg.h index e3e9ac5..c133663 100755 --- a/inc/Encoder_libjpeg.h +++ b/inc/Encoder_libjpeg.h @@ -100,6 +100,13 @@ class Encoder_libjpeg : public Thread { const char* format; size_t jpeg_size; }; + /* private member types and variables */ + public: + enum format { + YUV420SP, + YUV422I, + RGB24, + }; /* public member functions */ public: Encoder_libjpeg(params* main_jpeg, diff --git a/inc/V4LCameraAdapter/V4LCameraAdapter.h b/inc/V4LCameraAdapter/V4LCameraAdapter.h index 6b20171..6085547 100644 --- a/inc/V4LCameraAdapter/V4LCameraAdapter.h +++ b/inc/V4LCameraAdapter/V4LCameraAdapter.h @@ -25,8 +25,8 @@ namespace android { -//#define DEFAULT_PIXEL_FORMAT V4L2_PIX_FMT_YUYV -#define DEFAULT_PIXEL_FORMAT V4L2_PIX_FMT_NV21 +#define DEFAULT_PREVIEW_PIXEL_FORMAT V4L2_PIX_FMT_NV21 +#define DEFAULT_IMAGE_CAPTURE_PIXEL_FORMAT V4L2_PIX_FMT_RGB24 #define NB_BUFFER 6 #define DEVICE "/dev/video0" @@ -116,6 +116,8 @@ private: } }; + status_t setBuffersFormat(int width, int height, int pixelformat); + //Used for calculation of the average frame rate during preview status_t recalculateFPS(); |