Bug 809259 - improve camera stability when switching between picture and video modes r=kanru

This commit is contained in:
Mike Habicher 2012-11-23 13:31:42 +08:00
parent b0c1553fa9
commit 038e6a66bd
3 changed files with 18 additions and 15 deletions

View File

@ -311,15 +311,8 @@ CameraControlImpl::OnRecorderStateChange(const nsString& aStateMsg, int32_t aSta
nsresult
CameraControlImpl::GetPreviewStream(CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError)
{
/**
* The camera preview stream object is DOM-facing, and as such
* must be a cycle-collection participant created on the main
* thread.
*/
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> getPreviewStreamTask = new GetPreviewStreamTask(this, aSize, onSuccess, onError);
return NS_DispatchToCurrentThread(getPreviewStreamTask);
return mCameraThread->Dispatch(getPreviewStreamTask, NS_DISPATCH_NORMAL);
}
nsresult
@ -387,6 +380,11 @@ CameraControlImpl::ReceiveFrame(void* aBuffer, ImageFormat aFormat, FrameBuilder
NS_IMETHODIMP
GetPreviewStreamResult::Run()
{
/**
* The camera preview stream object is DOM-facing, and as such
* must be a cycle-collection participant created on the main
* thread.
*/
MOZ_ASSERT(NS_IsMainThread());
if (mOnSuccessCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {

View File

@ -591,9 +591,11 @@ nsGonkCameraControl::SetParameter(uint32_t aKey, int aValue)
nsresult
nsGonkCameraControl::GetPreviewStreamImpl(GetPreviewStreamTask* aGetPreviewStream)
{
SetPreviewSize(aGetPreviewStream->mSize.width, aGetPreviewStream->mSize.height);
// stop any currently running preview
StopPreviewInternal(true /* forced */);
DOM_CAMERA_LOGI("config preview: wated %d x %d, got %d x %d (%d fps, format %d)\n", aGetPreviewStream->mSize.width, aGetPreviewStream->mSize.height, mWidth, mHeight, mFps, mFormat);
SetPreviewSize(aGetPreviewStream->mSize.width, aGetPreviewStream->mSize.height);
DOM_CAMERA_LOGI("picture preview: wanted %d x %d, got %d x %d (%d fps, format %d)\n", aGetPreviewStream->mSize.width, aGetPreviewStream->mSize.height, mWidth, mHeight, mFps, mFormat);
nsCOMPtr<GetPreviewStreamResult> getPreviewStreamResult = new GetPreviewStreamResult(this, mWidth, mHeight, mFps, aGetPreviewStream->mOnSuccessCb, mWindowId);
return NS_DispatchToMainThread(getPreviewStreamResult);
@ -608,9 +610,7 @@ nsGonkCameraControl::StartPreviewImpl(StartPreviewTask* aStartPreview)
* currently set DOM-facing preview object.
*/
if (aStartPreview->mDOMPreview) {
if (mDOMPreview) {
mDOMPreview->Stopped(true);
}
StopPreviewInternal(true /* forced */);
mDOMPreview = aStartPreview->mDOMPreview;
} else if (!mDOMPreview) {
return NS_ERROR_INVALID_ARG;
@ -631,7 +631,7 @@ nsGonkCameraControl::StartPreviewImpl(StartPreviewTask* aStartPreview)
nsresult
nsGonkCameraControl::StopPreviewInternal(bool aForced)
{
DOM_CAMERA_LOGI("%s: stopping preview\n", __func__);
DOM_CAMERA_LOGI("%s: stopping preview (mDOMPreview=%p)\n", __func__, mDOMPreview);
// StopPreview() is a synchronous call--it doesn't return
// until the camera preview thread exits.

View File

@ -377,7 +377,7 @@ int
GonkCameraHardware::StartPreview(uint32_t aHwHandle)
{
GonkCameraHardware* hw = GetHardware(aHwHandle);
DOM_CAMERA_LOGI("%s:%d : aHwHandle = %d, hw = %p\n", __func__, __LINE__, aHwHandle, hw);
DOM_CAMERA_LOGI("%s : aHwHandle = %d, hw = %p\n", __func__, aHwHandle, hw);
if (!hw) {
return DEAD_OBJECT;
}
@ -389,7 +389,12 @@ void
GonkCameraHardware::StopPreview(uint32_t aHwHandle)
{
GonkCameraHardware* hw = GetHardware(aHwHandle);
DOM_CAMERA_LOGI("%s : aHwHandle = %d, hw = %p\n", __func__, aHwHandle, hw);
if (hw) {
// Must disable messages first; else some drivers will silently discard
// the stopPreview() request, which can lead to crashes and other
// Very Bad Things that are Hard To Diagnose.
hw->mHardware->disableMsgType(CAMERA_MSG_ALL_MSGS);
hw->mHardware->stopPreview();
}
}