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/. */
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "DOMCameraPreview.h"
|
2012-10-23 15:30:28 -07:00
|
|
|
#include "CameraRecorderProfiles.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "CameraControlImpl.h"
|
|
|
|
#include "CameraCommon.h"
|
2013-02-15 00:04:11 -08:00
|
|
|
#include "nsGlobalWindow.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-11-10 07:45:52 -08:00
|
|
|
using namespace mozilla::dom;
|
2013-02-11 11:37:50 -08:00
|
|
|
using namespace mozilla::idl;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
CameraControlImpl::CameraControlImpl(uint32_t aCameraId, nsIThread* aCameraThread, uint64_t aWindowId)
|
|
|
|
: mCameraId(aCameraId)
|
|
|
|
, mCameraThread(aCameraThread)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
, mFileFormat()
|
|
|
|
, mMaxMeteringAreas(0)
|
|
|
|
, mMaxFocusAreas(0)
|
|
|
|
, mDOMPreview(nullptr)
|
|
|
|
, mAutoFocusOnSuccessCb(nullptr)
|
|
|
|
, mAutoFocusOnErrorCb(nullptr)
|
|
|
|
, mTakePictureOnSuccessCb(nullptr)
|
|
|
|
, mTakePictureOnErrorCb(nullptr)
|
|
|
|
, mOnShutterCb(nullptr)
|
|
|
|
, mOnClosedCb(nullptr)
|
2012-11-02 13:11:50 -07:00
|
|
|
, mOnRecorderStateChangeCb(nullptr)
|
2012-10-23 15:30:28 -07:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraControlImpl::~CameraControlImpl()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
// Helpers for string properties.
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Set(uint32_t aKey, const nsAString& aValue)
|
|
|
|
{
|
|
|
|
SetParameter(aKey, NS_ConvertUTF16toUTF8(aValue).get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Get(uint32_t aKey, nsAString& aValue)
|
|
|
|
{
|
|
|
|
const char* value = GetParameterConstChar(aKey);
|
|
|
|
if (!value) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aValue.AssignASCII(value);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helpers for doubles.
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Set(uint32_t aKey, double aValue)
|
|
|
|
{
|
|
|
|
SetParameter(aKey, aValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Get(uint32_t aKey, double* aValue)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aValue);
|
|
|
|
*aValue = GetParameterDouble(aKey);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper for weighted regions.
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::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;
|
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JSObject*> regions(aCx, &aValue.toObject());
|
2012-09-04 18:01:56 -07:00
|
|
|
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<CameraRegion> regionArray;
|
|
|
|
regionArray.SetCapacity(length);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_GetElement(aCx, regions, i, v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraRegion* r = regionArray.AppendElement();
|
|
|
|
/**
|
|
|
|
* These are the default values. We can remove these when the xpidl
|
|
|
|
* dictionary parser gains the ability to grok default values.
|
|
|
|
*/
|
|
|
|
r->top = -1000;
|
|
|
|
r->left = -1000;
|
|
|
|
r->bottom = 1000;
|
|
|
|
r->right = 1000;
|
|
|
|
r->weight = 1000;
|
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
nsresult rv = r->Init(aCx, v.address());
|
2012-09-04 18:01:56 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("region %d: top=%d, left=%d, bottom=%d, right=%d, weight=%d\n",
|
|
|
|
i,
|
|
|
|
r->top,
|
|
|
|
r->left,
|
|
|
|
r->bottom,
|
|
|
|
r->right,
|
|
|
|
r->weight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
SetParameter(aKey, regionArray);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Get(JSContext* aCx, uint32_t aKey, JS::Value* aValue)
|
|
|
|
{
|
|
|
|
nsTArray<CameraRegion> regionArray;
|
|
|
|
|
|
|
|
GetParameter(aKey, regionArray);
|
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0, nullptr));
|
2012-09-04 18:01:56 -07:00
|
|
|
if (!array) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
CameraRegion* r = ®ionArray[i];
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2013-05-10 19:39:45 -07:00
|
|
|
JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, nullptr, nullptr));
|
2012-09-04 18:01:56 -07:00
|
|
|
if (!o) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("top=%d\n", r->top);
|
|
|
|
v = INT_TO_JSVAL(r->top);
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_SetProperty(aCx, o, "top", v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("left=%d\n", r->left);
|
|
|
|
v = INT_TO_JSVAL(r->left);
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_SetProperty(aCx, o, "left", v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("bottom=%d\n", r->bottom);
|
|
|
|
v = INT_TO_JSVAL(r->bottom);
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_SetProperty(aCx, o, "bottom", v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("right=%d\n", r->right);
|
|
|
|
v = INT_TO_JSVAL(r->right);
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_SetProperty(aCx, o, "right", v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("weight=%d\n", r->weight);
|
|
|
|
v = INT_TO_JSVAL(r->weight);
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_SetProperty(aCx, o, "weight", v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = OBJECT_TO_JSVAL(o);
|
2013-05-04 00:52:57 -07:00
|
|
|
if (!JS_SetElement(aCx, array, i, v.address())) {
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = JS::ObjectValue(*array);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Set(nsICameraShutterCallback* aOnShutter)
|
|
|
|
{
|
2013-01-08 15:43:50 -08:00
|
|
|
mOnShutterCb = new nsMainThreadPtrHolder<nsICameraShutterCallback>(aOnShutter);
|
2012-09-30 17:37:47 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Get(nsICameraShutterCallback** aOnShutter)
|
|
|
|
{
|
|
|
|
*aOnShutter = mOnShutterCb;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Set(nsICameraClosedCallback* aOnClosed)
|
|
|
|
{
|
2013-01-08 15:43:50 -08:00
|
|
|
mOnClosedCb = new nsMainThreadPtrHolder<nsICameraClosedCallback>(aOnClosed);
|
2012-09-30 17:37:47 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Get(nsICameraClosedCallback** aOnClosed)
|
|
|
|
{
|
|
|
|
*aOnClosed = mOnClosedCb;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:11:50 -07:00
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Set(nsICameraRecorderStateChange* aOnRecorderStateChange)
|
|
|
|
{
|
2013-01-08 15:43:50 -08:00
|
|
|
mOnRecorderStateChangeCb = new nsMainThreadPtrHolder<nsICameraRecorderStateChange>(aOnRecorderStateChange);
|
2012-11-02 13:11:50 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::Get(nsICameraRecorderStateChange** aOnRecorderStateChange)
|
|
|
|
{
|
|
|
|
*aOnRecorderStateChange = mOnRecorderStateChangeCb;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
already_AddRefed<RecorderProfileManager>
|
|
|
|
CameraControlImpl::GetRecorderProfileManager()
|
|
|
|
{
|
|
|
|
return GetRecorderProfileManagerImpl();
|
|
|
|
}
|
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
void
|
|
|
|
CameraControlImpl::Shutdown()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
|
|
|
mTakePictureOnSuccessCb = nullptr;
|
|
|
|
mTakePictureOnErrorCb = nullptr;
|
|
|
|
mOnShutterCb = nullptr;
|
|
|
|
mOnClosedCb = nullptr;
|
2012-11-02 13:11:50 -07:00
|
|
|
mOnRecorderStateChangeCb = nullptr;
|
2012-09-30 17:37:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraControlImpl::OnShutterInternal()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI("** SNAP **\n");
|
2013-01-08 15:43:50 -08:00
|
|
|
if (mOnShutterCb.get()) {
|
2012-09-30 17:37:47 -07:00
|
|
|
mOnShutterCb->HandleEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraControlImpl::OnShutter()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> onShutter = NS_NewRunnableMethod(this, &CameraControlImpl::OnShutterInternal);
|
|
|
|
nsresult rv = NS_DispatchToMainThread(onShutter);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGW("Failed to dispatch onShutter event to main thread (%d)\n", rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 07:30:44 -07:00
|
|
|
class OnClosedTask : public nsRunnable
|
2012-09-30 17:37:47 -07:00
|
|
|
{
|
2013-04-17 07:30:44 -07:00
|
|
|
public:
|
|
|
|
OnClosedTask(nsMainThreadPtrHandle<nsICameraClosedCallback> onClosed, uint64_t aWindowId)
|
|
|
|
: mOnClosedCb(onClosed)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2012-09-30 17:37:47 -07:00
|
|
|
}
|
2013-04-17 07:30:44 -07:00
|
|
|
|
|
|
|
virtual ~OnClosedTask()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mOnClosedCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
|
|
|
mOnClosedCb->HandleEvent();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsMainThreadPtrHandle<nsICameraClosedCallback> mOnClosedCb;
|
|
|
|
uint64_t mWindowId;
|
|
|
|
};
|
2012-09-30 17:37:47 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
CameraControlImpl::OnClosed()
|
|
|
|
{
|
2013-04-17 07:30:44 -07:00
|
|
|
nsCOMPtr<nsIRunnable> onClosed = new OnClosedTask(mOnClosedCb, mWindowId);
|
2012-09-30 17:37:47 -07:00
|
|
|
nsresult rv = NS_DispatchToMainThread(onClosed);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGW("Failed to dispatch onClosed event to main thread (%d)\n", rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:11:50 -07:00
|
|
|
void
|
|
|
|
CameraControlImpl::OnRecorderStateChange(const nsString& aStateMsg, int32_t aStatus, int32_t aTrackNumber)
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI("OnRecorderStateChange: '%s'\n", NS_ConvertUTF16toUTF8(aStateMsg).get());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> onRecorderStateChange = new CameraRecorderStateChange(mOnRecorderStateChangeCb, aStateMsg, aStatus, aTrackNumber, mWindowId);
|
|
|
|
nsresult rv = NS_DispatchToMainThread(onRecorderStateChange);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to dispatch onRecorderStateChange event to main thread (%d)\n", rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
nsresult
|
|
|
|
CameraControlImpl::GetPreviewStream(CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> getPreviewStreamTask = new GetPreviewStreamTask(this, aSize, onSuccess, onError);
|
2012-11-22 21:31:42 -08:00
|
|
|
return mCameraThread->Dispatch(getPreviewStreamTask, NS_DISPATCH_NORMAL);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::AutoFocus(nsICameraAutoFocusCallback* onSuccess, nsICameraErrorCallback* onError)
|
|
|
|
{
|
2013-01-08 15:43:50 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
bool cancel = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.get();
|
|
|
|
if (cb) {
|
|
|
|
/**
|
|
|
|
* We already have a callback, so someone has already
|
|
|
|
* called autoFocus() -- cancel it.
|
|
|
|
*/
|
|
|
|
mAutoFocusOnSuccessCb = nullptr;
|
|
|
|
mAutoFocusOnErrorCb = nullptr;
|
|
|
|
cancel = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> autoFocusTask = new AutoFocusTask(this, cancel, onSuccess, onError);
|
2012-09-04 18:01:56 -07:00
|
|
|
return mCameraThread->Dispatch(autoFocusTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-18 13:06:28 -08:00
|
|
|
CameraControlImpl::TakePicture(CameraSize aSize, int32_t aRotation, const nsAString& aFileFormat, CameraPosition aPosition, uint64_t aDateTime, nsICameraTakePictureCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2013-01-08 15:43:50 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
bool cancel = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICameraTakePictureCallback> cb = mTakePictureOnSuccessCb.get();
|
|
|
|
if (cb) {
|
|
|
|
/**
|
|
|
|
* We already have a callback, so someone has already
|
|
|
|
* called takePicture() -- cancel it.
|
|
|
|
*/
|
|
|
|
mTakePictureOnSuccessCb = nullptr;
|
|
|
|
mTakePictureOnErrorCb = nullptr;
|
|
|
|
cancel = true;
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:06:28 -08:00
|
|
|
nsCOMPtr<nsIRunnable> takePictureTask = new TakePictureTask(this, cancel, aSize, aRotation, aFileFormat, aPosition, aDateTime, onSuccess, onError);
|
2012-09-04 18:01:56 -07:00
|
|
|
return mCameraThread->Dispatch(takePictureTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-10-23 15:30:28 -07:00
|
|
|
CameraControlImpl::StartRecording(CameraStartRecordingOptions* aOptions, nsIFile* aFolder, const nsAString& aFilename, nsICameraStartRecordingCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2012-10-23 15:30:28 -07:00
|
|
|
nsCOMPtr<nsIFile> clone;
|
|
|
|
aFolder->Clone(getter_AddRefs(clone));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> startRecordingTask = new StartRecordingTask(this, *aOptions, clone, aFilename, onSuccess, onError, mWindowId);
|
2012-09-04 18:01:56 -07:00
|
|
|
return mCameraThread->Dispatch(startRecordingTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::StopRecording()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> stopRecordingTask = new StopRecordingTask(this);
|
|
|
|
return mCameraThread->Dispatch(stopRecordingTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraControlImpl::StartPreview(DOMCameraPreview* aDOMPreview)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> startPreviewTask = new StartPreviewTask(this, aDOMPreview);
|
|
|
|
return mCameraThread->Dispatch(startPreviewTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraControlImpl::StopPreview()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> stopPreviewTask = new StopPreviewTask(this);
|
|
|
|
mCameraThread->Dispatch(stopPreviewTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
nsresult
|
2012-10-23 15:30:28 -07:00
|
|
|
CameraControlImpl::GetPreviewStreamVideoMode(CameraRecorderOptions* aOptions, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError)
|
2012-09-28 22:30:52 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> getPreviewStreamVideoModeTask = new GetPreviewStreamVideoModeTask(this, *aOptions, onSuccess, onError);
|
|
|
|
return mCameraThread->Dispatch(getPreviewStreamVideoModeTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2012-12-23 07:54:54 -08:00
|
|
|
nsresult
|
|
|
|
CameraControlImpl::ReleaseHardware(nsICameraReleaseCallback* onSuccess, nsICameraErrorCallback* onError)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> releaseHardwareTask = new ReleaseHardwareTask(this, onSuccess, onError);
|
|
|
|
return mCameraThread->Dispatch(releaseHardwareTask, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2012-09-07 13:23:01 -07:00
|
|
|
bool
|
2012-09-04 18:01:56 -07:00
|
|
|
CameraControlImpl::ReceiveFrame(void* aBuffer, ImageFormat aFormat, FrameBuilder aBuilder)
|
|
|
|
{
|
2012-09-07 13:23:01 -07:00
|
|
|
if (!mDOMPreview) {
|
|
|
|
return false;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2012-09-07 13:23:01 -07:00
|
|
|
|
|
|
|
return mDOMPreview->ReceiveFrame(aBuffer, aFormat, aBuilder);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GetPreviewStreamResult::Run()
|
|
|
|
{
|
2012-11-22 21:31:42 -08:00
|
|
|
/**
|
|
|
|
* The camera preview stream object is DOM-facing, and as such
|
|
|
|
* must be a cycle-collection participant created on the main
|
|
|
|
* thread.
|
|
|
|
*/
|
2012-09-04 18:01:56 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-01-08 15:43:50 -08:00
|
|
|
nsCOMPtr<nsICameraPreviewStreamCallback> onSuccess = mOnSuccessCb.get();
|
2013-02-15 00:04:11 -08:00
|
|
|
nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mWindowId);
|
|
|
|
if (onSuccess && nsDOMCameraManager::IsWindowStillActive(mWindowId) && window) {
|
|
|
|
nsCOMPtr<nsIDOMMediaStream> stream =
|
|
|
|
new DOMCameraPreview(window, mCameraControl, mWidth, mHeight,
|
|
|
|
mFramesPerSecond);
|
2013-01-08 15:43:50 -08:00
|
|
|
onSuccess->HandleEvent(stream);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|