2012-06-03 11:34:40 +04: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 MEDIAENGINEDEFAULT_H_
|
|
|
|
#define MEDIAENGINEDEFAULT_H_
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2013-02-15 12:01:58 +04:00
|
|
|
#include "DOMMediaStream.h"
|
2012-06-03 11:34:40 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-08-15 01:01:16 +04:00
|
|
|
#include "mozilla/Monitor.h"
|
2012-06-03 11:34:40 +04:00
|
|
|
|
|
|
|
#include "VideoUtils.h"
|
|
|
|
#include "MediaEngine.h"
|
|
|
|
#include "VideoSegment.h"
|
|
|
|
#include "AudioSegment.h"
|
|
|
|
#include "StreamBuffer.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-07-31 04:42:26 +04:00
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
|
|
|
class PlanarYCbCrImage;
|
|
|
|
}
|
|
|
|
|
2013-02-20 19:18:54 +04:00
|
|
|
class MediaEngineDefault;
|
|
|
|
|
2012-06-03 11:34:40 +04:00
|
|
|
/**
|
|
|
|
* The default implementation of the MediaEngine interface.
|
|
|
|
*/
|
|
|
|
class MediaEngineDefaultVideoSource : public nsITimerCallback,
|
|
|
|
public MediaEngineVideoSource
|
|
|
|
{
|
|
|
|
public:
|
2013-03-05 01:02:17 +04:00
|
|
|
MediaEngineDefaultVideoSource();
|
2012-06-03 11:34:40 +04:00
|
|
|
|
|
|
|
virtual void GetName(nsAString&);
|
|
|
|
virtual void GetUUID(nsAString&);
|
|
|
|
|
2014-04-18 23:15:10 +04:00
|
|
|
virtual nsresult Allocate(const VideoTrackConstraintsN &aConstraints,
|
|
|
|
const MediaEnginePrefs &aPrefs);
|
2012-06-03 11:34:40 +04:00
|
|
|
virtual nsresult Deallocate();
|
|
|
|
virtual nsresult Start(SourceMediaStream*, TrackID);
|
2013-01-01 03:12:12 +04:00
|
|
|
virtual nsresult Stop(SourceMediaStream*, TrackID);
|
2014-07-14 09:48:02 +04:00
|
|
|
virtual void SetDirectListeners(bool aHasDirectListeners) {};
|
2013-01-29 20:55:09 +04:00
|
|
|
virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
|
|
|
|
bool aAgcOn, uint32_t aAGC,
|
2014-04-02 21:58:19 +04:00
|
|
|
bool aNoiseOn, uint32_t aNoise,
|
|
|
|
int32_t aPlayoutDelay) { return NS_OK; };
|
2013-01-01 03:12:12 +04:00
|
|
|
virtual void NotifyPull(MediaStreamGraph* aGraph,
|
|
|
|
SourceMediaStream *aSource,
|
|
|
|
TrackID aId,
|
|
|
|
StreamTime aDesiredTime,
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime &aLastEndTime);
|
2014-09-25 03:00:02 +04:00
|
|
|
virtual bool SatisfiesConstraintSets(
|
|
|
|
const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-03 11:34:40 +04:00
|
|
|
|
2013-07-05 09:53:10 +04:00
|
|
|
virtual bool IsFake() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-18 06:23:00 +04:00
|
|
|
virtual const MediaSourceType GetMediaSource() {
|
|
|
|
return MediaSourceType::Camera;
|
|
|
|
}
|
|
|
|
|
2014-09-09 02:17:00 +04:00
|
|
|
virtual nsresult TakePhoto(PhotoCallback* aCallback)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2013-07-19 06:21:19 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-06-03 11:34:40 +04:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
|
|
|
protected:
|
2014-06-24 20:36:43 +04:00
|
|
|
~MediaEngineDefaultVideoSource();
|
|
|
|
|
2013-02-20 19:18:54 +04:00
|
|
|
friend class MediaEngineDefault;
|
|
|
|
|
2012-06-03 11:34:40 +04:00
|
|
|
TrackID mTrackID;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2013-08-15 01:01:16 +04:00
|
|
|
// mMonitor protects mImage access/changes, and transitions of mState
|
|
|
|
// from kStarted to kStopped (which are combined with EndTrack() and
|
|
|
|
// image changes). Note that mSources is not accessed from other threads
|
|
|
|
// for video and is not protected.
|
|
|
|
Monitor mMonitor;
|
|
|
|
nsRefPtr<layers::Image> mImage;
|
|
|
|
|
2012-06-03 11:34:40 +04:00
|
|
|
nsRefPtr<layers::ImageContainer> mImageContainer;
|
|
|
|
|
2013-03-05 01:02:17 +04:00
|
|
|
MediaEnginePrefs mOpts;
|
2012-11-28 04:15:55 +04:00
|
|
|
int mCb;
|
|
|
|
int mCr;
|
2012-06-03 11:34:40 +04:00
|
|
|
};
|
|
|
|
|
2013-09-05 16:34:49 +04:00
|
|
|
class SineWaveGenerator;
|
|
|
|
|
2012-06-03 11:34:40 +04:00
|
|
|
class MediaEngineDefaultAudioSource : public nsITimerCallback,
|
|
|
|
public MediaEngineAudioSource
|
|
|
|
{
|
|
|
|
public:
|
2012-10-17 04:53:55 +04:00
|
|
|
MediaEngineDefaultAudioSource();
|
2012-06-03 11:34:40 +04:00
|
|
|
|
|
|
|
virtual void GetName(nsAString&);
|
|
|
|
virtual void GetUUID(nsAString&);
|
|
|
|
|
2014-04-18 23:15:10 +04:00
|
|
|
virtual nsresult Allocate(const AudioTrackConstraintsN &aConstraints,
|
|
|
|
const MediaEnginePrefs &aPrefs);
|
2012-06-03 11:34:40 +04:00
|
|
|
virtual nsresult Deallocate();
|
|
|
|
virtual nsresult Start(SourceMediaStream*, TrackID);
|
2013-01-01 03:12:12 +04:00
|
|
|
virtual nsresult Stop(SourceMediaStream*, TrackID);
|
2014-07-14 09:48:02 +04:00
|
|
|
virtual void SetDirectListeners(bool aHasDirectListeners) {};
|
2013-01-29 20:55:09 +04:00
|
|
|
virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
|
|
|
|
bool aAgcOn, uint32_t aAGC,
|
2014-04-02 21:58:19 +04:00
|
|
|
bool aNoiseOn, uint32_t aNoise,
|
|
|
|
int32_t aPlayoutDelay) { return NS_OK; };
|
2013-01-01 03:12:12 +04:00
|
|
|
virtual void NotifyPull(MediaStreamGraph* aGraph,
|
|
|
|
SourceMediaStream *aSource,
|
|
|
|
TrackID aId,
|
|
|
|
StreamTime aDesiredTime,
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime &aLastEndTime) {}
|
2012-06-03 11:34:40 +04:00
|
|
|
|
2013-07-05 09:53:10 +04:00
|
|
|
virtual bool IsFake() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-18 06:23:00 +04:00
|
|
|
virtual const MediaSourceType GetMediaSource() {
|
|
|
|
return MediaSourceType::Microphone;
|
|
|
|
}
|
|
|
|
|
2014-09-09 02:17:00 +04:00
|
|
|
virtual nsresult TakePhoto(PhotoCallback* aCallback)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2013-07-19 06:21:19 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-06-03 11:34:40 +04:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
|
|
|
protected:
|
2014-06-24 20:36:43 +04:00
|
|
|
~MediaEngineDefaultAudioSource();
|
|
|
|
|
2012-06-03 11:34:40 +04:00
|
|
|
TrackID mTrackID;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
|
|
|
|
SourceMediaStream* mSource;
|
2014-04-10 00:59:25 +04:00
|
|
|
nsAutoPtr<SineWaveGenerator> mSineGenerator;
|
2012-06-03 11:34:40 +04:00
|
|
|
};
|
|
|
|
|
2013-07-19 06:21:19 +04:00
|
|
|
|
2012-06-03 11:34:40 +04:00
|
|
|
class MediaEngineDefault : public MediaEngine
|
|
|
|
{
|
|
|
|
public:
|
2012-10-20 02:06:18 +04:00
|
|
|
MediaEngineDefault()
|
|
|
|
: mMutex("mozilla::MediaEngineDefault")
|
|
|
|
{}
|
2012-06-03 11:34:40 +04:00
|
|
|
|
2014-07-18 06:23:00 +04:00
|
|
|
virtual void EnumerateVideoDevices(MediaSourceType,
|
2014-07-07 11:46:00 +04:00
|
|
|
nsTArray<nsRefPtr<MediaEngineVideoSource> >*);
|
2014-07-18 06:23:00 +04:00
|
|
|
virtual void EnumerateAudioDevices(MediaSourceType,
|
2014-07-07 11:46:00 +04:00
|
|
|
nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
|
2012-06-03 11:34:40 +04:00
|
|
|
|
|
|
|
private:
|
2014-04-11 19:35:34 +04:00
|
|
|
~MediaEngineDefault() {}
|
|
|
|
|
2012-10-20 02:06:18 +04:00
|
|
|
Mutex mMutex;
|
|
|
|
// protected with mMutex:
|
|
|
|
|
2012-10-17 04:53:55 +04:00
|
|
|
nsTArray<nsRefPtr<MediaEngineVideoSource> > mVSources;
|
|
|
|
nsTArray<nsRefPtr<MediaEngineAudioSource> > mASources;
|
2012-06-03 11:34:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NSMEDIAENGINEDEFAULT_H_ */
|