Fix callback sequence on picture taking

Also fixes a bug in JPEG converter.

Change-Id: I5bbeec96ec2bb0a9a6a333a3798880bb0b837c65
This commit is contained in:
Vladimir Chtchetkine
2011-09-21 10:56:35 -07:00
parent 318ae8e9fe
commit 1f37cd45f6
3 changed files with 27 additions and 20 deletions

View File

@@ -217,6 +217,16 @@ void CallbackNotifier::onNextFrameAvailable(const void* frame,
} }
if (mTakingPicture) { if (mTakingPicture) {
/* This happens just once. */
mTakingPicture = false;
/* The sequence of callbacks during picture taking is:
* - CAMERA_MSG_SHUTTER
* - CAMERA_MSG_RAW_IMAGE_NOTIFY
* - CAMERA_MSG_COMPRESSED_IMAGE
*/
if (isMessageEnabled(CAMERA_MSG_SHUTTER)) {
mNotifyCB(CAMERA_MSG_SHUTTER, 0, 0, mCBOpaque);
}
if (isMessageEnabled(CAMERA_MSG_RAW_IMAGE_NOTIFY)) { if (isMessageEnabled(CAMERA_MSG_RAW_IMAGE_NOTIFY)) {
mNotifyCB(CAMERA_MSG_RAW_IMAGE_NOTIFY, 0, 0, mCBOpaque); mNotifyCB(CAMERA_MSG_RAW_IMAGE_NOTIFY, 0, 0, mCBOpaque);
} }
@@ -240,11 +250,6 @@ void CallbackNotifier::onNextFrameAvailable(const void* frame,
LOGE("%s: Compression failure in CAMERA_MSG_VIDEO_FRAME", __FUNCTION__); LOGE("%s: Compression failure in CAMERA_MSG_VIDEO_FRAME", __FUNCTION__);
} }
} }
if (isMessageEnabled(CAMERA_MSG_SHUTTER)) {
mNotifyCB(CAMERA_MSG_SHUTTER, 0, 0, mCBOpaque);
}
/* This happens just once. */
mTakingPicture = false;
} }
} }

View File

@@ -503,15 +503,16 @@ status_t EmulatedCamera::doStartPreview()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
EmulatedCameraDevice* camera_dev = getCameraDevice();
if (camera_dev->isStarted()) {
camera_dev->stopDeliveringFrames();
camera_dev->stopDevice();
}
status_t res = mPreviewWindow.startPreview(); status_t res = mPreviewWindow.startPreview();
if (res != NO_ERROR) { if (res != NO_ERROR) {
return res; return res;
} }
if (getCameraDevice()->isStarted()) {
return NO_ERROR;
}
EmulatedCameraDevice* camera_dev = getCameraDevice();
/* Make sure camera device is connected. */ /* Make sure camera device is connected. */
if (!camera_dev->isConnected()) { if (!camera_dev->isConnected()) {
@@ -573,15 +574,17 @@ status_t EmulatedCamera::doStopPreview()
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
status_t res = NO_ERROR; status_t res = NO_ERROR;
/* Stop the camera. */ if (mPreviewWindow.isPreviewEnabled()) {
if (getCameraDevice()->isStarted()) { /* Stop the camera. */
getCameraDevice()->stopDeliveringFrames(); if (getCameraDevice()->isStarted()) {
res = getCameraDevice()->stopDevice(); getCameraDevice()->stopDeliveringFrames();
} res = getCameraDevice()->stopDevice();
}
if (res == NO_ERROR) { if (res == NO_ERROR) {
/* Disable preview as well. */ /* Disable preview as well. */
mPreviewWindow.stopPreview(); mPreviewWindow.stopPreview();
}
} }
return NO_ERROR; return NO_ERROR;

View File

@@ -50,7 +50,7 @@ status_t NV21JpegCompressor::compressRawImage(const void* image,
offsets[0] = 0; offsets[0] = 0;
offsets[1] = width * height; offsets[1] = width * height;
mStrides[0] = width; mStrides[0] = width;
mStrides[1] = mStrides[2] = width / 4; mStrides[1] = width;
if (encode(&mStream, pY, width, height, offsets, quality)) { if (encode(&mStream, pY, width, height, offsets, quality)) {
LOGV("%s: Compressed JPEG: %d[%dx%d] -> %d bytes", LOGV("%s: Compressed JPEG: %d[%dx%d] -> %d bytes",
__FUNCTION__, (width * height * 12) / 8, width, height, mStream.getOffset()); __FUNCTION__, (width * height * 12) / 8, width, height, mStream.getOffset());
@@ -59,7 +59,6 @@ status_t NV21JpegCompressor::compressRawImage(const void* image,
LOGE("%s: JPEG compression failed", __FUNCTION__); LOGE("%s: JPEG compression failed", __FUNCTION__);
return errno ? errno : EINVAL; return errno ? errno : EINVAL;
} }
} }
}; /* namespace android */ }; /* namespace android */