Skip to content

Commit

Permalink
Bug 1131782 - add vendor-specific feature-detection to GonkCameraPara…
Browse files Browse the repository at this point in the history
…meters, r=aosmond
  • Loading branch information
Mike Habicher committed Feb 12, 2015
1 parent 4a9221a commit 7b5b291
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
45 changes: 38 additions & 7 deletions dom/camera/GonkCameraParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,25 @@ GonkCameraParameters::IsLowMemoryPlatform()
return false;
}

/* static */ const char*
const char*
GonkCameraParameters::Parameters::FindVendorSpecificKey(const char* aPotentialKeys[],
size_t aPotentialKeyCount)
{
const char* val;

for (size_t i = 0; i < aPotentialKeyCount; ++i) {
get(aPotentialKeys[i], val);
if (val) {
// We received a value (potentially an empty-string one),
// which indicates that this key exists.
return aPotentialKeys[i];
}
}

return nullptr;
}

const char*
GonkCameraParameters::Parameters::GetTextKey(uint32_t aKey)
{
switch (aKey) {
Expand Down Expand Up @@ -105,9 +123,15 @@ GonkCameraParameters::Parameters::GetTextKey(uint32_t aKey)
case CAMERA_PARAM_VIDEOSIZE:
return KEY_VIDEO_SIZE;
case CAMERA_PARAM_ISOMODE:
// Not every platform defines KEY_ISO_MODE;
// for those that don't, we use the raw string key.
return "iso";
if (!mVendorSpecificKeyIsoMode) {
const char* isoModeKeys[] = {
"iso",
"sony-iso"
};
mVendorSpecificKeyIsoMode =
FindVendorSpecificKey(isoModeKeys, MOZ_ARRAY_LENGTH(isoModeKeys));
}
return mVendorSpecificKeyIsoMode;
case CAMERA_PARAM_LUMINANCE:
return "luminance-condition";
case CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE:
Expand Down Expand Up @@ -161,9 +185,16 @@ GonkCameraParameters::Parameters::GetTextKey(uint32_t aKey)
case CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES:
return KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES;
case CAMERA_PARAM_SUPPORTED_ISOMODES:
// Not every platform defines KEY_SUPPORTED_ISO_MODES;
// for those that don't, we use the raw string key.
return "iso-values";
if (!mVendorSpecificKeySupportedIsoModes) {
const char* supportedIsoModesKeys[] = {
"iso-values",
"sony-iso-values"
};
mVendorSpecificKeySupportedIsoModes =
FindVendorSpecificKey(supportedIsoModesKeys,
MOZ_ARRAY_LENGTH(supportedIsoModesKeys));
}
return mVendorSpecificKeySupportedIsoModes;
case CAMERA_PARAM_SUPPORTED_METERINGMODES:
// Not every platform defines KEY_SUPPORTED_AUTO_EXPOSURE.
return "auto-exposure-values";
Expand Down
20 changes: 16 additions & 4 deletions dom/camera/GonkCameraParameters.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2014 Mozilla Foundation
* Copyright (C) 2013-2015 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -110,6 +110,12 @@ class GonkCameraParameters
class Parameters : public android::CameraParameters
{
public:
Parameters()
: mVendorSpecificKeyIsoMode(nullptr)
, mVendorSpecificKeySupportedIsoModes(nullptr)
{ }
virtual ~Parameters() { }

using android::CameraParameters::set;
using android::CameraParameters::get;
using android::CameraParameters::TRUE;
Expand All @@ -132,7 +138,13 @@ class GonkCameraParameters

void remove(const char* aKey) { android::CameraParameters::remove(aKey); }

static const char* GetTextKey(uint32_t aKey);
const char* GetTextKey(uint32_t aKey);

protected:
const char* FindVendorSpecificKey(const char* aPotentialKeys[], size_t aPotentialKeyCount);

const char* mVendorSpecificKeyIsoMode;
const char* mVendorSpecificKeySupportedIsoModes;
};

Parameters mParams;
Expand All @@ -147,7 +159,7 @@ class GonkCameraParameters
template<typename T> nsresult
SetImpl(uint32_t aKey, const T& aValue)
{
const char* key = Parameters::GetTextKey(aKey);
const char* key = mParams.GetTextKey(aKey);
NS_ENSURE_TRUE(key, NS_ERROR_NOT_IMPLEMENTED);

mParams.set(key, aValue);
Expand All @@ -157,7 +169,7 @@ class GonkCameraParameters
template<typename T> nsresult
GetImpl(uint32_t aKey, T& aValue)
{
const char* key = Parameters::GetTextKey(aKey);
const char* key = mParams.GetTextKey(aKey);
NS_ENSURE_TRUE(key, NS_ERROR_NOT_IMPLEMENTED);

mParams.get(key, aValue);
Expand Down

0 comments on commit 7b5b291

Please sign in to comment.