2012-09-04 18:01:56 -07: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-14 14:41:07 -08:00
|
|
|
#include "DOMCameraControl.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMClassInfo.h"
|
2013-10-23 04:11:18 -07:00
|
|
|
#include "nsHashPropertyBag.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "nsThread.h"
|
2013-07-06 13:55:10 -07:00
|
|
|
#include "DeviceStorage.h"
|
2014-01-16 17:01:43 -08:00
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
2013-10-23 04:11:18 -07:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-02-28 12:02:55 -08:00
|
|
|
#include "mozilla/ipc/FileDescriptorUtils.h"
|
2013-11-25 22:22:22 -08:00
|
|
|
#include "mozilla/MediaManager.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "mozilla/Services.h"
|
2013-01-24 18:45:36 -08:00
|
|
|
#include "mozilla/unused.h"
|
2013-10-23 04:11:18 -07:00
|
|
|
#include "nsIAppsService.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "nsIObserverService.h"
|
2012-09-28 22:30:52 -07:00
|
|
|
#include "nsIDOMDeviceStorage.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "nsIDOMEventListener.h"
|
2013-10-23 04:11:18 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-01-24 18:45:36 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "DOMCameraManager.h"
|
|
|
|
#include "DOMCameraCapabilities.h"
|
|
|
|
#include "CameraCommon.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "CameraPreviewMediaStream.h"
|
|
|
|
#include "mozilla/dom/CameraControlBinding.h"
|
2013-05-17 18:48:25 -07:00
|
|
|
#include "mozilla/dom/CameraManagerBinding.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "mozilla/dom/CameraCapabilitiesBinding.h"
|
2013-05-17 18:48:25 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-05-17 18:48:25 -07:00
|
|
|
using namespace mozilla::dom;
|
2014-02-28 12:02:55 -08:00
|
|
|
using namespace mozilla::ipc;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMCameraControl)
|
2012-09-04 18:01:56 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaStream)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMCameraControl, DOMMediaStream)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMCameraControl, DOMMediaStream)
|
|
|
|
|
2014-02-28 09:56:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED_18(nsDOMCameraControl, DOMMediaStream,
|
|
|
|
mCapabilities,
|
|
|
|
mWindow,
|
|
|
|
mGetCameraOnSuccessCb,
|
|
|
|
mGetCameraOnErrorCb,
|
|
|
|
mAutoFocusOnSuccessCb,
|
|
|
|
mAutoFocusOnErrorCb,
|
|
|
|
mTakePictureOnSuccessCb,
|
|
|
|
mTakePictureOnErrorCb,
|
|
|
|
mStartRecordingOnSuccessCb,
|
|
|
|
mStartRecordingOnErrorCb,
|
|
|
|
mReleaseOnSuccessCb,
|
|
|
|
mReleaseOnErrorCb,
|
|
|
|
mSetConfigurationOnSuccessCb,
|
|
|
|
mSetConfigurationOnErrorCb,
|
|
|
|
mOnShutterCb,
|
|
|
|
mOnClosedCb,
|
|
|
|
mOnRecorderStateChangeCb,
|
|
|
|
mOnPreviewStateChangeCb)
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
class mozilla::StartRecordingHelper : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
StartRecordingHelper(nsDOMCameraControl* aDOMCameraControl)
|
|
|
|
: mDOMCameraControl(aDOMCameraControl)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(StartRecordingHelper);
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08: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-02-24 10:01:21 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(mozilla::StartRecordingHelper, nsIDOMEventListener)
|
2014-02-14 14:41:07 -08: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
|
|
|
|
const CameraConfiguration& aInitialConfig,
|
|
|
|
GetCameraCallback* aOnSuccess,
|
|
|
|
CameraErrorCallback* aOnError,
|
|
|
|
nsPIDOMWindow* aWindow)
|
|
|
|
: DOMMediaStream()
|
|
|
|
, mCameraControl(nullptr)
|
|
|
|
, mAudioChannelAgent(nullptr)
|
|
|
|
, 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)
|
|
|
|
, mWindow(aWindow)
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
mInput = new CameraPreviewMediaStream(this);
|
|
|
|
|
|
|
|
SetIsDOMBinding();
|
|
|
|
|
|
|
|
nsRefPtr<DOMCameraConfiguration> initialConfig =
|
|
|
|
new DOMCameraConfiguration(aInitialConfig);
|
|
|
|
|
|
|
|
// Create and initialize the underlying camera.
|
|
|
|
ICameraControl::Configuration config;
|
|
|
|
|
|
|
|
switch (aInitialConfig.mMode) {
|
|
|
|
case CameraMode::Picture:
|
|
|
|
config.mMode = ICameraControl::kPictureMode;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraMode::Video:
|
|
|
|
config.mMode = ICameraControl::kVideoMode;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSUME_UNREACHABLE("Unanticipated camera mode!");
|
|
|
|
}
|
|
|
|
|
|
|
|
config.mPreviewSize.width = aInitialConfig.mPreviewSize.mWidth;
|
|
|
|
config.mPreviewSize.height = aInitialConfig.mPreviewSize.mHeight;
|
|
|
|
config.mRecorderProfile = aInitialConfig.mRecorderProfile;
|
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
mCameraControl = ICameraControl::Create(aCameraId);
|
2014-02-14 14:41:07 -08:00
|
|
|
mCurrentConfiguration = initialConfig.forget();
|
|
|
|
|
|
|
|
// Attach our DOM-facing media stream to our viewfinder stream.
|
|
|
|
mStream = mInput;
|
|
|
|
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-19 20:18:52 -08:00
|
|
|
|
|
|
|
// Start the camera...
|
|
|
|
nsresult rv = mCameraControl->Start(&config);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mListener->OnError(DOMCameraControlListener::kInStartCamera,
|
|
|
|
DOMCameraControlListener::kErrorApiFailed);
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
nsDOMCameraControl::~nsDOMCameraControl()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
JSObject*
|
|
|
|
nsDOMCameraControl::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
|
|
|
{
|
|
|
|
return CameraControlBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
bool
|
|
|
|
nsDOMCameraControl::IsWindowStillActive()
|
|
|
|
{
|
|
|
|
return nsDOMCameraManager::IsWindowStillActive(mWindow->WindowID());
|
|
|
|
}
|
|
|
|
|
|
|
|
// JS-to-native helpers
|
|
|
|
// Setter for weighted regions: { top, bottom, left, right, weight }
|
|
|
|
nsresult
|
|
|
|
nsDOMCameraControl::Set(JSContext* aCx, uint32_t aKey, const JS::Value& aValue, uint32_t aLimit)
|
|
|
|
{
|
|
|
|
if (aLimit == 0) {
|
|
|
|
DOM_CAMERA_LOGI("%s:%d : aLimit = 0, nothing to do\n", __func__, __LINE__);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aValue.isObject()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t length = 0;
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> regions(aCx, &aValue.toObject());
|
|
|
|
if (!JS_GetArrayLength(aCx, regions, &length)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("%s:%d : got %d regions (limited to %d)\n", __func__, __LINE__, length, aLimit);
|
|
|
|
if (length > aLimit) {
|
|
|
|
length = aLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<ICameraControl::Region> regionArray;
|
|
|
|
regionArray.SetCapacity(length);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
|
|
|
|
|
|
|
if (!JS_GetElement(aCx, regions, i, &v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraRegion region;
|
|
|
|
if (!region.Init(aCx, v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICameraControl::Region* r = regionArray.AppendElement();
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return mCameraControl->Set(aKey, regionArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getter for weighted regions: { top, bottom, left, right, weight }
|
|
|
|
nsresult
|
|
|
|
nsDOMCameraControl::Get(JSContext* aCx, uint32_t aKey, JS::Value* aValue)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsTArray<ICameraControl::Region> regionArray;
|
|
|
|
|
|
|
|
nsresult rv = mCameraControl->Get(aKey, regionArray);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
|
|
|
|
if (!array) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t length = regionArray.Length();
|
|
|
|
DOM_CAMERA_LOGI("%s:%d : got %d regions\n", __func__, __LINE__, length);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
ICameraControl::Region* r = ®ionArray[i];
|
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
|
|
|
if (!o) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("top=%d\n", r->top);
|
|
|
|
v = INT_TO_JSVAL(r->top);
|
|
|
|
if (!JS_SetProperty(aCx, o, "top", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("left=%d\n", r->left);
|
|
|
|
v = INT_TO_JSVAL(r->left);
|
|
|
|
if (!JS_SetProperty(aCx, o, "left", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("bottom=%d\n", r->bottom);
|
|
|
|
v = INT_TO_JSVAL(r->bottom);
|
|
|
|
if (!JS_SetProperty(aCx, o, "bottom", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("right=%d\n", r->right);
|
|
|
|
v = INT_TO_JSVAL(r->right);
|
|
|
|
if (!JS_SetProperty(aCx, o, "right", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("weight=%d\n", r->weight);
|
|
|
|
v = INT_TO_JSVAL(r->weight);
|
|
|
|
if (!JS_SetProperty(aCx, o, "weight", v)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_SetElement(aCx, array, i, o)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = JS::ObjectValue(*array);
|
|
|
|
return NS_OK;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetEffect(nsString& aEffect, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_EFFECT, aEffect);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetEffect(const nsAString& aEffect, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EFFECT, aEffect);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetWhiteBalanceMode(nsString& aWhiteBalanceMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_WHITEBALANCE, aWhiteBalanceMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetWhiteBalanceMode(const nsAString& aWhiteBalanceMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_WHITEBALANCE, aWhiteBalanceMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetSceneMode(nsString& aSceneMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_SCENEMODE, aSceneMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetSceneMode(const nsAString& aSceneMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_SCENEMODE, aSceneMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetFlashMode(nsString& aFlashMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FLASHMODE, aFlashMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetFlashMode(const nsAString& aFlashMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_FLASHMODE, aFlashMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::GetFocusMode(nsString& aFocusMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSMODE, aFocusMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetFocusMode(const nsAString& aFocusMode, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_FOCUSMODE, aFocusMode);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2014-03-06 22:00:43 -08: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);
|
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetZoom(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double zoom;
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_ZOOM, zoom);
|
2013-07-06 13:55:10 -07:00
|
|
|
return zoom;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetZoom(double aZoom, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_ZOOM, aZoom);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute jsval meteringAreas; */
|
2013-07-06 13:55:10 -07:00
|
|
|
JS::Value
|
|
|
|
nsDOMCameraControl::GetMeteringAreas(JSContext* cx, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2013-07-06 13:55:10 -07:00
|
|
|
JS::Rooted<JS::Value> areas(cx);
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = Get(cx, CAMERA_PARAM_METERINGAREAS, areas.address());
|
2013-07-06 13:55:10 -07:00
|
|
|
return areas;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetMeteringAreas(JSContext* cx, JS::Handle<JS::Value> aMeteringAreas, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = Set(cx, CAMERA_PARAM_METERINGAREAS, aMeteringAreas,
|
|
|
|
mCurrentConfiguration->mMaxMeteringAreas);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
JS::Value
|
|
|
|
nsDOMCameraControl::GetFocusAreas(JSContext* cx, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2013-07-06 13:55:10 -07:00
|
|
|
JS::Rooted<JS::Value> value(cx);
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = Get(cx, CAMERA_PARAM_FOCUSAREAS, value.address());
|
2013-07-06 13:55:10 -07:00
|
|
|
return value;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetFocusAreas(JSContext* cx, JS::Handle<JS::Value> aFocusAreas, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = Set(cx, CAMERA_PARAM_FOCUSAREAS, aFocusAreas,
|
|
|
|
mCurrentConfiguration->mMaxFocusAreas);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-10-30 12:41:08 -07:00
|
|
|
static nsresult
|
2014-02-14 14:41:07 -08:00
|
|
|
GetSize(JSContext* aCx, JS::Value* aValue, const ICameraControl::Size& aSize)
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-10-30 12:41:08 -07:00
|
|
|
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);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
ICameraControl::Size size;
|
2013-10-30 12:41:08 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_PICTURESIZE, size);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = GetSize(cx, value.address(), size);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::SetPictureSize(JSContext* aCx, JS::Handle<JS::Value> aSize, ErrorResult& aRv)
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
|
|
|
CameraSize size;
|
2014-02-14 14:41:07 -08:00
|
|
|
if (!size.Init(aCx, aSize)) {
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
2013-10-30 12:41:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 19:09:23 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
ICameraControl::Size s = { size.mWidth, size.mHeight };
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_PICTURESIZE, s);
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute any thumbnailSize */
|
|
|
|
JS::Value
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::GetThumbnailSize(JSContext* aCx, ErrorResult& aRv)
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
|
|
|
|
ICameraControl::Size size;
|
2013-10-30 12:41:08 -07:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_THUMBNAILSIZE, size);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = GetSize(aCx, value.address(), size);
|
2013-10-30 12:41:08 -07:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::SetThumbnailSize(JSContext* aCx, JS::Handle<JS::Value> aSize, ErrorResult& aRv)
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
|
|
|
CameraSize size;
|
2014-02-14 14:41:07 -08:00
|
|
|
if (!size.Init(aCx, aSize)) {
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
2013-10-30 12:41:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
ICameraControl::Size s = { size.mWidth, size.mHeight };
|
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_THUMBNAILSIZE, s);
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocalLength(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double focalLength;
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCALLENGTH, focalLength);
|
2013-07-06 13:55:10 -07:00
|
|
|
return focalLength;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocusDistanceNear(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double distance;
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCENEAR, distance);
|
2013-07-06 13:55:10 -07:00
|
|
|
return distance;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocusDistanceOptimum(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double distance;
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCEOPTIMUM, distance);
|
2013-07-06 13:55:10 -07:00
|
|
|
return distance;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetFocusDistanceFar(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double distance;
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_FOCUSDISTANCEFAR, distance);
|
2013-07-06 13:55:10 -07:00
|
|
|
return distance;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetExposureCompensation(const Optional<double>& aCompensation, ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
if (!aCompensation.WasPassed()) {
|
2012-09-04 18:01:56 -07:00
|
|
|
// use NaN to switch the camera back into auto mode
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EXPOSURECOMPENSATION, NAN);
|
2014-02-14 14:41:07 -08:00
|
|
|
return;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->Set(CAMERA_PARAM_EXPOSURECOMPENSATION, aCompensation.Value());
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double
|
|
|
|
nsDOMCameraControl::GetExposureCompensation(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
double compensation;
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = mCameraControl->Get(CAMERA_PARAM_EXPOSURECOMPENSATION, compensation);
|
2013-07-06 13:55:10 -07:00
|
|
|
return compensation;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-12-06 06:47:29 -08:00
|
|
|
int32_t
|
|
|
|
nsDOMCameraControl::SensorAngle()
|
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
2014-02-24 10:01:21 -08:00
|
|
|
int32_t angle = 0;
|
2014-02-14 14:41:07 -08:00
|
|
|
mCameraControl->Get(CAMERA_PARAM_SENSORANGLE, angle);
|
2013-12-06 06:47:29 -08:00
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
already_AddRefed<CameraShutterCallback>
|
|
|
|
nsDOMCameraControl::GetOnShutter()
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<CameraShutterCallback> cb = mOnShutterCb;
|
2013-07-06 13:55:10 -07:00
|
|
|
return cb.forget();
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::SetOnShutter(CameraShutterCallback* aCb)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
mOnShutterCb = aCb;
|
2012-09-30 17:37:47 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
/* attribute CameraClosedCallback onClosed; */
|
|
|
|
already_AddRefed<CameraClosedCallback>
|
|
|
|
nsDOMCameraControl::GetOnClosed()
|
2012-09-30 17:37:47 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<CameraClosedCallback> onClosed = mOnClosedCb;
|
2013-07-06 13:55:10 -07:00
|
|
|
return onClosed.forget();
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::SetOnClosed(CameraClosedCallback* aCb)
|
2012-11-02 13:11:50 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
mOnClosedCb = aCb;
|
2012-11-02 13:11:50 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
already_AddRefed<CameraRecorderStateChange>
|
|
|
|
nsDOMCameraControl::GetOnRecorderStateChange()
|
2013-08-05 13:24:43 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
|
2013-07-06 13:55:10 -07:00
|
|
|
return cb.forget();
|
2013-08-05 13:24:43 -07:00
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::SetOnRecorderStateChange(CameraRecorderStateChange* aCb)
|
2013-08-05 13:24:43 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
mOnRecorderStateChangeCb = aCb;
|
2013-08-05 13:24:43 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
/* attribute CameraPreviewStateChange onPreviewStateChange; */
|
|
|
|
already_AddRefed<CameraPreviewStateChange>
|
|
|
|
nsDOMCameraControl::GetOnPreviewStateChange()
|
|
|
|
{
|
|
|
|
nsCOMPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
|
|
|
|
return cb.forget();
|
|
|
|
}
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::SetOnPreviewStateChange(CameraPreviewStateChange* aCb)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
mOnPreviewStateChangeCb = aCb;
|
|
|
|
}
|
2013-10-21 15:38:50 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
already_AddRefed<dom::CameraCapabilities>
|
|
|
|
nsDOMCameraControl::Capabilities()
|
|
|
|
{
|
|
|
|
nsRefPtr<CameraCapabilities> caps = mCapabilities;
|
|
|
|
|
|
|
|
if (!caps) {
|
|
|
|
caps = new CameraCapabilities(mWindow);
|
|
|
|
nsresult rv = caps->Populate(mCameraControl);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGW("Failed to populate camera capabilities (%d)\n", rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mCapabilities = caps;
|
2013-10-21 15:38:50 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return caps.forget();
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Methods.
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::StartRecording(const CameraStartRecordingOptions& aOptions,
|
|
|
|
nsDOMDeviceStorage& aStorageArea,
|
|
|
|
const nsAString& aFilename,
|
|
|
|
CameraStartRecordingCallback& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
NotifyRecordingStatusChange(NS_LITERAL_STRING("starting"));
|
|
|
|
|
|
|
|
#ifdef MOZ_B2G
|
2012-12-11 02:14:06 -08: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-03-11 03:46:04 -07:00
|
|
|
mAudioChannelAgent->Init(mWindow, AUDIO_CHANNEL_CONTENT, nullptr);
|
2012-12-11 02:14:06 -08:00
|
|
|
// Video recording doesn't output any sound, so it's not necessary to check canPlay.
|
2013-09-02 02:45:44 -07:00
|
|
|
int32_t canPlay;
|
2012-12-11 02:14:06 -08:00
|
|
|
mAudioChannelAgent->StartPlaying(&canPlay);
|
|
|
|
}
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
#endif
|
2012-12-11 02:14:06 -08:00
|
|
|
|
2014-01-16 17:01:43 -08:00
|
|
|
nsCOMPtr<nsIDOMDOMRequest> request;
|
|
|
|
mDSFileDescriptor = new DeviceStorageFileDescriptor();
|
2014-02-14 14:41:07 -08:00
|
|
|
aRv = aStorageArea.CreateFileDescriptor(aFilename, mDSFileDescriptor.get(),
|
2014-01-16 17:01:43 -08:00
|
|
|
getter_AddRefs(request));
|
2013-07-06 13:55:10 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-16 17:01:43 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
mOptions = aOptions;
|
|
|
|
mStartRecordingOnSuccessCb = &aOnSuccess;
|
|
|
|
mStartRecordingOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mStartRecordingOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
2014-01-16 17:01:43 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<nsIDOMEventListener> listener = new StartRecordingHelper(this);
|
|
|
|
request->AddEventListener(NS_LITERAL_STRING("success"), listener, false);
|
|
|
|
request->AddEventListener(NS_LITERAL_STRING("error"), listener, false);
|
2014-01-16 17:01:43 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnCreatedFileDescriptor(bool aSucceeded)
|
2014-01-16 17:01:43 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
if (aSucceeded && mDSFileDescriptor->mFileDescriptor.IsValid()) {
|
|
|
|
ICameraControl::StartRecordingOptions o;
|
|
|
|
|
|
|
|
o.rotation = mOptions.mRotation;
|
|
|
|
o.maxFileSizeBytes = mOptions.mMaxFileSizeBytes;
|
|
|
|
o.maxVideoLengthMs = mOptions.mMaxVideoLengthMs;
|
|
|
|
nsresult rv = mCameraControl->StartRecording(mDSFileDescriptor.get(), &o);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return;
|
2014-01-16 17:01:43 -08:00
|
|
|
}
|
2014-02-10 19:09:23 -08:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
OnError(CameraControlListener::kInStartRecording, NS_LITERAL_STRING("FAILURE"));
|
2014-02-28 12:02:55 -08: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-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::StopRecording(ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
#ifdef MOZ_B2G
|
2012-12-11 02:14:06 -08:00
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
mAudioChannelAgent->StopPlaying();
|
|
|
|
mAudioChannelAgent = nullptr;
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
#endif
|
2012-12-11 02:14:06 -08:00
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
aRv = mCameraControl->StopRecording();
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::ResumePreview(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
aRv = mCameraControl->StartPreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraControl::SetConfiguration(const CameraConfiguration& aConfiguration,
|
|
|
|
const Optional<OwningNonNull<CameraSetConfigurationCallback> >& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
2013-07-06 13:55:10 -07:00
|
|
|
ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
nsCOMPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb;
|
|
|
|
if (cb) {
|
|
|
|
// We're busy taking a picture, can't change modes right now.
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
aOnError.Value().Call(NS_LITERAL_STRING("Busy"), ignored);
|
|
|
|
}
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
2013-07-06 13:55:10 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSetConfigurationOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mSetConfigurationOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
|
|
|
mSetConfigurationOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mSetConfigurationOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->SetConfiguration(config);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::AutoFocus(CameraAutoFocusCallback& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
nsCOMPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
|
|
|
|
bool cancel = false;
|
|
|
|
if (cb) {
|
|
|
|
// we have a callback, which means we're already in the process of
|
|
|
|
// auto-focusing--cancel the old callback
|
|
|
|
nsCOMPtr<CameraErrorCallback> ecb = mAutoFocusOnErrorCb.forget();
|
2014-03-10 05:35:52 -07:00
|
|
|
if (ecb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
ecb->Call(NS_LITERAL_STRING("Interrupted"), ignored);
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
cancel = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAutoFocusOnSuccessCb = &aOnSuccess;
|
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mAutoFocusOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->AutoFocus(cancel);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::TakePicture(const CameraPictureOptions& aOptions,
|
|
|
|
CameraTakePictureCallback& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
nsCOMPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb;
|
|
|
|
if (cb) {
|
|
|
|
// There is already a call to TakePicture() in progress, abort this one and
|
|
|
|
// invoke the error callback (if one was passed in).
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
aOnError.Value().Call(NS_LITERAL_STRING("TakePictureAlreadyInProgress"), ignored);
|
|
|
|
}
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
mTakePictureOnSuccessCb = &aOnSuccess;
|
|
|
|
mTakePictureOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mTakePictureOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mCameraControl->TakePicture();
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::ReleaseHardware(const Optional<OwningNonNull<CameraReleaseCallback> >& aOnSuccess,
|
|
|
|
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(mCameraControl);
|
|
|
|
|
|
|
|
mReleaseOnSuccessCb = nullptr;
|
|
|
|
if (aOnSuccess.WasPassed()) {
|
|
|
|
mReleaseOnSuccessCb = &aOnSuccess.Value();
|
|
|
|
}
|
|
|
|
mReleaseOnErrorCb = nullptr;
|
|
|
|
if (aOnError.WasPassed()) {
|
|
|
|
mReleaseOnErrorCb = &aOnError.Value();
|
|
|
|
}
|
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
aRv = mCameraControl->Stop();
|
2013-07-06 13:55:10 -07:00
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08: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.
|
|
|
|
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;
|
|
|
|
|
|
|
|
mCameraControl->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDOMCameraControl::NotifyRecordingStatusChange(const nsString& aMsg)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return MediaManager::NotifyRecordingStatusChange(mWindow,
|
|
|
|
aMsg,
|
|
|
|
true /* aIsAudio */,
|
|
|
|
true /* aIsVideo */);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Camera Control event handlers--must only be called from the Main Thread!
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::OnHardwareStateChange(CameraControlListener::HardwareState aState)
|
2013-07-06 13:55:10 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ErrorResult ignored;
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("DOM OnHardwareStateChange(%d)\n", aState);
|
|
|
|
|
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kHardwareOpen:
|
|
|
|
// The hardware is open, so we can return a camera to JS, even if
|
|
|
|
// the preview hasn't started yet.
|
|
|
|
if (mGetCameraOnSuccessCb) {
|
|
|
|
nsCOMPtr<GetCameraCallback> cb = mGetCameraOnSuccessCb.forget();
|
|
|
|
ErrorResult ignored;
|
|
|
|
mGetCameraOnErrorCb = nullptr;
|
|
|
|
cb->Call(*this, *mCurrentConfiguration, ignored);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kHardwareClosed:
|
|
|
|
if (mReleaseOnSuccessCb) {
|
|
|
|
// If we have this event handler, this was a solicited hardware close.
|
|
|
|
nsCOMPtr<CameraReleaseCallback> cb = mReleaseOnSuccessCb.forget();
|
|
|
|
mReleaseOnErrorCb = nullptr;
|
|
|
|
cb->Call(ignored);
|
|
|
|
} else if(mOnClosedCb) {
|
|
|
|
// If not, something else closed the hardware.
|
|
|
|
nsCOMPtr<CameraClosedCallback> cb = mOnClosedCb;
|
|
|
|
cb->Call(ignored);
|
|
|
|
}
|
|
|
|
break;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
default:
|
|
|
|
MOZ_ASSUME_UNREACHABLE("Unanticipated camera hardware state");
|
2013-05-17 18:48:25 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnShutter()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("DOM ** SNAP **\n");
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<CameraShutterCallback> cb = mOnShutterCb;
|
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(ignored);
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::OnPreviewStateChange(CameraControlListener::PreviewState aState)
|
2012-09-28 22:30:52 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mOnPreviewStateChangeCb) {
|
2013-10-21 15:38:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsString state;
|
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kPreviewStarted:
|
|
|
|
state = NS_LITERAL_STRING("started");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
state = NS_LITERAL_STRING("stopped");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(state, ignored);
|
2012-09-28 22:30:52 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::OnRecorderStateChange(CameraControlListener::RecorderState aState,
|
|
|
|
int32_t aArg, int32_t aTrackNum)
|
2012-12-23 07:54:54 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
// For now, we do nothing with 'aStatus' and 'aTrackNum'.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-12-23 07:54:54 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
ErrorResult ignored;
|
|
|
|
nsString state;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
switch (aState) {
|
|
|
|
case CameraControlListener::kRecorderStarted:
|
|
|
|
if (mStartRecordingOnSuccessCb) {
|
|
|
|
nsCOMPtr<CameraStartRecordingCallback> cb = mStartRecordingOnSuccessCb.forget();
|
|
|
|
mStartRecordingOnErrorCb = nullptr;
|
|
|
|
cb->Call(ignored);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2014-02-26 15:07:11 -08:00
|
|
|
state = NS_LITERAL_STRING("Started");
|
|
|
|
break;
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
case CameraControlListener::kRecorderStopped:
|
|
|
|
NotifyRecordingStatusChange(NS_LITERAL_STRING("shutdown"));
|
2014-02-26 15:07:11 -08:00
|
|
|
state = NS_LITERAL_STRING("Stopped");
|
|
|
|
break;
|
2014-02-14 14:41:07 -08: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:
|
|
|
|
MOZ_ASSUME_UNREACHABLE("Unanticipated video recorder error");
|
|
|
|
return;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
|
|
|
|
if (cb) {
|
|
|
|
cb->Call(state, ignored);
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnConfigurationChange(DOMCameraConfiguration* aConfiguration)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
|
|
|
|
nsCOMPtr<CameraSetConfigurationCallback> cb = mSetConfigurationOnSuccessCb.forget();
|
|
|
|
mSetConfigurationOnErrorCb = nullptr;
|
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(*mCurrentConfiguration, ignored);
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2012-09-30 17:37:47 -07:00
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl::OnAutoFocusComplete(bool aAutoFocusSucceeded)
|
2012-09-30 17:37:47 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
|
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
2014-02-25 14:01:29 -08:00
|
|
|
if (cb) {
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(aAutoFocusSucceeded, ignored);
|
|
|
|
}
|
2012-09-30 17:37:47 -07:00
|
|
|
}
|
2013-05-02 04:59:58 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
|
2013-05-02 04:59:58 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb.forget();
|
|
|
|
mTakePictureOnErrorCb = nullptr;
|
2014-02-25 14:01:29 -08:00
|
|
|
if (!cb) {
|
|
|
|
// Warn because it shouldn't be possible to get here without
|
|
|
|
// having passed a success callback into takePicture(), even
|
|
|
|
// though we guard against a nullptr dereference.
|
|
|
|
NS_WARNING("DOM Null success callback in OnTakePictureComplete()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult ignored;
|
2014-02-14 14:41:07 -08:00
|
|
|
cb->Call(aPicture, ignored);
|
2013-05-02 04:59:58 -07:00
|
|
|
}
|
2013-10-23 04:11:18 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
|
|
|
nsDOMCameraControl::OnError(CameraControlListener::CameraErrorContext aContext, const nsAString& aError)
|
2013-10-23 04:11:18 -07:00
|
|
|
{
|
2014-02-24 10:01:21 -08:00
|
|
|
DOM_CAMERA_LOGI("DOM OnError context=%d, error='%s'\n", aContext,
|
|
|
|
NS_LossyConvertUTF16toASCII(aError).get());
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<CameraErrorCallback>* errorCb;
|
|
|
|
switch (aContext) {
|
2014-02-19 20:18:52 -08:00
|
|
|
case CameraControlListener::kInStartCamera:
|
2014-02-14 14:41:07 -08:00
|
|
|
mGetCameraOnSuccessCb = nullptr;
|
|
|
|
errorCb = &mGetCameraOnErrorCb;
|
|
|
|
break;
|
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
case CameraControlListener::kInStopCamera:
|
|
|
|
mReleaseOnSuccessCb = nullptr;
|
|
|
|
errorCb = &mReleaseOnErrorCb;
|
|
|
|
break;
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
case CameraControlListener::kInSetConfiguration:
|
|
|
|
mSetConfigurationOnSuccessCb = nullptr;
|
|
|
|
errorCb = &mSetConfigurationOnErrorCb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInAutoFocus:
|
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
|
|
|
errorCb = &mAutoFocusOnErrorCb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInTakePicture:
|
|
|
|
mTakePictureOnSuccessCb = nullptr;
|
|
|
|
errorCb = &mTakePictureOnErrorCb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInStartRecording:
|
|
|
|
mStartRecordingOnSuccessCb = nullptr;
|
|
|
|
errorCb = &mStartRecordingOnErrorCb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CameraControlListener::kInStopRecording:
|
2014-02-24 10:01:21 -08: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-14 14:41:07 -08:00
|
|
|
|
|
|
|
case CameraControlListener::kInStartPreview:
|
2014-02-24 10:01:21 -08: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-14 14:41:07 -08:00
|
|
|
|
|
|
|
case CameraControlListener::kInUnspecified:
|
|
|
|
if (aError.EqualsASCII("ErrorServiceFailed")) {
|
|
|
|
// If the camera service fails, we will get preview-stopped and
|
2014-02-24 10:01:21 -08:00
|
|
|
// hardware-closed events, so nothing to do here.
|
|
|
|
NS_WARNING("Camera service failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aError.EqualsASCII("ErrorSetPictureSizeFailed") ||
|
|
|
|
aError.EqualsASCII("ErrorSetThumbnailSizeFailed")) {
|
|
|
|
// We currently don't handle attribute setter failure. Practically,
|
|
|
|
// this only ever happens if a setter is called after the hardware
|
|
|
|
// has gone away before an asynchronous set gets to happen, so we
|
|
|
|
// swallow these.
|
|
|
|
NS_WARNING("Failed to set either picture or thumbnail size");
|
2014-02-14 14:41:07 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSUME_UNREACHABLE("Error occurred in unanticipated camera state");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(errorCb);
|
|
|
|
|
|
|
|
if (!*errorCb) {
|
2014-02-24 10:01:21 -08:00
|
|
|
DOM_CAMERA_LOGW("DOM No error handler for error '%s' in context=%d\n",
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_LossyConvertUTF16toASCII(aError).get(), aContext);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// kung-fu death grip
|
|
|
|
nsCOMPtr<CameraErrorCallback> cb = (*errorCb).forget();
|
|
|
|
ErrorResult ignored;
|
|
|
|
cb->Call(aError, ignored);
|
2013-10-23 04:11:18 -07:00
|
|
|
}
|
2013-11-25 22:22:22 -08:00
|
|
|
|