2012-07-30 14:59:05 -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/. */
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#ifndef DOM_CAMERA_CAMERACONTROLIMPL_H
|
|
|
|
#define DOM_CAMERA_CAMERACONTROLIMPL_H
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMFile.h"
|
|
|
|
#include "DictionaryHelpers.h"
|
|
|
|
#include "nsIDOMCameraManager.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "ICameraControl.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "CameraCommon.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace dom;
|
|
|
|
|
|
|
|
class GetPreviewStreamTask;
|
2012-09-04 18:01:56 -07:00
|
|
|
class StartPreviewTask;
|
|
|
|
class StopPreviewTask;
|
2012-07-30 14:59:05 -07:00
|
|
|
class AutoFocusTask;
|
|
|
|
class TakePictureTask;
|
|
|
|
class StartRecordingTask;
|
|
|
|
class StopRecordingTask;
|
|
|
|
class SetParameterTask;
|
|
|
|
class GetParameterTask;
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
class DOMCameraPreview;
|
|
|
|
|
|
|
|
class CameraControlImpl : public ICameraControl
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
friend class GetPreviewStreamTask;
|
2012-09-04 18:01:56 -07:00
|
|
|
friend class StartPreviewTask;
|
|
|
|
friend class StopPreviewTask;
|
2012-07-30 14:59:05 -07:00
|
|
|
friend class AutoFocusTask;
|
|
|
|
friend class TakePictureTask;
|
|
|
|
friend class StartRecordingTask;
|
|
|
|
friend class StopRecordingTask;
|
|
|
|
friend class SetParameterTask;
|
|
|
|
friend class GetParameterTask;
|
|
|
|
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
CameraControlImpl(uint32_t aCameraId, nsIThread* aCameraThread)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mCameraId(aCameraId)
|
|
|
|
, mCameraThread(aCameraThread)
|
|
|
|
, mFileFormat()
|
|
|
|
, mMaxMeteringAreas(0)
|
|
|
|
, mMaxFocusAreas(0)
|
2012-09-04 18:01:56 -07:00
|
|
|
, mDOMPreview(nullptr)
|
2012-07-30 14:59:05 -07:00
|
|
|
, mAutoFocusOnSuccessCb(nullptr)
|
|
|
|
, mAutoFocusOnErrorCb(nullptr)
|
|
|
|
, mTakePictureOnSuccessCb(nullptr)
|
|
|
|
, mTakePictureOnErrorCb(nullptr)
|
|
|
|
, mStartRecordingOnSuccessCb(nullptr)
|
|
|
|
, mStartRecordingOnErrorCb(nullptr)
|
|
|
|
, mOnShutterCb(nullptr)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsresult GetPreviewStream(CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError);
|
|
|
|
nsresult StartPreview(DOMCameraPreview* aDOMPreview);
|
|
|
|
void StopPreview();
|
|
|
|
nsresult AutoFocus(nsICameraAutoFocusCallback* onSuccess, nsICameraErrorCallback* onError);
|
|
|
|
nsresult TakePicture(CameraSize aSize, int32_t aRotation, const nsAString& aFileFormat, CameraPosition aPosition, nsICameraTakePictureCallback* onSuccess, nsICameraErrorCallback* onError);
|
|
|
|
nsresult StartRecording(CameraSize aSize, nsICameraStartRecordingCallback* onSuccess, nsICameraErrorCallback* onError);
|
|
|
|
nsresult StopRecording();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
nsresult SetFocusAreas(JSContext* aCx, const JS::Value& aValue)
|
|
|
|
{
|
|
|
|
return Set(aCx, CAMERA_PARAM_FOCUSAREAS, aValue, mMaxFocusAreas);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsresult SetMeteringAreas(JSContext* aCx, const JS::Value& aValue)
|
|
|
|
{
|
|
|
|
return Set(aCx, CAMERA_PARAM_METERINGAREAS, aValue, mMaxMeteringAreas);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char* GetParameter(const char* aKey) = 0;
|
|
|
|
virtual const char* GetParameterConstChar(uint32_t aKey) = 0;
|
|
|
|
virtual double GetParameterDouble(uint32_t aKey) = 0;
|
|
|
|
virtual void GetParameter(uint32_t aKey, nsTArray<CameraRegion>& aRegions) = 0;
|
|
|
|
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;
|
|
|
|
virtual void SetParameter(uint32_t aKey, const nsTArray<CameraRegion>& aRegions) = 0;
|
|
|
|
virtual nsresult PushParameters() = 0;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-07 13:23:01 -07:00
|
|
|
bool ReceiveFrame(void* aBuffer, ImageFormat aFormat, FrameBuilder aBuilder);
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CameraControlImpl()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
virtual nsresult GetPreviewStreamImpl(GetPreviewStreamTask* aGetPreviewStream) = 0;
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual nsresult StartPreviewImpl(StartPreviewTask* aStartPreview) = 0;
|
|
|
|
virtual nsresult StopPreviewImpl(StopPreviewTask* aStopPreview) = 0;
|
2012-07-30 14:59:05 -07: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-04 18:01:56 -07:00
|
|
|
virtual nsresult PushParametersImpl() = 0;
|
|
|
|
virtual nsresult PullParametersImpl() = 0;
|
|
|
|
|
|
|
|
uint32_t mCameraId;
|
|
|
|
nsCOMPtr<nsIThread> mCameraThread;
|
|
|
|
nsString mFileFormat;
|
|
|
|
uint32_t mMaxMeteringAreas;
|
|
|
|
uint32_t mMaxFocusAreas;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* '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 14:59:05 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsICameraAutoFocusCallback> mAutoFocusOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mAutoFocusOnErrorCb;
|
|
|
|
nsCOMPtr<nsICameraTakePictureCallback> mTakePictureOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mTakePictureOnErrorCb;
|
|
|
|
nsCOMPtr<nsICameraStartRecordingCallback> mStartRecordingOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mStartRecordingOnErrorCb;
|
|
|
|
nsCOMPtr<nsICameraShutterCallback> mOnShutterCb;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
CameraControlImpl(const CameraControlImpl&) MOZ_DELETE;
|
|
|
|
CameraControlImpl& operator=(const CameraControlImpl&) MOZ_DELETE;
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return the resulting preview stream to JS. Runs on the main thread.
|
|
|
|
class GetPreviewStreamResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
GetPreviewStreamResult(CameraControlImpl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint32_t aFramesPerSecond, nsICameraPreviewStreamCallback* onSuccess)
|
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mWidth(aWidth)
|
|
|
|
, mHeight(aHeight)
|
|
|
|
, mFramesPerSecond(aFramesPerSecond)
|
2012-07-30 14:59:05 -07:00
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
{
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual ~GetPreviewStreamResult()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
// Run() method is implementation specific.
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
protected:
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
|
|
|
uint32_t mFramesPerSecond;
|
2012-07-30 14:59:05 -07:00
|
|
|
nsCOMPtr<nsICameraPreviewStreamCallback> mOnSuccessCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get the desired preview stream.
|
|
|
|
class GetPreviewStreamTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
GetPreviewStreamTask(CameraControlImpl* aCameraControl, CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mSize(aSize)
|
|
|
|
, mCameraControl(aCameraControl)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
, mOnErrorCb(onError)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsresult rv = mCameraControl->GetPreviewStreamImpl(this);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) && mOnErrorCb) {
|
|
|
|
rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE")));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraSize mSize;
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 14:59:05 -07:00
|
|
|
nsCOMPtr<nsICameraPreviewStreamCallback> mOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mOnErrorCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the autofocus status to JS. Runs on the main thread.
|
|
|
|
class AutoFocusResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoFocusResult(bool aSuccess, nsICameraAutoFocusCallback* onSuccess)
|
|
|
|
: mSuccess(aSuccess)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
{ }
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual ~AutoFocusResult() { }
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mOnSuccessCb) {
|
|
|
|
mOnSuccessCb->HandleEvent(mSuccess);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool mSuccess;
|
|
|
|
nsCOMPtr<nsICameraAutoFocusCallback> mOnSuccessCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Autofocus the camera.
|
|
|
|
class AutoFocusTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
AutoFocusTask(CameraControlImpl* aCameraControl, nsICameraAutoFocusCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
, mOnErrorCb(onError)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult rv = mCameraControl->AutoFocusImpl(this);
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv) && mOnErrorCb) {
|
|
|
|
rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE")));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 14:59:05 -07:00
|
|
|
nsCOMPtr<nsICameraAutoFocusCallback> mOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mOnErrorCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the captured picture to JS. Runs on the main thread.
|
|
|
|
class TakePictureResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TakePictureResult(nsIDOMBlob* aImage, nsICameraTakePictureCallback* onSuccess)
|
|
|
|
: mImage(aImage)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2012-07-30 14:59:05 -07:00
|
|
|
if (mOnSuccessCb) {
|
|
|
|
mOnSuccessCb->HandleEvent(mImage);
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2012-07-30 14:59:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIDOMBlob> mImage;
|
|
|
|
nsCOMPtr<nsICameraTakePictureCallback> mOnSuccessCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Capture a still image with the camera.
|
|
|
|
class TakePictureTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
TakePictureTask(CameraControlImpl* aCameraControl, CameraSize aSize, int32_t aRotation, const nsAString& aFileFormat, CameraPosition aPosition, nsICameraTakePictureCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mSize(aSize)
|
|
|
|
, mRotation(aRotation)
|
|
|
|
, mFileFormat(aFileFormat)
|
|
|
|
, mPosition(aPosition)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
, mOnErrorCb(onError)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult rv = mCameraControl->TakePictureImpl(this);
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv) && mOnErrorCb) {
|
|
|
|
rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE")));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 14:59:05 -07:00
|
|
|
CameraSize mSize;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRotation;
|
2012-07-30 14:59:05 -07:00
|
|
|
nsString mFileFormat;
|
|
|
|
CameraPosition mPosition;
|
|
|
|
nsCOMPtr<nsICameraTakePictureCallback> mOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mOnErrorCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the captured video to JS. Runs on the main thread.
|
|
|
|
class StartRecordingResult : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StartRecordingResult(nsIDOMMediaStream* aStream, nsICameraStartRecordingCallback* onSuccess)
|
|
|
|
: mStream(aStream)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
{ }
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual ~StartRecordingResult() { }
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mOnSuccessCb) {
|
|
|
|
mOnSuccessCb->HandleEvent(mStream);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIDOMMediaStream> mStream;
|
|
|
|
nsCOMPtr<nsICameraStartRecordingCallback> mOnSuccessCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Start video recording.
|
|
|
|
class StartRecordingTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
StartRecordingTask(CameraControlImpl* aCameraControl, CameraSize aSize, nsICameraStartRecordingCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mSize(aSize)
|
|
|
|
, mCameraControl(aCameraControl)
|
|
|
|
, mOnSuccessCb(onSuccess)
|
|
|
|
, mOnErrorCb(onError)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult rv = mCameraControl->StartRecordingImpl(this);
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv) && mOnErrorCb) {
|
|
|
|
rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE")));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraSize mSize;
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 14:59:05 -07:00
|
|
|
nsCOMPtr<nsICameraStartRecordingCallback> mOnSuccessCb;
|
|
|
|
nsCOMPtr<nsICameraErrorCallback> mOnErrorCb;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Stop video recording.
|
|
|
|
class StopRecordingTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
StopRecordingTask(CameraControlImpl* aCameraControl)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mCameraControl(aCameraControl)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult rv = mCameraControl->StopRecordingImpl(this);
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
// Start the preview.
|
|
|
|
class StartPreviewTask : public nsRunnable
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
StartPreviewTask(CameraControlImpl* aCameraControl, DOMCameraPreview* aDOMPreview)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mCameraControl(aCameraControl)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
|
|
|
DOMCameraPreview* mDOMPreview; // DOMCameraPreview NS_ADDREFs itself for us
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
// Stop the preview.
|
|
|
|
class StopPreviewTask : public nsRunnable
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
StopPreviewTask(CameraControlImpl* aCameraControl)
|
2012-07-30 14:59:05 -07:00
|
|
|
: mCameraControl(aCameraControl)
|
2012-09-04 18:01:56 -07: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 14:59:05 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
mCameraControl->StopPreviewImpl(this);
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsRefPtr<CameraControlImpl> mCameraControl;
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#endif // DOM_CAMERA_CAMERACONTROLIMPL_H
|