2012-09-05 05:01:56 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "DOMCameraControl.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMClassInfo.h"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "nsHashPropertyBag.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "nsThread.h"
|
2013-07-07 00:55:10 +04:00
|
|
|
#include "DeviceStorage.h"
|
2014-01-17 05:01:43 +04:00
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-03-01 00:02:55 +04:00
|
|
|
#include "mozilla/ipc/FileDescriptorUtils.h"
|
2013-11-26 10:22:22 +04:00
|
|
|
#include "mozilla/MediaManager.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "mozilla/Services.h"
|
2013-01-25 06:45:36 +04:00
|
|
|
#include "mozilla/unused.h"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "nsIAppsService.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "nsIObserverService.h"
|
2012-09-29 09:30:52 +04:00
|
|
|
#include "nsIDOMDeviceStorage.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2014-04-09 19:53:34 +04:00
|
|
|
#include "Navigator.h"
|
2013-01-25 06:45:36 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "DOMCameraManager.h"
|
|
|
|
#include "DOMCameraCapabilities.h"
|
|
|
|
#include "CameraCommon.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "CameraPreviewMediaStream.h"
|
2014-10-03 12:19:00 +04:00
|
|
|
#include "mozilla/dom/CameraUtilBinding.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "mozilla/dom/CameraControlBinding.h"
|
2013-05-18 05:48:25 +04:00
|
|
|
#include "mozilla/dom/CameraManagerBinding.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "mozilla/dom/CameraCapabilitiesBinding.h"
|
2014-10-03 12:19:00 +04:00
|
|
|
#include "mozilla/dom/CameraConfigurationEvent.h"
|
|
|
|
#include "mozilla/dom/CameraConfigurationEventBinding.h"
|
|
|
|
#include "mozilla/dom/CameraFacesDetectedEvent.h"
|
|
|
|
#include "mozilla/dom/CameraFacesDetectedEventBinding.h"
|
|
|
|
#include "mozilla/dom/CameraStateChangeEvent.h"
|
|
|
|
#include "mozilla/dom/BlobEvent.h"
|
2014-04-09 19:52:10 +04:00
|
|
|
#include "DOMCameraDetectedFace.h"
|
2013-05-18 05:48:25 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2014-04-26 00:28:15 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-05-18 05:48:25 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-03-01 00:02:55 +04:00
|
|
|
using namespace mozilla::ipc;
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
StaticRefPtr<ICameraControl> nsDOMCameraControl::sCachedCameraControl;
|
|
|
|
/* static */ nsresult nsDOMCameraControl::sCachedCameraControlStartResult = NS_OK;
|
|
|
|
/* static */ nsCOMPtr<nsITimer> nsDOMCameraControl::sDiscardCachedCameraControlTimer;
|
|
|
|
#endif
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMCameraControl)
|
2012-09-05 05:01:56 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2014-02-15 02:41:07 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMCameraControl, DOMMediaStream)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMCameraControl, DOMMediaStream)
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsDOMCameraControl, DOMMediaStream,
|
|
|
|
mCapabilities,
|
|
|
|
mWindow,
|
2014-10-03 12:19:00 +04:00
|
|
|
mGetCameraPromise,
|
|
|
|
mAutoFocusPromise,
|
|
|
|
mTakePicturePromise,
|
|
|
|
mStartRecordingPromise,
|
|
|
|
mReleasePromise,
|
|
|
|
mSetConfigurationPromise,
|
2014-04-25 20:49:00 +04:00
|
|
|
mGetCameraOnSuccessCb,
|
|
|
|
mGetCameraOnErrorCb,
|
|
|
|
mAutoFocusOnSuccessCb,
|
|
|
|
mAutoFocusOnErrorCb,
|
|
|
|
mTakePictureOnSuccessCb,
|
|
|
|
mTakePictureOnErrorCb,
|
|
|
|
mStartRecordingOnSuccessCb,
|
|
|
|
mStartRecordingOnErrorCb,
|
|
|
|
mReleaseOnSuccessCb,
|
|
|
|
mReleaseOnErrorCb,
|
|
|
|
mSetConfigurationOnSuccessCb,
|
|
|
|
mSetConfigurationOnErrorCb,
|
|
|
|
mOnShutterCb,
|
|
|
|
mOnClosedCb,
|
|
|
|
mOnRecorderStateChangeCb,
|
|
|
|
mOnPreviewStateChangeCb,
|
|
|
|
mOnAutoFocusMovingCb,
|
2014-09-22 07:25:00 +04:00
|
|
|
mOnAutoFocusCompletedCb,
|
2014-04-25 20:49:00 +04:00
|
|
|
mOnFacesDetectedCb)
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-04-09 19:53:34 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
nsDOMCameraControl::HasSupport(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
return Navigator::HasCameraSupport(aCx, aGlobal);
|
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
class mozilla::StartRecordingHelper : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit StartRecordingHelper(nsDOMCameraControl* aDOMCameraControl)
|
2014-02-15 02:41:07 +04:00
|
|
|
: mDOMCameraControl(aDOMCameraControl)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(StartRecordingHelper);
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
protected:
|
|
|
|
virtual ~StartRecordingHelper()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(StartRecordingHelper);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<nsDOMCameraControl> mDOMCameraControl;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StartRecordingHelper::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
|
|
|
|
mDOMCameraControl->OnCreatedFileDescriptor(eventType.EqualsLiteral("success"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(mozilla::StartRecordingHelper, nsIDOMEventListener)
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
nsDOMCameraControl::DOMCameraConfiguration::DOMCameraConfiguration()
|
|
|
|
: CameraConfiguration()
|
|
|
|
, mMaxFocusAreas(0)
|
|
|
|
, mMaxMeteringAreas(0)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDOMCameraControl::DOMCameraConfiguration);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCameraControl::DOMCameraConfiguration::DOMCameraConfiguration(const CameraConfiguration& aConfiguration)
|
|
|
|
: CameraConfiguration(aConfiguration)
|
|
|
|
, mMaxFocusAreas(0)
|
|
|
|
, mMaxMeteringAreas(0)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDOMCameraControl::DOMCameraConfiguration);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCameraControl::DOMCameraConfiguration::~DOMCameraConfiguration()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDOMCameraControl::DOMCameraConfiguration);
|
|
|
|
}
|
|
|
|
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// This shoudl be long enough for even our slowest platforms.
|
|
|
|
static const unsigned long kCachedCameraTimeoutMs = 3500;
|
|
|
|
|
|
|
|
// Open the battery-door-facing camera by default.
|
|
|
|
static const uint32_t kDefaultCameraId = 0;
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsDOMCameraControl::PreinitCameraHardware()
|
|
|
|
{
|
|
|
|
// Assume a default, minimal configuration. This should initialize the
|
|
|
|
// hardware, but won't (can't) start the preview.
|
|
|
|
nsRefPtr<ICameraControl> cameraControl = ICameraControl::Create(kDefaultCameraId);
|
|
|
|
if (NS_WARN_IF(!cameraControl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sCachedCameraControlStartResult = cameraControl->Start();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(sCachedCameraControlStartResult))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sCachedCameraControl = cameraControl;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
if (NS_WARN_IF(!timer)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = timer->InitWithFuncCallback(DiscardCachedCameraInstance,
|
|
|
|
nullptr,
|
|
|
|
kCachedCameraTimeoutMs,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If we can't start the timer, it's possible for an app to never grab the
|
|
|
|
// camera, leaving the hardware tied up indefinitely. Better to take the
|
|
|
|
// performance hit.
|
|
|
|
sCachedCameraControl = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sDiscardCachedCameraControlTimer = timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsDOMCameraControl::DiscardCachedCameraInstance(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
sDiscardCachedCameraControlTimer = nullptr;
|
|
|
|
sCachedCameraControl = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
|
|
|
|
const CameraConfiguration& aInitialConfig,
|
|
|
|
GetCameraCallback* aOnSuccess,
|
|
|
|
CameraErrorCallback* aOnError,
|
2014-10-03 12:19:00 +04:00
|
|
|
Promise* aPromise,
|
2014-02-15 02:41:07 +04:00
|
|
|
nsPIDOMWindow* aWindow)
|
|
|
|
: DOMMediaStream()
|
|
|
|
, mCameraControl(nullptr)
|
|
|
|
, mAudioChannelAgent(nullptr)
|
2014-10-03 12:19:00 +04:00
|
|
|
, mGetCameraPromise(aPromise)
|
2014-02-15 02:41:07 +04:00
|
|
|
, mGetCameraOnSuccessCb(aOnSuccess)
|
|
|
|
, mGetCameraOnErrorCb(aOnError)
|
|
|
|
, mAutoFocusOnSuccessCb(nullptr)
|
|
|
|
, mAutoFocusOnErrorCb(nullptr)
|
|
|
|
, mTakePictureOnSuccessCb(nullptr)
|
|
|
|
, mTakePictureOnErrorCb(nullptr)
|
|
|
|
, mStartRecordingOnSuccessCb(nullptr)
|
|
|
|
, mStartRecordingOnErrorCb(nullptr)
|
|
|
|
, mReleaseOnSuccessCb(nullptr)
|
|
|
|
, mReleaseOnErrorCb(nullptr)
|
|
|
|
, mSetConfigurationOnSuccessCb(nullptr)
|
|
|
|
, mSetConfigurationOnErrorCb(nullptr)
|
|
|
|
, mOnShutterCb(nullptr)
|
|
|
|
, mOnClosedCb(nullptr)
|
|
|
|
, mOnRecorderStateChangeCb(nullptr)
|
|
|
|
, mOnPreviewStateChangeCb(nullptr)
|
2014-04-09 19:12:25 +04:00
|
|
|
, mOnAutoFocusMovingCb(nullptr)
|
2014-09-22 07:25:00 +04:00
|
|
|
, mOnAutoFocusCompletedCb(nullptr)
|
2014-04-09 19:52:10 +04:00
|
|
|
, mOnFacesDetectedCb(nullptr)
|
2014-02-15 02:41:07 +04:00
|
|
|
, mWindow(aWindow)
|
2014-10-03 12:19:00 +04:00
|
|
|
, mPreviewState(CameraControlListener::kPreviewStopped)
|
2014-02-15 02:41:07 +04:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
mInput = new CameraPreviewMediaStream(this);
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
BindToOwner(aWindow);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
nsRefPtr<DOMCameraConfiguration> initialConfig =
|
|
|
|
new DOMCameraConfiguration(aInitialConfig);
|
|
|
|
|
|
|
|
// Create and initialize the underlying camera.
|
|
|
|
ICameraControl::Configuration config;
|
2014-08-05 21:20:31 +04:00
|
|
|
bool haveInitialConfig = false;
|
|
|
|
nsresult rv;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
switch (aInitialConfig.mMode) {
|
|
|
|
case CameraMode::Picture:
|
|
|
|
config.mMode = ICameraControl::kPictureMode;
|
2014-08-05 21:20:31 +04:00
|
|
|
haveInitialConfig = true;
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraMode::Video:
|
|
|
|
config.mMode = ICameraControl::kVideoMode;
|
2014-08-05 21:20:31 +04:00
|
|
|
haveInitialConfig = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraMode::Unspecified:
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unanticipated camera mode!");
|
2014-08-05 21:20:31 +04:00
|
|
|
break;
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 21:20:31 +04:00
|
|
|
if (haveInitialConfig) {
|
|
|
|
config.mPreviewSize.width = aInitialConfig.mPreviewSize.mWidth;
|
|
|
|
config.mPreviewSize.height = aInitialConfig.mPreviewSize.mHeight;
|
|
|
|
config.mRecorderProfile = aInitialConfig.mRecorderProfile;
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
bool gotCached = false;
|
|
|
|
if (sCachedCameraControl && aCameraId == kDefaultCameraId) {
|
|
|
|
mCameraControl = sCachedCameraControl;
|
|
|
|
sCachedCameraControl = nullptr;
|
|
|
|
gotCached = true;
|
|
|
|
} else {
|
|
|
|
sCachedCameraControl = nullptr;
|
|
|
|
#endif
|
|
|
|
mCameraControl = ICameraControl::Create(aCameraId);
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-15 02:41:07 +04:00
|
|
|
mCurrentConfiguration = initialConfig.forget();
|
|
|
|
|
|
|
|
// Attach our DOM-facing media stream to our viewfinder stream.
|
2014-10-14 06:18:22 +04:00
|
|
|
mStream = mInput;
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mWindow, "Shouldn't be created with a null window!");
|
|
|
|
if (mWindow->GetExtantDoc()) {
|
|
|
|
CombineWithPrincipal(mWindow->GetExtantDoc()->NodePrincipal());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register a listener for camera events.
|
|
|
|
mListener = new DOMCameraControlListener(this, mInput);
|
|
|
|
mCameraControl->AddListener(mListener);
|
2014-02-20 08:18:52 +04:00
|
|
|
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (!gotCached || NS_FAILED(sCachedCameraControlStartResult)) {
|
|
|
|
#endif
|
|
|
|
// Start the camera...
|
|
|
|
if (haveInitialConfig) {
|
|
|
|
rv = mCameraControl->Start(&config);
|
|
|
|
} else {
|
|
|
|
rv = mCameraControl->Start();
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-08-05 21:20:31 +04:00
|
|
|
} else {
|
2014-11-06 19:40:00 +03:00
|
|
|
if (haveInitialConfig) {
|
|
|
|
rv = mCameraControl->SetConfiguration(config);
|
|
|
|
} else {
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
2014-08-05 21:20:31 +04:00
|
|
|
}
|
2014-10-31 20:54:02 +03:00
|
|
|
#endif
|
2014-02-20 08:18:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-04-26 00:28:15 +04:00
|
|
|
mListener->OnUserError(DOMCameraControlListener::kInStartCamera, rv);
|
2014-02-20 08:18:52 +04:00
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
|
|
|
nsDOMCameraControl::~nsDOMCameraControl()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
nsDOMCameraControl::WrapObject(JSContext* aCx)
|
2013-07-07 00:55:10 +04: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-09 02:27:17 +04:00
|
|
|
return CameraControlBinding::Wrap(aCx, this);
|
2013-07-07 00:55:10 +04:00
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
bool
|
|
|
|
nsDOMCameraControl::IsWindowStillActive()
|
|
|
|
{
|
|
|
|
return nsDOMCameraManager::IsWindowStillActive(mWindow->WindowID());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setter for weighted regions: { top, bottom, left, right, weight }
|
|
|
|
nsresult
|
2014-05-01 01:15:01 +04:00
|
|
|
nsDOMCameraControl::Set(uint32_t aKey, const Optional<Sequence<CameraRegion> >& aValue, uint32_t aLimit)
|
2014-02-15 02:41:07 +04:00
|
|
|
{
|
|
|
|
if (aLimit == 0) {
|
|
|
|
DOM_CAMERA_LOGI("%s:%d : aLimit = 0, nothing to do\n", __func__, __LINE__);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<ICameraControl::Region> regionArray;
|
2014-05-01 01:15:01 +04:00
|
|
|
if (aValue.WasPassed()) {
|
|
|
|
const Sequence<CameraRegion>& regions = aValue.Value();
|
|
|
|
uint32_t length = regions.Length();
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
DOM_CAMERA_LOGI("%s:%d : got %d regions (limited to %d)\n", __func__, __LINE__, length, aLimit);
|
|
|
|
if (length > aLimit) {
|
|
|
|
length = aLimit;
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
// aLimit supplied by camera library provides sane ceiling (i.e. <10)
|
|
|
|
regionArray.SetCapacity(length);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
ICameraControl::Region* r = regionArray.AppendElement();
|
|
|
|
const CameraRegion ®ion = regions[i];
|
|
|
|
r->top = region.mTop;
|
|
|
|
r->left = region.mLeft;
|
|
|
|
r->bottom = region.mBottom;
|
|
|
|
r->right = region.mRight;
|
|
|
|
r->weight = region.mWeight;
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("region %d: top=%d, left=%d, bottom=%d, right=%d, weight=%u\n",
|
|
|
|
i,
|
|
|
|
r->top,
|
|
|
|
r->left,
|
|
|
|
r->bottom,
|
|
|
|
r->right,
|
|
|
|
r->weight
|
|
|
|
);
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2014-05-01 01:15:01 +04:00
|
|
|
} else {
|
|
|
|
DOM_CAMERA_LOGI("%s:%d : clear regions\n", __func__, __LINE__);
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
return mCameraControl->Set(aKey, regionArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getter for weighted regions: { top, bottom, left, right, weight }
|
|
|
|
nsresult
|
2014-05-01 01:15:01 +04:00
|
|
|
nsDOMCameraControl::Get(uint32_t aKey, nsTArray<CameraRegion>& aValue)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
nsTArray<ICameraControl::Region> regionArray;
|
|
|
|
|
|
|
|
nsresult rv = mCameraControl->Get(aKey, regionArray);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
uint32_t length = regionArray.Length();
|
|
|
|
DOM_CAMERA_LOGI("%s:%d : got %d regions\n", __func__, __LINE__, length);
|
2014-05-01 01:15:01 +04:00
|
|
|
aValue.SetLength(length);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2014-05-01 01:15:01 +04:00
|
|
|
ICameraControl::Region& r = regionArray[i];
|
|
|
|
CameraRegion& v = aValue[i];
|
|
|
|
v.mTop = r.top;
|
|
|
|
v.mLeft = r.left;
|
|
|
|
v.mBottom = r.bottom;
|
|
|
|
v.mRight = r.right;
|
|
|
|
v.mWeight = r.weight;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
DOM_CAMERA_LOGI("region %d: top=%d, left=%d, bottom=%d, right=%d, weight=%u\n",
|
|
|
|
i,
|
|
|
|
v.mTop,
|
|
|
|
v.mLeft,
|
|
|
|
v.mBottom,
|
|
|
|
v.mRight,
|
|
|
|
v.mWeight
|
|
|
|
);
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetEffect(nsString& aEffect, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_EFFECT, aEffect);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetEffect(const nsAString& aEffect, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EFFECT, aEffect);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetWhiteBalanceMode(nsString& aWhiteBalanceMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_WHITEBALANCE, aWhiteBalanceMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetWhiteBalanceMode(const nsAString& aWhiteBalanceMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_WHITEBALANCE, aWhiteBalanceMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetSceneMode(nsString& aSceneMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_SCENEMODE, aSceneMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetSceneMode(const nsAString& aSceneMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_SCENEMODE, aSceneMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetFlashMode(nsString& aFlashMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FLASHMODE, aFlashMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetFlashMode(const nsAString& aFlashMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_FLASHMODE, aFlashMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetFocusMode(nsString& aFocusMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSMODE, aFocusMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetFocusMode(const nsAString& aFocusMode, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_FOCUSMODE, aFocusMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-03-07 10:00:43 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetIsoMode(nsString& aIsoMode, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_ISOMODE, aIsoMode);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetIsoMode(const nsAString& aIsoMode, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_ISOMODE, aIsoMode);
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:12:49 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetPictureQuality(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
double quality;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_PICTURE_QUALITY, quality);
|
|
|
|
return quality;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetPictureQuality(double aQuality, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_PICTURE_QUALITY, aQuality);
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetZoom(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-08-25 23:12:49 +04:00
|
|
|
double zoom = 1.0;
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_ZOOM, zoom);
|
2013-07-07 00:55:10 +04:00
|
|
|
return zoom;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetZoom(double aZoom, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_ZOOM, aZoom);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetMeteringAreas(nsTArray<CameraRegion>& aAreas, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-05-01 01:15:01 +04:00
|
|
|
aRv = Get(CAMERA_PARAM_METERINGAREAS, aAreas);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-05-01 01:15:01 +04:00
|
|
|
nsDOMCameraControl::SetMeteringAreas(const Optional<Sequence<CameraRegion> >& aMeteringAreas, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-05-01 01:15:01 +04:00
|
|
|
aRv = Set(CAMERA_PARAM_METERINGAREAS, aMeteringAreas,
|
2014-02-15 02:41:07 +04:00
|
|
|
mCurrentConfiguration->mMaxMeteringAreas);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetFocusAreas(nsTArray<CameraRegion>& aAreas, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-05-01 01:15:01 +04:00
|
|
|
aRv = Get(CAMERA_PARAM_FOCUSAREAS, aAreas);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-05-01 01:15:01 +04:00
|
|
|
nsDOMCameraControl::SetFocusAreas(const Optional<Sequence<CameraRegion> >& aFocusAreas, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-05-01 01:15:01 +04:00
|
|
|
aRv = Set(CAMERA_PARAM_FOCUSAREAS, aFocusAreas,
|
2014-02-15 02:41:07 +04:00
|
|
|
mCurrentConfiguration->mMaxFocusAreas);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetPictureSize(CameraSize& aSize, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
ICameraControl::Size size;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_PICTURE_SIZE, size);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSize.mWidth = size.width;
|
|
|
|
aSize.mHeight = size.height;
|
|
|
|
}
|
2014-06-05 19:21:02 +04:00
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetPictureSize(const CameraSize& aSize, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
ICameraControl::Size s = { aSize.mWidth, aSize.mHeight };
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_PICTURE_SIZE, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetThumbnailSize(CameraSize& aSize, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
ICameraControl::Size size;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_THUMBNAILSIZE, size);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSize.mWidth = size.width;
|
|
|
|
aSize.mHeight = size.height;
|
|
|
|
}
|
2014-06-05 19:21:02 +04:00
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetThumbnailSize(const CameraSize& aSize, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
ICameraControl::Size s = { aSize.mWidth, aSize.mHeight };
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_THUMBNAILSIZE, s);
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocalLength(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double focalLength;
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCALLENGTH, focalLength);
|
2013-07-07 00:55:10 +04:00
|
|
|
return focalLength;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocusDistanceNear(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double distance;
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCENEAR, distance);
|
2013-07-07 00:55:10 +04:00
|
|
|
return distance;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocusDistanceOptimum(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double distance;
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCEOPTIMUM, distance);
|
2013-07-07 00:55:10 +04:00
|
|
|
return distance;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocusDistanceFar(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double distance;
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCEFAR, distance);
|
2013-07-07 00:55:10 +04:00
|
|
|
return distance;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-06-06 23:37:15 +04:00
|
|
|
nsDOMCameraControl::SetExposureCompensation(double aCompensation, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2014-06-06 23:37:15 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EXPOSURECOMPENSATION, aCompensation);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetExposureCompensation(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double compensation;
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_EXPOSURECOMPENSATION, compensation);
|
2013-07-07 00:55:10 +04:00
|
|
|
return compensation;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:47:29 +04:00
|
|
|
int32_t
|
|
|
|
nsDOMCameraControl::SensorAngle()
|
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-02-24 22:01:21 +04:00
|
|
|
int32_t angle = 0;
|
2014-02-15 02:41:07 +04:00
|
|
|
mCameraControl->Get(CAMERA_PARAM_SENSORANGLE, angle);
|
2013-12-06 18:47:29 +04:00
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
// Callback attributes
|
|
|
|
|
|
|
|
CameraShutterCallback*
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::GetOnShutter()
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-04-09 19:52:10 +04:00
|
|
|
return mOnShutterCb;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::SetOnShutter(CameraShutterCallback* aCb)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
mOnShutterCb = aCb;
|
2012-10-01 04:37:47 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
CameraClosedCallback*
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::GetOnClosed()
|
2012-10-01 04:37:47 +04:00
|
|
|
{
|
2014-04-09 19:52:10 +04:00
|
|
|
return mOnClosedCb;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::SetOnClosed(CameraClosedCallback* aCb)
|
2012-11-03 00:11:50 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
mOnClosedCb = aCb;
|
2012-11-03 00:11:50 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
CameraRecorderStateChange*
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::GetOnRecorderStateChange()
|
2013-08-06 00:24:43 +04:00
|
|
|
{
|
2014-04-09 19:52:10 +04:00
|
|
|
return mOnRecorderStateChangeCb;
|
2013-08-06 00:24:43 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::SetOnRecorderStateChange(CameraRecorderStateChange* aCb)
|
2013-08-06 00:24:43 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
mOnRecorderStateChangeCb = aCb;
|
2013-08-06 00:24:43 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
CameraPreviewStateChange*
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::GetOnPreviewStateChange()
|
|
|
|
{
|
2014-04-09 19:52:10 +04:00
|
|
|
return mOnPreviewStateChangeCb;
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::SetOnPreviewStateChange(CameraPreviewStateChange* aCb)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
mOnPreviewStateChangeCb = aCb;
|
|
|
|
}
|
2013-10-22 02:38:50 +04:00
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
CameraAutoFocusMovingCallback*
|
2014-04-09 19:12:25 +04:00
|
|
|
nsDOMCameraControl::GetOnAutoFocusMoving()
|
|
|
|
{
|
2014-04-09 19:52:10 +04:00
|
|
|
return mOnAutoFocusMovingCb;
|
2014-04-09 19:12:25 +04:00
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnAutoFocusMoving(CameraAutoFocusMovingCallback* aCb)
|
|
|
|
{
|
|
|
|
mOnAutoFocusMovingCb = aCb;
|
|
|
|
}
|
|
|
|
|
2014-09-22 07:25:00 +04:00
|
|
|
CameraAutoFocusCallback*
|
|
|
|
nsDOMCameraControl::GetOnAutoFocusCompleted()
|
|
|
|
{
|
|
|
|
return mOnAutoFocusCompletedCb;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnAutoFocusCompleted(CameraAutoFocusCallback* aCb)
|
|
|
|
{
|
|
|
|
mOnAutoFocusCompletedCb = aCb;
|
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
CameraFaceDetectionCallback*
|
|
|
|
nsDOMCameraControl::GetOnFacesDetected()
|
|
|
|
{
|
|
|
|
return mOnFacesDetectedCb;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnFacesDetected(CameraFaceDetectionCallback* aCb)
|
|
|
|
{
|
|
|
|
mOnFacesDetectedCb = aCb;
|
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
already_AddRefed<dom::CameraCapabilities>
|
|
|
|
nsDOMCameraControl::Capabilities()
|
|
|
|
{
|
|
|
|
nsRefPtr<CameraCapabilities> caps = mCapabilities;
|
|
|
|
|
|
|
|
if (!caps) {
|
2014-10-31 20:19:06 +03:00
|
|
|
caps = new CameraCapabilities(mWindow, mCameraControl);
|
2014-02-15 02:41:07 +04:00
|
|
|
mCapabilities = caps;
|
2013-10-22 02:38:50 +04:00
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
return caps.forget();
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-09-12 05:55:00 +04:00
|
|
|
class ImmediateErrorCallback : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImmediateErrorCallback(CameraErrorCallback* aCallback, const nsAString& aMessage)
|
|
|
|
: mCallback(aCallback)
|
|
|
|
, mMessage(aMessage)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ErrorResult ignored;
|
|
|
|
mCallback->Call(mMessage, ignored);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<CameraErrorCallback> mCallback;
|
|
|
|
nsString mMessage;
|
|
|
|
};
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
// Methods.
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::StartRecording(const CameraStartRecordingOptions& aOptions,
|
|
|
|
nsDOMDeviceStorage& aStorageArea,
|
|
|
|
const nsAString& aFilename,
|
2014-10-03 12:19:00 +04:00
|
|
|
const Optional<OwningNonNull<CameraStartRecordingCallback> >& aOnSuccess,
|
2014-02-15 02:41:07 +04:00
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = CreatePromise(aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStartRecordingPromise) {
|
|
|
|
promise->MaybeReject(NS_ERROR_IN_PROGRESS);
|
2014-09-12 05:55:00 +04:00
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
DOM_CAMERA_LOGT("%s:onError WasPassed\n", __func__);
|
|
|
|
NS_DispatchToMainThread(new ImmediateErrorCallback(&aOnError.Value(),
|
|
|
|
NS_LITERAL_STRING("StartRecordingInProgress")));
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2014-09-12 05:55:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
NotifyRecordingStatusChange(NS_LITERAL_STRING("starting"));
|
|
|
|
|
|
|
|
#ifdef MOZ_B2G
|
2012-12-11 14:14:06 +04:00
|
|
|
if (!mAudioChannelAgent) {
|
|
|
|
mAudioChannelAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
|
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
// Camera app will stop recording when it falls to the background, so no callback is necessary.
|
2014-04-10 21:39:20 +04:00
|
|
|
mAudioChannelAgent->Init(mWindow, (int32_t)AudioChannel::Content, nullptr);
|
2012-12-11 14:14:06 +04:00
|
|
|
// Video recording doesn't output any sound, so it's not necessary to check canPlay.
|
2013-09-02 13:45:44 +04:00
|
|
|
int32_t canPlay;
|
2012-12-11 14:14:06 +04:00
|
|
|
mAudioChannelAgent->StartPlaying(&canPlay);
|
|
|
|
}
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
#endif
|
2012-12-11 14:14:06 +04:00
|
|
|
|
2014-01-17 05:01:43 +04:00
|
|
|
nsCOMPtr<nsIDOMDOMRequest> request;
|
|
|
|
mDSFileDescriptor = new DeviceStorageFileDescriptor();
|
2014-02-15 02:41:07 +04:00
|
|
|
aRv = aStorageArea.CreateFileDescriptor(aFilename, mDSFileDescriptor.get(),
|
2014-04-26 00:28:15 +04:00
|
|
|
getter_AddRefs(request));
|
2013-07-07 00:55:10 +04:00
|
|
|
if (aRv.Failed()) {
|
2014-10-03 12:19:00 +04:00
|
|
|
return nullptr;
|
2013-07-07 00:55:10 +04:00
|
|
|
}
|
2014-01-17 05:01:43 +04:00
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
mStartRecordingPromise = promise;
|
2014-02-15 02:41:07 +04:00
|
|
|
mOptions = aOptions;
|
2014-10-03 12:19:00 +04:00
|
|
|
mStartRecordingOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mStartRecordingOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
mStartRecordingOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mStartRecordingOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
2014-01-17 05:01:43 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
nsCOMPtr<nsIDOMEventListener> listener = new StartRecordingHelper(this);
|
|
|
|
request->AddEventListener(NS_LITERAL_STRING("success"), listener, false);
|
|
|
|
request->AddEventListener(NS_LITERAL_STRING("error"), listener, false);
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2014-01-17 05:01:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnCreatedFileDescriptor(bool aSucceeded)
|
2014-01-17 05:01:43 +04:00
|
|
|
{
|
2014-04-26 00:28:15 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
if (aSucceeded && mDSFileDescriptor->mFileDescriptor.IsValid()) {
|
|
|
|
ICameraControl::StartRecordingOptions o;
|
|
|
|
|
|
|
|
o.rotation = mOptions.mRotation;
|
|
|
|
o.maxFileSizeBytes = mOptions.mMaxFileSizeBytes;
|
|
|
|
o.maxVideoLengthMs = mOptions.mMaxVideoLengthMs;
|
2014-04-09 19:53:41 +04:00
|
|
|
o.autoEnableLowLightTorch = mOptions.mAutoEnableLowLightTorch;
|
2014-04-26 00:28:15 +04:00
|
|
|
rv = mCameraControl->StartRecording(mDSFileDescriptor.get(), &o);
|
2014-02-15 02:41:07 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return;
|
2014-01-17 05:01:43 +04:00
|
|
|
}
|
2014-02-11 07:09:23 +04:00
|
|
|
}
|
2014-04-26 00:28:15 +04:00
|
|
|
|
|
|
|
OnUserError(CameraControlListener::kInStartRecording, rv);
|
2014-03-01 00:02:55 +04:00
|
|
|
|
|
|
|
if (mDSFileDescriptor->mFileDescriptor.IsValid()) {
|
|
|
|
// An error occured. We need to manually close the file associated with the
|
|
|
|
// FileDescriptor, and we shouldn't do this on the main thread, so we
|
|
|
|
// use a little helper.
|
|
|
|
nsRefPtr<CloseFileRunnable> closer =
|
|
|
|
new CloseFileRunnable(mDSFileDescriptor->mFileDescriptor);
|
|
|
|
closer->Dispatch();
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::StopRecording(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
#ifdef MOZ_B2G
|
2012-12-11 14:14:06 +04:00
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
mAudioChannelAgent->StopPlaying();
|
|
|
|
mAudioChannelAgent = nullptr;
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
#endif
|
2012-12-11 14:14:06 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->StopRecording();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::ResumePreview(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->StartPreview();
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::SetConfiguration(const CameraConfiguration& aConfiguration,
|
|
|
|
const Optional<OwningNonNull<CameraSetConfigurationCallback> >& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
2013-07-07 00:55:10 +04:00
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = CreatePromise(aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTakePicturePromise) {
|
|
|
|
promise->MaybeReject(NS_ERROR_IN_PROGRESS);
|
2014-02-15 02:41:07 +04:00
|
|
|
// We're busy taking a picture, can't change modes right now.
|
|
|
|
if (aOnError.WasPassed()) {
|
2014-04-26 00:28:15 +04:00
|
|
|
// There is already a call to TakePicture() in progress, abort this
|
|
|
|
// call and invoke the error callback (if one was passed in).
|
|
|
|
NS_DispatchToMainThread(new ImmediateErrorCallback(&aOnError.Value(),
|
|
|
|
NS_LITERAL_STRING("TakePictureInProgress")));
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2013-07-07 00:55:10 +04:00
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
ICameraControl::Configuration config;
|
|
|
|
config.mRecorderProfile = aConfiguration.mRecorderProfile;
|
|
|
|
config.mPreviewSize.width = aConfiguration.mPreviewSize.mWidth;
|
|
|
|
config.mPreviewSize.height = aConfiguration.mPreviewSize.mHeight;
|
|
|
|
config.mMode = ICameraControl::kPictureMode;
|
|
|
|
if (aConfiguration.mMode == CameraMode::Video) {
|
|
|
|
config.mMode = ICameraControl::kVideoMode;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
aRv = mCameraControl->SetConfiguration(config);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSetConfigurationPromise = promise;
|
2014-02-15 02:41:07 +04:00
|
|
|
mSetConfigurationOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mSetConfigurationOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
|
|
|
mSetConfigurationOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mSetConfigurationOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
nsDOMCameraControl::AutoFocus(const Optional<OwningNonNull<CameraAutoFocusCallback> >& aOnSuccess,
|
2014-02-15 02:41:07 +04:00
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = mAutoFocusPromise.forget();
|
|
|
|
if (promise) {
|
2014-06-12 22:56:46 +04:00
|
|
|
// There is already a call to AutoFocus() in progress, cancel it and
|
|
|
|
// invoke the error callback (if one was passed in).
|
2014-10-03 12:19:00 +04:00
|
|
|
promise->MaybeReject(NS_ERROR_IN_PROGRESS);
|
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
|
|
|
nsRefPtr<CameraErrorCallback> ecb = mAutoFocusOnErrorCb.forget();
|
|
|
|
if (ecb) {
|
|
|
|
NS_DispatchToMainThread(new ImmediateErrorCallback(ecb,
|
|
|
|
NS_LITERAL_STRING("AutoFocusInterrupted")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
promise = CreatePromise(aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
aRv = mCameraControl->AutoFocus();
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("focus"), NS_LITERAL_STRING("focusing"));
|
|
|
|
|
|
|
|
mAutoFocusPromise = promise;
|
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mAutoFocusOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mAutoFocusOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::StartFaceDetection(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->StartFaceDetection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::StopFaceDetection(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->StopFaceDetection();
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::TakePicture(const CameraPictureOptions& aOptions,
|
2014-10-03 12:19:00 +04:00
|
|
|
const Optional<OwningNonNull<CameraTakePictureCallback> >& aOnSuccess,
|
2014-02-15 02:41:07 +04:00
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = CreatePromise(aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTakePicturePromise) {
|
|
|
|
// There is already a call to TakePicture() in progress, abort this new
|
|
|
|
// one and invoke the error callback (if one was passed in).
|
|
|
|
promise->MaybeReject(NS_ERROR_IN_PROGRESS);
|
2014-02-15 02:41:07 +04:00
|
|
|
if (aOnError.WasPassed()) {
|
2014-04-15 23:46:40 +04:00
|
|
|
NS_DispatchToMainThread(new ImmediateErrorCallback(&aOnError.Value(),
|
|
|
|
NS_LITERAL_STRING("TakePictureAlreadyInProgress")));
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ICameraControlParameterSetAutoEnter batch(mCameraControl);
|
|
|
|
|
|
|
|
// XXXmikeh - remove this: see bug 931155
|
|
|
|
ICameraControl::Size s;
|
|
|
|
s.width = aOptions.mPictureSize.mWidth;
|
|
|
|
s.height = aOptions.mPictureSize.mHeight;
|
|
|
|
|
|
|
|
ICameraControl::Position p;
|
|
|
|
p.latitude = aOptions.mPosition.mLatitude;
|
|
|
|
p.longitude = aOptions.mPosition.mLongitude;
|
|
|
|
p.altitude = aOptions.mPosition.mAltitude;
|
|
|
|
p.timestamp = aOptions.mPosition.mTimestamp;
|
|
|
|
|
|
|
|
if (s.width && s.height) {
|
|
|
|
mCameraControl->Set(CAMERA_PARAM_PICTURE_SIZE, s);
|
|
|
|
}
|
|
|
|
mCameraControl->Set(CAMERA_PARAM_PICTURE_ROTATION, aOptions.mRotation);
|
|
|
|
mCameraControl->Set(CAMERA_PARAM_PICTURE_FILEFORMAT, aOptions.mFileFormat);
|
|
|
|
mCameraControl->Set(CAMERA_PARAM_PICTURE_DATETIME, aOptions.mDateTime);
|
|
|
|
mCameraControl->SetLocation(p);
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
aRv = mCameraControl->TakePicture();
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTakePicturePromise = promise;
|
|
|
|
mTakePictureOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mTakePictureOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
mTakePictureOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mTakePictureOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::ReleaseHardware(const Optional<OwningNonNull<CameraReleaseCallback> >& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = CreatePromise(aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->Stop();
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mReleasePromise = promise;
|
2014-02-15 02:41:07 +04:00
|
|
|
mReleaseOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mReleaseOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
|
|
|
mReleaseOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mReleaseOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
return promise.forget();
|
2013-07-07 00:55:10 +04:00
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-04-15 23:46:40 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::ResumeContinuousFocus(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->ResumeContinuousFocus();
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::Shutdown()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI("%s:%d\n", __func__, __LINE__);
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
// Remove any pending solicited event handlers; these
|
|
|
|
// reference our window object, which in turn references
|
|
|
|
// us. If we don't remove them, we can leak DOM objects.
|
2014-10-03 12:19:00 +04:00
|
|
|
AbortPromise(mGetCameraPromise);
|
|
|
|
AbortPromise(mAutoFocusPromise);
|
|
|
|
AbortPromise(mTakePicturePromise);
|
|
|
|
AbortPromise(mStartRecordingPromise);
|
|
|
|
AbortPromise(mReleasePromise);
|
|
|
|
AbortPromise(mSetConfigurationPromise);
|
2014-02-15 02:41:07 +04:00
|
|
|
mGetCameraOnSuccessCb = nullptr;
|
|
|
|
mGetCameraOnErrorCb = nullptr;
|
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
|
|
|
mTakePictureOnSuccessCb = nullptr;
|
|
|
|
mTakePictureOnErrorCb = nullptr;
|
|
|
|
mStartRecordingOnSuccessCb = nullptr;
|
|
|
|
mStartRecordingOnErrorCb = nullptr;
|
|
|
|
mReleaseOnSuccessCb = nullptr;
|
|
|
|
mReleaseOnErrorCb = nullptr;
|
|
|
|
mSetConfigurationOnSuccessCb = nullptr;
|
|
|
|
mSetConfigurationOnErrorCb = nullptr;
|
|
|
|
|
|
|
|
// Remove all of the unsolicited event handlers too.
|
|
|
|
mOnShutterCb = nullptr;
|
|
|
|
mOnClosedCb = nullptr;
|
|
|
|
mOnRecorderStateChangeCb = nullptr;
|
|
|
|
mOnPreviewStateChangeCb = nullptr;
|
2014-04-09 19:12:25 +04:00
|
|
|
mOnAutoFocusMovingCb = nullptr;
|
2014-09-22 07:25:00 +04:00
|
|
|
mOnAutoFocusCompletedCb = nullptr;
|
2014-04-09 19:52:10 +04:00
|
|
|
mOnFacesDetectedCb = nullptr;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
mCameraControl->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDOMCameraControl::NotifyRecordingStatusChange(const nsString& aMsg)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return MediaManager::NotifyRecordingStatusChange(mWindow,
|
|
|
|
aMsg,
|
|
|
|
true /* aIsAudio */,
|
|
|
|
true /* aIsVideo */);
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
nsDOMCameraControl::CreatePromise(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
|
|
|
|
if (!global) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return Promise::Create(global, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::AbortPromise(nsRefPtr<Promise>& aPromise)
|
|
|
|
{
|
|
|
|
nsRefPtr<Promise> promise = aPromise.forget();
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::EventListenerAdded(nsIAtom* aType)
|
|
|
|
{
|
|
|
|
if (aType == nsGkAtoms::onpreviewstatechange) {
|
|
|
|
DispatchPreviewStateEvent(mPreviewState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::DispatchPreviewStateEvent(CameraControlListener::PreviewState aState)
|
|
|
|
{
|
|
|
|
nsString state;
|
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kPreviewStarted:
|
|
|
|
state = NS_LITERAL_STRING("started");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
state = NS_LITERAL_STRING("stopped");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("previewstatechange"), state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::DispatchStateEvent(const nsString& aType, const nsString& aState)
|
|
|
|
{
|
|
|
|
CameraStateChangeEventInit eventInit;
|
|
|
|
eventInit.mNewState = aState;
|
|
|
|
|
|
|
|
nsRefPtr<CameraStateChangeEvent> event =
|
|
|
|
CameraStateChangeEvent::Constructor(this, aType, eventInit);
|
|
|
|
|
|
|
|
DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
// Camera Control event handlers--must only be called from the Main Thread!
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::OnHardwareStateChange(CameraControlListener::HardwareState aState)
|
2013-07-07 00:55:10 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ErrorResult ignored;
|
|
|
|
|
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kHardwareOpen:
|
2014-10-31 20:19:06 +03:00
|
|
|
DOM_CAMERA_LOGI("DOM OnHardwareStateChange: open\n");
|
2014-10-03 12:19:00 +04:00
|
|
|
{
|
|
|
|
// The hardware is open, so we can return a camera to JS, even if
|
|
|
|
// the preview hasn't started yet.
|
|
|
|
nsRefPtr<Promise> promise = mGetCameraPromise.forget();
|
|
|
|
if (promise) {
|
|
|
|
CameraGetPromiseData data;
|
|
|
|
data.mCamera = this;
|
|
|
|
data.mConfiguration = *mCurrentConfiguration;
|
|
|
|
promise->MaybeResolve(data);
|
|
|
|
}
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<GetCameraCallback> cb = mGetCameraOnSuccessCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mGetCameraOnErrorCb = nullptr;
|
2014-10-03 12:19:00 +04:00
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(*this, *mCurrentConfiguration, ignored);
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kHardwareClosed:
|
2014-10-31 20:19:06 +03:00
|
|
|
DOM_CAMERA_LOGI("DOM OnHardwareStateChange: closed\n");
|
2014-10-03 12:19:00 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<Promise> promise = mReleasePromise.forget();
|
|
|
|
if (promise || mReleaseOnSuccessCb) {
|
|
|
|
// If we have this event handler, this was a solicited hardware close.
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeResolve(JS::UndefinedHandleValue);
|
|
|
|
}
|
|
|
|
nsRefPtr<CameraReleaseCallback> cb = mReleaseOnSuccessCb.forget();
|
|
|
|
mReleaseOnErrorCb = nullptr;
|
|
|
|
if (cb) {
|
|
|
|
cb->Call(ignored);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If not, something else closed the hardware.
|
|
|
|
nsRefPtr<CameraClosedCallback> cb = mOnClosedCb;
|
|
|
|
if (cb) {
|
|
|
|
cb->Call(ignored);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DispatchTrustedEvent(NS_LITERAL_STRING("close"));
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
|
|
|
break;
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-11-12 21:54:48 +03:00
|
|
|
case CameraControlListener::kHardwareOpenFailed:
|
|
|
|
DOM_CAMERA_LOGI("DOM OnHardwareStateChange: open failed\n");
|
|
|
|
OnUserError(DOMCameraControlListener::kInStartCamera, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
break;
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
default:
|
2014-10-31 20:19:06 +03:00
|
|
|
DOM_CAMERA_LOGE("DOM OnHardwareStateChange: UNKNOWN=%d\n", aState);
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unanticipated camera hardware state");
|
2013-05-18 05:48:25 +04:00
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnShutter()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("DOM ** SNAP **\n");
|
2014-02-14 17:27:44 +04:00
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<CameraShutterCallback> cb = mOnShutterCb;
|
2014-02-15 02:41:07 +04:00
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(ignored);
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
DispatchTrustedEvent(NS_LITERAL_STRING("shutter"));
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::OnPreviewStateChange(CameraControlListener::PreviewState aState)
|
2012-09-29 09:30:52 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
mPreviewState = aState;
|
2014-02-15 02:41:07 +04:00
|
|
|
nsString state;
|
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kPreviewStarted:
|
|
|
|
state = NS_LITERAL_STRING("started");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
state = NS_LITERAL_STRING("stopped");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
|
2014-10-03 12:19:00 +04:00
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(state, ignored);
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchPreviewStateEvent(aState);
|
2012-09-29 09:30:52 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::OnRecorderStateChange(CameraControlListener::RecorderState aState,
|
|
|
|
int32_t aArg, int32_t aTrackNum)
|
2012-12-23 19:54:54 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
// For now, we do nothing with 'aStatus' and 'aTrackNum'.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-12-23 19:54:54 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
ErrorResult ignored;
|
|
|
|
nsString state;
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kRecorderStarted:
|
2014-10-03 12:19:00 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<Promise> promise = mStartRecordingPromise.forget();
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeResolve(JS::UndefinedHandleValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<CameraStartRecordingCallback> scb = mStartRecordingOnSuccessCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mStartRecordingOnErrorCb = nullptr;
|
2014-10-03 12:19:00 +04:00
|
|
|
if (scb) {
|
|
|
|
scb->Call(ignored);
|
|
|
|
}
|
|
|
|
state = NS_LITERAL_STRING("Started");
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2014-02-27 03:07:11 +04:00
|
|
|
break;
|
2014-02-14 09:28:57 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
case CameraControlListener::kRecorderStopped:
|
|
|
|
NotifyRecordingStatusChange(NS_LITERAL_STRING("shutdown"));
|
2014-02-27 03:07:11 +04:00
|
|
|
state = NS_LITERAL_STRING("Stopped");
|
|
|
|
break;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_B2G_CAMERA
|
|
|
|
case CameraControlListener::kFileSizeLimitReached:
|
|
|
|
state = NS_LITERAL_STRING("FileSizeLimitReached");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kVideoLengthLimitReached:
|
|
|
|
state = NS_LITERAL_STRING("VideoLengthLimitReached");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kTrackCompleted:
|
|
|
|
state = NS_LITERAL_STRING("TrackCompleted");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kTrackFailed:
|
|
|
|
state = NS_LITERAL_STRING("TrackFailed");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kMediaRecorderFailed:
|
|
|
|
state = NS_LITERAL_STRING("MediaRecorderFailed");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kMediaServerFailed:
|
|
|
|
state = NS_LITERAL_STRING("MediaServerFailed");
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unanticipated video recorder error");
|
2014-02-15 02:41:07 +04:00
|
|
|
return;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
|
2014-02-15 02:41:07 +04:00
|
|
|
if (cb) {
|
|
|
|
cb->Call(state, ignored);
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("recorderstatechange"), state);
|
2014-02-15 02:41:07 +04:00
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnConfigurationChange(DOMCameraConfiguration* aConfiguration)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-10-03 12:19:00 +04:00
|
|
|
MOZ_ASSERT(aConfiguration != nullptr);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
// Update our record of the current camera configuration
|
|
|
|
mCurrentConfiguration = aConfiguration;
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("DOM OnConfigurationChange: this=%p\n", this);
|
|
|
|
DOM_CAMERA_LOGI(" mode : %s\n",
|
|
|
|
mCurrentConfiguration->mMode == CameraMode::Video ? "video" : "picture");
|
|
|
|
DOM_CAMERA_LOGI(" maximum focus areas : %d\n",
|
|
|
|
mCurrentConfiguration->mMaxFocusAreas);
|
|
|
|
DOM_CAMERA_LOGI(" maximum metering areas : %d\n",
|
|
|
|
mCurrentConfiguration->mMaxMeteringAreas);
|
|
|
|
DOM_CAMERA_LOGI(" preview size (w x h) : %d x %d\n",
|
|
|
|
mCurrentConfiguration->mPreviewSize.mWidth, mCurrentConfiguration->mPreviewSize.mHeight);
|
|
|
|
DOM_CAMERA_LOGI(" recorder profile : %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(mCurrentConfiguration->mRecorderProfile).get());
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = mSetConfigurationPromise.forget();
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeResolve(*aConfiguration);
|
|
|
|
}
|
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<CameraSetConfigurationCallback> cb = mSetConfigurationOnSuccessCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mSetConfigurationOnErrorCb = nullptr;
|
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(*mCurrentConfiguration, ignored);
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
CameraConfigurationEventInit eventInit;
|
|
|
|
eventInit.mMode = mCurrentConfiguration->mMode;
|
|
|
|
eventInit.mRecorderProfile = mCurrentConfiguration->mRecorderProfile;
|
|
|
|
eventInit.mPreviewSize = new DOMRect(this, 0, 0,
|
|
|
|
mCurrentConfiguration->mPreviewSize.mWidth,
|
|
|
|
mCurrentConfiguration->mPreviewSize.mHeight);
|
|
|
|
|
|
|
|
nsRefPtr<CameraConfigurationEvent> event =
|
|
|
|
CameraConfigurationEvent::Constructor(this,
|
|
|
|
NS_LITERAL_STRING("configurationchanged"),
|
|
|
|
eventInit);
|
|
|
|
|
|
|
|
DispatchTrustedEvent(event);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2012-10-01 04:37:47 +04:00
|
|
|
|
|
|
|
void
|
2014-02-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl::OnAutoFocusComplete(bool aAutoFocusSucceeded)
|
2012-10-01 04:37:47 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise = mAutoFocusPromise.forget();
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeResolve(aAutoFocusSucceeded);
|
|
|
|
}
|
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
2014-02-26 02:01:29 +04:00
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(aAutoFocusSucceeded, ignored);
|
2014-09-22 07:25:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cb = mOnAutoFocusCompletedCb;
|
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(aAutoFocusSucceeded, ignored);
|
2014-02-26 02:01:29 +04:00
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
if (aAutoFocusSucceeded) {
|
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("focus"), NS_LITERAL_STRING("focused"));
|
|
|
|
} else {
|
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("focus"), NS_LITERAL_STRING("unfocused"));
|
|
|
|
}
|
2012-10-01 04:37:47 +04:00
|
|
|
}
|
2013-05-02 15:59:58 +04:00
|
|
|
|
2014-04-09 19:12:25 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnAutoFocusMoving(bool aIsMoving)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsRefPtr<CameraAutoFocusMovingCallback> cb = mOnAutoFocusMovingCb;
|
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(aIsMoving, ignored);
|
|
|
|
}
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
if (aIsMoving) {
|
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("focus"), NS_LITERAL_STRING("focusing"));
|
|
|
|
}
|
2014-04-09 19:12:25 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 19:52:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces)
|
|
|
|
{
|
2014-10-31 20:19:06 +03:00
|
|
|
DOM_CAMERA_LOGI("DOM OnFacesDetected %zu face(s)\n", aFaces.Length());
|
2014-04-09 19:52:10 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
Sequence<OwningNonNull<DOMCameraDetectedFace> > faces;
|
|
|
|
uint32_t len = aFaces.Length();
|
|
|
|
|
|
|
|
if (faces.SetCapacity(len)) {
|
|
|
|
nsRefPtr<DOMCameraDetectedFace> f;
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
|
|
f = new DOMCameraDetectedFace(this, aFaces[i]);
|
|
|
|
*faces.AppendElement() = f.forget().take();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<CameraFaceDetectionCallback> cb = mOnFacesDetectedCb;
|
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(faces, ignored);
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraFacesDetectedEventInit eventInit;
|
|
|
|
eventInit.mFaces.SetValue(faces);
|
|
|
|
|
|
|
|
nsRefPtr<CameraFacesDetectedEvent> event =
|
|
|
|
CameraFacesDetectedEvent::Constructor(this,
|
|
|
|
NS_LITERAL_STRING("facesdetected"),
|
|
|
|
eventInit);
|
|
|
|
|
|
|
|
DispatchTrustedEvent(event);
|
2014-04-09 19:52:10 +04:00
|
|
|
}
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
|
2013-05-02 15:59:58 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-10-08 20:15:22 +04:00
|
|
|
MOZ_ASSERT(aPicture);
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
nsRefPtr<Promise> promise = mTakePicturePromise.forget();
|
|
|
|
if (promise) {
|
|
|
|
nsCOMPtr<nsIDOMBlob> picture = aPicture;
|
|
|
|
promise->MaybeResolve(picture);
|
|
|
|
}
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
nsRefPtr<File> blob = static_cast<File*>(aPicture);
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mTakePictureOnErrorCb = nullptr;
|
2014-10-03 12:19:00 +04:00
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
2014-10-08 20:15:22 +04:00
|
|
|
cb->Call(*blob, ignored);
|
2014-02-26 02:01:29 +04:00
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
BlobEventInit eventInit;
|
2014-10-08 20:15:22 +04:00
|
|
|
eventInit.mData = blob;
|
2014-10-03 12:19:00 +04:00
|
|
|
|
|
|
|
nsRefPtr<BlobEvent> event = BlobEvent::Constructor(this,
|
|
|
|
NS_LITERAL_STRING("picture"),
|
|
|
|
eventInit);
|
|
|
|
|
|
|
|
DispatchTrustedEvent(event);
|
2013-05-02 15:59:58 +04:00
|
|
|
}
|
2013-10-23 15:11:18 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
void
|
2014-04-26 00:28:15 +04:00
|
|
|
nsDOMCameraControl::OnUserError(CameraControlListener::UserContext aContext, nsresult aError)
|
2013-10-23 15:11:18 +04:00
|
|
|
{
|
2014-02-15 02:41:07 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-02-14 09:28:57 +04:00
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
nsRefPtr<Promise> promise;
|
2014-03-25 01:32:31 +04:00
|
|
|
nsRefPtr<CameraErrorCallback> errorCb;
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
switch (aContext) {
|
2014-02-20 08:18:52 +04:00
|
|
|
case CameraControlListener::kInStartCamera:
|
2014-10-03 12:19:00 +04:00
|
|
|
promise = mGetCameraPromise.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mGetCameraOnSuccessCb = nullptr;
|
2014-03-25 01:32:31 +04:00
|
|
|
errorCb = mGetCameraOnErrorCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
2014-02-20 08:18:52 +04:00
|
|
|
case CameraControlListener::kInStopCamera:
|
2014-10-03 12:19:00 +04:00
|
|
|
promise = mReleasePromise.forget();
|
2014-02-20 08:18:52 +04:00
|
|
|
mReleaseOnSuccessCb = nullptr;
|
2014-03-25 01:32:31 +04:00
|
|
|
errorCb = mReleaseOnErrorCb.forget();
|
2014-02-20 08:18:52 +04:00
|
|
|
break;
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
case CameraControlListener::kInSetConfiguration:
|
2014-10-03 12:19:00 +04:00
|
|
|
promise = mSetConfigurationPromise.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mSetConfigurationOnSuccessCb = nullptr;
|
2014-03-25 01:32:31 +04:00
|
|
|
errorCb = mSetConfigurationOnErrorCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInAutoFocus:
|
2014-10-03 12:19:00 +04:00
|
|
|
promise = mAutoFocusPromise.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
2014-03-25 01:32:31 +04:00
|
|
|
errorCb = mAutoFocusOnErrorCb.forget();
|
2014-10-03 12:19:00 +04:00
|
|
|
DispatchStateEvent(NS_LITERAL_STRING("focus"), NS_LITERAL_STRING("unfocused"));
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInTakePicture:
|
2014-10-03 12:19:00 +04:00
|
|
|
promise = mTakePicturePromise.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mTakePictureOnSuccessCb = nullptr;
|
2014-03-25 01:32:31 +04:00
|
|
|
errorCb = mTakePictureOnErrorCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInStartRecording:
|
2014-10-03 12:19:00 +04:00
|
|
|
promise = mStartRecordingPromise.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
mStartRecordingOnSuccessCb = nullptr;
|
2014-03-25 01:32:31 +04:00
|
|
|
errorCb = mStartRecordingOnErrorCb.forget();
|
2014-02-15 02:41:07 +04:00
|
|
|
break;
|
|
|
|
|
2014-05-29 21:37:44 +04:00
|
|
|
case CameraControlListener::kInStartFaceDetection:
|
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to start face detection");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case CameraControlListener::kInStopFaceDetection:
|
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to stop face detection");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case CameraControlListener::kInResumeContinuousFocus:
|
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to resume continuous focus");
|
|
|
|
return;
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
case CameraControlListener::kInStopRecording:
|
2014-02-24 22:01:21 +04:00
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to stop recording");
|
|
|
|
return;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
case CameraControlListener::kInStartPreview:
|
2014-02-24 22:01:21 +04:00
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to (re)start preview");
|
|
|
|
return;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-04-26 00:28:15 +04:00
|
|
|
case CameraControlListener::kInStopPreview:
|
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to stop preview");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case CameraControlListener::kInSetPictureSize:
|
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to set picture size");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case CameraControlListener::kInSetThumbnailSize:
|
|
|
|
// This method doesn't have any callbacks, so all we can do is log the
|
|
|
|
// failure. This only happens after the hardware has been released.
|
|
|
|
NS_WARNING("Failed to set thumbnail size");
|
|
|
|
return;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
default:
|
2014-04-26 00:28:15 +04:00
|
|
|
{
|
|
|
|
nsPrintfCString msg("Unhandled aContext=%u, aError=0x%x\n", aContext, aError);
|
|
|
|
NS_WARNING(msg.get());
|
|
|
|
}
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unhandled user error");
|
2014-02-15 02:41:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
if (!promise && !errorCb) {
|
2014-04-26 00:28:15 +04:00
|
|
|
DOM_CAMERA_LOGW("DOM No error handler for aError=0x%x in aContext=%u\n",
|
|
|
|
aError, aContext);
|
2014-02-15 02:41:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
DOM_CAMERA_LOGI("DOM OnUserError aContext=%u, aError=0x%x\n", aContext, aError);
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeReject(aError);
|
|
|
|
}
|
2014-09-25 14:44:16 +04:00
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
if (errorCb) {
|
|
|
|
nsString error;
|
|
|
|
switch (aError) {
|
|
|
|
case NS_ERROR_INVALID_ARG:
|
|
|
|
error = NS_LITERAL_STRING("InvalidArgument");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_ERROR_NOT_AVAILABLE:
|
|
|
|
error = NS_LITERAL_STRING("NotAvailable");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_ERROR_NOT_IMPLEMENTED:
|
|
|
|
error = NS_LITERAL_STRING("NotImplemented");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_ERROR_NOT_INITIALIZED:
|
|
|
|
error = NS_LITERAL_STRING("HardwareClosed");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_ERROR_ALREADY_INITIALIZED:
|
|
|
|
error = NS_LITERAL_STRING("HardwareAlreadyOpen");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_ERROR_OUT_OF_MEMORY:
|
|
|
|
error = NS_LITERAL_STRING("OutOfMemory");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
nsPrintfCString msg("Reporting aError=0x%x as generic\n", aError);
|
|
|
|
NS_WARNING(msg.get());
|
|
|
|
}
|
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
case NS_ERROR_FAILURE:
|
|
|
|
error = NS_LITERAL_STRING("GeneralFailure");
|
|
|
|
break;
|
|
|
|
}
|
2014-09-25 14:44:16 +04:00
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
ErrorResult ignored;
|
|
|
|
errorCb->Call(error, ignored);
|
2014-04-26 00:28:15 +04:00
|
|
|
}
|
2013-10-23 15:11:18 +04:00
|
|
|
}
|