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
;
20 typedef void (*FrameBuilder
)(Image
* aImage
, void* aBuffer
, uint32_t aWidth
, uint32_t aHeight
);
23 * DOMCameraPreview is only exposed to the DOM as an nsDOMMediaStream,
24 * which is a cycle-collection participant already.
26 class DOMCameraPreview
: public nsDOMMediaStream
29 enum { TRACK_VIDEO
= 1 };
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();
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();
52 virtual ~DOMCameraPreview();
64 uint32_t mFramesPerSecond
;
65 SourceMediaStream
* mInput
;
66 nsRefPtr
<ImageContainer
> mImageContainer
;
67 VideoSegment mVideoSegment
;
69 nsRefPtr
<ICameraControl
> mCameraControl
;
71 // Raw pointer; AddListener() keeps the reference for us
72 MediaStreamListener
* mListener
;
75 DOMCameraPreview(const DOMCameraPreview
&) MOZ_DELETE
;
76 DOMCameraPreview
& operator=(const DOMCameraPreview
&) MOZ_DELETE
;
79 } // namespace mozilla
81 #endif // DOM_CAMERA_DOMCAMERAPREVIEW_H