Bug 788829 - Call SetSizeConstraints even if a popup is not open. r=enndeakin
[gecko.git] / dom / camera / DOMCameraPreview.h
blob6285ff7c94d6b8ae8e5397f36f6b61976464ec1e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef DOM_CAMERA_DOMCAMERAPREVIEW_H
6 #define DOM_CAMERA_DOMCAMERAPREVIEW_H
8 #include "nsCycleCollectionParticipant.h"
9 #include "MediaStreamGraph.h"
10 #include "StreamBuffer.h"
11 #include "ICameraControl.h"
12 #include "nsDOMMediaStream.h"
13 #include "CameraCommon.h"
15 using namespace mozilla;
16 using namespace mozilla::layers;
18 namespace mozilla {
20 typedef void (*FrameBuilder)(Image* aImage, void* aBuffer, uint32_t aWidth, uint32_t aHeight);
22 /**
23 * DOMCameraPreview is only exposed to the DOM as an nsDOMMediaStream,
24 * which is a cycle-collection participant already.
26 class DOMCameraPreview : public nsDOMMediaStream
28 protected:
29 enum { TRACK_VIDEO = 1 };
31 public:
32 DOMCameraPreview(ICameraControl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint32_t aFramesPerSecond = 30);
33 bool ReceiveFrame(void* aBuffer, ImageFormat aFormat, FrameBuilder aBuilder);
34 bool HaveEnoughBuffered();
36 NS_IMETHODIMP
37 GetCurrentTime(double* aCurrentTime) {
38 return nsDOMMediaStream::GetCurrentTime(aCurrentTime);
41 void Start(); // called by the MediaStreamListener to start preview
42 void Started(); // called by the CameraControl when preview is started
43 void Stop(); // called by the MediaStreamListener to stop preview
44 void Stopped(bool aForced = false);
45 // called by the CameraControl when preview is stopped
46 void Error(); // something went wrong, NS_RELEASE needed
48 void SetStateStarted();
49 void SetStateStopped();
51 protected:
52 virtual ~DOMCameraPreview();
54 enum {
55 STOPPED,
56 STARTING,
57 STARTED,
58 STOPPING
60 uint32_t mState;
62 uint32_t mWidth;
63 uint32_t mHeight;
64 uint32_t mFramesPerSecond;
65 SourceMediaStream* mInput;
66 nsRefPtr<ImageContainer> mImageContainer;
67 VideoSegment mVideoSegment;
68 uint32_t mFrameCount;
69 nsRefPtr<ICameraControl> mCameraControl;
71 // Raw pointer; AddListener() keeps the reference for us
72 MediaStreamListener* mListener;
74 private:
75 DOMCameraPreview(const DOMCameraPreview&) MOZ_DELETE;
76 DOMCameraPreview& operator=(const DOMCameraPreview&) MOZ_DELETE;
79 } // namespace mozilla
81 #endif // DOM_CAMERA_DOMCAMERAPREVIEW_H