2012-07-30 14:59:05 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#ifndef DOM_CAMERA_CAMERACONTROLIMPL_H
|
|
|
|
#define DOM_CAMERA_CAMERACONTROLIMPL_H
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2013-06-05 09:15:48 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
|
|
#include "nsIFile.h"
|
2013-01-08 15:43:50 -08:00
|
|
|
#include "nsProxyRelease.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "AutoRwLock.h"
|
2012-09-28 22:30:52 -07:00
|
|
|
#include "nsIDOMDeviceStorage.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "ICameraControl.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "CameraCommon.h"
|
2014-01-16 17:01:43 -08:00
|
|
|
#include "DeviceStorage.h"
|
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "CameraControlListener.h"
|
2014-01-16 17:01:43 -08:00
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
namespace layers {
|
|
|
|
class Image;
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
class CameraControlImpl : public ICameraControl
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 15:26:43 -07:00
|
|
|
explicit CameraControlImpl(uint32_t aCameraId);
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual void AddListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
|
|
|
virtual void RemoveListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-04-25 13:28:15 -07:00
|
|
|
// See ICameraControl.h for these methods' return values.
|
2014-02-19 20:18:52 -08:00
|
|
|
virtual nsresult Start(const Configuration* aConfig = nullptr) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Stop() MOZ_OVERRIDE;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult SetConfiguration(const Configuration& aConfig) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartPreview() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopPreview() MOZ_OVERRIDE;
|
2014-04-15 12:46:40 -07:00
|
|
|
virtual nsresult AutoFocus() MOZ_OVERRIDE;
|
2014-04-09 08:52:10 -07:00
|
|
|
virtual nsresult StartFaceDetection() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopFaceDetection() MOZ_OVERRIDE;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult TakePicture() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopRecording() MOZ_OVERRIDE;
|
2014-04-15 12:46:40 -07:00
|
|
|
virtual nsresult ResumeContinuousFocus() MOZ_OVERRIDE;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
uint32_t GetCameraId() { return mCameraId; }
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual void Shutdown() MOZ_OVERRIDE;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-04-09 08:12:25 -07:00
|
|
|
// Event handlers called directly from outside this class.
|
2012-09-30 17:37:47 -07:00
|
|
|
void OnShutter();
|
2014-04-25 13:28:15 -07:00
|
|
|
void OnUserError(CameraControlListener::UserContext aContext, nsresult aError);
|
|
|
|
void OnSystemError(CameraControlListener::SystemContext aContext, nsresult aError);
|
2014-04-09 08:12:25 -07:00
|
|
|
void OnAutoFocusMoving(bool aIsMoving);
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 05:27:44 -08:00
|
|
|
protected:
|
2014-02-14 14:41:07 -08:00
|
|
|
// Event handlers.
|
|
|
|
void OnAutoFocusComplete(bool aAutoFocusSucceeded);
|
2014-04-09 08:52:10 -07:00
|
|
|
void OnFacesDetected(const nsTArray<Face>& aFaces);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
|
|
|
|
|
2014-07-02 16:55:00 -07:00
|
|
|
void OnRateLimitPreview(bool aLimit);
|
2014-02-14 14:41:07 -08:00
|
|
|
bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
|
|
|
|
void OnRecorderStateChange(CameraControlListener::RecorderState aState,
|
2014-02-19 20:18:52 -08:00
|
|
|
int32_t aStatus = -1, int32_t aTrackNumber = -1);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnPreviewStateChange(CameraControlListener::PreviewState aState);
|
2014-11-25 11:45:00 -08:00
|
|
|
void OnHardwareStateChange(CameraControlListener::HardwareState aState,
|
|
|
|
nsresult aReason);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnConfigurationChange();
|
|
|
|
|
|
|
|
// When we create a new CameraThread, we keep a static reference to it so
|
|
|
|
// that multiple CameraControl instances can find and reuse it; but we
|
|
|
|
// don't want that reference to keep the thread object around unnecessarily,
|
|
|
|
// so we make it a weak reference. The strong dynamic references will keep
|
|
|
|
// the thread object alive as needed.
|
|
|
|
static nsWeakPtr sCameraThread;
|
|
|
|
nsCOMPtr<nsIThread> mCameraThread;
|
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
virtual ~CameraControlImpl();
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual void BeginBatchParameterSet() MOZ_OVERRIDE { }
|
|
|
|
virtual void EndBatchParameterSet() MOZ_OVERRIDE { }
|
|
|
|
|
|
|
|
// Manage camera event listeners.
|
|
|
|
void AddListenerImpl(already_AddRefed<CameraControlListener> aListener);
|
|
|
|
void RemoveListenerImpl(CameraControlListener* aListener);
|
|
|
|
nsTArray<nsRefPtr<CameraControlListener> > mListeners;
|
|
|
|
PRRWLock* mListenerLock;
|
|
|
|
|
|
|
|
class ControlMessage;
|
|
|
|
class ListenerMessage;
|
|
|
|
|
2014-04-25 13:28:15 -07:00
|
|
|
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.
|
2014-02-19 20:18:52 -08:00
|
|
|
virtual nsresult StartImpl(const Configuration* aConfig = nullptr) = 0;
|
|
|
|
virtual nsresult StopImpl() = 0;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) = 0;
|
|
|
|
virtual nsresult StartPreviewImpl() = 0;
|
|
|
|
virtual nsresult StopPreviewImpl() = 0;
|
2014-04-15 12:46:40 -07:00
|
|
|
virtual nsresult AutoFocusImpl() = 0;
|
2014-04-09 08:52:10 -07:00
|
|
|
virtual nsresult StartFaceDetectionImpl() = 0;
|
|
|
|
virtual nsresult StopFaceDetectionImpl() = 0;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult TakePictureImpl() = 0;
|
|
|
|
virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions) = 0;
|
|
|
|
virtual nsresult StopRecordingImpl() = 0;
|
2014-04-15 12:46:40 -07:00
|
|
|
virtual nsresult ResumeContinuousFocusImpl() = 0;
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual nsresult PushParametersImpl() = 0;
|
|
|
|
virtual nsresult PullParametersImpl() = 0;
|
2014-04-25 13:28:15 -07:00
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
void OnShutterInternal();
|
|
|
|
void OnClosedInternal();
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t mCameraId;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
CameraControlListener::CameraListenerConfiguration mCurrentConfiguration;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
CameraControlListener::PreviewState mPreviewState;
|
|
|
|
CameraControlListener::HardwareState mHardwareState;
|
2014-11-25 11:45:00 -08:00
|
|
|
nsresult mHardwareStateChangeReason;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
CameraControlImpl(const CameraControlImpl&) MOZ_DELETE;
|
|
|
|
CameraControlImpl& operator=(const CameraControlImpl&) MOZ_DELETE;
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#endif // DOM_CAMERA_CAMERACONTROLIMPL_H
|