OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 }; | 46 }; |
47 | 47 |
48 class NotifierInterface { | 48 class NotifierInterface { |
49 public: | 49 public: |
50 virtual void RegisterObserver(ObserverInterface* observer) = 0; | 50 virtual void RegisterObserver(ObserverInterface* observer) = 0; |
51 virtual void UnregisterObserver(ObserverInterface* observer) = 0; | 51 virtual void UnregisterObserver(ObserverInterface* observer) = 0; |
52 | 52 |
53 virtual ~NotifierInterface() {} | 53 virtual ~NotifierInterface() {} |
54 }; | 54 }; |
55 | 55 |
56 // Base class for sources. A MediaStreamTrack have an underlying source that | 56 // Base class for sources. A MediaStreamTrack has an underlying source that |
57 // provide media. A source can be shared with multiple tracks. | 57 // provides media. A source can be shared by multiple tracks. |
58 class MediaSourceInterface : public rtc::RefCountInterface, | 58 class MediaSourceInterface : public rtc::RefCountInterface, |
59 public NotifierInterface { | 59 public NotifierInterface { |
60 public: | 60 public: |
61 enum SourceState { | 61 enum SourceState { |
62 kInitializing, | 62 kInitializing, |
63 kLive, | 63 kLive, |
64 kEnded, | 64 kEnded, |
65 kMuted | 65 kMuted |
66 }; | 66 }; |
67 | 67 |
68 virtual SourceState state() const = 0; | 68 virtual SourceState state() const = 0; |
69 | 69 |
70 virtual bool remote() const = 0; | 70 virtual bool remote() const = 0; |
71 | 71 |
72 protected: | 72 protected: |
73 virtual ~MediaSourceInterface() {} | 73 virtual ~MediaSourceInterface() {} |
74 }; | 74 }; |
75 | 75 |
76 // Information about a track. | 76 // C++ version of MediaStreamTrack. |
| 77 // See: https://www.w3.org/TR/mediacapture-streams/#mediastreamtrack |
77 class MediaStreamTrackInterface : public rtc::RefCountInterface, | 78 class MediaStreamTrackInterface : public rtc::RefCountInterface, |
78 public NotifierInterface { | 79 public NotifierInterface { |
79 public: | 80 public: |
80 enum TrackState { | 81 enum TrackState { |
81 kLive, | 82 kLive, |
82 kEnded, | 83 kEnded, |
83 }; | 84 }; |
84 | 85 |
85 static const char kAudioKind[]; | 86 static const char kAudioKind[]; |
86 static const char kVideoKind[]; | 87 static const char kVideoKind[]; |
87 | 88 |
88 // The kind() method must return kAudioKind only if the object is a | 89 // The kind() method must return kAudioKind only if the object is a |
89 // subclass of AudioTrackInterface, and kVideoKind only if the | 90 // subclass of AudioTrackInterface, and kVideoKind only if the |
90 // object is a subclass of VideoTrackInterface. It is typically used | 91 // object is a subclass of VideoTrackInterface. It is typically used |
91 // to protect a static_cast<> to the corresponding subclass. | 92 // to protect a static_cast<> to the corresponding subclass. |
92 virtual std::string kind() const = 0; | 93 virtual std::string kind() const = 0; |
| 94 |
| 95 // Track identifier. |
93 virtual std::string id() const = 0; | 96 virtual std::string id() const = 0; |
| 97 |
| 98 // A disabled track will produce silence (if audio) or black frames (if |
| 99 // video). Can be disabled and re-enabled. |
94 virtual bool enabled() const = 0; | 100 virtual bool enabled() const = 0; |
| 101 virtual bool set_enabled(bool enable) = 0; |
| 102 |
| 103 // Live or ended. A track will never be live again after becoming ended. |
95 virtual TrackState state() const = 0; | 104 virtual TrackState state() const = 0; |
96 virtual bool set_enabled(bool enable) = 0; | |
97 | 105 |
98 protected: | 106 protected: |
99 virtual ~MediaStreamTrackInterface() {} | 107 virtual ~MediaStreamTrackInterface() {} |
100 }; | 108 }; |
101 | 109 |
102 // VideoTrackSourceInterface is a reference counted source used for VideoTracks. | 110 // VideoTrackSourceInterface is a reference counted source used for |
103 // The same source can be used in multiple VideoTracks. | 111 // VideoTracks. The same source can be used by multiple VideoTracks. |
104 class VideoTrackSourceInterface | 112 class VideoTrackSourceInterface |
105 : public MediaSourceInterface, | 113 : public MediaSourceInterface, |
106 public rtc::VideoSourceInterface<VideoFrame> { | 114 public rtc::VideoSourceInterface<VideoFrame> { |
107 public: | 115 public: |
108 struct Stats { | 116 struct Stats { |
109 // Original size of captured frame, before video adaptation. | 117 // Original size of captured frame, before video adaptation. |
110 int input_width; | 118 int input_width; |
111 int input_height; | 119 int input_height; |
112 }; | 120 }; |
113 | 121 |
114 // Indicates that parameters suitable for screencasts should be automatically | 122 // Indicates that parameters suitable for screencasts should be automatically |
115 // applied to RtpSenders. | 123 // applied to RtpSenders. |
116 // TODO(perkj): Remove these once all known applications have moved to | 124 // TODO(perkj): Remove these once all known applications have moved to |
117 // explicitly setting suitable parameters for screencasts and dont' need this | 125 // explicitly setting suitable parameters for screencasts and don't need this |
118 // implicit behavior. | 126 // implicit behavior. |
119 virtual bool is_screencast() const = 0; | 127 virtual bool is_screencast() const = 0; |
120 | 128 |
121 // Indicates that the encoder should denoise video before encoding it. | 129 // Indicates that the encoder should denoise video before encoding it. |
122 // If it is not set, the default configuration is used which is different | 130 // If it is not set, the default configuration is used which is different |
123 // depending on video codec. | 131 // depending on video codec. |
124 // TODO(perkj): Remove this once denoising is done by the source, and not by | 132 // TODO(perkj): Remove this once denoising is done by the source, and not by |
125 // the encoder. | 133 // the encoder. |
126 virtual rtc::Optional<bool> needs_denoising() const = 0; | 134 virtual rtc::Optional<bool> needs_denoising() const = 0; |
127 | 135 |
128 // Returns false if no stats are available, e.g, for a remote | 136 // Returns false if no stats are available, e.g, for a remote source, or a |
129 // source, or a source which has not seen its first frame yet. | 137 // source which has not seen its first frame yet. |
130 // Should avoid blocking. | 138 // |
| 139 // Implementation should avoid blocking. |
131 virtual bool GetStats(Stats* stats) = 0; | 140 virtual bool GetStats(Stats* stats) = 0; |
132 | 141 |
133 protected: | 142 protected: |
134 virtual ~VideoTrackSourceInterface() {} | 143 virtual ~VideoTrackSourceInterface() {} |
135 }; | 144 }; |
136 | 145 |
137 class VideoTrackInterface | 146 class VideoTrackInterface |
138 : public MediaStreamTrackInterface, | 147 : public MediaStreamTrackInterface, |
139 public rtc::VideoSourceInterface<VideoFrame> { | 148 public rtc::VideoSourceInterface<VideoFrame> { |
140 public: | 149 public: |
141 // Video track content hint, used to override the source is_screencast | 150 // Video track content hint, used to override the source is_screencast |
142 // property. | 151 // property. |
143 // See https://crbug.com/653531 and https://github.com/WICG/mst-content-hint. | 152 // See https://crbug.com/653531 and https://github.com/WICG/mst-content-hint. |
144 enum class ContentHint { kNone, kFluid, kDetailed }; | 153 enum class ContentHint { kNone, kFluid, kDetailed }; |
145 | 154 |
146 // Register a video sink for this track. | 155 // Register a video sink for this track. Used to connect the track to the |
| 156 // underlying video engine. |
147 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, | 157 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
148 const rtc::VideoSinkWants& wants) override {} | 158 const rtc::VideoSinkWants& wants) override {} |
149 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {} | 159 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {} |
150 | 160 |
151 virtual VideoTrackSourceInterface* GetSource() const = 0; | 161 virtual VideoTrackSourceInterface* GetSource() const = 0; |
152 | 162 |
153 virtual ContentHint content_hint() const { return ContentHint::kNone; } | 163 virtual ContentHint content_hint() const { return ContentHint::kNone; } |
154 virtual void set_content_hint(ContentHint hint) {} | 164 virtual void set_content_hint(ContentHint hint) {} |
155 | 165 |
156 protected: | 166 protected: |
157 virtual ~VideoTrackInterface() {} | 167 virtual ~VideoTrackInterface() {} |
158 }; | 168 }; |
159 | 169 |
160 // Interface for receiving audio data from a AudioTrack. | 170 // Interface for receiving audio data from a AudioTrack. |
161 class AudioTrackSinkInterface { | 171 class AudioTrackSinkInterface { |
162 public: | 172 public: |
163 virtual void OnData(const void* audio_data, | 173 virtual void OnData(const void* audio_data, |
164 int bits_per_sample, | 174 int bits_per_sample, |
165 int sample_rate, | 175 int sample_rate, |
166 size_t number_of_channels, | 176 size_t number_of_channels, |
167 size_t number_of_frames) = 0; | 177 size_t number_of_frames) = 0; |
168 | 178 |
169 protected: | 179 protected: |
170 virtual ~AudioTrackSinkInterface() {} | 180 virtual ~AudioTrackSinkInterface() {} |
171 }; | 181 }; |
172 | 182 |
173 // AudioSourceInterface is a reference counted source used for AudioTracks. | 183 // AudioSourceInterface is a reference counted source used for AudioTracks. |
174 // The same source can be used in multiple AudioTracks. | 184 // The same source can be used by multiple AudioTracks. |
175 class AudioSourceInterface : public MediaSourceInterface { | 185 class AudioSourceInterface : public MediaSourceInterface { |
176 public: | 186 public: |
177 class AudioObserver { | 187 class AudioObserver { |
178 public: | 188 public: |
179 virtual void OnSetVolume(double volume) = 0; | 189 virtual void OnSetVolume(double volume) = 0; |
180 | 190 |
181 protected: | 191 protected: |
182 virtual ~AudioObserver() {} | 192 virtual ~AudioObserver() {} |
183 }; | 193 }; |
184 | 194 |
185 // TODO(xians): Makes all the interface pure virtual after Chrome has their | 195 // TODO(deadbeef): Makes all the interfaces pure virtual after they're |
186 // implementations. | 196 // implemented in chromium. |
187 // Sets the volume to the source. |volume| is in the range of [0, 10]. | 197 |
| 198 // Sets the volume of the source. |volume| is in the range of [0, 10]. |
188 // TODO(tommi): This method should be on the track and ideally volume should | 199 // TODO(tommi): This method should be on the track and ideally volume should |
189 // be applied in the track in a way that does not affect clones of the track. | 200 // be applied in the track in a way that does not affect clones of the track. |
190 virtual void SetVolume(double volume) {} | 201 virtual void SetVolume(double volume) {} |
191 | 202 |
192 // Registers/unregisters observer to the audio source. | 203 // Registers/unregisters observers to the audio source. |
193 virtual void RegisterAudioObserver(AudioObserver* observer) {} | 204 virtual void RegisterAudioObserver(AudioObserver* observer) {} |
194 virtual void UnregisterAudioObserver(AudioObserver* observer) {} | 205 virtual void UnregisterAudioObserver(AudioObserver* observer) {} |
195 | 206 |
196 // TODO(tommi): Make pure virtual. | 207 // TODO(tommi): Make pure virtual. |
197 virtual void AddSink(AudioTrackSinkInterface* sink) {} | 208 virtual void AddSink(AudioTrackSinkInterface* sink) {} |
198 virtual void RemoveSink(AudioTrackSinkInterface* sink) {} | 209 virtual void RemoveSink(AudioTrackSinkInterface* sink) {} |
199 }; | 210 }; |
200 | 211 |
201 // Interface of the audio processor used by the audio track to collect | 212 // Interface of the audio processor used by the audio track to collect |
202 // statistics. | 213 // statistics. |
(...skipping 25 matching lines...) Expand all Loading... |
228 | 239 |
229 // Get audio processor statistics. | 240 // Get audio processor statistics. |
230 virtual void GetStats(AudioProcessorStats* stats) = 0; | 241 virtual void GetStats(AudioProcessorStats* stats) = 0; |
231 | 242 |
232 protected: | 243 protected: |
233 virtual ~AudioProcessorInterface() {} | 244 virtual ~AudioProcessorInterface() {} |
234 }; | 245 }; |
235 | 246 |
236 class AudioTrackInterface : public MediaStreamTrackInterface { | 247 class AudioTrackInterface : public MediaStreamTrackInterface { |
237 public: | 248 public: |
238 // TODO(xians): Figure out if the following interface should be const or not. | 249 // TODO(deadbeef): Figure out if the following interface should be const or |
| 250 // not. |
239 virtual AudioSourceInterface* GetSource() const = 0; | 251 virtual AudioSourceInterface* GetSource() const = 0; |
240 | 252 |
241 // Add/Remove a sink that will receive the audio data from the track. | 253 // Add/Remove a sink that will receive the audio data from the track. |
242 virtual void AddSink(AudioTrackSinkInterface* sink) = 0; | 254 virtual void AddSink(AudioTrackSinkInterface* sink) = 0; |
243 virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0; | 255 virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0; |
244 | 256 |
245 // Get the signal level from the audio track. | 257 // Get the signal level from the audio track. |
246 // Return true on success, otherwise false. | 258 // Return true on success, otherwise false. |
247 // TODO(xians): Change the interface to int GetSignalLevel() and pure virtual | 259 // TODO(deadbeef): Change the interface to int GetSignalLevel() and pure |
248 // after Chrome has the correct implementation of the interface. | 260 // virtual after it's implemented in chromium. |
249 virtual bool GetSignalLevel(int* level) { return false; } | 261 virtual bool GetSignalLevel(int* level) { return false; } |
250 | 262 |
251 // Get the audio processor used by the audio track. Return NULL if the track | 263 // Get the audio processor used by the audio track. Return NULL if the track |
252 // does not have any processor. | 264 // does not have any processor. |
253 // TODO(xians): Make the interface pure virtual. | 265 // TODO(deadbeef): Make the interface pure virtual. |
254 virtual rtc::scoped_refptr<AudioProcessorInterface> | 266 virtual rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() { |
255 GetAudioProcessor() { return NULL; } | 267 return nullptr; |
| 268 } |
256 | 269 |
257 protected: | 270 protected: |
258 virtual ~AudioTrackInterface() {} | 271 virtual ~AudioTrackInterface() {} |
259 }; | 272 }; |
260 | 273 |
261 typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> > | 274 typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> > |
262 AudioTrackVector; | 275 AudioTrackVector; |
263 typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> > | 276 typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> > |
264 VideoTrackVector; | 277 VideoTrackVector; |
265 | 278 |
| 279 // C++ version of https://www.w3.org/TR/mediacapture-streams/#mediastream. |
| 280 // |
| 281 // A major difference is that remote audio/video tracks (received by a |
| 282 // PeerConnection/RtpReceiver) are not synchronized simply by adding them to |
| 283 // the same stream; a session description with the correct "a=msid" attributes |
| 284 // must be pushed down. |
| 285 // |
| 286 // Thus, this interface acts as simply a container for tracks. |
266 class MediaStreamInterface : public rtc::RefCountInterface, | 287 class MediaStreamInterface : public rtc::RefCountInterface, |
267 public NotifierInterface { | 288 public NotifierInterface { |
268 public: | 289 public: |
269 virtual std::string label() const = 0; | 290 virtual std::string label() const = 0; |
270 | 291 |
271 virtual AudioTrackVector GetAudioTracks() = 0; | 292 virtual AudioTrackVector GetAudioTracks() = 0; |
272 virtual VideoTrackVector GetVideoTracks() = 0; | 293 virtual VideoTrackVector GetVideoTracks() = 0; |
273 virtual rtc::scoped_refptr<AudioTrackInterface> | 294 virtual rtc::scoped_refptr<AudioTrackInterface> |
274 FindAudioTrack(const std::string& track_id) = 0; | 295 FindAudioTrack(const std::string& track_id) = 0; |
275 virtual rtc::scoped_refptr<VideoTrackInterface> | 296 virtual rtc::scoped_refptr<VideoTrackInterface> |
276 FindVideoTrack(const std::string& track_id) = 0; | 297 FindVideoTrack(const std::string& track_id) = 0; |
277 | 298 |
278 virtual bool AddTrack(AudioTrackInterface* track) = 0; | 299 virtual bool AddTrack(AudioTrackInterface* track) = 0; |
279 virtual bool AddTrack(VideoTrackInterface* track) = 0; | 300 virtual bool AddTrack(VideoTrackInterface* track) = 0; |
280 virtual bool RemoveTrack(AudioTrackInterface* track) = 0; | 301 virtual bool RemoveTrack(AudioTrackInterface* track) = 0; |
281 virtual bool RemoveTrack(VideoTrackInterface* track) = 0; | 302 virtual bool RemoveTrack(VideoTrackInterface* track) = 0; |
282 | 303 |
283 protected: | 304 protected: |
284 virtual ~MediaStreamInterface() {} | 305 virtual ~MediaStreamInterface() {} |
285 }; | 306 }; |
286 | 307 |
287 } // namespace webrtc | 308 } // namespace webrtc |
288 | 309 |
289 #endif // WEBRTC_API_MEDIASTREAMINTERFACE_H_ | 310 #endif // WEBRTC_API_MEDIASTREAMINTERFACE_H_ |
OLD | NEW |