2012-09-04 18:01:56 -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/. */
|
|
|
|
|
|
|
|
#ifndef DOM_CAMERA_DOMCAMERAPREVIEW_H
|
|
|
|
#define DOM_CAMERA_DOMCAMERAPREVIEW_H
|
|
|
|
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
|
|
|
#include "StreamBuffer.h"
|
|
|
|
#include "ICameraControl.h"
|
2013-02-15 00:01:58 -08:00
|
|
|
#include "DOMMediaStream.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "CameraCommon.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-11-10 07:45:52 -08:00
|
|
|
typedef void (*FrameBuilder)(mozilla::layers::Image* aImage, void* aBuffer, uint32_t aWidth, uint32_t aHeight);
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DOMCameraPreview is only exposed to the DOM as an nsDOMMediaStream,
|
|
|
|
* which is a cycle-collection participant already.
|
|
|
|
*/
|
2013-02-15 00:01:58 -08:00
|
|
|
class DOMCameraPreview : public DOMMediaStream
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
enum { TRACK_VIDEO = 1 };
|
|
|
|
|
|
|
|
public:
|
2013-01-30 02:03:17 -08:00
|
|
|
DOMCameraPreview(ICameraControl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint64_t aWindowId, uint32_t aFramesPerSecond = 30);
|
2012-11-10 07:45:52 -08:00
|
|
|
bool ReceiveFrame(void* aBuffer, ImageFormat aFormat, mozilla::FrameBuilder aBuilder);
|
2012-09-04 18:01:56 -07:00
|
|
|
bool HaveEnoughBuffered();
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GetCurrentTime(double* aCurrentTime) {
|
2013-02-15 00:01:58 -08:00
|
|
|
return DOMMediaStream::GetCurrentTime(aCurrentTime);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Start(); // called by the MediaStreamListener to start preview
|
|
|
|
void Started(); // called by the CameraControl when preview is started
|
2012-12-23 07:54:54 -08:00
|
|
|
void StopPreview(); // called by the MediaStreamListener to stop preview
|
2012-09-04 18:01:56 -07:00
|
|
|
void Stopped(bool aForced = false);
|
|
|
|
// called by the CameraControl when preview is stopped
|
|
|
|
void Error(); // something went wrong, NS_RELEASE needed
|
|
|
|
|
|
|
|
void SetStateStarted();
|
|
|
|
void SetStateStopped();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~DOMCameraPreview();
|
|
|
|
|
|
|
|
enum {
|
|
|
|
STOPPED,
|
|
|
|
STARTING,
|
|
|
|
STARTED,
|
|
|
|
STOPPING
|
|
|
|
};
|
|
|
|
uint32_t mState;
|
|
|
|
|
2012-12-23 07:54:54 -08:00
|
|
|
// Helper function, used in conjunction with the macro below, to make
|
|
|
|
// it easy to track state changes, which must happen only on the main
|
|
|
|
// thread.
|
|
|
|
void
|
|
|
|
SetState(uint32_t aNewState, const char* aFileOrFunc, int aLine)
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
const char* states[] = { "stopped", "starting", "started", "stopping" };
|
|
|
|
MOZ_ASSERT(mState < sizeof(states) / sizeof(states[0]));
|
|
|
|
MOZ_ASSERT(aNewState < sizeof(states) / sizeof(states[0]));
|
|
|
|
DOM_CAMERA_LOGI("SetState: (this=%p) '%s' --> '%s' : %s:%d\n", this, states[mState], states[aNewState], aFileOrFunc, aLine);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Preview state set OFF OF main thread!");
|
|
|
|
mState = aNewState;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
|
|
|
uint32_t mFramesPerSecond;
|
|
|
|
SourceMediaStream* mInput;
|
2012-11-10 07:45:52 -08:00
|
|
|
nsRefPtr<mozilla::layers::ImageContainer> mImageContainer;
|
2012-09-04 18:01:56 -07:00
|
|
|
VideoSegment mVideoSegment;
|
|
|
|
uint32_t mFrameCount;
|
|
|
|
nsRefPtr<ICameraControl> mCameraControl;
|
|
|
|
|
|
|
|
// Raw pointer; AddListener() keeps the reference for us
|
|
|
|
MediaStreamListener* mListener;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DOMCameraPreview(const DOMCameraPreview&) MOZ_DELETE;
|
|
|
|
DOMCameraPreview& operator=(const DOMCameraPreview&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-12-23 07:54:54 -08:00
|
|
|
#define DOM_CAMERA_SETSTATE(newState) SetState((newState), __func__, __LINE__)
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#endif // DOM_CAMERA_DOMCAMERAPREVIEW_H
|