Bug 1222122 - Add picture size to verified parameters when reconfiguring the camera. r=dhylands
authorAndrew Osmond <aosmond@mozilla.com>
Thu, 05 Nov 2015 16:00:57 -0500
changeset 293153 542763d3a90da3b0f09fd36b71d41d412a90693c
parent 293152 1ffd4c86448513d8f7f3a99681cae18a8adf43ff
child 293154 6cf483eb34a6309ecaa56549be0a1529f4c043bb
push id8824
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:18:56 +0000
treeherdermozilla-aurora@e2031358e2a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1222122
milestone45.0a1
Bug 1222122 - Add picture size to verified parameters when reconfiguring the camera. r=dhylands
dom/camera/GonkCameraControl.cpp
dom/camera/ICameraControl.h
dom/camera/test/test_camera_configuration.html
--- a/dom/camera/GonkCameraControl.cpp
+++ b/dom/camera/GonkCameraControl.cpp
@@ -326,19 +326,19 @@ nsGonkCameraControl::ValidateConfigurati
   RecorderProfile* profile;
   if (!mRecorderProfiles.Get(profileName, &profile)) {
     DOM_CAMERA_LOGE("Recorder profile '%s' is not supported\n",
       NS_ConvertUTF16toUTF8(aConfig.mRecorderProfile).get());
     return NS_ERROR_INVALID_ARG;
   }
 
   if (mCurrentConfiguration.mMode == aConfig.mMode &&
-      mRequestedPreviewSize.width == aConfig.mPreviewSize.width &&
-      mRequestedPreviewSize.height == aConfig.mPreviewSize.height &&
-      mCurrentConfiguration.mRecorderProfile.Equals(profile->GetName()))
+      mCurrentConfiguration.mRecorderProfile.Equals(profile->GetName()) &&
+      mRequestedPreviewSize.Equals(aConfig.mPreviewSize) &&
+      mCurrentConfiguration.mPictureSize.Equals(aValidatedConfig.mPictureSize))
   {
     DOM_CAMERA_LOGI("Camera configuration is unchanged\n");
     return NS_ERROR_ALREADY_INITIALIZED;
   }
 
   aValidatedConfig.mMode = aConfig.mMode;
   aValidatedConfig.mPreviewSize = aConfig.mPreviewSize;
   aValidatedConfig.mRecorderProfile = profile->GetName();
--- a/dom/camera/ICameraControl.h
+++ b/dom/camera/ICameraControl.h
@@ -111,16 +111,21 @@ public:
     kUnspecifiedMode,
     kPictureMode,
     kVideoMode,
   };
 
   struct Size {
     uint32_t  width;
     uint32_t  height;
+
+    bool Equals(const Size& aSize) const
+    {
+      return width == aSize.width && height == aSize.height;
+    }
   };
 
   struct Region {
     int32_t   top;
     int32_t   left;
     int32_t   bottom;
     int32_t   right;
     uint32_t  weight;
--- a/dom/camera/test/test_camera_configuration.html
+++ b/dom/camera/test/test_camera_configuration.html
@@ -106,17 +106,17 @@ suite.test('start-unspecified', function
     .then(configure)
     .then(resolveConfigure, suite.rejectConfigure);
 });
 
 suite.test('picture-mode', function() {
   suite.hw.params['preview-size'] = '1x1';
   suite.hw.params['picture-size'] = '1x1';
   suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
-  suite.hw.params['picture-size-values'] = '640x480,320x240,1x1';
+  suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,1x1';
   suite.hw.params['video-size-values'] = '320x240';
 
   var setConfig = {
     mode: 'picture',
     previewSize: {
       width: 640,
       height: 480
     }
@@ -125,22 +125,75 @@ suite.test('picture-mode', function() {
   var expConfig = {
     mode: 'picture',
     recorderProfile: 'qvga',
     previewSize: {
       width: 640,
       height: 480
     },
     pictureSize: {
+      width: 1280,
+      height: 960
+    }
+  };
+
+  var postConfig = {
+    mode: 'picture',
+    recorderProfile: 'qvga',
+    previewSize: {
+      width: 640,
+      height: 480
+    },
+    pictureSize: {
       width: 640,
       height: 480
     }
   };
 
-  return setAndVerifyConfig(setConfig, expConfig);
+  function syncPreview() {
+    return new Promise(function(resolve, reject) {
+      function onEvent(e) {
+        if (e.newState === 'started') {
+          resolve();
+        }
+      }
+      suite.camera.addEventListener('previewstatechange', onEvent);
+    });
+  }
+
+  function reconfigure(p) {
+    // The preview restarting confirms the configuration actually happened
+    var sync = new Promise(function(resolve, reject) {
+      var i = 0;
+      var expState = ['started', 'stopped', 'started'];
+
+      function onEvent(e) {
+        ok(e.newState === expState[i], 'preview event state ' + expState[i] +
+                                       ' === ' + e.newState);
+        ++i;
+        if (i === expState.length) { return; }
+        suite.camera.removeEventListener('previewstatechange', onEvent);
+        resolve();
+      }
+
+      suite.camera.addEventListener('previewstatechange', onEvent);
+    });
+
+    var configure = suite.camera.setConfiguration(postConfig)
+                      .then(resolveReconfigure);
+    return Promise.all([sync, configure]);
+  }
+
+  function resolveReconfigure(cfg) {
+    verifyConfig(cfg, postConfig);
+  }
+
+  return setAndVerifyConfig(setConfig, expConfig)
+    .then(syncPreview)
+    .then(reconfigure);
 });
 
 suite.test('picture-mode-larger-picture-size', function() {
   suite.hw.params['preview-size'] = '1x1';
   suite.hw.params['picture-size'] = '1x1';
   suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
   suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,1x1';
   suite.hw.params['video-size-values'] = '320x240';