2014-02-14 14:41:07 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-07-30 14:59:05 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2014-02-14 14:41:07 -08:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "DOMCameraCapabilities.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "mozilla/dom/CameraManagerBinding.h"
|
|
|
|
#include "mozilla/dom/CameraCapabilitiesBinding.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "CameraCommon.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "ICameraControl.h"
|
|
|
|
#include "CameraRecorderProfiles.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CameraCapabilities)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CameraCapabilities)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
tmp->mRecorderProfiles = JS::UndefinedValue();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CameraCapabilities)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CameraCapabilities)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mRecorderProfiles)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(CameraCapabilities)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(CameraCapabilities)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CameraCapabilities)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-30 14:59:05 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
CameraCapabilities::CameraCapabilities(nsPIDOMWindow* aWindow)
|
|
|
|
: mRecorderProfiles(JS::UndefinedValue())
|
|
|
|
, mWindow(aWindow)
|
2014-02-13 21:28:57 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
MOZ_COUNT_CTOR(CameraCapabilities);
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
CameraCapabilities::~CameraCapabilities()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
mRecorderProfiles = JS::UndefinedValue();
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
MOZ_COUNT_DTOR(CameraCapabilities);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
CameraCapabilities::WrapObject(JSContext* aCx)
|
2014-02-14 14:41:07 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return CameraCapabilitiesBinding::Wrap(aCx, this);
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
#define LOG_IF_ERROR(rv, param) \
|
|
|
|
do { \
|
|
|
|
if (NS_FAILED(rv)) { \
|
|
|
|
DOM_CAMERA_LOGW("Error %x trying to get " #param "\n", \
|
|
|
|
(rv)); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraCapabilities::TranslateToDictionary(ICameraControl* aCameraControl,
|
|
|
|
uint32_t aKey, nsTArray<CameraSize>& aSizes)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult rv;
|
|
|
|
nsTArray<ICameraControl::Size> sizes;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(aKey, sizes);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
aSizes.Clear();
|
|
|
|
aSizes.SetCapacity(sizes.Length());
|
|
|
|
for (uint32_t i = 0; i < sizes.Length(); ++i) {
|
|
|
|
CameraSize* s = aSizes.AppendElement();
|
|
|
|
s->mWidth = sizes[i].width;
|
|
|
|
s->mHeight = sizes[i].height;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
CameraCapabilities::Populate(ICameraControl* aCameraControl)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_ENSURE_TRUE(aCameraControl, NS_ERROR_INVALID_ARG);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult rv;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, mPreviewSizes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_PREVIEWSIZES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_PICTURESIZES, mPictureSizes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_PICTURESIZES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES, mThumbnailSizes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_VIDEOSIZES, mVideoSizes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_VIDEOSIZES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_PICTUREFORMATS, mFileFormats);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_PICTUREFORMATS);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_WHITEBALANCES, mWhiteBalanceModes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_WHITEBALANCES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_SCENEMODES, mSceneModes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_SCENEMODES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_EFFECTS, mEffects);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_EFFECTS);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_FLASHMODES, mFlashModes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_FLASHMODES);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_FOCUSMODES, mFocusModes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_FOCUSMODES);
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-03-06 22:00:43 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_ISOMODES, mIsoModes);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_ISOMODES);
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_ZOOMRATIOS, mZoomRatios);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_ZOOMRATIOS);
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
int32_t areas;
|
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS, areas);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS);
|
|
|
|
mMaxFocusAreas = areas < 0 ? 0 : areas;
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS, areas);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS);
|
|
|
|
mMaxMeteringAreas = areas < 0 ? 0 : areas;
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION, mMinExposureCompensation);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION);
|
|
|
|
|
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION, mMaxExposureCompensation);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION);
|
|
|
|
|
|
|
|
rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP, mExposureCompensationStep);
|
|
|
|
LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP);
|
|
|
|
|
|
|
|
mRecorderProfileManager = aCameraControl->GetRecorderProfileManager();
|
|
|
|
if (!mRecorderProfileManager) {
|
|
|
|
DOM_CAMERA_LOGW("Unable to get recorder profile manager\n");
|
|
|
|
} else {
|
|
|
|
AutoJSContext js;
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> o(js);
|
|
|
|
nsresult rv = mRecorderProfileManager->GetJsObject(js, o.address());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to JS-objectify profile manager (%d)\n", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
mRecorderProfiles = JS::ObjectValue(*o);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// For now, always return success, since the presence or absence of capabilities
|
|
|
|
// indicates whether or not they are supported.
|
2012-07-30 14:59:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetPreviewSizes(nsTArray<dom::CameraSize>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mPreviewSizes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetPictureSizes(nsTArray<dom::CameraSize>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mPictureSizes;
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetThumbnailSizes(nsTArray<dom::CameraSize>& retval) const
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mThumbnailSizes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetVideoSizes(nsTArray<dom::CameraSize>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mVideoSizes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetFileFormats(nsTArray<nsString>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mFileFormats;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetWhiteBalanceModes(nsTArray<nsString>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mWhiteBalanceModes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetSceneModes(nsTArray<nsString>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mSceneModes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetEffects(nsTArray<nsString>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mEffects;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetFlashModes(nsTArray<nsString>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mFlashModes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetFocusModes(nsTArray<nsString>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mFocusModes;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetZoomRatios(nsTArray<double>& retval) const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
retval = mZoomRatios;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t
|
|
|
|
CameraCapabilities::MaxFocusAreas() const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mMaxFocusAreas;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t
|
|
|
|
CameraCapabilities::MaxMeteringAreas() const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mMaxMeteringAreas;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
double
|
|
|
|
CameraCapabilities::MinExposureCompensation() const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mMinExposureCompensation;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
double
|
|
|
|
CameraCapabilities::MaxExposureCompensation() const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mMaxExposureCompensation;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
double
|
|
|
|
CameraCapabilities::ExposureCompensationStep() const
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mExposureCompensationStep;
|
2012-10-23 15:30:28 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
JS::Value
|
|
|
|
CameraCapabilities::RecorderProfiles(JSContext* aCx) const
|
2012-10-23 15:30:28 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mRecorderProfiles;
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-03-06 22:00:43 -08:00
|
|
|
void
|
|
|
|
CameraCapabilities::GetIsoModes(nsTArray<nsString>& retval) const
|
|
|
|
{
|
|
|
|
retval = mIsoModes;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|