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/. */
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "mozilla/dom/CameraControlBinding.h"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "mozilla/dom/TabChild.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"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "nsIScriptSecurityManager.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 "DOMCameraControl.h"
|
|
|
|
#include "CameraCommon.h"
|
2013-05-18 05:48:25 +04:00
|
|
|
#include "mozilla/dom/CameraManagerBinding.h"
|
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-05-18 05:48:25 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-10-30 23:41:08 +04:00
|
|
|
using namespace mozilla::idl;
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(nsDOMCameraControl, mDOMCapabilities, mWindow)
|
2012-09-05 05:01:56 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCameraControl)
|
2013-07-07 00:55:10 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-09-05 05:01:56 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCameraControl)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCameraControl)
|
|
|
|
|
|
|
|
nsDOMCameraControl::~nsDOMCameraControl()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
JSObject*
|
|
|
|
nsDOMCameraControl::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
|
|
|
{
|
|
|
|
return CameraControlBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsICameraCapabilities*
|
|
|
|
nsDOMCameraControl::Capabilities()
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
|
|
|
if (!mDOMCapabilities) {
|
|
|
|
mDOMCapabilities = new DOMCameraCapabilities(mCameraControl);
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
return mDOMCapabilities;
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_FOCUSMODE, aFocusMode);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetZoom(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
double zoom;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_ZOOM, &zoom);
|
|
|
|
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
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_ZOOM, aZoom);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute jsval meteringAreas; */
|
2013-07-07 00:55:10 +04:00
|
|
|
JS::Value
|
|
|
|
nsDOMCameraControl::GetMeteringAreas(JSContext* cx, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
JS::Rooted<JS::Value> areas(cx);
|
|
|
|
aRv = mCameraControl->Get(cx, CAMERA_PARAM_METERINGAREAS, areas.address());
|
|
|
|
return areas;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetMeteringAreas(JSContext* cx, JS::Handle<JS::Value> aMeteringAreas, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->SetMeteringAreas(cx, aMeteringAreas);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
JS::Value
|
|
|
|
nsDOMCameraControl::GetFocusAreas(JSContext* cx, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
aRv = mCameraControl->Get(cx, CAMERA_PARAM_FOCUSAREAS, value.address());
|
|
|
|
return value;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetFocusAreas(JSContext* cx, JS::Handle<JS::Value> aFocusAreas, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->SetFocusAreas(cx, aFocusAreas);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-10-30 23:41:08 +04:00
|
|
|
static nsresult
|
|
|
|
GetSize(JSContext* aCx, JS::Value* aValue, const CameraSize& aSize)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, nullptr, nullptr));
|
|
|
|
if (!o) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
|
|
|
|
|
|
|
v = INT_TO_JSVAL(aSize.width);
|
|
|
|
if (!JS_SetProperty(aCx, o, "width", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
v = INT_TO_JSVAL(aSize.height);
|
|
|
|
if (!JS_SetProperty(aCx, o, "height", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = JS::ObjectValue(*o);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute any pictureSize */
|
|
|
|
JS::Value
|
|
|
|
nsDOMCameraControl::GetPictureSize(JSContext* cx, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
|
|
|
|
CameraSize size;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_PICTURESIZE, size);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = GetSize(cx, value.address(), size);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetPictureSize(JSContext* cx, JS::Handle<JS::Value> aSize, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CameraSize size;
|
|
|
|
aRv = size.Init(cx, aSize.address());
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_PICTURESIZE, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute any thumbnailSize */
|
|
|
|
JS::Value
|
|
|
|
nsDOMCameraControl::GetThumbnailSize(JSContext* cx, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
|
|
|
|
CameraSize size;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_THUMBNAILSIZE, size);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = GetSize(cx, value.address(), size);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetThumbnailSize(JSContext* cx, JS::Handle<JS::Value> aSize, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CameraSize size;
|
|
|
|
aRv = size.Init(cx, aSize.address());
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_THUMBNAILSIZE, size);
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocalLength(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
double focalLength;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCALLENGTH, &focalLength);
|
|
|
|
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
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
double distance;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCENEAR, &distance);
|
|
|
|
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
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
double distance;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCEOPTIMUM, &distance);
|
|
|
|
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
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
double distance;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCEFAR, &distance);
|
|
|
|
return distance;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetExposureCompensation(const Optional<double>& aCompensation, ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
if (!aCompensation.WasPassed()) {
|
2012-09-05 05:01:56 +04:00
|
|
|
// use NaN to switch the camera back into auto mode
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EXPOSURECOMPENSATION, NAN);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EXPOSURECOMPENSATION, aCompensation.Value());
|
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
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
double compensation;
|
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_EXPOSURECOMPENSATION, &compensation);
|
|
|
|
return compensation;
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:47:29 +04:00
|
|
|
int32_t
|
|
|
|
nsDOMCameraControl::SensorAngle()
|
|
|
|
{
|
|
|
|
int32_t angle;
|
|
|
|
mCameraControl->Get(CAMERA_PARAM_SENSORANGLE, &angle);
|
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
already_AddRefed<nsICameraShutterCallback>
|
|
|
|
nsDOMCameraControl::GetOnShutter(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
nsCOMPtr<nsICameraShutterCallback> cb;
|
|
|
|
aRv = mCameraControl->Get(getter_AddRefs(cb));
|
|
|
|
return cb.forget();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnShutter(nsICameraShutterCallback* aOnShutter,
|
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(aOnShutter);
|
2012-10-01 04:37:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute nsICameraClosedCallback onClosed; */
|
2013-07-07 00:55:10 +04:00
|
|
|
already_AddRefed<nsICameraClosedCallback>
|
|
|
|
nsDOMCameraControl::GetOnClosed(ErrorResult& aRv)
|
2012-10-01 04:37:47 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
nsCOMPtr<nsICameraClosedCallback> onClosed;
|
|
|
|
aRv = mCameraControl->Get(getter_AddRefs(onClosed));
|
|
|
|
return onClosed.forget();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnClosed(nsICameraClosedCallback* aOnClosed,
|
|
|
|
ErrorResult& aRv)
|
2012-11-03 00:11:50 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(aOnClosed);
|
2012-11-03 00:11:50 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
already_AddRefed<nsICameraRecorderStateChange>
|
|
|
|
nsDOMCameraControl::GetOnRecorderStateChange(ErrorResult& aRv)
|
2013-08-06 00:24:43 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
nsCOMPtr<nsICameraRecorderStateChange> cb;
|
|
|
|
aRv = mCameraControl->Get(getter_AddRefs(cb));
|
|
|
|
return cb.forget();
|
2013-08-06 00:24:43 +04:00
|
|
|
}
|
2013-07-07 00:55:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnRecorderStateChange(nsICameraRecorderStateChange* aOnRecorderStateChange,
|
|
|
|
ErrorResult& aRv)
|
2013-08-06 00:24:43 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->Set(aOnRecorderStateChange);
|
2013-08-06 00:24:43 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2013-10-22 02:38:50 +04:00
|
|
|
nsDOMCameraControl::StartRecording(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aOptions,
|
2013-07-07 00:55:10 +04:00
|
|
|
nsDOMDeviceStorage& storageArea,
|
|
|
|
const nsAString& filename,
|
|
|
|
nsICameraStartRecordingCallback* onSuccess,
|
|
|
|
const Optional<nsICameraErrorCallback*>& onError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
MOZ_ASSERT(onSuccess, "no onSuccess handler passed");
|
2013-10-22 02:38:50 +04:00
|
|
|
mozilla::idl::CameraStartRecordingOptions options;
|
|
|
|
|
|
|
|
// Default values, until the dictionary parser can handle them.
|
|
|
|
options.rotation = 0;
|
|
|
|
options.maxFileSizeBytes = 0;
|
|
|
|
options.maxVideoLengthMs = 0;
|
|
|
|
aRv = options.Init(aCx, aOptions.address());
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-26 10:22:22 +04:00
|
|
|
aRv = NotifyRecordingStatusChange(NS_LITERAL_STRING("starting"));
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2012-12-11 14:14:06 +04:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
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.
|
|
|
|
mAudioChannelAgent->Init(AUDIO_CHANNEL_CONTENT, nullptr);
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-24 02:30:28 +04:00
|
|
|
nsCOMPtr<nsIFile> folder;
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = storageArea.GetRootDirectoryForFile(filename, getter_AddRefs(folder));
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 02:38:50 +04:00
|
|
|
aRv = mCameraControl->StartRecording(&options, folder, filename, onSuccess,
|
2013-07-07 00:55:10 +04:00
|
|
|
onError.WasPassed() ? onError.Value() : nullptr);
|
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
|
|
|
{
|
2013-11-26 10:22:22 +04:00
|
|
|
aRv = NotifyRecordingStatusChange(NS_LITERAL_STRING("shutdown"));
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2012-12-11 14:14:06 +04:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
mAudioChannelAgent->StopPlaying();
|
|
|
|
mAudioChannelAgent = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
nsDOMCameraControl::GetPreviewStream(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aOptions,
|
|
|
|
nsICameraPreviewStreamCallback* onSuccess,
|
|
|
|
const Optional<nsICameraErrorCallback*>& onError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-02-11 23:37:50 +04:00
|
|
|
mozilla::idl::CameraSize size;
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = size.Init(aCx, aOptions.address());
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->GetPreviewStream(size, onSuccess,
|
|
|
|
onError.WasPassed()
|
|
|
|
? onError.Value() : nullptr);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::ResumePreview(ErrorResult& aRv)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = mCameraControl->StartPreview(nullptr);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
already_AddRefed<nsICameraPreviewStateChange>
|
|
|
|
nsDOMCameraControl::GetOnPreviewStateChange() const
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
nsCOMPtr<nsICameraPreviewStateChange> cb;
|
|
|
|
mCameraControl->Get(getter_AddRefs(cb));
|
|
|
|
return cb.forget();
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetOnPreviewStateChange(nsICameraPreviewStateChange* aCb)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
mCameraControl->Set(aCb);
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::AutoFocus(nsICameraAutoFocusCallback* onSuccess,
|
|
|
|
const Optional<nsICameraErrorCallback*>& onError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = mCameraControl->AutoFocus(onSuccess,
|
|
|
|
onError.WasPassed() ? onError.Value() : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::TakePicture(JSContext* aCx,
|
|
|
|
const CameraPictureOptions& aOptions,
|
|
|
|
nsICameraTakePictureCallback* onSuccess,
|
|
|
|
const Optional<nsICameraErrorCallback*>& aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-02-11 23:37:50 +04:00
|
|
|
mozilla::idl::CameraSize size;
|
|
|
|
mozilla::idl::CameraPosition pos;
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = size.Init(aCx, &aOptions.mPictureSize);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
2013-05-18 05:48:25 +04:00
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default values, until the dictionary parser can handle them.
|
|
|
|
* NaN indicates no value provided.
|
|
|
|
*/
|
|
|
|
pos.latitude = NAN;
|
|
|
|
pos.longitude = NAN;
|
|
|
|
pos.altitude = NAN;
|
|
|
|
pos.timestamp = NAN;
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv = pos.Init(aCx, &aOptions.mPosition);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
nsICameraErrorCallback* onError =
|
|
|
|
aOnError.WasPassed() ? aOnError.Value() : nullptr;
|
|
|
|
aRv = mCameraControl->TakePicture(size, aOptions.mRotation,
|
|
|
|
aOptions.mFileFormat, pos,
|
|
|
|
aOptions.mDateTime, onSuccess, onError);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
2013-10-22 02:38:50 +04:00
|
|
|
nsDOMCameraControl::GetPreviewStreamVideoMode(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aOptions,
|
2013-07-07 00:55:10 +04:00
|
|
|
nsICameraPreviewStreamCallback* onSuccess,
|
|
|
|
const Optional<nsICameraErrorCallback*>& onError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-29 09:30:52 +04:00
|
|
|
{
|
2013-10-22 02:38:50 +04:00
|
|
|
mozilla::idl::CameraRecorderOptions options;
|
|
|
|
aRv = options.Init(aCx, aOptions.address());
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->GetPreviewStreamVideoMode(&options, onSuccess,
|
2013-07-07 00:55:10 +04:00
|
|
|
onError.WasPassed()
|
|
|
|
? onError.Value() : nullptr);
|
2012-09-29 09:30:52 +04:00
|
|
|
}
|
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::ReleaseHardware(const Optional<nsICameraReleaseCallback*>& onSuccess,
|
|
|
|
const Optional<nsICameraErrorCallback*>& onError,
|
|
|
|
ErrorResult& aRv)
|
2012-12-23 19:54:54 +04:00
|
|
|
{
|
2013-07-07 00:55:10 +04:00
|
|
|
aRv =
|
|
|
|
mCameraControl->ReleaseHardware(
|
|
|
|
onSuccess.WasPassed() ? onSuccess.Value() : nullptr,
|
|
|
|
onError.WasPassed() ? onError.Value() : nullptr);
|
2012-12-23 19:54:54 +04:00
|
|
|
}
|
|
|
|
|
2012-09-05 05:01:56 +04:00
|
|
|
class GetCameraResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-06-17 19:59:53 +04:00
|
|
|
GetCameraResult(nsDOMCameraControl* aDOMCameraControl,
|
|
|
|
nsresult aResult,
|
|
|
|
const nsMainThreadPtrHandle<nsICameraGetCameraCallback>& onSuccess,
|
|
|
|
const nsMainThreadPtrHandle<nsICameraErrorCallback>& onError,
|
|
|
|
uint64_t aWindowId)
|
2012-09-05 05:01:56 +04:00
|
|
|
: mDOMCameraControl(aDOMCameraControl)
|
|
|
|
, mResult(aResult)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
, mOnErrorCb(onError)
|
2012-10-01 04:37:47 +04:00
|
|
|
, mWindowId(aWindowId)
|
2012-09-05 05:01:56 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-01 04:37:47 +04:00
|
|
|
if (nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
|
|
|
DOM_CAMERA_LOGT("%s : this=%p -- BEFORE CALLBACK\n", __func__, this);
|
|
|
|
if (NS_FAILED(mResult)) {
|
2013-06-17 19:59:53 +04:00
|
|
|
if (mOnErrorCb.get()) {
|
2012-10-01 04:37:47 +04:00
|
|
|
mOnErrorCb->HandleEvent(NS_LITERAL_STRING("FAILURE"));
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-17 19:59:53 +04:00
|
|
|
if (mOnSuccessCb.get()) {
|
2012-10-01 04:37:47 +04:00
|
|
|
mOnSuccessCb->HandleEvent(mDOMCameraControl);
|
|
|
|
}
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
2012-10-01 04:37:47 +04:00
|
|
|
DOM_CAMERA_LOGT("%s : this=%p -- AFTER CALLBACK\n", __func__, this);
|
2012-09-05 05:01:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finally, release the extra reference to the DOM-facing camera control.
|
|
|
|
* See the nsDOMCameraControl constructor for the corresponding call to
|
|
|
|
* NS_ADDREF_THIS().
|
|
|
|
*/
|
|
|
|
NS_RELEASE(mDOMCameraControl);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* 'mDOMCameraControl' is a raw pointer to a previously ADDREF()ed object,
|
|
|
|
* which is released in Run().
|
|
|
|
*/
|
|
|
|
nsDOMCameraControl* mDOMCameraControl;
|
|
|
|
nsresult mResult;
|
2013-06-17 19:59:53 +04:00
|
|
|
nsMainThreadPtrHandle<nsICameraGetCameraCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-10-01 04:37:47 +04:00
|
|
|
uint64_t mWindowId;
|
2012-09-05 05:01:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2013-06-17 19:59:53 +04:00
|
|
|
nsDOMCameraControl::Result(nsresult aResult,
|
|
|
|
const nsMainThreadPtrHandle<nsICameraGetCameraCallback>& onSuccess,
|
|
|
|
const nsMainThreadPtrHandle<nsICameraErrorCallback>& onError,
|
|
|
|
uint64_t aWindowId)
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
2012-10-01 04:37:47 +04:00
|
|
|
nsCOMPtr<GetCameraResult> getCameraResult = new GetCameraResult(this, aResult, onSuccess, onError, aWindowId);
|
2012-09-05 05:01:56 +04:00
|
|
|
return NS_DispatchToMainThread(getCameraResult);
|
|
|
|
}
|
2012-10-01 04:37:47 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::Shutdown()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI("%s:%d\n", __func__, __LINE__);
|
|
|
|
mCameraControl->Shutdown();
|
|
|
|
}
|
2013-05-02 15:59:58 +04:00
|
|
|
|
|
|
|
nsRefPtr<ICameraControl>
|
|
|
|
nsDOMCameraControl::GetNativeCameraControl()
|
|
|
|
{
|
|
|
|
return mCameraControl;
|
|
|
|
}
|
2013-10-23 15:11:18 +04:00
|
|
|
|
2013-11-26 10:22:22 +04:00
|
|
|
nsresult
|
|
|
|
nsDOMCameraControl::NotifyRecordingStatusChange(const nsString& aMsg)
|
2013-10-23 15:11:18 +04:00
|
|
|
{
|
2013-11-26 10:22:22 +04:00
|
|
|
NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE);
|
2013-10-23 15:11:18 +04:00
|
|
|
|
2013-11-26 10:22:22 +04:00
|
|
|
return MediaManager::NotifyRecordingStatusChange(mWindow,
|
|
|
|
aMsg,
|
|
|
|
true /* aIsAudio */,
|
|
|
|
true /* aIsVideo */);
|
2013-10-23 15:11:18 +04:00
|
|
|
}
|
2013-11-26 10:22:22 +04:00
|
|
|
|