|
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/. */ |
|
4 |
|
5 #ifndef MEDIAENGINEDEFAULT_H_ |
|
6 #define MEDIAENGINEDEFAULT_H_ |
|
7 |
|
8 #include "nsITimer.h" |
|
9 |
|
10 #include "nsCOMPtr.h" |
|
11 #include "DOMMediaStream.h" |
|
12 #include "nsComponentManagerUtils.h" |
|
13 #include "mozilla/Monitor.h" |
|
14 |
|
15 #include "VideoUtils.h" |
|
16 #include "MediaEngine.h" |
|
17 #include "VideoSegment.h" |
|
18 #include "AudioSegment.h" |
|
19 #include "StreamBuffer.h" |
|
20 #include "MediaStreamGraph.h" |
|
21 |
|
22 namespace mozilla { |
|
23 |
|
24 namespace layers { |
|
25 class ImageContainer; |
|
26 class PlanarYCbCrImage; |
|
27 } |
|
28 |
|
29 class MediaEngineDefault; |
|
30 |
|
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(); |
|
40 |
|
41 virtual void GetName(nsAString&); |
|
42 virtual void GetUUID(nsAString&); |
|
43 |
|
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); |
|
59 |
|
60 virtual bool IsFake() { |
|
61 return true; |
|
62 } |
|
63 |
|
64 NS_DECL_THREADSAFE_ISUPPORTS |
|
65 NS_DECL_NSITIMERCALLBACK |
|
66 |
|
67 protected: |
|
68 friend class MediaEngineDefault; |
|
69 |
|
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; |
|
78 |
|
79 nsRefPtr<layers::ImageContainer> mImageContainer; |
|
80 |
|
81 MediaEnginePrefs mOpts; |
|
82 int mCb; |
|
83 int mCr; |
|
84 }; |
|
85 |
|
86 class SineWaveGenerator; |
|
87 |
|
88 class MediaEngineDefaultAudioSource : public nsITimerCallback, |
|
89 public MediaEngineAudioSource |
|
90 { |
|
91 public: |
|
92 MediaEngineDefaultAudioSource(); |
|
93 ~MediaEngineDefaultAudioSource(); |
|
94 |
|
95 virtual void GetName(nsAString&); |
|
96 virtual void GetUUID(nsAString&); |
|
97 |
|
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) {} |
|
113 |
|
114 virtual bool IsFake() { |
|
115 return true; |
|
116 } |
|
117 |
|
118 NS_DECL_THREADSAFE_ISUPPORTS |
|
119 NS_DECL_NSITIMERCALLBACK |
|
120 |
|
121 protected: |
|
122 TrackID mTrackID; |
|
123 nsCOMPtr<nsITimer> mTimer; |
|
124 |
|
125 SourceMediaStream* mSource; |
|
126 nsAutoPtr<SineWaveGenerator> mSineGenerator; |
|
127 }; |
|
128 |
|
129 |
|
130 class MediaEngineDefault : public MediaEngine |
|
131 { |
|
132 public: |
|
133 MediaEngineDefault() |
|
134 : mMutex("mozilla::MediaEngineDefault") |
|
135 {} |
|
136 |
|
137 virtual void EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >*); |
|
138 virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*); |
|
139 |
|
140 private: |
|
141 ~MediaEngineDefault() {} |
|
142 |
|
143 Mutex mMutex; |
|
144 // protected with mMutex: |
|
145 |
|
146 nsTArray<nsRefPtr<MediaEngineVideoSource> > mVSources; |
|
147 nsTArray<nsRefPtr<MediaEngineAudioSource> > mASources; |
|
148 }; |
|
149 |
|
150 } |
|
151 |
|
152 #endif /* NSMEDIAENGINEDEFAULT_H_ */ |