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-13 21:28:57 -08:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2013-06-05 09:15:48 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-02-13 21:28:57 -08:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
|
|
#include "nsIFile.h"
|
2013-01-08 15:43:50 -08:00
|
|
|
#include "nsProxyRelease.h"
|
2014-02-13 21:28:57 -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-13 21:28:57 -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-13 21:28:57 -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-13 21:28:57 -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-13 21:28:57 -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;
|
|
|
|
virtual nsresult TakePicture() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopRecording() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult ReleaseHardware() 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-13 21:28:57 -08:00
|
|
|
virtual void Shutdown() MOZ_OVERRIDE;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
void OnShutter();
|
|
|
|
void OnClosed();
|
2014-02-13 21:28:57 -08:00
|
|
|
void OnError(CameraControlListener::CameraErrorContext aContext,
|
|
|
|
CameraControlListener::CameraError aError);
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-02-10 19:09:23 -08:00
|
|
|
protected:
|
2014-02-13 21:28:57 -08:00
|
|
|
// Event handlers.
|
|
|
|
void OnAutoFocusComplete(bool aAutoFocusSucceeded);
|
|
|
|
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,
|
|
|
|
int32_t aStatus, int32_t aTrackNumber);
|
|
|
|
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-13 21:28:57 -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;
|
|
|
|
|
|
|
|
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) = 0;
|
|
|
|
virtual nsresult StartPreviewImpl() = 0;
|
|
|
|
virtual nsresult StopPreviewImpl() = 0;
|
|
|
|
virtual nsresult AutoFocusImpl(bool aCancelExistingCall) = 0;
|
|
|
|
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;
|
2014-02-13 21:28:57 -08:00
|
|
|
virtual nsresult ReleaseHardwareImpl() = 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-13 21:28:57 -08:00
|
|
|
uint32_t mCameraId;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-13 21:28:57 -08:00
|
|
|
CameraControlListener::CameraListenerConfiguration mCurrentConfiguration;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-13 21:28:57 -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
|