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