mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1037322 - change CameraConfiguration default mode to 'unspecified' r=dhylands,khuey
This commit is contained in:
parent
429534db88
commit
2f751308dd
@ -168,23 +168,33 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
|
||||
|
||||
// Create and initialize the underlying camera.
|
||||
ICameraControl::Configuration config;
|
||||
bool haveInitialConfig = false;
|
||||
nsresult rv;
|
||||
|
||||
switch (aInitialConfig.mMode) {
|
||||
case CameraMode::Picture:
|
||||
config.mMode = ICameraControl::kPictureMode;
|
||||
haveInitialConfig = true;
|
||||
break;
|
||||
|
||||
case CameraMode::Video:
|
||||
config.mMode = ICameraControl::kVideoMode;
|
||||
haveInitialConfig = true;
|
||||
break;
|
||||
|
||||
case CameraMode::Unspecified:
|
||||
break;
|
||||
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Unanticipated camera mode!");
|
||||
break;
|
||||
}
|
||||
|
||||
config.mPreviewSize.width = aInitialConfig.mPreviewSize.mWidth;
|
||||
config.mPreviewSize.height = aInitialConfig.mPreviewSize.mHeight;
|
||||
config.mRecorderProfile = aInitialConfig.mRecorderProfile;
|
||||
if (haveInitialConfig) {
|
||||
config.mPreviewSize.width = aInitialConfig.mPreviewSize.mWidth;
|
||||
config.mPreviewSize.height = aInitialConfig.mPreviewSize.mHeight;
|
||||
config.mRecorderProfile = aInitialConfig.mRecorderProfile;
|
||||
}
|
||||
|
||||
mCameraControl = ICameraControl::Create(aCameraId);
|
||||
mCurrentConfiguration = initialConfig.forget();
|
||||
@ -201,7 +211,11 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
|
||||
mCameraControl->AddListener(mListener);
|
||||
|
||||
// Start the camera...
|
||||
nsresult rv = mCameraControl->Start(&config);
|
||||
if (haveInitialConfig) {
|
||||
rv = mCameraControl->Start(&config);
|
||||
} else {
|
||||
rv = mCameraControl->Start();
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
mListener->OnUserError(DOMCameraControlListener::kInStartCamera, rv);
|
||||
}
|
||||
|
@ -122,7 +122,11 @@ nsGonkCameraControl::StartImpl(const Configuration* aInitialConfig)
|
||||
}
|
||||
|
||||
OnHardwareStateChange(CameraControlListener::kHardwareOpen);
|
||||
return StartPreviewImpl();
|
||||
if (aInitialConfig) {
|
||||
return StartPreviewImpl();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -257,6 +261,11 @@ nsGonkCameraControl::SetConfigurationImpl(const Configuration& aConfig)
|
||||
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
||||
|
||||
if (aConfig.mMode == kUnspecifiedMode) {
|
||||
DOM_CAMERA_LOGW("Can't set camera mode to 'unspecified', ignoring\n");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Stop any currently running preview
|
||||
nsresult rv = PausePreview();
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -11,3 +11,4 @@ support-files = camera_common.js
|
||||
[test_camera_hardware_face_detection.html]
|
||||
[test_camera_hardware_auto_focus_moving_cb.html]
|
||||
[test_bug1022766.html]
|
||||
[test_bug1037322.html]
|
||||
|
84
dom/camera/test/test_bug1037322.html
Normal file
84
dom/camera/test/test_bug1037322.html
Normal file
@ -0,0 +1,84 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for bug 1037322</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="camera_common.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<video id="viewfinder" width="200" height="200" autoplay></video>
|
||||
<img src="#" alt="This image is going to load" id="testimage"/>
|
||||
<script class="testbody" type="text/javascript;version=1.7">
|
||||
|
||||
var whichCamera = navigator.mozCameras.getListOfCameras()[0];
|
||||
var config = {
|
||||
mode: 'picture',
|
||||
recorderProfile: 'cif',
|
||||
previewSize: {
|
||||
width: 352,
|
||||
height: 288
|
||||
}
|
||||
};
|
||||
|
||||
function onError(e) {
|
||||
ok(false, "Error: " + JSON.stringify(e));
|
||||
}
|
||||
|
||||
var Camera = {
|
||||
cameraObj: null,
|
||||
|
||||
get viewfinder() {
|
||||
return document.getElementById('viewfinder');
|
||||
},
|
||||
|
||||
start: function test_start() {
|
||||
function setConfig_onSuccess(cfg) {
|
||||
// Check our specific configuration
|
||||
ok(cfg.mode === config.mode, "Configured mode = " + cfg.mode);
|
||||
ok(cfg.previewSize.width === config.previewSize.width &&
|
||||
cfg.previewSize.height === config.previewSize.height,
|
||||
"Configured preview size = " + cfg.previewSize.width + "x" + cfg.previewSize.height);
|
||||
ok(cfg.recorderProfile === config.recorderProfile,
|
||||
"Configured recorder profile = '" + cfg.recorderProfile + "'");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function getCamera_onSuccess(camera, cfg) {
|
||||
Camera.cameraObj = camera;
|
||||
Camera.viewfinder.mozSrcObject = camera;
|
||||
Camera.viewfinder.play();
|
||||
|
||||
// Check the default configuration
|
||||
ok(cfg.mode === "unspecified", "Initial mode = " + cfg.mode);
|
||||
ok(cfg.previewSize.width === 0 && cfg.previewSize.height === 0,
|
||||
"Initial preview size = " + cfg.previewSize.width + "x" + cfg.previewSize.height);
|
||||
ok(cfg.recorderProfile === "",
|
||||
"Initial recorder profile = '" + cfg.recorderProfile + "'");
|
||||
|
||||
// Apply our specific configuration
|
||||
camera.setConfiguration(config, setConfig_onSuccess, onError);
|
||||
}
|
||||
|
||||
navigator.mozCameras.getCamera(whichCamera, {}, getCamera_onSuccess, onError);
|
||||
}
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
window.addEventListener('beforeunload', function() {
|
||||
Camera.viewfinder.mozSrcObject = null;
|
||||
if (Camera.cameraObj) {
|
||||
Camera.cameraObj.release();
|
||||
Camera.cameraObj = null;
|
||||
}
|
||||
});
|
||||
|
||||
Camera.start();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -5,7 +5,7 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
enum CameraMode { "picture", "video" };
|
||||
enum CameraMode { "unspecified", "picture", "video" };
|
||||
|
||||
/* Used for the dimensions of a captured picture,
|
||||
a preview stream, a video capture stream, etc. */
|
||||
@ -18,10 +18,10 @@ dictionary CameraSize
|
||||
/* Pre-emptive camera configuration options. */
|
||||
dictionary CameraConfiguration
|
||||
{
|
||||
CameraMode mode = "picture";
|
||||
CameraMode mode = "unspecified";
|
||||
CameraSize previewSize = null;
|
||||
DOMString recorderProfile = "cif"; // or some other recording profile
|
||||
// supported by the CameraControl
|
||||
DOMString recorderProfile = ""; // one of the profiles reported by
|
||||
// CameraControl.capabilities.recorderProfiles
|
||||
};
|
||||
|
||||
callback CameraErrorCallback = void (DOMString error);
|
||||
|
Loading…
Reference in New Issue
Block a user