зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset a73dece39b01 (bug 985496) for mochitest-5 orange
This commit is contained in:
Родитель
5cc9dd49eb
Коммит
e015d5da87
|
@ -170,7 +170,7 @@ public:
|
|||
|
||||
void OnHardwareStateChange(HardwareState aState);
|
||||
bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
|
||||
void OnUserError(UserContext aContext, nsresult aError);
|
||||
void OnError(CameraErrorContext aContext, CameraError aError);
|
||||
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
|
||||
|
||||
void AllocImpl();
|
||||
|
|
|
@ -635,7 +635,7 @@ MediaEngineWebRTCVideoSource::OnHardwareStateChange(HardwareState aState)
|
|||
}
|
||||
|
||||
void
|
||||
MediaEngineWebRTCVideoSource::OnUserError(UserContext aContext, nsresult aError)
|
||||
MediaEngineWebRTCVideoSource::OnError(CameraErrorContext aContext, CameraError aError)
|
||||
{
|
||||
ReentrantMonitorAutoEnter sync(mCallbackMonitor);
|
||||
mCallbackMonitor.Notify();
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "base/basictypes.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "CameraRecorderProfiles.h"
|
||||
#include "CameraCommon.h"
|
||||
|
@ -19,8 +18,7 @@ using namespace mozilla;
|
|||
nsWeakPtr CameraControlImpl::sCameraThread;
|
||||
|
||||
CameraControlImpl::CameraControlImpl(uint32_t aCameraId)
|
||||
: mListenerLock(PR_NewRWLock(PR_RWLOCK_RANK_NONE, "CameraControlImpl.Listeners.Lock"))
|
||||
, mCameraId(aCameraId)
|
||||
: mCameraId(aCameraId)
|
||||
, mPreviewState(CameraControlListener::kPreviewStopped)
|
||||
, mHardwareState(CameraControlListener::kHardwareClosed)
|
||||
{
|
||||
|
@ -32,9 +30,9 @@ CameraControlImpl::CameraControlImpl(uint32_t aCameraId)
|
|||
mCameraThread = ct.forget();
|
||||
} else {
|
||||
nsresult rv = NS_NewNamedThread("CameraThread", getter_AddRefs(mCameraThread));
|
||||
if (NS_FAILED(rv)) {
|
||||
MOZ_CRASH("Failed to create new Camera Thread");
|
||||
}
|
||||
unused << rv; // swallow rv to suppress a compiler warning when the macro
|
||||
// is #defined to nothing (i.e. in non-DEBUG builds).
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
// keep a weak reference to the new thread
|
||||
sCameraThread = do_GetWeakReference(mCameraThread);
|
||||
|
@ -51,14 +49,11 @@ CameraControlImpl::CameraControlImpl(uint32_t aCameraId)
|
|||
//
|
||||
// Multiple parallel listeners being invoked are not a problem because
|
||||
// the read-write lock allows multiple simultaneous read-locks.
|
||||
if (!mListenerLock) {
|
||||
MOZ_CRASH("Out of memory getting new PRRWLock");
|
||||
}
|
||||
mListenerLock = PR_NewRWLock(PR_RWLOCK_RANK_NONE, "CameraControlImpl.Listeners.Lock");
|
||||
}
|
||||
|
||||
CameraControlImpl::~CameraControlImpl()
|
||||
{
|
||||
MOZ_ASSERT(mListenerLock, "mListenerLock missing in ~CameraControlImpl()");
|
||||
if (mListenerLock) {
|
||||
PR_DestroyRWLock(mListenerLock);
|
||||
mListenerLock = nullptr;
|
||||
|
@ -268,14 +263,23 @@ CameraControlImpl::OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uin
|
|||
}
|
||||
|
||||
void
|
||||
CameraControlImpl::OnUserError(CameraControlListener::UserContext aContext,
|
||||
nsresult aError)
|
||||
CameraControlImpl::OnError(CameraControlListener::CameraErrorContext aContext,
|
||||
CameraControlListener::CameraError aError)
|
||||
{
|
||||
// This callback can run on threads other than the Main Thread and
|
||||
// the Camera Thread.
|
||||
RwLockAutoEnterRead lock(mListenerLock);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
const char* error[] = {
|
||||
"api-failed",
|
||||
"init-failed",
|
||||
"invalid-configuration",
|
||||
"service-failed",
|
||||
"set-picture-size-failed",
|
||||
"set-thumbnail-size-failed",
|
||||
"unknown"
|
||||
};
|
||||
const char* context[] = {
|
||||
"StartCamera",
|
||||
"StopCamera",
|
||||
|
@ -288,50 +292,22 @@ CameraControlImpl::OnUserError(CameraControlListener::UserContext aContext,
|
|||
"SetConfiguration",
|
||||
"StartPreview",
|
||||
"StopPreview",
|
||||
"SetPictureSize",
|
||||
"SetThumbnailSize",
|
||||
"ResumeContinuousFocus",
|
||||
"Unspecified"
|
||||
};
|
||||
if (static_cast<size_t>(aContext) < sizeof(context) / sizeof(context[0])) {
|
||||
DOM_CAMERA_LOGW("CameraControlImpl::OnUserError : aContext='%s' (%d), aError=0x%x\n",
|
||||
context[aContext], aContext, aError);
|
||||
if (static_cast<unsigned int>(aError) < sizeof(error) / sizeof(error[0]) &&
|
||||
static_cast<unsigned int>(aContext) < sizeof(context) / sizeof(context[0])) {
|
||||
DOM_CAMERA_LOGW("CameraControlImpl::OnError : aContext='%s' (%u), aError='%s' (%u)\n",
|
||||
context[aContext], aContext, error[aError], aError);
|
||||
} else {
|
||||
DOM_CAMERA_LOGE("CameraControlImpl::OnUserError : aContext=%d, aError=0x%x\n",
|
||||
DOM_CAMERA_LOGE("CameraControlImpl::OnError : aContext=%u, aError=%d\n",
|
||||
aContext, aError);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (uint32_t i = 0; i < mListeners.Length(); ++i) {
|
||||
CameraControlListener* l = mListeners[i];
|
||||
l->OnUserError(aContext, aError);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CameraControlImpl::OnSystemError(CameraControlListener::SystemContext aContext,
|
||||
nsresult aError)
|
||||
{
|
||||
// This callback can run on threads other than the Main Thread and
|
||||
// the Camera Thread.
|
||||
RwLockAutoEnterRead lock(mListenerLock);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
const char* context[] = {
|
||||
"Camera Service"
|
||||
};
|
||||
if (static_cast<size_t>(aContext) < sizeof(context) / sizeof(context[0])) {
|
||||
DOM_CAMERA_LOGW("CameraControlImpl::OnSystemError : aContext='%s' (%d), aError=0x%x\n",
|
||||
context[aContext], aContext, aError);
|
||||
} else {
|
||||
DOM_CAMERA_LOGE("CameraControlImpl::OnSystemError : aContext=%d, aError=0x%x\n",
|
||||
aContext, aError);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (uint32_t i = 0; i < mListeners.Length(); ++i) {
|
||||
CameraControlListener* l = mListeners[i];
|
||||
l->OnSystemError(aContext, aError);
|
||||
l->OnError(aContext, aError);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,10 +318,17 @@ class CameraControlImpl::ControlMessage : public nsRunnable
|
|||
{
|
||||
public:
|
||||
ControlMessage(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: mCameraControl(aCameraControl)
|
||||
, mContext(aContext)
|
||||
{ }
|
||||
{
|
||||
MOZ_COUNT_CTOR(CameraControlImpl::ControlMessage);
|
||||
}
|
||||
|
||||
virtual ~ControlMessage()
|
||||
{
|
||||
MOZ_COUNT_DTOR(CameraControlImpl::ControlMessage);
|
||||
}
|
||||
|
||||
virtual nsresult RunImpl() = 0;
|
||||
|
||||
|
@ -357,34 +340,19 @@ public:
|
|||
|
||||
nsresult rv = RunImpl();
|
||||
if (NS_FAILED(rv)) {
|
||||
nsPrintfCString msg("Camera control API(%d) failed with 0x%x", mContext, rv);
|
||||
NS_WARNING(msg.get());
|
||||
mCameraControl->OnUserError(mContext, rv);
|
||||
DOM_CAMERA_LOGW("Camera control API failed at %d with 0x%x\n", mContext, rv);
|
||||
// XXXmikeh - do we want to report a more specific error code?
|
||||
mCameraControl->OnError(mContext, CameraControlListener::kErrorApiFailed);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~ControlMessage() { }
|
||||
|
||||
nsRefPtr<CameraControlImpl> mCameraControl;
|
||||
CameraControlListener::UserContext mContext;
|
||||
CameraControlListener::CameraErrorContext mContext;
|
||||
};
|
||||
|
||||
nsresult
|
||||
CameraControlImpl::Dispatch(ControlMessage* aMessage)
|
||||
{
|
||||
nsresult rv = mCameraThread->Dispatch(aMessage, NS_DISPATCH_NORMAL);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsPrintfCString msg("Failed to dispatch camera control message (0x%x)", rv);
|
||||
NS_WARNING(msg.get());
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CameraControlImpl::Start(const Configuration* aConfig)
|
||||
{
|
||||
|
@ -392,7 +360,7 @@ CameraControlImpl::Start(const Configuration* aConfig)
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext,
|
||||
CameraControlListener::CameraErrorContext aContext,
|
||||
const Configuration* aConfig)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
, mHaveInitialConfig(false)
|
||||
|
@ -417,7 +385,8 @@ CameraControlImpl::Start(const Configuration* aConfig)
|
|||
Configuration mConfig;
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStartCamera, aConfig));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStartCamera, aConfig), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -427,7 +396,7 @@ CameraControlImpl::SetConfiguration(const Configuration& aConfig)
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext,
|
||||
CameraControlListener::CameraErrorContext aContext,
|
||||
const Configuration& aConfig)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
, mConfig(aConfig)
|
||||
|
@ -443,7 +412,8 @@ CameraControlImpl::SetConfiguration(const Configuration& aConfig)
|
|||
Configuration mConfig;
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInSetConfiguration, aConfig));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInSetConfiguration, aConfig), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -453,7 +423,7 @@ CameraControlImpl::AutoFocus()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -464,7 +434,8 @@ CameraControlImpl::AutoFocus()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInAutoFocus));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInAutoFocus), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -474,7 +445,7 @@ CameraControlImpl::StartFaceDetection()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -485,7 +456,8 @@ CameraControlImpl::StartFaceDetection()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStartFaceDetection));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStartFaceDetection), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -495,7 +467,7 @@ CameraControlImpl::StopFaceDetection()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -506,7 +478,8 @@ CameraControlImpl::StopFaceDetection()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStopFaceDetection));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStopFaceDetection), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -516,7 +489,7 @@ CameraControlImpl::TakePicture()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -527,7 +500,8 @@ CameraControlImpl::TakePicture()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInTakePicture));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInTakePicture), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -538,7 +512,7 @@ CameraControlImpl::StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext,
|
||||
CameraControlListener::CameraErrorContext aContext,
|
||||
const StartRecordingOptions* aOptions,
|
||||
DeviceStorageFileDescriptor* aFileDescriptor)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
|
@ -564,11 +538,9 @@ CameraControlImpl::StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
|||
nsRefPtr<DeviceStorageFileDescriptor> mFileDescriptor;
|
||||
};
|
||||
|
||||
if (!aFileDescriptor) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStartRecording,
|
||||
aOptions, aFileDescriptor));
|
||||
|
||||
return mCameraThread->Dispatch(new Message(this, CameraControlListener::kInStartRecording,
|
||||
aOptions, aFileDescriptor), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -578,7 +550,7 @@ CameraControlImpl::StopRecording()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -589,7 +561,8 @@ CameraControlImpl::StopRecording()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStopRecording));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStopRecording), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -599,7 +572,7 @@ CameraControlImpl::StartPreview()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -610,7 +583,8 @@ CameraControlImpl::StartPreview()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStartPreview));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStartPreview), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -620,7 +594,7 @@ CameraControlImpl::StopPreview()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -631,7 +605,8 @@ CameraControlImpl::StopPreview()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStopPreview));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStopPreview), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -641,7 +616,7 @@ CameraControlImpl::ResumeContinuousFocus()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -652,7 +627,8 @@ CameraControlImpl::ResumeContinuousFocus()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInResumeContinuousFocus));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInResumeContinuousFocus), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -662,7 +638,7 @@ CameraControlImpl::Stop()
|
|||
{
|
||||
public:
|
||||
Message(CameraControlImpl* aCameraControl,
|
||||
CameraControlListener::UserContext aContext)
|
||||
CameraControlListener::CameraErrorContext aContext)
|
||||
: ControlMessage(aCameraControl, aContext)
|
||||
{ }
|
||||
|
||||
|
@ -673,7 +649,8 @@ CameraControlImpl::Stop()
|
|||
}
|
||||
};
|
||||
|
||||
return Dispatch(new Message(this, CameraControlListener::kInStopCamera));
|
||||
return mCameraThread->Dispatch(
|
||||
new Message(this, CameraControlListener::kInStopCamera), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
class CameraControlImpl::ListenerMessage : public CameraControlImpl::ControlMessage
|
||||
|
@ -722,9 +699,7 @@ CameraControlImpl::AddListener(CameraControlListener* aListener)
|
|||
}
|
||||
};
|
||||
|
||||
if (aListener) {
|
||||
Dispatch(new Message(this, aListener));
|
||||
}
|
||||
mCameraThread->Dispatch(new Message(this, aListener), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -756,7 +731,5 @@ CameraControlImpl::RemoveListener(CameraControlListener* aListener)
|
|||
}
|
||||
};
|
||||
|
||||
if (aListener) {
|
||||
Dispatch(new Message(this, aListener));
|
||||
}
|
||||
mCameraThread->Dispatch(new Message(this, aListener), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ public:
|
|||
virtual void AddListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
||||
virtual void RemoveListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
||||
|
||||
// See ICameraControl.h for these methods' return values.
|
||||
virtual nsresult Start(const Configuration* aConfig = nullptr) MOZ_OVERRIDE;
|
||||
virtual nsresult Stop() MOZ_OVERRIDE;
|
||||
|
||||
virtual nsresult SetConfiguration(const Configuration& aConfig) MOZ_OVERRIDE;
|
||||
virtual nsresult StartPreview() MOZ_OVERRIDE;
|
||||
virtual nsresult StopPreview() MOZ_OVERRIDE;
|
||||
|
@ -57,8 +57,8 @@ public:
|
|||
// Event handlers called directly from outside this class.
|
||||
void OnShutter();
|
||||
void OnClosed();
|
||||
void OnUserError(CameraControlListener::UserContext aContext, nsresult aError);
|
||||
void OnSystemError(CameraControlListener::SystemContext aContext, nsresult aError);
|
||||
void OnError(CameraControlListener::CameraErrorContext aContext,
|
||||
CameraControlListener::CameraError aError);
|
||||
void OnAutoFocusMoving(bool aIsMoving);
|
||||
|
||||
protected:
|
||||
|
@ -96,21 +96,6 @@ protected:
|
|||
class ControlMessage;
|
||||
class ListenerMessage;
|
||||
|
||||
nsresult Dispatch(ControlMessage* aMessage);
|
||||
|
||||
// Asynchronous method implementations, invoked on the Camera Thread.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if one or more arguments is invalid;
|
||||
// - NS_ERROR_NOT_INITIALIZED if the underlying hardware is not initialized,
|
||||
// failed to initialize (in the case of StartImpl()), or has been stopped;
|
||||
// for StartRecordingImpl(), this indicates that no recorder has been
|
||||
// configured (either by calling StartImpl() or SetConfigurationImpl());
|
||||
// - NS_ERROR_ALREADY_INITIALIZED if the underlying hardware is already
|
||||
// initialized;
|
||||
// - NS_ERROR_NOT_IMPLEMENTED if the method is not implemented;
|
||||
// - NS_ERROR_FAILURE on general failures.
|
||||
virtual nsresult StartImpl(const Configuration* aConfig = nullptr) = 0;
|
||||
virtual nsresult StopImpl() = 0;
|
||||
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) = 0;
|
||||
|
@ -126,7 +111,6 @@ protected:
|
|||
virtual nsresult ResumeContinuousFocusImpl() = 0;
|
||||
virtual nsresult PushParametersImpl() = 0;
|
||||
virtual nsresult PullParametersImpl() = 0;
|
||||
|
||||
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() = 0;
|
||||
|
||||
void OnShutterInternal();
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
virtual void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) { }
|
||||
virtual void OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces) { }
|
||||
|
||||
enum UserContext
|
||||
enum CameraErrorContext
|
||||
{
|
||||
kInStartCamera,
|
||||
kInStopCamera,
|
||||
|
@ -95,21 +95,20 @@ public:
|
|||
kInSetConfiguration,
|
||||
kInStartPreview,
|
||||
kInStopPreview,
|
||||
kInSetPictureSize,
|
||||
kInSetThumbnailSize,
|
||||
kInResumeContinuousFocus,
|
||||
kInUnspecified
|
||||
};
|
||||
// Error handler for problems arising due to user-initiated actions.
|
||||
virtual void OnUserError(UserContext aContext, nsresult aError) { }
|
||||
|
||||
enum SystemContext
|
||||
enum CameraError
|
||||
{
|
||||
kSystemService
|
||||
kErrorApiFailed,
|
||||
kErrorInitFailed,
|
||||
kErrorInvalidConfiguration,
|
||||
kErrorServiceFailed,
|
||||
kErrorSetPictureSizeFailed,
|
||||
kErrorSetThumbnailSizeFailed,
|
||||
kErrorUnknown
|
||||
};
|
||||
// Error handler for problems arising due to system failures, not triggered
|
||||
// by something the CameraControl API user did.
|
||||
virtual void OnSystemError(SystemContext aContext, nsresult aError) { }
|
||||
virtual void OnError(CameraErrorContext aContext, CameraError aError) { }
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -44,14 +44,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
// Get a representation of this video profile that can be returned
|
||||
// to JS, possibly as a child member of another object.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aObject' is null;
|
||||
// - NS_ERROR_OUT_OF_MEMORY if a new object could not be allocated;
|
||||
// - NS_ERROR_FAILURE if construction of the JS object fails.
|
||||
nsresult GetJsObject(JSContext* aCx, JSObject** aObject);
|
||||
|
||||
protected:
|
||||
|
@ -81,6 +73,7 @@ public:
|
|||
UNKNOWN
|
||||
};
|
||||
|
||||
public:
|
||||
Codec GetCodec() const { return mCodec; }
|
||||
const char* GetCodecName() const
|
||||
{
|
||||
|
@ -92,14 +85,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
// Get a representation of this audio profile that can be returned
|
||||
// to JS, possibly as a child member of another object.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aObject' is null;
|
||||
// - NS_ERROR_OUT_OF_MEMORY if a new object could not be allocated;
|
||||
// - NS_ERROR_FAILURE if construction of the JS object fails.
|
||||
nsresult GetJsObject(JSContext* aCx, JSObject** aObject);
|
||||
|
||||
protected:
|
||||
|
@ -145,14 +130,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
// Get a representation of this recorder profile that can be returned
|
||||
// to JS, possibly as a child member of another object.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aObject' is null;
|
||||
// - NS_ERROR_OUT_OF_MEMORY if a new object could not be allocated;
|
||||
// - NS_ERROR_FAILURE if construction of the JS object fails.
|
||||
virtual nsresult GetJsObject(JSContext* aCx, JSObject** aObject) = 0;
|
||||
|
||||
protected:
|
||||
|
@ -184,24 +161,14 @@ public:
|
|||
const RecorderVideoProfile* GetVideoProfile() const { return &mVideo; }
|
||||
const RecorderAudioProfile* GetAudioProfile() const { return &mAudio; }
|
||||
|
||||
// Get a representation of this recorder profile that can be returned
|
||||
// to JS, possibly as a child member of another object.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aObject' is null;
|
||||
// - NS_ERROR_OUT_OF_MEMORY if a new object could not be allocated;
|
||||
// - NS_ERROR_NOT_AVAILABLE if the profile has no file format name;
|
||||
// - NS_ERROR_FAILURE if construction of the JS object fails.
|
||||
nsresult
|
||||
GetJsObject(JSContext* aCx, JSObject** aObject)
|
||||
nsresult GetJsObject(JSContext* aCx, JSObject** aObject)
|
||||
{
|
||||
NS_ENSURE_TRUE(aObject, NS_ERROR_INVALID_ARG);
|
||||
|
||||
const char* format = GetFileFormatName();
|
||||
if (!format) {
|
||||
// the profile must have a file format
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
||||
|
@ -249,16 +216,6 @@ public:
|
|||
virtual already_AddRefed<RecorderProfile> Get(uint32_t aQualityIndex) const = 0;
|
||||
|
||||
uint32_t GetMaxQualityIndex() const { return mMaxQualityIndex; }
|
||||
|
||||
// Get a representation of all supported recorder profiles that can be
|
||||
// returned to JS.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aObject' is null;
|
||||
// - NS_ERROR_OUT_OF_MEMORY if a new object could not be allocated;
|
||||
// - NS_ERROR_NOT_AVAILABLE if the profile has no file format name;
|
||||
// - NS_ERROR_FAILURE if construction of the JS object fails.
|
||||
nsresult GetJsObject(JSContext* aCx, JSObject** aObject) const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -180,10 +180,11 @@ CameraCapabilities::Populate(ICameraControl* aCameraControl)
|
|||
JS::Rooted<JSObject*> o(js);
|
||||
nsresult rv = mRecorderProfileManager->GetJsObject(js, o.address());
|
||||
if (NS_FAILED(rv)) {
|
||||
DOM_CAMERA_LOGE("Failed to JS-objectify profile manager (0x%x)\n", rv);
|
||||
} else {
|
||||
mRecorderProfiles = JS::ObjectValue(*o);
|
||||
DOM_CAMERA_LOGE("Failed to JS-objectify profile manager (%d)\n", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
mRecorderProfiles = JS::ObjectValue(*o);
|
||||
}
|
||||
|
||||
// For now, always return success, since the presence or absence of capabilities
|
||||
|
|
|
@ -41,13 +41,8 @@ public:
|
|||
static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
CameraCapabilities(nsPIDOMWindow* aWindow);
|
||||
~CameraCapabilities();
|
||||
|
||||
// Populate the camera capabilities interface from the specific
|
||||
// camera control object.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aCameraControl' is null.
|
||||
nsresult Populate(ICameraControl* aCameraControl);
|
||||
|
||||
nsPIDOMWindow* GetParentObject() const { return mWindow; }
|
||||
|
@ -75,8 +70,6 @@ public:
|
|||
void GetIsoModes(nsTArray<nsString>& aRetVal) const;
|
||||
|
||||
protected:
|
||||
~CameraCapabilities();
|
||||
|
||||
nsresult TranslateToDictionary(ICameraControl* aCameraControl,
|
||||
uint32_t aKey, nsTArray<CameraSize>& aSizes);
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "mozilla/dom/CameraCapabilitiesBinding.h"
|
||||
#include "DOMCameraDetectedFace.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
@ -203,7 +202,8 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
|
|||
// Start the camera...
|
||||
nsresult rv = mCameraControl->Start(&config);
|
||||
if (NS_FAILED(rv)) {
|
||||
mListener->OnUserError(DOMCameraControlListener::kInStartCamera, rv);
|
||||
mListener->OnError(DOMCameraControlListener::kInStartCamera,
|
||||
DOMCameraControlListener::kErrorApiFailed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -738,7 +738,7 @@ nsDOMCameraControl::StartRecording(const CameraStartRecordingOptions& aOptions,
|
|||
nsCOMPtr<nsIDOMDOMRequest> request;
|
||||
mDSFileDescriptor = new DeviceStorageFileDescriptor();
|
||||
aRv = aStorageArea.CreateFileDescriptor(aFilename, mDSFileDescriptor.get(),
|
||||
getter_AddRefs(request));
|
||||
getter_AddRefs(request));
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
@ -758,8 +758,6 @@ nsDOMCameraControl::StartRecording(const CameraStartRecordingOptions& aOptions,
|
|||
void
|
||||
nsDOMCameraControl::OnCreatedFileDescriptor(bool aSucceeded)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
if (aSucceeded && mDSFileDescriptor->mFileDescriptor.IsValid()) {
|
||||
ICameraControl::StartRecordingOptions o;
|
||||
|
||||
|
@ -767,13 +765,12 @@ nsDOMCameraControl::OnCreatedFileDescriptor(bool aSucceeded)
|
|||
o.maxFileSizeBytes = mOptions.mMaxFileSizeBytes;
|
||||
o.maxVideoLengthMs = mOptions.mMaxVideoLengthMs;
|
||||
o.autoEnableLowLightTorch = mOptions.mAutoEnableLowLightTorch;
|
||||
rv = mCameraControl->StartRecording(mDSFileDescriptor.get(), &o);
|
||||
nsresult rv = mCameraControl->StartRecording(mDSFileDescriptor.get(), &o);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OnUserError(CameraControlListener::kInStartRecording, rv);
|
||||
OnError(CameraControlListener::kInStartRecording, NS_LITERAL_STRING("FAILURE"));
|
||||
|
||||
if (mDSFileDescriptor->mFileDescriptor.IsValid()) {
|
||||
// An error occured. We need to manually close the file associated with the
|
||||
|
@ -807,28 +804,6 @@ nsDOMCameraControl::ResumePreview(ErrorResult& aRv)
|
|||
aRv = mCameraControl->StartPreview();
|
||||
}
|
||||
|
||||
class ImmediateErrorCallback : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ImmediateErrorCallback(CameraErrorCallback* aCallback, const nsAString& aMessage)
|
||||
: mCallback(aCallback)
|
||||
, mMessage(aMessage)
|
||||
{ }
|
||||
|
||||
NS_IMETHODIMP
|
||||
Run()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
ErrorResult ignored;
|
||||
mCallback->Call(mMessage, ignored);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsRefPtr<CameraErrorCallback> mCallback;
|
||||
nsString mMessage;
|
||||
};
|
||||
|
||||
void
|
||||
nsDOMCameraControl::SetConfiguration(const CameraConfiguration& aConfiguration,
|
||||
const Optional<OwningNonNull<CameraSetConfigurationCallback> >& aOnSuccess,
|
||||
|
@ -841,14 +816,10 @@ nsDOMCameraControl::SetConfiguration(const CameraConfiguration& aConfiguration,
|
|||
if (cb) {
|
||||
// We're busy taking a picture, can't change modes right now.
|
||||
if (aOnError.WasPassed()) {
|
||||
// There is already a call to TakePicture() in progress, abort this
|
||||
// call and invoke the error callback (if one was passed in).
|
||||
NS_DispatchToMainThread(new ImmediateErrorCallback(&aOnError.Value(),
|
||||
NS_LITERAL_STRING("TakePictureInProgress")));
|
||||
} else {
|
||||
// Only throw if no error callback was passed in.
|
||||
aRv = NS_ERROR_FAILURE;
|
||||
ErrorResult ignored;
|
||||
aOnError.Value().Call(NS_LITERAL_STRING("Busy"), ignored);
|
||||
}
|
||||
aRv = NS_ERROR_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -873,6 +844,29 @@ nsDOMCameraControl::SetConfiguration(const CameraConfiguration& aConfiguration,
|
|||
aRv = mCameraControl->SetConfiguration(config);
|
||||
}
|
||||
|
||||
class ImmediateErrorCallback : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ImmediateErrorCallback(CameraErrorCallback* aCallback, const nsAString& aMessage)
|
||||
: mCallback(aCallback)
|
||||
, mMessage(aMessage)
|
||||
{ }
|
||||
|
||||
NS_IMETHODIMP
|
||||
Run()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
ErrorResult ignored;
|
||||
mCallback->Call(mMessage, ignored);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsRefPtr<CameraErrorCallback> mCallback;
|
||||
nsString mMessage;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
nsDOMCameraControl::AutoFocus(CameraAutoFocusCallback& aOnSuccess,
|
||||
const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
|
||||
|
@ -887,10 +881,8 @@ nsDOMCameraControl::AutoFocus(CameraAutoFocusCallback& aOnSuccess,
|
|||
// and invoke the error callback (if one was passed in).
|
||||
NS_DispatchToMainThread(new ImmediateErrorCallback(&aOnError.Value(),
|
||||
NS_LITERAL_STRING("AutoFocusAlreadyInProgress")));
|
||||
} else {
|
||||
// Only throw if no error callback was passed in.
|
||||
aRv = NS_ERROR_FAILURE;
|
||||
}
|
||||
aRv = NS_ERROR_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -932,10 +924,8 @@ nsDOMCameraControl::TakePicture(const CameraPictureOptions& aOptions,
|
|||
// one and invoke the error callback (if one was passed in).
|
||||
NS_DispatchToMainThread(new ImmediateErrorCallback(&aOnError.Value(),
|
||||
NS_LITERAL_STRING("TakePictureAlreadyInProgress")));
|
||||
} else {
|
||||
// Only throw if no error callback was passed in.
|
||||
aRv = NS_ERROR_FAILURE;
|
||||
}
|
||||
aRv = NS_ERROR_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1280,8 +1270,10 @@ nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
|
|||
}
|
||||
|
||||
void
|
||||
nsDOMCameraControl::OnUserError(CameraControlListener::UserContext aContext, nsresult aError)
|
||||
nsDOMCameraControl::OnError(CameraControlListener::CameraErrorContext aContext, const nsAString& aError)
|
||||
{
|
||||
DOM_CAMERA_LOGI("DOM OnError context=%d, error='%s'\n", aContext,
|
||||
NS_LossyConvertUTF16toASCII(aError).get());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsRefPtr<CameraErrorCallback> errorCb;
|
||||
|
@ -1329,79 +1321,36 @@ nsDOMCameraControl::OnUserError(CameraControlListener::UserContext aContext, nsr
|
|||
NS_WARNING("Failed to (re)start preview");
|
||||
return;
|
||||
|
||||
case CameraControlListener::kInStopPreview:
|
||||
// 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 preview");
|
||||
return;
|
||||
|
||||
case CameraControlListener::kInSetPictureSize:
|
||||
// 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 set picture size");
|
||||
return;
|
||||
|
||||
case CameraControlListener::kInSetThumbnailSize:
|
||||
// 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 set thumbnail size");
|
||||
return;
|
||||
case CameraControlListener::kInUnspecified:
|
||||
if (aError.EqualsASCII("ErrorServiceFailed")) {
|
||||
// If the camera service fails, we will get preview-stopped and
|
||||
// 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");
|
||||
return;
|
||||
}
|
||||
// fallthrough
|
||||
|
||||
default:
|
||||
{
|
||||
nsPrintfCString msg("Unhandled aContext=%u, aError=0x%x\n", aContext, aError);
|
||||
NS_WARNING(msg.get());
|
||||
}
|
||||
MOZ_ASSUME_UNREACHABLE("Unhandled user error");
|
||||
MOZ_ASSUME_UNREACHABLE("Error occurred in unanticipated camera state");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!errorCb) {
|
||||
DOM_CAMERA_LOGW("DOM No error handler for aError=0x%x in aContext=%u\n",
|
||||
aError, aContext);
|
||||
DOM_CAMERA_LOGW("DOM No error handler for error '%s' in context=%d\n",
|
||||
NS_LossyConvertUTF16toASCII(aError).get(), aContext);
|
||||
return;
|
||||
}
|
||||
|
||||
nsString error;
|
||||
switch (aError) {
|
||||
case NS_ERROR_INVALID_ARG:
|
||||
error = NS_LITERAL_STRING("InvalidArgument");
|
||||
break;
|
||||
|
||||
case NS_ERROR_NOT_AVAILABLE:
|
||||
error = NS_LITERAL_STRING("NotAvailable");
|
||||
break;
|
||||
|
||||
case NS_ERROR_NOT_IMPLEMENTED:
|
||||
error = NS_LITERAL_STRING("NotImplemented");
|
||||
break;
|
||||
|
||||
case NS_ERROR_NOT_INITIALIZED:
|
||||
error = NS_LITERAL_STRING("HardwareClosed");
|
||||
break;
|
||||
|
||||
case NS_ERROR_ALREADY_INITIALIZED:
|
||||
error = NS_LITERAL_STRING("HardwareAlreadyOpen");
|
||||
break;
|
||||
|
||||
case NS_ERROR_OUT_OF_MEMORY:
|
||||
error = NS_LITERAL_STRING("OutOfMemory");
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
nsPrintfCString msg("Reporting aError=0x%x as generic\n", aError);
|
||||
NS_WARNING(msg.get());
|
||||
}
|
||||
// fallthrough
|
||||
|
||||
case NS_ERROR_FAILURE:
|
||||
error = NS_LITERAL_STRING("GeneralFailure");
|
||||
break;
|
||||
}
|
||||
|
||||
DOM_CAMERA_LOGI("DOM OnUserError aContext=%u, error='%s'\n", aContext,
|
||||
NS_ConvertUTF16toUTF8(error).get());
|
||||
ErrorResult ignored;
|
||||
errorCb->Call(error, ignored);
|
||||
errorCb->Call(aError, ignored);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ protected:
|
|||
void OnRecorderStateChange(CameraControlListener::RecorderState aState, int32_t aStatus, int32_t aTrackNum);
|
||||
void OnConfigurationChange(DOMCameraConfiguration* aConfiguration);
|
||||
void OnShutter();
|
||||
void OnUserError(CameraControlListener::UserContext aContext, nsresult aError);
|
||||
void OnError(CameraControlListener::CameraErrorContext aContext, const nsAString& mError);
|
||||
|
||||
bool IsWindowStillActive();
|
||||
|
||||
|
|
|
@ -354,14 +354,14 @@ DOMCameraControlListener::OnTakePictureComplete(uint8_t* aData, uint32_t aLength
|
|||
}
|
||||
|
||||
void
|
||||
DOMCameraControlListener::OnUserError(UserContext aContext, nsresult aError)
|
||||
DOMCameraControlListener::OnError(CameraErrorContext aContext, CameraError aError)
|
||||
{
|
||||
class Callback : public DOMCallback
|
||||
{
|
||||
public:
|
||||
Callback(nsMainThreadPtrHandle<nsDOMCameraControl> aDOMCameraControl,
|
||||
UserContext aContext,
|
||||
nsresult aError)
|
||||
CameraErrorContext aContext,
|
||||
CameraError aError)
|
||||
: DOMCallback(aDOMCameraControl)
|
||||
, mContext(aContext)
|
||||
, mError(aError)
|
||||
|
@ -370,12 +370,36 @@ DOMCameraControlListener::OnUserError(UserContext aContext, nsresult aError)
|
|||
virtual void
|
||||
RunCallback(nsDOMCameraControl* aDOMCameraControl) MOZ_OVERRIDE
|
||||
{
|
||||
aDOMCameraControl->OnUserError(mContext, mError);
|
||||
nsString error;
|
||||
|
||||
switch (mError) {
|
||||
case kErrorServiceFailed:
|
||||
error = NS_LITERAL_STRING("ErrorServiceFailed");
|
||||
break;
|
||||
|
||||
case kErrorSetPictureSizeFailed:
|
||||
error = NS_LITERAL_STRING("ErrorSetPictureSizeFailed");
|
||||
break;
|
||||
|
||||
case kErrorSetThumbnailSizeFailed:
|
||||
error = NS_LITERAL_STRING("ErrorSetThumbnailSizeFailed");
|
||||
break;
|
||||
|
||||
case kErrorApiFailed:
|
||||
// XXXmikeh legacy error placeholder
|
||||
error = NS_LITERAL_STRING("FAILURE");
|
||||
break;
|
||||
|
||||
default:
|
||||
error = NS_LITERAL_STRING("ErrorUnknown");
|
||||
break;
|
||||
}
|
||||
aDOMCameraControl->OnError(mContext, error);
|
||||
}
|
||||
|
||||
protected:
|
||||
UserContext mContext;
|
||||
nsresult mError;
|
||||
CameraErrorContext mContext;
|
||||
CameraError mError;
|
||||
};
|
||||
|
||||
NS_DispatchToMainThread(new Callback(mDOMCameraControl, aContext, aError));
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
virtual void OnConfigurationChange(const CameraListenerConfiguration& aConfiguration) MOZ_OVERRIDE;
|
||||
virtual void OnShutter() MOZ_OVERRIDE;
|
||||
virtual bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight) MOZ_OVERRIDE;
|
||||
virtual void OnUserError(UserContext aContext, nsresult aError) MOZ_OVERRIDE;
|
||||
virtual void OnError(CameraErrorContext aContext, CameraError aError) MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual ~DOMCameraControlListener();
|
||||
|
|
|
@ -24,43 +24,53 @@ class FallbackCameraControl : public CameraControlImpl
|
|||
public:
|
||||
FallbackCameraControl(uint32_t aCameraId) : CameraControlImpl(aCameraId) { }
|
||||
|
||||
virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
void OnAutoFocusComplete(bool aSuccess);
|
||||
void OnAutoFocusMoving(bool aIsMoving) { }
|
||||
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength) { }
|
||||
void OnTakePictureError() { }
|
||||
void OnNewPreviewFrame(layers::GraphicBufferLocked* aBuffer) { }
|
||||
void OnRecorderEvent(int msg, int ext1, int ext2) { }
|
||||
void OnError(CameraControlListener::CameraErrorContext aWhere,
|
||||
CameraControlListener::CameraError aError) { }
|
||||
|
||||
virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
|
||||
nsresult PushParameters() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
nsresult PullParameters() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
|
||||
nsresult PushParameters() { return NS_ERROR_FAILURE; }
|
||||
nsresult PullParameters() { return NS_ERROR_FAILURE; }
|
||||
|
||||
protected:
|
||||
~FallbackCameraControl();
|
||||
|
||||
virtual nsresult StartPreviewImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult StopPreviewImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult AutoFocusImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult StartFaceDetectionImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult StopFaceDetectionImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult TakePictureImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult StartPreviewImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult StopPreviewImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult AutoFocusImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult TakePictureImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
||||
const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE
|
||||
{ return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult StopRecordingImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult PushParametersImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
virtual nsresult PullParametersImpl() { return NS_ERROR_NOT_INITIALIZED; }
|
||||
{ return NS_ERROR_FAILURE; }
|
||||
virtual nsresult StopRecordingImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult PushParametersImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual nsresult PullParametersImpl() MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
|
||||
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE { return nullptr; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -53,9 +53,8 @@ using namespace android;
|
|||
#define RETURN_IF_NO_CAMERA_HW() \
|
||||
do { \
|
||||
if (!mCameraHw.get()) { \
|
||||
NS_WARNING("Camera hardware is not initialized"); \
|
||||
DOM_CAMERA_LOGE("%s:%d : mCameraHw is null\n", __func__, __LINE__); \
|
||||
return NS_ERROR_NOT_INITIALIZED; \
|
||||
return NS_ERROR_NOT_AVAILABLE; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
@ -108,7 +107,7 @@ nsGonkCameraControl::StartImpl(const Configuration* aInitialConfig)
|
|||
|
||||
nsresult rv = Initialize();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aInitialConfig) {
|
||||
|
@ -127,15 +126,10 @@ nsGonkCameraControl::StartImpl(const Configuration* aInitialConfig)
|
|||
nsresult
|
||||
nsGonkCameraControl::Initialize()
|
||||
{
|
||||
if (mCameraHw.get()) {
|
||||
DOM_CAMERA_LOGI("Camera %d already connected (this=%p)\n", mCameraId, this);
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
}
|
||||
|
||||
mCameraHw = GonkCameraHardware::Connect(this, mCameraId);
|
||||
if (!mCameraHw.get()) {
|
||||
DOM_CAMERA_LOGE("Failed to connect to camera %d (this=%p)\n", mCameraId, this);
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
DOM_CAMERA_LOGI("Initializing camera %d (this=%p, mCameraHw=%p)\n", mCameraId, this, mCameraHw.get());
|
||||
|
@ -702,7 +696,8 @@ nsGonkCameraControl::SetThumbnailSize(const Size& aSize)
|
|||
{
|
||||
nsresult rv = mCameraControl->SetThumbnailSizeImpl(mSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
mCameraControl->OnUserError(CameraControlListener::kInSetThumbnailSize, rv);
|
||||
mCameraControl->OnError(CameraControlListener::kInUnspecified,
|
||||
CameraControlListener::kErrorSetThumbnailSizeFailed);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -837,7 +832,8 @@ nsGonkCameraControl::SetPictureSize(const Size& aSize)
|
|||
{
|
||||
nsresult rv = mCameraControl->SetPictureSizeImpl(mSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
mCameraControl->OnUserError(CameraControlListener::kInSetPictureSize, rv);
|
||||
mCameraControl->OnError(CameraControlListener::kInUnspecified,
|
||||
CameraControlListener::kErrorSetPictureSizeFailed);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -955,9 +951,7 @@ nsGonkCameraControl::StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescri
|
|||
* The camera app needs to provide the file extension '.3gp' for now.
|
||||
* See bug 795202.
|
||||
*/
|
||||
if (NS_WARN_IF(!aFileDescriptor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
NS_ENSURE_TRUE(aFileDescriptor, NS_ERROR_FAILURE);
|
||||
nsAutoString fullPath;
|
||||
mVideoFile = aFileDescriptor->mDSFile;
|
||||
mVideoFile->GetFullPath(fullPath);
|
||||
|
@ -1212,8 +1206,8 @@ nsGonkCameraControl::OnTakePictureComplete(uint8_t* aData, uint32_t aLength)
|
|||
void
|
||||
nsGonkCameraControl::OnTakePictureError()
|
||||
{
|
||||
CameraControlImpl::OnUserError(CameraControlListener::kInTakePicture,
|
||||
NS_ERROR_FAILURE);
|
||||
CameraControlImpl::OnError(CameraControlListener::kInTakePicture,
|
||||
CameraControlListener::kErrorApiFailed);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1648,15 +1642,15 @@ nsGonkCameraControl::OnNewPreviewFrame(layers::TextureClient* aBuffer)
|
|||
}
|
||||
|
||||
void
|
||||
nsGonkCameraControl::OnSystemError(CameraControlListener::SystemContext aWhere,
|
||||
nsresult aError)
|
||||
nsGonkCameraControl::OnError(CameraControlListener::CameraErrorContext aWhere,
|
||||
CameraControlListener::CameraError aError)
|
||||
{
|
||||
if (aWhere == CameraControlListener::kSystemService) {
|
||||
if (aError == CameraControlListener::kErrorServiceFailed) {
|
||||
OnPreviewStateChange(CameraControlListener::kPreviewStopped);
|
||||
OnHardwareStateChange(CameraControlListener::kHardwareClosed);
|
||||
}
|
||||
|
||||
CameraControlImpl::OnSystemError(aWhere, aError);
|
||||
CameraControlImpl::OnError(aWhere, aError);
|
||||
}
|
||||
|
||||
// Gonk callback handlers.
|
||||
|
@ -1711,17 +1705,16 @@ OnClosed(nsGonkCameraControl* gc)
|
|||
}
|
||||
|
||||
void
|
||||
OnSystemError(nsGonkCameraControl* gc,
|
||||
CameraControlListener::SystemContext aWhere,
|
||||
int32_t aArg1, int32_t aArg2)
|
||||
OnError(nsGonkCameraControl* gc, CameraControlListener::CameraError aError,
|
||||
int32_t aArg1, int32_t aArg2)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
DOM_CAMERA_LOGE("OnSystemError : aWhere=%d, aArg1=%d, aArg2=%d\n", aWhere, aArg1, aArg2);
|
||||
DOM_CAMERA_LOGE("OnError : aError=%d, aArg1=%d, aArg2=%d\n", aError, aArg1, aArg2);
|
||||
#else
|
||||
unused << aArg1;
|
||||
unused << aArg2;
|
||||
#endif
|
||||
gc->OnSystemError(aWhere, NS_ERROR_FAILURE);
|
||||
gc->OnError(CameraControlListener::kInUnspecified, aError);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -54,9 +54,9 @@ public:
|
|||
void OnTakePictureError();
|
||||
void OnNewPreviewFrame(layers::TextureClient* aBuffer);
|
||||
void OnRecorderEvent(int msg, int ext1, int ext2);
|
||||
void OnSystemError(CameraControlListener::SystemContext aWhere, nsresult aError);
|
||||
|
||||
// See ICameraControl.h for getter/setter return values.
|
||||
void OnError(CameraControlListener::CameraErrorContext aWhere,
|
||||
CameraControlListener::CameraError aError);
|
||||
|
||||
virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE;
|
||||
virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE;
|
||||
virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE;
|
||||
|
@ -87,23 +87,22 @@ protected:
|
|||
using CameraControlImpl::OnFacesDetected;
|
||||
using CameraControlImpl::OnTakePictureComplete;
|
||||
using CameraControlImpl::OnConfigurationChange;
|
||||
using CameraControlImpl::OnUserError;
|
||||
using CameraControlImpl::OnError;
|
||||
|
||||
virtual void BeginBatchParameterSet() MOZ_OVERRIDE;
|
||||
virtual void EndBatchParameterSet() MOZ_OVERRIDE;
|
||||
|
||||
virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE;
|
||||
virtual nsresult StopImpl() MOZ_OVERRIDE;
|
||||
nsresult Initialize();
|
||||
|
||||
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE;
|
||||
nsresult SetConfigurationInternal(const Configuration& aConfig);
|
||||
nsresult SetPictureConfiguration(const Configuration& aConfig);
|
||||
nsresult SetVideoConfiguration(const Configuration& aConfig);
|
||||
|
||||
template<class T> nsresult SetAndPush(uint32_t aKey, const T& aValue);
|
||||
|
||||
// See CameraControlImpl.h for these methods' return values.
|
||||
virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE;
|
||||
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE;
|
||||
virtual nsresult StopImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult StartPreviewImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult StopPreviewImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult AutoFocusImpl() MOZ_OVERRIDE;
|
||||
|
@ -180,9 +179,8 @@ void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData
|
|||
void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer);
|
||||
void OnShutter(nsGonkCameraControl* gc);
|
||||
void OnClosed(nsGonkCameraControl* gc);
|
||||
void OnSystemError(nsGonkCameraControl* gc,
|
||||
CameraControlListener::SystemContext aWhere,
|
||||
int32_t aArg1, int32_t aArg2);
|
||||
void OnError(nsGonkCameraControl* gc, CameraControlListener::CameraError aError,
|
||||
int32_t aArg1, int32_t aArg2);
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ GonkCameraHardware::notify(int32_t aMsgType, int32_t ext1, int32_t ext2)
|
|||
break;
|
||||
|
||||
case CAMERA_MSG_ERROR:
|
||||
OnSystemError(mTarget, CameraControlListener::kSystemService, ext1, ext2);
|
||||
OnError(mTarget, CameraControlListener::kErrorServiceFailed, ext1, ext2);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -148,7 +148,7 @@ GonkCameraHardware::Init()
|
|||
int rv = Camera::getCameraInfo(mCameraId, &info);
|
||||
if (rv != 0) {
|
||||
DOM_CAMERA_LOGE("%s: failed to get CameraInfo mCameraId %d\n", __func__, mCameraId);
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mRawSensorOrientation = info.orientation;
|
||||
|
|
|
@ -43,12 +43,6 @@ class GonkCameraHardware : public GonkNativeWindowNewFrameCallback
|
|||
protected:
|
||||
GonkCameraHardware(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId, const sp<Camera>& aCamera);
|
||||
virtual ~GonkCameraHardware();
|
||||
|
||||
// Initialize the AOSP camera interface.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_NOT_INITIALIZED if the interface could not be initialized.
|
||||
virtual nsresult Init();
|
||||
|
||||
public:
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
#include "CameraCommon.h"
|
||||
#include "GonkCameraControl.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "TestGonkCameraControl.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -42,7 +40,7 @@ ICameraControl::GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName)
|
|||
DOM_CAMERA_LOGI("GetCameraName : getNumberOfCameras() returned %d\n", count);
|
||||
if (deviceNum < 0 || deviceNum > count) {
|
||||
DOM_CAMERA_LOGE("GetCameraName : invalid device number (%u)\n", aDeviceNum);
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
android::CameraInfo info;
|
||||
|
@ -75,7 +73,6 @@ ICameraControl::GetListOfCameras(nsTArray<nsString>& aList)
|
|||
int32_t count = android::Camera::getNumberOfCameras();
|
||||
DOM_CAMERA_LOGI("getListOfCameras : getNumberOfCameras() returned %d\n", count);
|
||||
if (count <= 0) {
|
||||
aList.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -117,19 +114,10 @@ ICameraControl::GetListOfCameras(nsTArray<nsString>& aList)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static const char* sTestModeEnabled = "camera.control.test.enabled";
|
||||
|
||||
// implementation-specific camera factory
|
||||
already_AddRefed<ICameraControl>
|
||||
ICameraControl::Create(uint32_t aCameraId)
|
||||
{
|
||||
const nsAdoptingCString& test = Preferences::GetCString(sTestModeEnabled);
|
||||
nsRefPtr<nsGonkCameraControl> control;
|
||||
if (test.EqualsASCII("control")) {
|
||||
NS_WARNING("Using test CameraControl layer");
|
||||
control = new TestGonkCameraControl(aCameraId);
|
||||
} else {
|
||||
control = new nsGonkCameraControl(aCameraId);
|
||||
}
|
||||
nsRefPtr<nsGonkCameraControl> control = new nsGonkCameraControl(aCameraId);
|
||||
return control.forget();
|
||||
}
|
||||
|
|
|
@ -139,14 +139,13 @@ GonkCameraParameters::GonkCameraParameters()
|
|||
{
|
||||
MOZ_COUNT_CTOR(GonkCameraParameters);
|
||||
if (!mLock) {
|
||||
MOZ_CRASH("Out of memory getting new PRRWLock");
|
||||
MOZ_CRASH("OOM getting new PRRWLock");
|
||||
}
|
||||
}
|
||||
|
||||
GonkCameraParameters::~GonkCameraParameters()
|
||||
{
|
||||
MOZ_COUNT_DTOR(GonkCameraParameters);
|
||||
MOZ_ASSERT(mLock, "mLock missing in ~GonkCameraParameters()");
|
||||
if (mLock) {
|
||||
PR_DestroyRWLock(mLock);
|
||||
mLock = nullptr;
|
||||
|
@ -164,7 +163,7 @@ GonkCameraParameters::MapIsoToGonk(const nsAString& aIso, nsACString& aIsoOut)
|
|||
nsAutoCString v = NS_LossyConvertUTF16toASCII(aIso);
|
||||
unsigned int iso;
|
||||
if (sscanf(v.get(), "%u", &iso) != 1) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aIsoOut = nsPrintfCString("ISO%u", iso);
|
||||
}
|
||||
|
@ -182,7 +181,7 @@ GonkCameraParameters::MapIsoFromGonk(const char* aIso, nsAString& aIsoOut)
|
|||
} else {
|
||||
unsigned int iso;
|
||||
if (sscanf(aIso, "ISO%u", &iso) != 1) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aIsoOut.AppendInt(iso);
|
||||
}
|
||||
|
@ -334,18 +333,12 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, ICameraControl::Size& aSize)
|
|||
int height;
|
||||
|
||||
rv = GetImpl(Parameters::KEY_JPEG_THUMBNAIL_WIDTH, width);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (width < 0) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
if (NS_FAILED(rv) || width < 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
rv = GetImpl(Parameters::KEY_JPEG_THUMBNAIL_HEIGHT, height);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (height < 0) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
if (NS_FAILED(rv) || height < 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
aSize.width = static_cast<uint32_t>(width);
|
||||
|
@ -355,18 +348,14 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, ICameraControl::Size& aSize)
|
|||
|
||||
const char* value;
|
||||
rv = GetImpl(aKey, value);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (!value || *value == '\0') {
|
||||
DOM_CAMERA_LOGW("Camera parameter aKey=%d not available\n", aKey);
|
||||
if (NS_FAILED(rv) || !value || *value == '\0') {
|
||||
DOM_CAMERA_LOGW("Camera parameter aKey=%d not available (0x%x)\n", aKey, rv);
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
if (sscanf(value, "%ux%u", &aSize.width, &aSize.height) != 2) {
|
||||
DOM_CAMERA_LOGE("Camera parameter aKey=%d size tuple '%s' is invalid\n", aKey, value);
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -401,12 +390,8 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, nsTArray<ICameraControl::Regi
|
|||
|
||||
const char* value;
|
||||
nsresult rv = GetImpl(aKey, value);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (!value || *value == '\0') {
|
||||
DOM_CAMERA_LOGW("Camera parameter aKey=%d not available\n", aKey);
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
if (NS_FAILED(rv) || !value || *value == '\0') {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
const char* p = value;
|
||||
|
@ -426,9 +411,9 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, nsTArray<ICameraControl::Regi
|
|||
for (i = 0, p = value; p && i < count; ++i, p = strchr(p + 1, '(')) {
|
||||
r = aRegions.AppendElement();
|
||||
if (sscanf(p, "(%d,%d,%d,%d,%u)", &r->top, &r->left, &r->bottom, &r->right, &r->weight) != 5) {
|
||||
DOM_CAMERA_LOGE("Camera parameter aKey=%d region tuple has bad format: '%s'\n", aKey, p);
|
||||
DOM_CAMERA_LOGE("%s:%d : region tuple has bad format: '%s'\n", __func__, __LINE__, p);
|
||||
aRegions.Clear();
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,7 +443,6 @@ GonkCameraParameters::SetTranslated(uint32_t aKey, const ICameraControl::Positio
|
|||
DOM_CAMERA_LOGI("setting picture timestamp to %lf\n", aPosition.timestamp);
|
||||
SetImpl(Parameters::KEY_GPS_TIMESTAMP, nsPrintfCString("%lf", aPosition.timestamp).get());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -698,7 +682,7 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, uint32_t& aValue)
|
|||
return rv;
|
||||
}
|
||||
if (val < 0) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
aValue = val;
|
||||
|
@ -725,8 +709,8 @@ ParseItem(const char* aStart, const char* aEnd, ICameraControl::Size* aItem)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
DOM_CAMERA_LOGE("Size tuple has bad format: '%s'\n", aStart);
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
DOM_CAMERA_LOGE("Size tuple has bad format: '%s'\n", __func__, __LINE__, aStart);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -758,7 +742,7 @@ ParseItem(const char* aStart, const char* aEnd, double* aItem)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -768,7 +752,7 @@ ParseItem(const char* aStart, const char* aEnd, int* aItem)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
template<class T> nsresult
|
||||
|
@ -795,8 +779,11 @@ GonkCameraParameters::GetListAsArray(uint32_t aKey, nsTArray<T>& aArray)
|
|||
const char* comma;
|
||||
|
||||
while (p) {
|
||||
// nsTArray::AppendElement() is infallible
|
||||
T* v = aArray.AppendElement();
|
||||
if (!v) {
|
||||
aArray.Clear();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
comma = strchr(p, ',');
|
||||
if (comma != p) {
|
||||
rv = ParseItem(p, comma, v);
|
||||
|
|
|
@ -37,9 +37,6 @@ public:
|
|||
// ALL public methods must hold mLock, for either reading or writing,
|
||||
// for the life of their operation. Not doing so was the cause of
|
||||
// bug 928856, which was -painful- to track down.
|
||||
//
|
||||
// Return values:
|
||||
// - see return values for GetTranslated() and SetTranslated() below.
|
||||
template<class T> nsresult
|
||||
Set(uint32_t aKey, const T& aValue)
|
||||
{
|
||||
|
@ -127,15 +124,11 @@ protected:
|
|||
// The *Impl() templates handle converting the parameter keys from
|
||||
// their enum values to string types, if necessary. These are the
|
||||
// bottom layer accessors to mParams.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_NOT_IMPLEMENTED if the numeric 'aKey' value is invalid.
|
||||
template<typename T> nsresult
|
||||
SetImpl(uint32_t aKey, const T& aValue)
|
||||
{
|
||||
const char* key = Parameters::GetTextKey(aKey);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_NOT_IMPLEMENTED);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
mParams.set(key, aValue);
|
||||
return NS_OK;
|
||||
|
@ -145,7 +138,7 @@ protected:
|
|||
GetImpl(uint32_t aKey, T& aValue)
|
||||
{
|
||||
const char* key = Parameters::GetTextKey(aKey);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_NOT_IMPLEMENTED);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
mParams.get(key, aValue);
|
||||
return NS_OK;
|
||||
|
@ -169,15 +162,6 @@ protected:
|
|||
// for example, where the thumbnail size setting is exposed as an
|
||||
// ICameraControl::Size object, but is handled by the AOSP layer
|
||||
// as two separate parameters.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aValue' contains an invalid value;
|
||||
// - NS_ERROR_NOT_IMPLEMENTED if 'aKey' is invalid;
|
||||
// - NS_ERROR_NOT_AVAILABLE if the getter fails to retrieve a valid value,
|
||||
// or if a setter fails because it requires one or more values that
|
||||
// could not be retrieved;
|
||||
// - NS_ERROR_FAILURE on unexpected internal failures.
|
||||
nsresult SetTranslated(uint32_t aKey, const nsAString& aValue);
|
||||
nsresult GetTranslated(uint32_t aKey, nsAString& aValue);
|
||||
nsresult SetTranslated(uint32_t aKey, const ICameraControl::Size& aSize);
|
||||
|
@ -199,27 +183,10 @@ protected:
|
|||
nsresult GetTranslated(uint32_t aKey, nsTArray<nsString>& aValues);
|
||||
nsresult GetTranslated(uint32_t aKey, nsTArray<double>& aValues);
|
||||
|
||||
// Converts a string of multiple, comma-separated values into an array
|
||||
// of the appropriate type.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_NOT_IMPLEMENTED if 'aKey' is invalid;
|
||||
// - NS_ERROR_NOT_AVAILABLE if a valid value could not be returned.
|
||||
template<class T> nsresult GetListAsArray(uint32_t aKey, nsTArray<T>& aArray);
|
||||
|
||||
// Converts ISO values (e.g., "auto", "hjr", "100", "200", etc.) to and from
|
||||
// values understood by Gonk (e.g., "auto", "ISO_HJR", "ISO100", "ISO200",
|
||||
// respectively).
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if the 'aIso' argument is not a valid form.
|
||||
nsresult MapIsoToGonk(const nsAString& aIso, nsACString& aIsoOut);
|
||||
nsresult MapIsoFromGonk(const char* aIso, nsAString& aIsoOut);
|
||||
|
||||
// Call once to initialize local cached values used in translating other
|
||||
// arguments between Gecko and Gonk. Always returns NS_OK.
|
||||
nsresult Initialize();
|
||||
};
|
||||
|
||||
|
|
|
@ -93,11 +93,6 @@ GonkRecorderProfile::~GonkRecorderProfile()
|
|||
nsresult
|
||||
GonkRecorderProfile::ConfigureRecorder(GonkRecorder* aRecorder)
|
||||
{
|
||||
if (!aRecorder) {
|
||||
DOM_CAMERA_LOGW("ConfigureRecorder() called with null aRecorder\n");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
static const size_t SIZE = 256;
|
||||
char buffer[SIZE];
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
do { \
|
||||
if (x) { \
|
||||
DOM_CAMERA_LOGE(#x " failed\n"); \
|
||||
return NS_ERROR_NOT_AVAILABLE; \
|
||||
return NS_ERROR_INVALID_ARG; \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
@ -66,13 +66,6 @@ public:
|
|||
GonkRecorderVideoProfile* GetGonkVideoProfile() { return &mVideo; }
|
||||
|
||||
android::output_format GetOutputFormat() const { return mPlatformOutputFormat; }
|
||||
|
||||
// Configures the specified recorder using this profile.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aRecorder' is null;
|
||||
// - NS_ERROR_NOT_AVAILABLE if the recorder rejected this profile.
|
||||
nsresult ConfigureRecorder(android::GonkRecorder* aRecorder);
|
||||
|
||||
protected:
|
||||
|
@ -107,6 +100,7 @@ public:
|
|||
|
||||
already_AddRefed<RecorderProfile> Get(uint32_t aQualityIndex) const;
|
||||
already_AddRefed<GonkRecorderProfile> Get(const char* aProfileName) const;
|
||||
nsresult ConfigureRecorder(android::GonkRecorder* aRecorder);
|
||||
|
||||
protected:
|
||||
virtual ~GonkRecorderProfileManager();
|
||||
|
|
|
@ -80,28 +80,8 @@ class ICameraControl
|
|||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ICameraControl)
|
||||
|
||||
// Returns the number of cameras supported by the system.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_FAILURE if the camera count cannot be retrieved.
|
||||
static nsresult GetNumberOfCameras(int32_t& aDeviceCount);
|
||||
|
||||
// Gets the (possibly-meaningful) name of a particular camera.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aDeviceNum' is not a valid camera number;
|
||||
// - NS_ERROR_NOT_AVAILABLE if 'aDeviceNum' is valid but the camera name
|
||||
// could still not be retrieved.
|
||||
static nsresult GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName);
|
||||
|
||||
// Returns a list of names of all cameras supported by the system.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success, even if no camera names are returned (in which
|
||||
// case 'aList' will be empty);
|
||||
// - NS_ERROR_NOT_AVAILABLE if the list of cameras cannot be retrieved.
|
||||
static nsresult GetListOfCameras(nsTArray<nsString>& aList);
|
||||
|
||||
enum Mode {
|
||||
|
@ -143,7 +123,8 @@ public:
|
|||
nsString mRecorderProfile;
|
||||
};
|
||||
|
||||
struct Point {
|
||||
struct Point
|
||||
{
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
@ -162,19 +143,14 @@ public:
|
|||
|
||||
static already_AddRefed<ICameraControl> Create(uint32_t aCameraId);
|
||||
|
||||
virtual nsresult Start(const Configuration* aInitialConfig = nullptr) = 0;
|
||||
virtual nsresult Stop() = 0;
|
||||
|
||||
virtual nsresult SetConfiguration(const Configuration& aConfig) = 0;
|
||||
|
||||
virtual void AddListener(CameraControlListener* aListener) = 0;
|
||||
virtual void RemoveListener(CameraControlListener* aListener) = 0;
|
||||
|
||||
// Camera control methods.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success (if the method requires an asynchronous process,
|
||||
// this value indicates that the process has begun successfully);
|
||||
// - NS_ERROR_INVALID_ARG if one or more arguments is invalid;
|
||||
// - NS_ERROR_FAILURE if an asynchronous method could not be dispatched.
|
||||
virtual nsresult Start(const Configuration* aInitialConfig = nullptr) = 0;
|
||||
virtual nsresult Stop() = 0;
|
||||
virtual nsresult SetConfiguration(const Configuration& aConfig) = 0;
|
||||
virtual nsresult StartPreview() = 0;
|
||||
virtual nsresult StopPreview() = 0;
|
||||
virtual nsresult AutoFocus() = 0;
|
||||
|
@ -186,17 +162,6 @@ public:
|
|||
virtual nsresult StopFaceDetection() = 0;
|
||||
virtual nsresult ResumeContinuousFocus() = 0;
|
||||
|
||||
// Camera parameter getters and setters. 'aKey' must be one of the
|
||||
// CAMERA_PARAM_* values enumerated above.
|
||||
//
|
||||
// Return values:
|
||||
// - NS_OK on success;
|
||||
// - NS_ERROR_INVALID_ARG if 'aValue' contains an invalid value;
|
||||
// - NS_ERROR_NOT_IMPLEMENTED if 'aKey' is invalid;
|
||||
// - NS_ERROR_NOT_AVAILABLE if the getter fails to retrieve a valid value,
|
||||
// or if a setter fails because it requires one or more values that
|
||||
// could not be retrieved;
|
||||
// - NS_ERROR_FAILURE on unexpected internal failures.
|
||||
virtual nsresult Set(uint32_t aKey, const nsAString& aValue) = 0;
|
||||
virtual nsresult Get(uint32_t aKey, nsAString& aValue) = 0;
|
||||
virtual nsresult Set(uint32_t aKey, double aValue) = 0;
|
||||
|
|
|
@ -1,283 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "TestGonkCameraControl.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
static const char* sMethodErrorOverride = "camera.control.test.method.error";
|
||||
static const char* sAsyncErrorOverride = "camera.control.test.async.error";
|
||||
|
||||
TestGonkCameraControl::TestGonkCameraControl(uint32_t aCameraId)
|
||||
: nsGonkCameraControl(aCameraId)
|
||||
{
|
||||
DOM_CAMERA_LOGA("v===== Created TestGonkCameraControl =====v\n");
|
||||
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
||||
}
|
||||
|
||||
TestGonkCameraControl::~TestGonkCameraControl()
|
||||
{
|
||||
DOM_CAMERA_LOGA("^===== Destroyed TestGonkCameraControl =====^\n");
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::ForceMethodFailWithCodeInternal(const char* aFile, int aLine)
|
||||
{
|
||||
nsresult rv =
|
||||
static_cast<nsresult>(Preferences::GetInt(sMethodErrorOverride,
|
||||
static_cast<int32_t>(NS_OK)));
|
||||
if (NS_FAILED(rv)) {
|
||||
DOM_CAMERA_LOGI("[%s:%d] CameraControl method error override: 0x%x\n",
|
||||
aFile, aLine, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::ForceAsyncFailWithCodeInternal(const char* aFile, int aLine)
|
||||
{
|
||||
nsresult rv =
|
||||
static_cast<nsresult>(Preferences::GetInt(sAsyncErrorOverride,
|
||||
static_cast<int32_t>(NS_OK)));
|
||||
if (NS_FAILED(rv)) {
|
||||
DOM_CAMERA_LOGI("[%s:%d] CameraControl async error override: 0x%x\n",
|
||||
aFile, aLine, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::Start(const Configuration* aConfig)
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::Start(aConfig);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartImpl(const Configuration* aInitialConfig)
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartImpl(aInitialConfig);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::Stop()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::Stop();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StopImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::SetConfiguration(const Configuration& aConfig)
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::SetConfiguration(aConfig);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::SetConfigurationImpl(const Configuration& aConfig)
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::SetConfigurationImpl(aConfig);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartPreview()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartPreview();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartPreviewImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopPreview()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StopPreview();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopPreviewImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::AutoFocus()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::AutoFocus();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::AutoFocusImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::AutoFocusImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartFaceDetection()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartFaceDetection();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartFaceDetectionImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartFaceDetectionImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopFaceDetection()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StopFaceDetection();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopFaceDetectionImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StopFaceDetectionImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::TakePicture()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::TakePicture();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::TakePictureImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::TakePictureImpl();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
||||
const StartRecordingOptions* aOptions)
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartRecording(aFileDescriptor, aOptions);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
||||
const StartRecordingOptions* aOptions)
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StartRecordingImpl(aFileDescriptor, aOptions);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopRecording()
|
||||
{
|
||||
nsresult rv = ForceMethodFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StopRecording();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestGonkCameraControl::StopRecordingImpl()
|
||||
{
|
||||
nsresult rv = ForceAsyncFailWithCode();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return nsGonkCameraControl::StopRecordingImpl();
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DOM_CAMERA_TESTGONKCAMERACONTROL_H
|
||||
#define DOM_CAMERA_TESTGONKCAMERACONTROL_H
|
||||
|
||||
#include "GonkCameraControl.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class TestGonkCameraControl : public nsGonkCameraControl
|
||||
{
|
||||
public:
|
||||
TestGonkCameraControl(uint32_t aCameraId);
|
||||
|
||||
virtual nsresult Start(const Configuration* aConfig = nullptr) MOZ_OVERRIDE;
|
||||
virtual nsresult Stop() MOZ_OVERRIDE;
|
||||
virtual nsresult SetConfiguration(const Configuration& aConfig) MOZ_OVERRIDE;
|
||||
virtual nsresult StartPreview() MOZ_OVERRIDE;
|
||||
virtual nsresult StopPreview() MOZ_OVERRIDE;
|
||||
virtual nsresult AutoFocus() MOZ_OVERRIDE;
|
||||
virtual nsresult StartFaceDetection() MOZ_OVERRIDE;
|
||||
virtual nsresult StopFaceDetection() MOZ_OVERRIDE;
|
||||
virtual nsresult TakePicture() MOZ_OVERRIDE;
|
||||
virtual nsresult StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
||||
const StartRecordingOptions* aOptions) MOZ_OVERRIDE;
|
||||
virtual nsresult StopRecording() MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual ~TestGonkCameraControl();
|
||||
|
||||
virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE;
|
||||
virtual nsresult StopImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE;
|
||||
virtual nsresult StartPreviewImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult StopPreviewImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult AutoFocusImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult TakePictureImpl() MOZ_OVERRIDE;
|
||||
virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
||||
const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE;
|
||||
virtual nsresult StopRecordingImpl() MOZ_OVERRIDE;
|
||||
|
||||
nsresult ForceMethodFailWithCodeInternal(const char* aFile, int aLine);
|
||||
nsresult ForceAsyncFailWithCodeInternal(const char* aFile, int aLine);
|
||||
|
||||
private:
|
||||
TestGonkCameraControl(const TestGonkCameraControl&) MOZ_DELETE;
|
||||
TestGonkCameraControl& operator=(const TestGonkCameraControl&) MOZ_DELETE;
|
||||
};
|
||||
|
||||
#define ForceMethodFailWithCode() ForceMethodFailWithCodeInternal(__FILE__, __LINE__)
|
||||
#define ForceAsyncFailWithCode() ForceAsyncFailWithCodeInternal(__FILE__, __LINE__)
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // DOM_CAMERA_TESTGONKCAMERACONTROL_H
|
|
@ -43,7 +43,7 @@ nsresult
|
|||
TestGonkCameraHardware::Init()
|
||||
{
|
||||
if (IsTestCase("init-failure")) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return GonkCameraHardware::Init();
|
||||
|
|
|
@ -34,7 +34,6 @@ if CONFIG['MOZ_B2G_CAMERA']:
|
|||
'GonkCameraSource.cpp',
|
||||
'GonkRecorder.cpp',
|
||||
'GonkRecorderProfiles.cpp',
|
||||
'TestGonkCameraControl.cpp',
|
||||
'TestGonkCameraHardware.cpp',
|
||||
]
|
||||
else:
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<title>Test for bug 975472</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="camera_common.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -87,7 +86,7 @@ var tests = [
|
|||
ok(false, "autoFocus() succeeded incorrectly");
|
||||
}
|
||||
function onError(error) {
|
||||
ok(error === "hardware-closed", "autoFocus() failed with: " + error);
|
||||
ok(true, "autoFocus() failed correctly with: " + error);
|
||||
next();
|
||||
}
|
||||
camera.autoFocus(onSuccess, onError);
|
||||
|
@ -100,7 +99,7 @@ var tests = [
|
|||
ok(false, "takePicture() succeeded incorrectly");
|
||||
}
|
||||
function onError(error) {
|
||||
ok(error === "hardware-closed", "takePicture() failed with: " + error);
|
||||
ok(true, "takePicture() failed correctly with: " + error);
|
||||
next();
|
||||
}
|
||||
camera.takePicture(null, onSuccess, onError);
|
||||
|
@ -113,7 +112,7 @@ var tests = [
|
|||
ok(false, "startRecording() process succeeded incorrectly");
|
||||
}
|
||||
function onError(error) {
|
||||
ok(error === "hardware-closed", "startRecording() failed with: " + error);
|
||||
ok(true, "startRecording() process failed correctly with: " + error);
|
||||
next();
|
||||
}
|
||||
var recordingOptions = {
|
||||
|
@ -140,7 +139,7 @@ var tests = [
|
|||
ok(false, "setConfiguration() process succeeded incorrectly");
|
||||
}
|
||||
function onError(error) {
|
||||
ok(error === "hardware-closed", "setConfiguration() failed with: " + error);
|
||||
ok(true, "setConfiguration() process failed correctly with: " + error);
|
||||
next();
|
||||
}
|
||||
camera.setConfiguration(config, onSuccess, onError);
|
||||
|
@ -168,7 +167,7 @@ var Camera = {
|
|||
t.func(Camera.cameraObj);
|
||||
} catch(e) {
|
||||
if (e instanceof StopIteration) {
|
||||
CameraTest.end();
|
||||
SimpleTest.finish();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче