2012-07-30 21:59:05 +00: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/. */
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
#ifndef DOM_CAMERA_CAMERACONTROLIMPL_H
|
|
|
|
#define DOM_CAMERA_CAMERACONTROLIMPL_H
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "nsDOMFile.h"
|
2013-01-08 23:43:50 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "DictionaryHelpers.h"
|
2012-09-29 05:30:52 +00:00
|
|
|
#include "nsIDOMDeviceStorage.h"
|
2012-10-01 00:37:47 +00:00
|
|
|
#include "DOMCameraManager.h"
|
2012-10-23 22:30:28 +00:00
|
|
|
#include "DOMCameraPreview.h"
|
2012-09-05 01:01:56 +00:00
|
|
|
#include "ICameraControl.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "CameraCommon.h"
|
2014-01-17 01:01:43 +00:00
|
|
|
#include "DeviceStorage.h"
|
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
|
|
|
|
|
|
|
class DeviceStorageFileDescriptor;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class GetPreviewStreamTask;
|
2012-09-05 01:01:56 +00:00
|
|
|
class StartPreviewTask;
|
|
|
|
class StopPreviewTask;
|
2012-07-30 21:59:05 +00:00
|
|
|
class AutoFocusTask;
|
|
|
|
class TakePictureTask;
|
|
|
|
class StartRecordingTask;
|
|
|
|
class StopRecordingTask;
|
|
|
|
class SetParameterTask;
|
|
|
|
class GetParameterTask;
|
2012-09-29 05:30:52 +00:00
|
|
|
class GetPreviewStreamVideoModeTask;
|
2012-12-23 15:54:54 +00:00
|
|
|
class ReleaseHardwareTask;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
class DOMCameraPreview;
|
2012-10-23 22:30:28 +00:00
|
|
|
class RecorderProfileManager;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
class CameraControlImpl : public ICameraControl
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
friend class GetPreviewStreamTask;
|
2012-09-05 01:01:56 +00:00
|
|
|
friend class StartPreviewTask;
|
|
|
|
friend class StopPreviewTask;
|
2012-07-30 21:59:05 +00:00
|
|
|
friend class AutoFocusTask;
|
|
|
|
friend class TakePictureTask;
|
|
|
|
friend class StartRecordingTask;
|
|
|
|
friend class StopRecordingTask;
|
|
|
|
friend class SetParameterTask;
|
|
|
|
friend class GetParameterTask;
|
2012-09-29 05:30:52 +00:00
|
|
|
friend class GetPreviewStreamVideoModeTask;
|
2012-12-23 15:54:54 +00:00
|
|
|
friend class ReleaseHardwareTask;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
public:
|
2012-10-23 22:30:28 +00:00
|
|
|
CameraControlImpl(uint32_t aCameraId, nsIThread* aCameraThread, uint64_t aWindowId);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-02-11 19:37:50 +00:00
|
|
|
nsresult GetPreviewStream(idl::CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError);
|
2012-09-05 01:01:56 +00:00
|
|
|
nsresult StartPreview(DOMCameraPreview* aDOMPreview);
|
|
|
|
void StopPreview();
|
|
|
|
nsresult AutoFocus(nsICameraAutoFocusCallback* onSuccess, nsICameraErrorCallback* onError);
|
2013-10-30 19:41:08 +00:00
|
|
|
nsresult TakePicture(const idl::CameraSize& aSize, int32_t aRotation, const nsAString& aFileFormat, idl::CameraPosition aPosition, uint64_t aDateTime, nsICameraTakePictureCallback* onSuccess, nsICameraErrorCallback* onError);
|
2014-01-17 01:01:43 +00:00
|
|
|
nsresult StartRecording(idl::CameraStartRecordingOptions* aOptions, DeviceStorageFileDescriptor *aDSFileDescriptor, nsICameraStartRecordingCallback* onSuccess, nsICameraErrorCallback* onError);
|
2012-09-05 01:01:56 +00:00
|
|
|
nsresult StopRecording();
|
2013-10-21 22:38:50 +00:00
|
|
|
nsresult GetPreviewStreamVideoMode(idl::CameraRecorderOptions* aOptions, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError);
|
2012-12-23 15:54:54 +00:00
|
|
|
nsresult ReleaseHardware(nsICameraReleaseCallback* onSuccess, nsICameraErrorCallback* onError);
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
nsresult Set(uint32_t aKey, const nsAString& aValue);
|
|
|
|
nsresult Get(uint32_t aKey, nsAString& aValue);
|
|
|
|
nsresult Set(uint32_t aKey, double aValue);
|
|
|
|
nsresult Get(uint32_t aKey, double* aValue);
|
|
|
|
nsresult Set(JSContext* aCx, uint32_t aKey, const JS::Value& aValue, uint32_t aLimit);
|
|
|
|
nsresult Get(JSContext* aCx, uint32_t aKey, JS::Value* aValue);
|
2012-10-01 00:37:47 +00:00
|
|
|
nsresult Set(nsICameraShutterCallback* aOnShutter);
|
|
|
|
nsresult Get(nsICameraShutterCallback** aOnShutter);
|
|
|
|
nsresult Set(nsICameraClosedCallback* aOnClosed);
|
|
|
|
nsresult Get(nsICameraClosedCallback** aOnClosed);
|
2012-11-02 20:11:50 +00:00
|
|
|
nsresult Set(nsICameraRecorderStateChange* aOnRecorderStateChange);
|
|
|
|
nsresult Get(nsICameraRecorderStateChange** aOnRecorderStateChange);
|
2013-08-05 20:24:43 +00:00
|
|
|
nsresult Set(nsICameraPreviewStateChange* aOnPreviewStateChange);
|
|
|
|
nsresult Get(nsICameraPreviewStateChange** aOnPreviewStateChange);
|
2013-10-30 19:41:08 +00:00
|
|
|
nsresult Set(uint32_t aKey, const idl::CameraSize& aSize);
|
|
|
|
nsresult Get(uint32_t aKey, idl::CameraSize& aSize);
|
2013-12-06 14:47:29 +00:00
|
|
|
nsresult Get(uint32_t aKey, int32_t* aValue);
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
nsresult SetFocusAreas(JSContext* aCx, const JS::Value& aValue)
|
|
|
|
{
|
|
|
|
return Set(aCx, CAMERA_PARAM_FOCUSAREAS, aValue, mMaxFocusAreas);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsresult SetMeteringAreas(JSContext* aCx, const JS::Value& aValue)
|
|
|
|
{
|
|
|
|
return Set(aCx, CAMERA_PARAM_METERINGAREAS, aValue, mMaxMeteringAreas);
|
|
|
|
}
|
|
|
|
|
2012-10-23 22:30:28 +00:00
|
|
|
already_AddRefed<RecorderProfileManager> GetRecorderProfileManager();
|
|
|
|
uint32_t GetCameraId() { return mCameraId; }
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual const char* GetParameter(const char* aKey) = 0;
|
|
|
|
virtual const char* GetParameterConstChar(uint32_t aKey) = 0;
|
|
|
|
virtual double GetParameterDouble(uint32_t aKey) = 0;
|
2013-12-06 14:47:29 +00:00
|
|
|
virtual int32_t GetParameterInt32(uint32_t aKey) = 0;
|
2013-02-11 19:37:50 +00:00
|
|
|
virtual void GetParameter(uint32_t aKey, nsTArray<idl::CameraRegion>& aRegions) = 0;
|
2013-10-30 19:41:08 +00:00
|
|
|
virtual void GetParameter(uint32_t aKey, idl::CameraSize& aSize) = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual void SetParameter(const char* aKey, const char* aValue) = 0;
|
|
|
|
virtual void SetParameter(uint32_t aKey, const char* aValue) = 0;
|
|
|
|
virtual void SetParameter(uint32_t aKey, double aValue) = 0;
|
2013-02-11 19:37:50 +00:00
|
|
|
virtual void SetParameter(uint32_t aKey, const nsTArray<idl::CameraRegion>& aRegions) = 0;
|
2013-10-30 19:41:08 +00:00
|
|
|
virtual void SetParameter(uint32_t aKey, const idl::CameraSize& aSize) = 0;
|
2013-02-11 19:37:50 +00:00
|
|
|
virtual nsresult GetVideoSizes(nsTArray<idl::CameraSize>& aVideoSizes) = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual nsresult PushParameters() = 0;
|
2012-10-01 00:37:47 +00:00
|
|
|
virtual void Shutdown();
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-09-07 20:23:01 +00:00
|
|
|
bool ReceiveFrame(void* aBuffer, ImageFormat aFormat, FrameBuilder aBuilder);
|
2012-10-01 00:37:47 +00:00
|
|
|
void OnShutter();
|
|
|
|
void OnClosed();
|
2012-11-02 20:11:50 +00:00
|
|
|
void OnRecorderStateChange(const nsString& aStateMsg, int32_t aStatus, int32_t aTrackNumber);
|
2012-10-01 00:37:47 +00:00
|
|
|
|
2013-08-05 20:24:43 +00:00
|
|
|
enum PreviewState {
|
|
|
|
PREVIEW_STOPPED,
|
|
|
|
PREVIEW_STARTED
|
|
|
|
};
|
|
|
|
void OnPreviewStateChange(PreviewState aNewState);
|
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
uint64_t GetWindowId()
|
|
|
|
{
|
|
|
|
return mWindowId;
|
|
|
|
}
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
protected:
|
2012-10-23 22:30:28 +00:00
|
|
|
virtual ~CameraControlImpl();
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
virtual nsresult GetPreviewStreamImpl(GetPreviewStreamTask* aGetPreviewStream) = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual nsresult StartPreviewImpl(StartPreviewTask* aStartPreview) = 0;
|
|
|
|
virtual nsresult StopPreviewImpl(StopPreviewTask* aStopPreview) = 0;
|
2012-07-30 21:59:05 +00:00
|
|
|
virtual nsresult AutoFocusImpl(AutoFocusTask* aAutoFocus) = 0;
|
|
|
|
virtual nsresult TakePictureImpl(TakePictureTask* aTakePicture) = 0;
|
|
|
|
virtual nsresult StartRecordingImpl(StartRecordingTask* aStartRecording) = 0;
|
|
|
|
virtual nsresult StopRecordingImpl(StopRecordingTask* aStopRecording) = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual nsresult PushParametersImpl() = 0;
|
|
|
|
virtual nsresult PullParametersImpl() = 0;
|
2012-09-29 05:30:52 +00:00
|
|
|
virtual nsresult GetPreviewStreamVideoModeImpl(GetPreviewStreamVideoModeTask* aGetPreviewStreamVideoMode) = 0;
|
2012-12-23 15:54:54 +00:00
|
|
|
virtual nsresult ReleaseHardwareImpl(ReleaseHardwareTask* aReleaseHardware) = 0;
|
2012-10-23 22:30:28 +00:00
|
|
|
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
void OnShutterInternal();
|
|
|
|
void OnClosedInternal();
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
uint32_t mCameraId;
|
|
|
|
nsCOMPtr<nsIThread> mCameraThread;
|
2012-10-01 00:37:47 +00:00
|
|
|
uint64_t mWindowId;
|
2012-09-05 01:01:56 +00:00
|
|
|
nsString mFileFormat;
|
|
|
|
uint32_t mMaxMeteringAreas;
|
|
|
|
uint32_t mMaxFocusAreas;
|
2013-08-05 20:24:43 +00:00
|
|
|
PreviewState mPreviewState;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 'mDOMPreview' is a raw pointer to the object that will receive incoming
|
|
|
|
* preview frames. This is guaranteed to be valid, or null.
|
|
|
|
*
|
|
|
|
* It is set by a call to StartPreview(), and set to null on StopPreview().
|
|
|
|
* It is up to the caller to ensure that the object will not disappear
|
|
|
|
* out from under this pointer--usually by calling NS_ADDREF().
|
|
|
|
*/
|
|
|
|
DOMCameraPreview* mDOMPreview;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraAutoFocusCallback> mAutoFocusOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mAutoFocusOnErrorCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraTakePictureCallback> mTakePictureOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mTakePictureOnErrorCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraShutterCallback> mOnShutterCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraClosedCallback> mOnClosedCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraRecorderStateChange> mOnRecorderStateChangeCb;
|
2013-08-05 20:24:43 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraPreviewStateChange> mOnPreviewStateChangeCb;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CameraControlImpl(const CameraControlImpl&) MOZ_DELETE;
|
|
|
|
CameraControlImpl& operator=(const CameraControlImpl&) MOZ_DELETE;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
// Error result runnable
|
|
|
|
class CameraErrorResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
CameraErrorResult(nsMainThreadPtrHandle<nsICameraErrorCallback> onError, const nsString& aErrorMsg, uint64_t aWindowId)
|
2013-01-09 15:39:37 +00:00
|
|
|
: mOnErrorCb(onError)
|
2012-10-01 00:37:47 +00:00
|
|
|
, mErrorMsg(aErrorMsg)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{ }
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-10-01 00:37:47 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-01-08 23:43:50 +00:00
|
|
|
if (mOnErrorCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
2012-10-01 00:37:47 +00:00
|
|
|
mOnErrorCb->HandleEvent(mErrorMsg);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-10-01 00:37:47 +00:00
|
|
|
const nsString mErrorMsg;
|
|
|
|
uint64_t mWindowId;
|
|
|
|
};
|
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
// Return the resulting preview stream to JS. Runs on the main thread.
|
|
|
|
class GetPreviewStreamResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
GetPreviewStreamResult(CameraControlImpl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint32_t aFramesPerSecond, nsMainThreadPtrHandle<nsICameraPreviewStreamCallback>& onSuccess, uint64_t aWindowId)
|
2012-09-05 01:01:56 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mWidth(aWidth)
|
|
|
|
, mHeight(aHeight)
|
|
|
|
, mFramesPerSecond(aFramesPerSecond)
|
2012-07-30 21:59:05 +00:00
|
|
|
, mOnSuccessCb(onSuccess)
|
2012-10-01 00:37:47 +00:00
|
|
|
, mWindowId(aWindowId)
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual ~GetPreviewStreamResult()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
// Run() method is implementation specific.
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
protected:
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
|
|
|
uint32_t mFramesPerSecond;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraPreviewStreamCallback> mOnSuccessCb;
|
2012-10-01 00:37:47 +00:00
|
|
|
uint64_t mWindowId;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Get the desired preview stream.
|
|
|
|
class GetPreviewStreamTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-02-11 19:37:50 +00:00
|
|
|
GetPreviewStreamTask(CameraControlImpl* aCameraControl, idl::CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mSize(aSize)
|
|
|
|
, mCameraControl(aCameraControl)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mOnSuccessCb(new nsMainThreadPtrHolder<nsICameraPreviewStreamCallback>(onSuccess))
|
|
|
|
, mOnErrorCb(new nsMainThreadPtrHolder<nsICameraErrorCallback>(onError))
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GetPreviewStreamTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
nsresult rv = mCameraControl->GetPreviewStreamImpl(this);
|
|
|
|
|
2013-01-15 15:57:22 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCOMPtr<nsIRunnable> cameraErrorResult = new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId());
|
|
|
|
rv = NS_DispatchToMainThread(cameraErrorResult);
|
2012-07-30 21:59:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-02-11 19:37:50 +00:00
|
|
|
idl::CameraSize mSize;
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraPreviewStreamCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return the autofocus status to JS. Runs on the main thread.
|
|
|
|
class AutoFocusResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
AutoFocusResult(bool aSuccess, nsMainThreadPtrHandle<nsICameraAutoFocusCallback> onSuccess, uint64_t aWindowId)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mSuccess(aSuccess)
|
2013-01-09 15:39:37 +00:00
|
|
|
, mOnSuccessCb(onSuccess)
|
2012-10-01 00:37:47 +00:00
|
|
|
, mWindowId(aWindowId)
|
2012-07-30 21:59:05 +00:00
|
|
|
{ }
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual ~AutoFocusResult() { }
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-01-08 23:43:50 +00:00
|
|
|
if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
2012-07-30 21:59:05 +00:00
|
|
|
mOnSuccessCb->HandleEvent(mSuccess);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool mSuccess;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraAutoFocusCallback> mOnSuccessCb;
|
2012-10-01 00:37:47 +00:00
|
|
|
uint64_t mWindowId;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Autofocus the camera.
|
|
|
|
class AutoFocusTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
AutoFocusTask(CameraControlImpl* aCameraControl, bool aCancel, nsICameraAutoFocusCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mCancel(aCancel)
|
|
|
|
, mOnSuccessCb(new nsMainThreadPtrHolder<nsICameraAutoFocusCallback>(onSuccess))
|
|
|
|
, mOnErrorCb(new nsMainThreadPtrHolder<nsICameraErrorCallback>(onError))
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~AutoFocusTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
nsresult rv = mCameraControl->AutoFocusImpl(this);
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-01-15 15:57:22 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCOMPtr<nsIRunnable> cameraErrorResult = new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId());
|
|
|
|
rv = NS_DispatchToMainThread(cameraErrorResult);
|
2012-07-30 21:59:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2013-01-08 23:43:50 +00:00
|
|
|
bool mCancel;
|
|
|
|
nsMainThreadPtrHandle<nsICameraAutoFocusCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return the captured picture to JS. Runs on the main thread.
|
|
|
|
class TakePictureResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
TakePictureResult(uint8_t* aData, uint64_t aLength, const nsAString& aMimeType, nsMainThreadPtrHandle<nsICameraTakePictureCallback> onSuccess, uint64_t aWindowId)
|
|
|
|
: mData(aData)
|
|
|
|
, mLength(aLength)
|
|
|
|
, mMimeType(aMimeType)
|
2013-01-09 15:39:37 +00:00
|
|
|
, mOnSuccessCb(onSuccess)
|
2012-10-01 00:37:47 +00:00
|
|
|
, mWindowId(aWindowId)
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~TakePictureResult()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2013-01-08 23:43:50 +00:00
|
|
|
if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
|
|
|
nsCOMPtr<nsIDOMBlob> image = new nsDOMMemoryFile(static_cast<void*>(mData), static_cast<uint64_t>(mLength), mMimeType);
|
|
|
|
mOnSuccessCb->HandleEvent(image);
|
|
|
|
} else {
|
|
|
|
delete[] mData;
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2012-07-30 21:59:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-08 23:43:50 +00:00
|
|
|
uint8_t* mData;
|
|
|
|
uint64_t mLength;
|
|
|
|
nsString mMimeType;
|
|
|
|
nsMainThreadPtrHandle<nsICameraTakePictureCallback> mOnSuccessCb;
|
2012-10-01 00:37:47 +00:00
|
|
|
uint64_t mWindowId;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Capture a still image with the camera.
|
|
|
|
class TakePictureTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-10-30 19:41:08 +00:00
|
|
|
TakePictureTask(CameraControlImpl* aCameraControl, bool aCancel, const idl::CameraSize& aSize, int32_t aRotation, const nsAString& aFileFormat, idl::CameraPosition aPosition, uint64_t aDateTime, nsICameraTakePictureCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mCancel(aCancel)
|
2012-07-30 21:59:05 +00:00
|
|
|
, mSize(aSize)
|
|
|
|
, mRotation(aRotation)
|
|
|
|
, mFileFormat(aFileFormat)
|
|
|
|
, mPosition(aPosition)
|
2013-01-18 21:06:28 +00:00
|
|
|
, mDateTime(aDateTime)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mOnSuccessCb(new nsMainThreadPtrHolder<nsICameraTakePictureCallback>(onSuccess))
|
|
|
|
, mOnErrorCb(new nsMainThreadPtrHolder<nsICameraErrorCallback>(onError))
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~TakePictureTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
nsresult rv = mCameraControl->TakePictureImpl(this);
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-01-15 15:57:22 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCOMPtr<nsIRunnable> cameraErrorResult = new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId());
|
|
|
|
rv = NS_DispatchToMainThread(cameraErrorResult);
|
2012-07-30 21:59:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2013-01-08 23:43:50 +00:00
|
|
|
bool mCancel;
|
2013-02-11 19:37:50 +00:00
|
|
|
idl::CameraSize mSize;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRotation;
|
2012-07-30 21:59:05 +00:00
|
|
|
nsString mFileFormat;
|
2013-02-11 19:37:50 +00:00
|
|
|
idl::CameraPosition mPosition;
|
2013-01-18 21:06:28 +00:00
|
|
|
uint64_t mDateTime;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraTakePictureCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
2012-10-23 22:30:28 +00:00
|
|
|
// Return the result of starting recording. Runs on the main thread.
|
2012-07-30 21:59:05 +00:00
|
|
|
class StartRecordingResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
StartRecordingResult(nsMainThreadPtrHandle<nsICameraStartRecordingCallback> onSuccess, uint64_t aWindowId)
|
2013-01-09 15:39:37 +00:00
|
|
|
: mOnSuccessCb(onSuccess)
|
2012-10-01 00:37:47 +00:00
|
|
|
, mWindowId(aWindowId)
|
2012-07-30 21:59:05 +00:00
|
|
|
{ }
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual ~StartRecordingResult() { }
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-01-08 23:43:50 +00:00
|
|
|
if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
2012-09-29 05:30:52 +00:00
|
|
|
mOnSuccessCb->HandleEvent();
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraStartRecordingCallback> mOnSuccessCb;
|
2012-10-01 00:37:47 +00:00
|
|
|
uint64_t mWindowId;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Start video recording.
|
|
|
|
class StartRecordingTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2014-01-17 01:01:43 +00:00
|
|
|
StartRecordingTask(CameraControlImpl* aCameraControl,
|
|
|
|
idl::CameraStartRecordingOptions aOptions,
|
|
|
|
DeviceStorageFileDescriptor *aDSFileDescriptor,
|
|
|
|
nsICameraStartRecordingCallback* onSuccess,
|
|
|
|
nsICameraErrorCallback* onError,
|
|
|
|
uint64_t aWindowId)
|
2012-09-29 05:30:52 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
2013-10-21 22:38:50 +00:00
|
|
|
, mOptions(aOptions)
|
2014-01-17 01:01:43 +00:00
|
|
|
, mDSFileDescriptor(aDSFileDescriptor)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mOnSuccessCb(new nsMainThreadPtrHolder<nsICameraStartRecordingCallback>(onSuccess))
|
|
|
|
, mOnErrorCb(new nsMainThreadPtrHolder<nsICameraErrorCallback>(onError))
|
2012-10-23 22:30:28 +00:00
|
|
|
, mWindowId(aWindowId)
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~StartRecordingTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
nsresult rv = mCameraControl->StartRecordingImpl(this);
|
2012-09-29 05:30:52 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : result %d\n", __func__, __LINE__, rv);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-10-23 22:30:28 +00:00
|
|
|
// dispatch the callback
|
|
|
|
nsCOMPtr<nsIRunnable> startRecordingResult;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
startRecordingResult = new StartRecordingResult(mOnSuccessCb, mWindowId);
|
|
|
|
} else {
|
|
|
|
startRecordingResult = new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mWindowId);
|
|
|
|
}
|
|
|
|
rv = NS_DispatchToMainThread(startRecordingResult);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to dispatch start recording result to main thread (%d)!", rv);
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2013-10-21 22:38:50 +00:00
|
|
|
idl::CameraStartRecordingOptions mOptions;
|
2014-01-17 01:01:43 +00:00
|
|
|
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraStartRecordingCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-10-23 22:30:28 +00:00
|
|
|
uint64_t mWindowId;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Stop video recording.
|
|
|
|
class StopRecordingTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-05 01:01:56 +00:00
|
|
|
StopRecordingTask(CameraControlImpl* aCameraControl)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~StopRecordingTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
nsresult rv = mCameraControl->StopRecordingImpl(this);
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
// Start the preview.
|
|
|
|
class StartPreviewTask : public nsRunnable
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-09-05 01:01:56 +00:00
|
|
|
StartPreviewTask(CameraControlImpl* aCameraControl, DOMCameraPreview* aDOMPreview)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
2012-09-05 01:01:56 +00:00
|
|
|
, mDOMPreview(aDOMPreview)
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~StartPreviewTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
nsresult rv = mCameraControl->StartPreviewImpl(this);
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
|
|
|
DOMCameraPreview* mDOMPreview; // DOMCameraPreview NS_ADDREFs itself for us
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
// Stop the preview.
|
|
|
|
class StopPreviewTask : public nsRunnable
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-09-05 01:01:56 +00:00
|
|
|
StopPreviewTask(CameraControlImpl* aCameraControl)
|
2012-07-30 21:59:05 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
2012-09-05 01:01:56 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~StopPreviewTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
mCameraControl->StopPreviewImpl(this);
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
2012-09-29 05:30:52 +00:00
|
|
|
// Get the video mode preview stream.
|
|
|
|
class GetPreviewStreamVideoModeTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-10-21 22:38:50 +00:00
|
|
|
GetPreviewStreamVideoModeTask(CameraControlImpl* aCameraControl, idl::CameraRecorderOptions aOptions, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-09-29 05:30:52 +00:00
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mOptions(aOptions)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mOnSuccessCb(new nsMainThreadPtrHolder<nsICameraPreviewStreamCallback>(onSuccess))
|
|
|
|
, mOnErrorCb(new nsMainThreadPtrHolder<nsICameraErrorCallback>(onError))
|
2012-09-29 05:30:52 +00:00
|
|
|
{ }
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-09-29 05:30:52 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI("%s:%d -- BEFORE IMPL\n", __func__, __LINE__);
|
|
|
|
nsresult rv = mCameraControl->GetPreviewStreamVideoModeImpl(this);
|
|
|
|
DOM_CAMERA_LOGI("%s:%d -- AFTER IMPL : rv = %d\n", __func__, __LINE__, rv);
|
|
|
|
|
2013-01-15 15:57:22 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCOMPtr<nsIRunnable> cameraErrorResult = new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId());
|
|
|
|
rv = NS_DispatchToMainThread(cameraErrorResult);
|
2012-09-29 05:30:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2013-10-21 22:38:50 +00:00
|
|
|
idl::CameraRecorderOptions mOptions;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraPreviewStreamCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-09-29 05:30:52 +00:00
|
|
|
};
|
|
|
|
|
2012-12-23 15:54:54 +00:00
|
|
|
// Return the result of releasing the camera hardware. Runs on the main thread.
|
|
|
|
class ReleaseHardwareResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
ReleaseHardwareResult(nsMainThreadPtrHandle<nsICameraReleaseCallback> onSuccess, uint64_t aWindowId)
|
2013-01-09 15:39:37 +00:00
|
|
|
: mOnSuccessCb(onSuccess)
|
2012-12-23 15:54:54 +00:00
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ReleaseHardwareResult()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-12-23 15:54:54 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-01-08 23:43:50 +00:00
|
|
|
if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
2012-12-23 15:54:54 +00:00
|
|
|
mOnSuccessCb->HandleEvent();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraReleaseCallback> mOnSuccessCb;
|
2012-12-23 15:54:54 +00:00
|
|
|
uint64_t mWindowId;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Release the camera hardware.
|
|
|
|
class ReleaseHardwareTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReleaseHardwareTask(CameraControlImpl* aCameraControl, nsICameraReleaseCallback* onSuccess, nsICameraErrorCallback* onError)
|
|
|
|
: mCameraControl(aCameraControl)
|
2013-01-08 23:43:50 +00:00
|
|
|
, mOnSuccessCb(new nsMainThreadPtrHolder<nsICameraReleaseCallback>(onSuccess))
|
|
|
|
, mOnErrorCb(new nsMainThreadPtrHolder<nsICameraErrorCallback>(onError))
|
2012-12-23 15:54:54 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ReleaseHardwareTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-12-23 15:54:54 +00:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
nsresult rv = mCameraControl->ReleaseHardwareImpl(this);
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
|
2013-01-15 15:57:22 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCOMPtr<nsIRunnable> cameraErrorResult = new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId());
|
|
|
|
rv = NS_DispatchToMainThread(cameraErrorResult);
|
2012-12-23 15:54:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraReleaseCallback> mOnSuccessCb;
|
|
|
|
nsMainThreadPtrHandle<nsICameraErrorCallback> mOnErrorCb;
|
2012-12-23 15:54:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Report that the video recorder state has changed.
|
2012-11-02 20:11:50 +00:00
|
|
|
class CameraRecorderStateChange : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-08 23:43:50 +00:00
|
|
|
CameraRecorderStateChange(nsMainThreadPtrHandle<nsICameraRecorderStateChange> onStateChange, const nsString& aStateMsg, int32_t aStatus, int32_t aTrackNumber, uint64_t aWindowId)
|
2013-01-09 15:39:37 +00:00
|
|
|
: mOnStateChangeCb(onStateChange)
|
2012-11-02 20:11:50 +00:00
|
|
|
, mStateMsg(aStateMsg)
|
|
|
|
, mStatus(aStatus)
|
|
|
|
, mTrackNumber(aTrackNumber)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{ }
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-11-02 20:11:50 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-01-08 23:43:50 +00:00
|
|
|
if (mOnStateChangeCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
2012-11-02 20:11:50 +00:00
|
|
|
// For now, just pass the state message and swallow mStatus and mTrackNumber
|
|
|
|
mOnStateChangeCb->HandleStateChange(mStateMsg);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-08 23:43:50 +00:00
|
|
|
nsMainThreadPtrHandle<nsICameraRecorderStateChange> mOnStateChangeCb;
|
2012-11-02 20:11:50 +00:00
|
|
|
const nsString mStateMsg;
|
|
|
|
int32_t mStatus;
|
|
|
|
int32_t mTrackNumber;
|
|
|
|
uint64_t mWindowId;
|
|
|
|
};
|
|
|
|
|
2013-08-05 20:24:43 +00:00
|
|
|
// Report that the preview stream state has changed.
|
|
|
|
class CameraPreviewStateChange : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CameraPreviewStateChange(nsMainThreadPtrHandle<nsICameraPreviewStateChange> onStateChange, const nsString& aStateMsg, uint64_t aWindowId)
|
|
|
|
: mOnStateChangeCb(onStateChange)
|
|
|
|
, mStateMsg(aStateMsg)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mOnStateChangeCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
|
|
|
mOnStateChangeCb->HandleStateChange(mStateMsg);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsMainThreadPtrHandle<nsICameraPreviewStateChange> mOnStateChangeCb;
|
|
|
|
const nsString mStateMsg;
|
|
|
|
uint64_t mWindowId;
|
|
|
|
};
|
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
#endif // DOM_CAMERA_CAMERACONTROLIMPL_H
|