mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-12 17:22:04 +00:00
Bug 1029367 - handle ISO modes without "ISO" prefixes, r=dhylands
This commit is contained in:
parent
1d08ceceda
commit
484c8ff35c
@ -230,16 +230,17 @@ nsGonkCameraControl::SetConfigurationInternal(const Configuration& aConfig)
|
||||
break;
|
||||
}
|
||||
|
||||
nsresult rv = Set(CAMERA_PARAM_RECORDINGHINT,
|
||||
aConfig.mMode == kVideoMode);
|
||||
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -149,6 +149,7 @@ GonkCameraParameters::GonkCameraParameters()
|
||||
GonkCameraParameters::~GonkCameraParameters()
|
||||
{
|
||||
MOZ_COUNT_DTOR(GonkCameraParameters);
|
||||
mIsoModeMap.Clear();
|
||||
MOZ_ASSERT(mLock, "mLock missing in ~GonkCameraParameters()");
|
||||
if (mLock) {
|
||||
PR_DestroyRWLock(mLock);
|
||||
@ -159,20 +160,19 @@ GonkCameraParameters::~GonkCameraParameters()
|
||||
nsresult
|
||||
GonkCameraParameters::MapIsoToGonk(const nsAString& aIso, nsACString& aIsoOut)
|
||||
{
|
||||
if (aIso.EqualsASCII("hjr")) {
|
||||
aIsoOut = "ISO_HJR";
|
||||
} else if (aIso.EqualsASCII("auto")) {
|
||||
aIsoOut = "auto";
|
||||
} else {
|
||||
nsAutoCString v = NS_LossyConvertUTF16toASCII(aIso);
|
||||
unsigned int iso;
|
||||
if (sscanf(v.get(), "%u", &iso) != 1) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
nsCString* s;
|
||||
if (mIsoModeMap.Get(aIso, &s)) {
|
||||
if (!s) {
|
||||
DOM_CAMERA_LOGE("ISO mode '%s' maps to null Gonk ISO value\n",
|
||||
NS_LossyConvertUTF16toASCII(aIso).get());
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aIsoOut = nsPrintfCString("ISO%u", iso);
|
||||
|
||||
aIsoOut = *s;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -184,9 +184,13 @@ GonkCameraParameters::MapIsoFromGonk(const char* aIso, nsAString& aIsoOut)
|
||||
aIsoOut.AssignASCII("auto");
|
||||
} else {
|
||||
unsigned int iso;
|
||||
if (sscanf(aIso, "ISO%u", &iso) != 1) {
|
||||
char ignored;
|
||||
// Some camera libraries return ISO modes as "ISO100", others as "100".
|
||||
if (sscanf(aIso, "ISO%u%c", &iso, &ignored) != 1 &&
|
||||
sscanf(aIso, "%u%c", &iso, &ignored) != 1) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
aIsoOut.Truncate(0);
|
||||
aIsoOut.AppendInt(iso);
|
||||
}
|
||||
|
||||
@ -239,14 +243,17 @@ GonkCameraParameters::Initialize()
|
||||
// The return code from GetListAsArray() doesn't matter. If it fails,
|
||||
// the isoModes array will be empty, and the subsequent loop won't
|
||||
// execute.
|
||||
nsString s;
|
||||
nsTArray<nsCString> isoModes;
|
||||
GetListAsArray(CAMERA_PARAM_SUPPORTED_ISOMODES, isoModes);
|
||||
for (uint32_t i = 0; i < isoModes.Length(); ++i) {
|
||||
nsString v;
|
||||
rv = MapIsoFromGonk(isoModes[i].get(), v);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*mIsoModes.AppendElement() = v;
|
||||
rv = MapIsoFromGonk(isoModes[i].get(), s);
|
||||
if (NS_FAILED(rv)) {
|
||||
DOM_CAMERA_LOGW("Unrecognized ISO mode value '%s'\n", isoModes[i].get());
|
||||
continue;
|
||||
}
|
||||
*mIsoModes.AppendElement() = s;
|
||||
mIsoModeMap.Put(s, new nsCString(isoModes[i]));
|
||||
}
|
||||
|
||||
mInitialized = true;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "nsString.h"
|
||||
#include "AutoRwLock.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "ICameraControl.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -100,6 +101,7 @@ protected:
|
||||
int32_t mExposureCompensationMaxIndex;
|
||||
nsTArray<int> mZoomRatios;
|
||||
nsTArray<nsString> mIsoModes;
|
||||
nsClassHashtable<nsStringHashKey, nsCString> mIsoModeMap;
|
||||
|
||||
// This subclass of android::CameraParameters just gives
|
||||
// all of the AOSP getters and setters the same signature.
|
||||
|
@ -120,19 +120,36 @@ var tests = [
|
||||
// we should recognize 'auto', 'hjr', and numeric modes; anything else
|
||||
// from the driver is ignored, which this test also verifies.
|
||||
test.setFakeParameters(
|
||||
"iso=auto;iso-values=auto,ISO_HJR,ISO100,foo,ISObar,ISO200,ISO400,ISO800,ISO1600",
|
||||
"iso=auto;iso-values=auto,ISO_HJR,ISO100,foo,ISObar,ISO150moz,ISO200,400,ISO800,1600",
|
||||
function () {
|
||||
run();
|
||||
});
|
||||
},
|
||||
test: function testFakeIso(cam, cap) {
|
||||
// values 'foo' and 'ISObar' should not be included in isoModes
|
||||
ok(cap.isoModes.length == 7, "ISO modes length = " + cap.isoModes.length);
|
||||
|
||||
// make sure we're not leaking any unexpected values formats
|
||||
ok(cap.isoModes.indexOf("ISO_HJR") == -1, "ISO mode 'ISO_HJR' does not appear");
|
||||
ok(cap.isoModes.indexOf("_HJR") == -1, "ISO mode '_HJR' does not appear");
|
||||
ok(cap.isoModes.indexOf("HJR") == -1, "ISO mode 'HJR' does not appear");
|
||||
ok(cap.isoModes.indexOf("ISO100") == -1, "ISO mode 'ISO100' does not appear");
|
||||
ok(cap.isoModes.indexOf("ISO200") == -1, "ISO mode 'ISO200' does not appear");
|
||||
ok(cap.isoModes.indexOf("ISO800") == -1, "ISO mode 'ISO800' does not appear");
|
||||
|
||||
// make sure any weird values are dropped entirely
|
||||
ok(cap.isoModes.indexOf("foo") == -1, "Unknown ISO mode 'foo' is ignored");
|
||||
ok(cap.isoModes.indexOf("ISObar") == -1, "Unknown ISO mode 'ISObar' is ignored");
|
||||
ok(cap.isoModes.indexOf("bar") == -1, "Unknown ISO mode 'bar' is ignored");
|
||||
ok(cap.isoModes.indexOf("ISO150moz") == -1, "Unknown ISO mode 'ISO150moz' is ignored");
|
||||
ok(cap.isoModes.indexOf("150moz") == -1, "Unknown ISO mode '150moz' is ignored");
|
||||
ok(cap.isoModes.indexOf("150") == -1, "Unknown ISO mode '150' is ignored");
|
||||
|
||||
// test individual ISO modes
|
||||
// make sure expected values are present
|
||||
[ "auto", "hjr", "100", "200", "400", "800", "1600" ].forEach(function(iso) {
|
||||
ok(cap.isoModes.indexOf(iso) != -1, "ISO mode '" + iso + "' is present");
|
||||
});
|
||||
|
||||
// test setters/getters for individual ISO modes
|
||||
cap.isoModes.forEach(function(iso, index) {
|
||||
cam.iso = iso;
|
||||
ok(cam.iso === iso,
|
||||
@ -251,7 +268,6 @@ var tests = [
|
||||
cam.exposureCompensation = -1.25;
|
||||
ok(cam.exposureCompensation == -1.5,
|
||||
"exposureCompensation(-1.25) = " + cam.exposureCompensation);
|
||||
|
||||
// Check out-of-bounds values
|
||||
cam.exposureCompensation = cap.minExposureCompensation - 1.0;
|
||||
ok(cam.exposureCompensation == cap.minExposureCompensation,
|
||||
|
Loading…
Reference in New Issue
Block a user