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