content/media/webrtc/MediaEngineDefault.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webrtc/MediaEngineDefault.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef MEDIAENGINEDEFAULT_H_
     1.9 +#define MEDIAENGINEDEFAULT_H_
    1.10 +
    1.11 +#include "nsITimer.h"
    1.12 +
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "DOMMediaStream.h"
    1.15 +#include "nsComponentManagerUtils.h"
    1.16 +#include "mozilla/Monitor.h"
    1.17 +
    1.18 +#include "VideoUtils.h"
    1.19 +#include "MediaEngine.h"
    1.20 +#include "VideoSegment.h"
    1.21 +#include "AudioSegment.h"
    1.22 +#include "StreamBuffer.h"
    1.23 +#include "MediaStreamGraph.h"
    1.24 +
    1.25 +namespace mozilla {
    1.26 +
    1.27 +namespace layers {
    1.28 +class ImageContainer;
    1.29 +class PlanarYCbCrImage;
    1.30 +}
    1.31 +
    1.32 +class MediaEngineDefault;
    1.33 +
    1.34 +/**
    1.35 + * The default implementation of the MediaEngine interface.
    1.36 + */
    1.37 +class MediaEngineDefaultVideoSource : public nsITimerCallback,
    1.38 +                                      public MediaEngineVideoSource
    1.39 +{
    1.40 +public:
    1.41 +  MediaEngineDefaultVideoSource();
    1.42 +  ~MediaEngineDefaultVideoSource();
    1.43 +
    1.44 +  virtual void GetName(nsAString&);
    1.45 +  virtual void GetUUID(nsAString&);
    1.46 +
    1.47 +  virtual nsresult Allocate(const VideoTrackConstraintsN &aConstraints,
    1.48 +                            const MediaEnginePrefs &aPrefs);
    1.49 +  virtual nsresult Deallocate();
    1.50 +  virtual nsresult Start(SourceMediaStream*, TrackID);
    1.51 +  virtual nsresult Stop(SourceMediaStream*, TrackID);
    1.52 +  virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile);
    1.53 +  virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
    1.54 +                          bool aAgcOn, uint32_t aAGC,
    1.55 +                          bool aNoiseOn, uint32_t aNoise,
    1.56 +                          int32_t aPlayoutDelay) { return NS_OK; };
    1.57 +  virtual void NotifyPull(MediaStreamGraph* aGraph,
    1.58 +                          SourceMediaStream *aSource,
    1.59 +                          TrackID aId,
    1.60 +                          StreamTime aDesiredTime,
    1.61 +                          TrackTicks &aLastEndTime);
    1.62 +
    1.63 +  virtual bool IsFake() {
    1.64 +    return true;
    1.65 +  }
    1.66 +
    1.67 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.68 +  NS_DECL_NSITIMERCALLBACK
    1.69 +
    1.70 +protected:
    1.71 +  friend class MediaEngineDefault;
    1.72 +
    1.73 +  TrackID mTrackID;
    1.74 +  nsCOMPtr<nsITimer> mTimer;
    1.75 +  // mMonitor protects mImage access/changes, and transitions of mState
    1.76 +  // from kStarted to kStopped (which are combined with EndTrack() and
    1.77 +  // image changes).  Note that mSources is not accessed from other threads
    1.78 +  // for video and is not protected.
    1.79 +  Monitor mMonitor;
    1.80 +  nsRefPtr<layers::Image> mImage;
    1.81 +
    1.82 +  nsRefPtr<layers::ImageContainer> mImageContainer;
    1.83 +
    1.84 +  MediaEnginePrefs mOpts;
    1.85 +  int mCb;
    1.86 +  int mCr;
    1.87 +};
    1.88 +
    1.89 +class SineWaveGenerator;
    1.90 +
    1.91 +class MediaEngineDefaultAudioSource : public nsITimerCallback,
    1.92 +                                      public MediaEngineAudioSource
    1.93 +{
    1.94 +public:
    1.95 +  MediaEngineDefaultAudioSource();
    1.96 +  ~MediaEngineDefaultAudioSource();
    1.97 +
    1.98 +  virtual void GetName(nsAString&);
    1.99 +  virtual void GetUUID(nsAString&);
   1.100 +
   1.101 +  virtual nsresult Allocate(const AudioTrackConstraintsN &aConstraints,
   1.102 +                            const MediaEnginePrefs &aPrefs);
   1.103 +  virtual nsresult Deallocate();
   1.104 +  virtual nsresult Start(SourceMediaStream*, TrackID);
   1.105 +  virtual nsresult Stop(SourceMediaStream*, TrackID);
   1.106 +  virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile);
   1.107 +  virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
   1.108 +                          bool aAgcOn, uint32_t aAGC,
   1.109 +                          bool aNoiseOn, uint32_t aNoise,
   1.110 +                          int32_t aPlayoutDelay) { return NS_OK; };
   1.111 +  virtual void NotifyPull(MediaStreamGraph* aGraph,
   1.112 +                          SourceMediaStream *aSource,
   1.113 +                          TrackID aId,
   1.114 +                          StreamTime aDesiredTime,
   1.115 +                          TrackTicks &aLastEndTime) {}
   1.116 +
   1.117 +  virtual bool IsFake() {
   1.118 +    return true;
   1.119 +  }
   1.120 +
   1.121 +  NS_DECL_THREADSAFE_ISUPPORTS
   1.122 +  NS_DECL_NSITIMERCALLBACK
   1.123 +
   1.124 +protected:
   1.125 +  TrackID mTrackID;
   1.126 +  nsCOMPtr<nsITimer> mTimer;
   1.127 +
   1.128 +  SourceMediaStream* mSource;
   1.129 +  nsAutoPtr<SineWaveGenerator> mSineGenerator;
   1.130 +};
   1.131 +
   1.132 +
   1.133 +class MediaEngineDefault : public MediaEngine
   1.134 +{
   1.135 +public:
   1.136 +  MediaEngineDefault()
   1.137 +  : mMutex("mozilla::MediaEngineDefault")
   1.138 +  {}
   1.139 +
   1.140 +  virtual void EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >*);
   1.141 +  virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
   1.142 +
   1.143 +private:
   1.144 +  ~MediaEngineDefault() {}
   1.145 +
   1.146 +  Mutex mMutex;
   1.147 +  // protected with mMutex:
   1.148 +
   1.149 +  nsTArray<nsRefPtr<MediaEngineVideoSource> > mVSources;
   1.150 +  nsTArray<nsRefPtr<MediaEngineAudioSource> > mASources;
   1.151 +};
   1.152 +
   1.153 +}
   1.154 +
   1.155 +#endif /* NSMEDIAENGINEDEFAULT_H_ */

mercurial