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
|
|
|
|
|
|
|
class DeviceStorageFileDescriptor;
|
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-10-23 15:30:28 -07:00
|
|
|
class RecorderProfileManager;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
class CameraControlImpl : public ICameraControl
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-02-14 14:41:07 -08:00
|
|
|
CameraControlImpl(uint32_t aCameraId);
|
|
|
|
virtual void AddListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
|
|
|
virtual void RemoveListener(CameraControlListener* aListener) MOZ_OVERRIDE;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
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;
|
|
|
|
virtual nsresult AutoFocus(bool aCancelExistingCall) 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;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
already_AddRefed<RecorderProfileManager> GetRecorderProfileManager();
|
|
|
|
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();
|
|
|
|
void OnClosed();
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnError(CameraControlListener::CameraErrorContext aContext,
|
|
|
|
CameraControlListener::CameraError 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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
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 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-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;
|
|
|
|
virtual nsresult AutoFocusImpl(bool aCancelExistingCall) = 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;
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual nsresult PushParametersImpl() = 0;
|
|
|
|
virtual nsresult PullParametersImpl() = 0;
|
2012-10-23 15:30:28 -07:00
|
|
|
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() = 0;
|
2012-09-04 18:01:56 -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;
|
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
|