Bug 1025197 - only clear the "recording hint" when switching to picture mode, r=dhylands
authorMike Habicher <mikeh@mozilla.com>
Wed, 25 Jun 2014 17:45:02 -0400
changeset 208452 c2ca5265a5b166ad76dbd9d375bd1ca3b1e4277e
parent 208451 cef7737c5627fc34f3f5305f910d09e252248e0d
child 208453 a2df04e4f4d8b41042e6b612ce08e9fc13e32b4f
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1025197
milestone32.0a2
Bug 1025197 - only clear the "recording hint" when switching to picture mode, r=dhylands
dom/camera/GonkCameraControl.cpp
--- a/dom/camera/GonkCameraControl.cpp
+++ b/dom/camera/GonkCameraControl.cpp
@@ -206,29 +206,39 @@ nsGonkCameraControl::~nsGonkCameraContro
 
 nsresult
 nsGonkCameraControl::SetConfigurationInternal(const Configuration& aConfig)
 {
   DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
 
   nsresult rv;
 
-  switch (aConfig.mMode) {
-    case kPictureMode:
-      rv = SetPictureConfiguration(aConfig);
-      break;
+  {
+    ICameraControlParameterSetAutoEnter set(this);
+
+    switch (aConfig.mMode) {
+      case kPictureMode:
+        rv = SetPictureConfiguration(aConfig);
+        break;
+
+      case kVideoMode:
+        rv = SetVideoConfiguration(aConfig);
+        break;
 
-    case kVideoMode:
-      rv = SetVideoConfiguration(aConfig);
-      break;
+      default:
+        MOZ_ASSERT_UNREACHABLE("Unanticipated camera mode in SetConfigurationInternal()");
+        rv = NS_ERROR_FAILURE;
+        break;
+    }
 
-    default:
-      MOZ_ASSERT_UNREACHABLE("Unanticipated camera mode in SetConfigurationInternal()");
-      rv = NS_ERROR_FAILURE;
-      break;
+    nsresult rv = Set(CAMERA_PARAM_RECORDINGHINT,
+                      aConfig.mMode == kVideoMode);
+    if (NS_FAILED(rv)) {
+      DOM_CAMERA_LOGE("Failed to set recording hint (0x%x)\n", rv);
+    }
   }
 
   DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mCurrentConfiguration.mMode = aConfig.mMode;
   mCurrentConfiguration.mRecorderProfile = aConfig.mRecorderProfile;
   if (aConfig.mMode == kVideoMode) {
@@ -243,18 +253,22 @@ nsresult
 nsGonkCameraControl::SetConfigurationImpl(const Configuration& aConfig)
 {
   DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
   MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
 
   // Stop any currently running preview
   nsresult rv = PausePreview();
   if (NS_FAILED(rv)) {
-    // warn, but plow ahead
-    NS_WARNING("PausePreview() in SetConfigurationImpl() failed");
+    DOM_CAMERA_LOGW("PausePreview() in SetConfigurationImpl() failed (0x%x)\n", rv);
+    if (rv == NS_ERROR_NOT_INITIALIZED) {
+      // If there no hardware available, nothing else we try will work,
+      // so bail out here.
+      return rv;
+    }
   }
 
   DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
   rv = SetConfigurationInternal(aConfig);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     StopPreviewImpl();
     return rv;
   }
@@ -272,21 +286,16 @@ nsGonkCameraControl::SetPictureConfigura
   // remove any existing recorder profile
   mRecorderProfile = nullptr;
 
   nsresult rv = SetPreviewSize(aConfig.mPreviewSize);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = PushParameters();
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
   mParams.Get(CAMERA_PARAM_PREVIEWFRAMERATE, mPreviewFps);
 
   DOM_CAMERA_LOGI("picture mode preview: wanted %ux%u, got %ux%u (%u fps)\n",
     aConfig.mPreviewSize.width, aConfig.mPreviewSize.height,
     mCurrentConfiguration.mPreviewSize.width, mCurrentConfiguration.mPreviewSize.height,
     mPreviewFps);
 
   return NS_OK;
@@ -1048,26 +1057,18 @@ nsGonkCameraControl::StopRecordingImpl()
 
   mRecorder->stop();
   mRecorder = nullptr;
   OnRecorderStateChange(CameraControlListener::kRecorderStopped);
 
   {
     ICameraControlParameterSetAutoEnter set(this);
 
-    // clear the recording hint once stopped because some drivers will solely
-    // check this flag to determine the mode, despite its actual internal state,
-    // thus causing problems when taking pictures
-    nsresult rv = mParams.Set(CAMERA_PARAM_RECORDINGHINT, false);
-    if (NS_FAILED(rv)) {
-      DOM_CAMERA_LOGE("Failed to set recording hint (0x%x)\n", rv);
-    }
-
     if (mAutoFlashModeOverridden) {
-      rv = mParams.Set(CAMERA_PARAM_FLASHMODE, NS_LITERAL_STRING("auto"));
+      nsresult rv = Set(CAMERA_PARAM_FLASHMODE, NS_LITERAL_STRING("auto"));
       if (NS_FAILED(rv)) {
         DOM_CAMERA_LOGE("Failed to set flash mode (0x%x)\n", rv);
       }
     }
   }
 
   // notify DeviceStorage that the new video file is closed and ready
   return NS_DispatchToMainThread(new RecordingComplete(mVideoFile));
@@ -1240,17 +1241,17 @@ nsGonkCameraControl::OnTakePictureError(
 }
 
 nsresult
 nsGonkCameraControl::SetPreviewSize(const Size& aSize)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
 
   nsTArray<Size> previewSizes;
-  nsresult rv = mParams.Get(CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, previewSizes);
+  nsresult rv = Get(CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, previewSizes);
   if (NS_FAILED(rv)) {
     DOM_CAMERA_LOGE("Camera failed to return any preview sizes (0x%x)\n", rv);
     return rv;
   }
 
   Size best;
   rv  = GetSupportedSize(aSize, previewSizes, best);
   if (NS_FAILED(rv)) {
@@ -1261,40 +1262,40 @@ nsGonkCameraControl::SetPreviewSize(cons
 
   // Some camera drivers will ignore our preview size if it's larger
   // than the currently set video recording size, so we need to set
   // the video size here as well, just in case.
   if (best.width > mLastRecorderSize.width || best.height > mLastRecorderSize.height) {
     SetVideoSize(best);
   }
   mCurrentConfiguration.mPreviewSize = best;
-  return mParams.Set(CAMERA_PARAM_PREVIEWSIZE, best);
+  return Set(CAMERA_PARAM_PREVIEWSIZE, best);
 }
 
 nsresult
 nsGonkCameraControl::SetVideoSize(const Size& aSize)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
 
   nsTArray<Size> videoSizes;
-  nsresult rv = mParams.Get(CAMERA_PARAM_SUPPORTED_VIDEOSIZES, videoSizes);
+  nsresult rv = Get(CAMERA_PARAM_SUPPORTED_VIDEOSIZES, videoSizes);
   if (NS_FAILED(rv)) {
     DOM_CAMERA_LOGE("Camera failed to return any video sizes (0x%x)\n", rv);
     return rv;
   }
 
   Size best;
   rv = GetSupportedSize(aSize, videoSizes, best);
   if (NS_FAILED(rv)) {
     DOM_CAMERA_LOGE("Failed to find a supported video size, requested size %dx%d",
         aSize.width, aSize.height);
     return rv;
   }
   mLastRecorderSize = best;
-  return mParams.Set(CAMERA_PARAM_VIDEOSIZE, best);
+  return Set(CAMERA_PARAM_VIDEOSIZE, best);
 }
 
 nsresult
 nsGonkCameraControl::GetSupportedSize(const Size& aSize,
                                       const nsTArray<Size>& supportedSizes,
                                       Size& best)
 {
   nsresult rv = NS_ERROR_INVALID_ARG;
@@ -1390,30 +1391,24 @@ nsGonkCameraControl::SetupVideoMode(cons
     }
 
     rv = SetPreviewSize(size);
     if (NS_FAILED(rv)) {
       DOM_CAMERA_LOGE("Failed to set video mode preview size (0x%x)\n", rv);
       return rv;
     }
 
-    rv = mParams.Set(CAMERA_PARAM_PREVIEWFRAMERATE, fps);
+    rv = Set(CAMERA_PARAM_PREVIEWFRAMERATE, fps);
     if (NS_FAILED(rv)) {
       DOM_CAMERA_LOGE("Failed to set video mode frame rate (0x%x)\n", rv);
       return rv;
     }
+  }
 
-    rv = PushParameters();
-    if (NS_FAILED(rv)) {
-      DOM_CAMERA_LOGE("Failed to set video mode settings (0x%x)\n", rv);
-      return rv;
-    }
-
-    mPreviewFps = fps;
-  }
+  mPreviewFps = fps;
   return NS_OK;
 }
 
 class GonkRecorderListener : public IMediaRecorderClient
 {
 public:
   GonkRecorderListener(nsGonkCameraControl* aCameraControl)
     : mCameraControl(aCameraControl)