2012-07-30 21:59:05 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
#ifndef DOM_CAMERA_CAMERACONTROLIMPL_H
|
|
|
|
#define DOM_CAMERA_CAMERACONTROLIMPL_H
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2013-06-05 16:15:48 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
|
|
#include "nsIFile.h"
|
2013-01-08 23:43:50 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "AutoRwLock.h"
|
2012-09-29 05:30:52 +00:00
|
|
|
#include "nsIDOMDeviceStorage.h"
|
2012-09-05 01:01:56 +00:00
|
|
|
#include "ICameraControl.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "CameraCommon.h"
|
2014-01-17 01:01:43 +00:00
|
|
|
#include "DeviceStorage.h"
|
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "CameraControlListener.h"
|
2014-01-17 01:01:43 +00:00
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
namespace layers {
|
|
|
|
class Image;
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-10-23 22:30:28 +00:00
|
|
|
class RecorderProfileManager;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
class CameraControlImpl : public ICameraControl
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-14 22:41:07 +00:00
|
|
|
CameraControlImpl(uint32_t aCameraId);
|
|
|
|
virtual void AddListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
|
|
|
virtual void RemoveListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2014-02-20 04:18:52 +00:00
|
|
|
virtual nsresult Start(const Configuration* aConfig = nullptr) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Stop() MOZ_OVERRIDE;
|
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
virtual nsresult SetConfiguration(const Configuration& aConfig) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartPreview() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopPreview() MOZ_OVERRIDE;
|
2014-04-15 19:46:40 +00:00
|
|
|
virtual nsresult AutoFocus() MOZ_OVERRIDE;
|
2014-04-09 15:52:10 +00:00
|
|
|
virtual nsresult StartFaceDetection() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopFaceDetection() MOZ_OVERRIDE;
|
2014-02-14 22:41:07 +00:00
|
|
|
virtual nsresult TakePicture() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopRecording() MOZ_OVERRIDE;
|
2014-04-15 19:46:40 +00:00
|
|
|
virtual nsresult ResumeContinuousFocus() MOZ_OVERRIDE;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2012-10-23 22:30:28 +00:00
|
|
|
already_AddRefed<RecorderProfileManager> GetRecorderProfileManager();
|
|
|
|
uint32_t GetCameraId() { return mCameraId; }
|
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
virtual void Shutdown() MOZ_OVERRIDE;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-04-09 15:12:25 +00:00
|
|
|
// Event handlers called directly from outside this class.
|
2012-10-01 00:37:47 +00:00
|
|
|
void OnShutter();
|
|
|
|
void OnClosed();
|
2014-02-14 22:41:07 +00:00
|
|
|
void OnError(CameraControlListener::CameraErrorContext aContext,
|
|
|
|
CameraControlListener::CameraError aError);
|
2014-04-09 15:12:25 +00:00
|
|
|
void OnAutoFocusMoving(bool aIsMoving);
|
2014-02-14 05:28:57 +00:00
|
|
|
|
2014-02-14 13:27:44 +00:00
|
|
|
protected:
|
2014-02-14 22:41:07 +00:00
|
|
|
// Event handlers.
|
|
|
|
void OnAutoFocusComplete(bool aAutoFocusSucceeded);
|
2014-04-09 15:52:10 +00:00
|
|
|
void OnFacesDetected(const nsTArray<Face>& aFaces);
|
2014-02-14 22:41:07 +00:00
|
|
|
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
|
|
|
|
|
|
|
|
bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
|
|
|
|
void OnRecorderStateChange(CameraControlListener::RecorderState aState,
|
2014-02-20 04:18:52 +00:00
|
|
|
int32_t aStatus = -1, int32_t aTrackNumber = -1);
|
2014-02-14 22:41:07 +00:00
|
|
|
void OnPreviewStateChange(CameraControlListener::PreviewState aState);
|
|
|
|
void OnHardwareStateChange(CameraControlListener::HardwareState aState);
|
|
|
|
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 22:30:28 +00:00
|
|
|
virtual ~CameraControlImpl();
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-02-14 22:41:07 +00: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-02-20 04:18:52 +00:00
|
|
|
virtual nsresult StartImpl(const Configuration* aConfig = nullptr) = 0;
|
|
|
|
virtual nsresult StopImpl() = 0;
|
2014-02-14 22:41:07 +00:00
|
|
|
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) = 0;
|
|
|
|
virtual nsresult StartPreviewImpl() = 0;
|
|
|
|
virtual nsresult StopPreviewImpl() = 0;
|
2014-04-15 19:46:40 +00:00
|
|
|
virtual nsresult AutoFocusImpl() = 0;
|
2014-04-09 15:52:10 +00:00
|
|
|
virtual nsresult StartFaceDetectionImpl() = 0;
|
|
|
|
virtual nsresult StopFaceDetectionImpl() = 0;
|
2014-02-14 22:41:07 +00:00
|
|
|
virtual nsresult TakePictureImpl() = 0;
|
|
|
|
virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions) = 0;
|
|
|
|
virtual nsresult StopRecordingImpl() = 0;
|
2014-04-15 19:46:40 +00:00
|
|
|
virtual nsresult ResumeContinuousFocusImpl() = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual nsresult PushParametersImpl() = 0;
|
|
|
|
virtual nsresult PullParametersImpl() = 0;
|
2012-10-23 22:30:28 +00:00
|
|
|
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() = 0;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
void OnShutterInternal();
|
|
|
|
void OnClosedInternal();
|
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
uint32_t mCameraId;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
CameraControlListener::CameraListenerConfiguration mCurrentConfiguration;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
CameraControlListener::PreviewState mPreviewState;
|
|
|
|
CameraControlListener::HardwareState mHardwareState;
|
2012-09-05 01:01:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CameraControlImpl(const CameraControlImpl&) MOZ_DELETE;
|
|
|
|
CameraControlImpl& operator=(const CameraControlImpl&) MOZ_DELETE;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
#endif // DOM_CAMERA_CAMERACONTROLIMPL_H
|