content/media/webrtc/MediaEngineDefault.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef MEDIAENGINEDEFAULT_H_
michael@0 6 #define MEDIAENGINEDEFAULT_H_
michael@0 7
michael@0 8 #include "nsITimer.h"
michael@0 9
michael@0 10 #include "nsCOMPtr.h"
michael@0 11 #include "DOMMediaStream.h"
michael@0 12 #include "nsComponentManagerUtils.h"
michael@0 13 #include "mozilla/Monitor.h"
michael@0 14
michael@0 15 #include "VideoUtils.h"
michael@0 16 #include "MediaEngine.h"
michael@0 17 #include "VideoSegment.h"
michael@0 18 #include "AudioSegment.h"
michael@0 19 #include "StreamBuffer.h"
michael@0 20 #include "MediaStreamGraph.h"
michael@0 21
michael@0 22 namespace mozilla {
michael@0 23
michael@0 24 namespace layers {
michael@0 25 class ImageContainer;
michael@0 26 class PlanarYCbCrImage;
michael@0 27 }
michael@0 28
michael@0 29 class MediaEngineDefault;
michael@0 30
michael@0 31 /**
michael@0 32 * The default implementation of the MediaEngine interface.
michael@0 33 */
michael@0 34 class MediaEngineDefaultVideoSource : public nsITimerCallback,
michael@0 35 public MediaEngineVideoSource
michael@0 36 {
michael@0 37 public:
michael@0 38 MediaEngineDefaultVideoSource();
michael@0 39 ~MediaEngineDefaultVideoSource();
michael@0 40
michael@0 41 virtual void GetName(nsAString&);
michael@0 42 virtual void GetUUID(nsAString&);
michael@0 43
michael@0 44 virtual nsresult Allocate(const VideoTrackConstraintsN &aConstraints,
michael@0 45 const MediaEnginePrefs &aPrefs);
michael@0 46 virtual nsresult Deallocate();
michael@0 47 virtual nsresult Start(SourceMediaStream*, TrackID);
michael@0 48 virtual nsresult Stop(SourceMediaStream*, TrackID);
michael@0 49 virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile);
michael@0 50 virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
michael@0 51 bool aAgcOn, uint32_t aAGC,
michael@0 52 bool aNoiseOn, uint32_t aNoise,
michael@0 53 int32_t aPlayoutDelay) { return NS_OK; };
michael@0 54 virtual void NotifyPull(MediaStreamGraph* aGraph,
michael@0 55 SourceMediaStream *aSource,
michael@0 56 TrackID aId,
michael@0 57 StreamTime aDesiredTime,
michael@0 58 TrackTicks &aLastEndTime);
michael@0 59
michael@0 60 virtual bool IsFake() {
michael@0 61 return true;
michael@0 62 }
michael@0 63
michael@0 64 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 65 NS_DECL_NSITIMERCALLBACK
michael@0 66
michael@0 67 protected:
michael@0 68 friend class MediaEngineDefault;
michael@0 69
michael@0 70 TrackID mTrackID;
michael@0 71 nsCOMPtr<nsITimer> mTimer;
michael@0 72 // mMonitor protects mImage access/changes, and transitions of mState
michael@0 73 // from kStarted to kStopped (which are combined with EndTrack() and
michael@0 74 // image changes). Note that mSources is not accessed from other threads
michael@0 75 // for video and is not protected.
michael@0 76 Monitor mMonitor;
michael@0 77 nsRefPtr<layers::Image> mImage;
michael@0 78
michael@0 79 nsRefPtr<layers::ImageContainer> mImageContainer;
michael@0 80
michael@0 81 MediaEnginePrefs mOpts;
michael@0 82 int mCb;
michael@0 83 int mCr;
michael@0 84 };
michael@0 85
michael@0 86 class SineWaveGenerator;
michael@0 87
michael@0 88 class MediaEngineDefaultAudioSource : public nsITimerCallback,
michael@0 89 public MediaEngineAudioSource
michael@0 90 {
michael@0 91 public:
michael@0 92 MediaEngineDefaultAudioSource();
michael@0 93 ~MediaEngineDefaultAudioSource();
michael@0 94
michael@0 95 virtual void GetName(nsAString&);
michael@0 96 virtual void GetUUID(nsAString&);
michael@0 97
michael@0 98 virtual nsresult Allocate(const AudioTrackConstraintsN &aConstraints,
michael@0 99 const MediaEnginePrefs &aPrefs);
michael@0 100 virtual nsresult Deallocate();
michael@0 101 virtual nsresult Start(SourceMediaStream*, TrackID);
michael@0 102 virtual nsresult Stop(SourceMediaStream*, TrackID);
michael@0 103 virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile);
michael@0 104 virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
michael@0 105 bool aAgcOn, uint32_t aAGC,
michael@0 106 bool aNoiseOn, uint32_t aNoise,
michael@0 107 int32_t aPlayoutDelay) { return NS_OK; };
michael@0 108 virtual void NotifyPull(MediaStreamGraph* aGraph,
michael@0 109 SourceMediaStream *aSource,
michael@0 110 TrackID aId,
michael@0 111 StreamTime aDesiredTime,
michael@0 112 TrackTicks &aLastEndTime) {}
michael@0 113
michael@0 114 virtual bool IsFake() {
michael@0 115 return true;
michael@0 116 }
michael@0 117
michael@0 118 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 119 NS_DECL_NSITIMERCALLBACK
michael@0 120
michael@0 121 protected:
michael@0 122 TrackID mTrackID;
michael@0 123 nsCOMPtr<nsITimer> mTimer;
michael@0 124
michael@0 125 SourceMediaStream* mSource;
michael@0 126 nsAutoPtr<SineWaveGenerator> mSineGenerator;
michael@0 127 };
michael@0 128
michael@0 129
michael@0 130 class MediaEngineDefault : public MediaEngine
michael@0 131 {
michael@0 132 public:
michael@0 133 MediaEngineDefault()
michael@0 134 : mMutex("mozilla::MediaEngineDefault")
michael@0 135 {}
michael@0 136
michael@0 137 virtual void EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >*);
michael@0 138 virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
michael@0 139
michael@0 140 private:
michael@0 141 ~MediaEngineDefault() {}
michael@0 142
michael@0 143 Mutex mMutex;
michael@0 144 // protected with mMutex:
michael@0 145
michael@0 146 nsTArray<nsRefPtr<MediaEngineVideoSource> > mVSources;
michael@0 147 nsTArray<nsRefPtr<MediaEngineAudioSource> > mASources;
michael@0 148 };
michael@0 149
michael@0 150 }
michael@0 151
michael@0 152 #endif /* NSMEDIAENGINEDEFAULT_H_ */

mercurial