Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef DOM_CAMERA_CAMERACONTROLIMPL_H |
michael@0 | 6 | #define DOM_CAMERA_CAMERACONTROLIMPL_H |
michael@0 | 7 | |
michael@0 | 8 | #include "nsTArray.h" |
michael@0 | 9 | #include "nsWeakPtr.h" |
michael@0 | 10 | #include "mozilla/Attributes.h" |
michael@0 | 11 | #include "mozilla/ReentrantMonitor.h" |
michael@0 | 12 | #include "nsIFile.h" |
michael@0 | 13 | #include "nsProxyRelease.h" |
michael@0 | 14 | #include "AutoRwLock.h" |
michael@0 | 15 | #include "nsIDOMDeviceStorage.h" |
michael@0 | 16 | #include "ICameraControl.h" |
michael@0 | 17 | #include "CameraCommon.h" |
michael@0 | 18 | #include "DeviceStorage.h" |
michael@0 | 19 | #include "DeviceStorageFileDescriptor.h" |
michael@0 | 20 | #include "CameraControlListener.h" |
michael@0 | 21 | |
michael@0 | 22 | namespace mozilla { |
michael@0 | 23 | |
michael@0 | 24 | namespace layers { |
michael@0 | 25 | class Image; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | class RecorderProfileManager; |
michael@0 | 29 | |
michael@0 | 30 | class CameraControlImpl : public ICameraControl |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | CameraControlImpl(uint32_t aCameraId); |
michael@0 | 34 | virtual void AddListener(CameraControlListener* aListener) MOZ_OVERRIDE; |
michael@0 | 35 | virtual void RemoveListener(CameraControlListener* aListener) MOZ_OVERRIDE; |
michael@0 | 36 | |
michael@0 | 37 | virtual nsresult Start(const Configuration* aConfig = nullptr) MOZ_OVERRIDE; |
michael@0 | 38 | virtual nsresult Stop() MOZ_OVERRIDE; |
michael@0 | 39 | |
michael@0 | 40 | virtual nsresult SetConfiguration(const Configuration& aConfig) MOZ_OVERRIDE; |
michael@0 | 41 | virtual nsresult StartPreview() MOZ_OVERRIDE; |
michael@0 | 42 | virtual nsresult StopPreview() MOZ_OVERRIDE; |
michael@0 | 43 | virtual nsresult AutoFocus() MOZ_OVERRIDE; |
michael@0 | 44 | virtual nsresult StartFaceDetection() MOZ_OVERRIDE; |
michael@0 | 45 | virtual nsresult StopFaceDetection() MOZ_OVERRIDE; |
michael@0 | 46 | virtual nsresult TakePicture() MOZ_OVERRIDE; |
michael@0 | 47 | virtual nsresult StartRecording(DeviceStorageFileDescriptor* aFileDescriptor, |
michael@0 | 48 | const StartRecordingOptions* aOptions) MOZ_OVERRIDE; |
michael@0 | 49 | virtual nsresult StopRecording() MOZ_OVERRIDE; |
michael@0 | 50 | virtual nsresult ResumeContinuousFocus() MOZ_OVERRIDE; |
michael@0 | 51 | |
michael@0 | 52 | already_AddRefed<RecorderProfileManager> GetRecorderProfileManager(); |
michael@0 | 53 | uint32_t GetCameraId() { return mCameraId; } |
michael@0 | 54 | |
michael@0 | 55 | virtual void Shutdown() MOZ_OVERRIDE; |
michael@0 | 56 | |
michael@0 | 57 | // Event handlers called directly from outside this class. |
michael@0 | 58 | void OnShutter(); |
michael@0 | 59 | void OnClosed(); |
michael@0 | 60 | void OnError(CameraControlListener::CameraErrorContext aContext, |
michael@0 | 61 | CameraControlListener::CameraError aError); |
michael@0 | 62 | void OnAutoFocusMoving(bool aIsMoving); |
michael@0 | 63 | |
michael@0 | 64 | protected: |
michael@0 | 65 | // Event handlers. |
michael@0 | 66 | void OnAutoFocusComplete(bool aAutoFocusSucceeded); |
michael@0 | 67 | void OnFacesDetected(const nsTArray<Face>& aFaces); |
michael@0 | 68 | void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType); |
michael@0 | 69 | |
michael@0 | 70 | bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight); |
michael@0 | 71 | void OnRecorderStateChange(CameraControlListener::RecorderState aState, |
michael@0 | 72 | int32_t aStatus = -1, int32_t aTrackNumber = -1); |
michael@0 | 73 | void OnPreviewStateChange(CameraControlListener::PreviewState aState); |
michael@0 | 74 | void OnHardwareStateChange(CameraControlListener::HardwareState aState); |
michael@0 | 75 | void OnConfigurationChange(); |
michael@0 | 76 | |
michael@0 | 77 | // When we create a new CameraThread, we keep a static reference to it so |
michael@0 | 78 | // that multiple CameraControl instances can find and reuse it; but we |
michael@0 | 79 | // don't want that reference to keep the thread object around unnecessarily, |
michael@0 | 80 | // so we make it a weak reference. The strong dynamic references will keep |
michael@0 | 81 | // the thread object alive as needed. |
michael@0 | 82 | static nsWeakPtr sCameraThread; |
michael@0 | 83 | nsCOMPtr<nsIThread> mCameraThread; |
michael@0 | 84 | |
michael@0 | 85 | virtual ~CameraControlImpl(); |
michael@0 | 86 | |
michael@0 | 87 | virtual void BeginBatchParameterSet() MOZ_OVERRIDE { } |
michael@0 | 88 | virtual void EndBatchParameterSet() MOZ_OVERRIDE { } |
michael@0 | 89 | |
michael@0 | 90 | // Manage camera event listeners. |
michael@0 | 91 | void AddListenerImpl(already_AddRefed<CameraControlListener> aListener); |
michael@0 | 92 | void RemoveListenerImpl(CameraControlListener* aListener); |
michael@0 | 93 | nsTArray<nsRefPtr<CameraControlListener> > mListeners; |
michael@0 | 94 | PRRWLock* mListenerLock; |
michael@0 | 95 | |
michael@0 | 96 | class ControlMessage; |
michael@0 | 97 | class ListenerMessage; |
michael@0 | 98 | |
michael@0 | 99 | virtual nsresult StartImpl(const Configuration* aConfig = nullptr) = 0; |
michael@0 | 100 | virtual nsresult StopImpl() = 0; |
michael@0 | 101 | virtual nsresult SetConfigurationImpl(const Configuration& aConfig) = 0; |
michael@0 | 102 | virtual nsresult StartPreviewImpl() = 0; |
michael@0 | 103 | virtual nsresult StopPreviewImpl() = 0; |
michael@0 | 104 | virtual nsresult AutoFocusImpl() = 0; |
michael@0 | 105 | virtual nsresult StartFaceDetectionImpl() = 0; |
michael@0 | 106 | virtual nsresult StopFaceDetectionImpl() = 0; |
michael@0 | 107 | virtual nsresult TakePictureImpl() = 0; |
michael@0 | 108 | virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor, |
michael@0 | 109 | const StartRecordingOptions* aOptions) = 0; |
michael@0 | 110 | virtual nsresult StopRecordingImpl() = 0; |
michael@0 | 111 | virtual nsresult ResumeContinuousFocusImpl() = 0; |
michael@0 | 112 | virtual nsresult PushParametersImpl() = 0; |
michael@0 | 113 | virtual nsresult PullParametersImpl() = 0; |
michael@0 | 114 | virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() = 0; |
michael@0 | 115 | |
michael@0 | 116 | void OnShutterInternal(); |
michael@0 | 117 | void OnClosedInternal(); |
michael@0 | 118 | |
michael@0 | 119 | uint32_t mCameraId; |
michael@0 | 120 | |
michael@0 | 121 | CameraControlListener::CameraListenerConfiguration mCurrentConfiguration; |
michael@0 | 122 | |
michael@0 | 123 | CameraControlListener::PreviewState mPreviewState; |
michael@0 | 124 | CameraControlListener::HardwareState mHardwareState; |
michael@0 | 125 | |
michael@0 | 126 | private: |
michael@0 | 127 | CameraControlImpl(const CameraControlImpl&) MOZ_DELETE; |
michael@0 | 128 | CameraControlImpl& operator=(const CameraControlImpl&) MOZ_DELETE; |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | } // namespace mozilla |
michael@0 | 132 | |
michael@0 | 133 | #endif // DOM_CAMERA_CAMERACONTROLIMPL_H |