OLD | NEW |
| (Empty) |
1 /* | |
2 * libjingle | |
3 * Copyright 2004 Google Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright notice, | |
9 * this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 * this list of conditions and the following disclaimer in the documentation | |
12 * and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 #ifndef TALK_MEDIA_BASE_MEDIACHANNEL_H_ | |
29 #define TALK_MEDIA_BASE_MEDIACHANNEL_H_ | |
30 | |
31 #include <string> | |
32 #include <vector> | |
33 | |
34 #include "talk/media/base/codec.h" | |
35 #include "talk/media/base/constants.h" | |
36 #include "talk/media/base/streamparams.h" | |
37 #include "webrtc/base/basictypes.h" | |
38 #include "webrtc/base/buffer.h" | |
39 #include "webrtc/base/dscp.h" | |
40 #include "webrtc/base/logging.h" | |
41 #include "webrtc/base/optional.h" | |
42 #include "webrtc/base/sigslot.h" | |
43 #include "webrtc/base/socket.h" | |
44 #include "webrtc/base/window.h" | |
45 #include "webrtc/media/base/videosinkinterface.h" | |
46 // TODO(juberti): re-evaluate this include | |
47 #include "talk/session/media/audiomonitor.h" | |
48 | |
49 namespace rtc { | |
50 class Buffer; | |
51 class RateLimiter; | |
52 class Timing; | |
53 } | |
54 | |
55 namespace webrtc { | |
56 class AudioSinkInterface; | |
57 } | |
58 | |
59 namespace cricket { | |
60 | |
61 class AudioRenderer; | |
62 class ScreencastId; | |
63 class VideoCapturer; | |
64 class VideoFrame; | |
65 struct RtpHeader; | |
66 struct VideoFormat; | |
67 | |
68 const int kMinRtpHeaderExtensionId = 1; | |
69 const int kMaxRtpHeaderExtensionId = 255; | |
70 const int kScreencastDefaultFps = 5; | |
71 | |
72 template <class T> | |
73 static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) { | |
74 std::string str; | |
75 if (val) { | |
76 str = key; | |
77 str += ": "; | |
78 str += val ? rtc::ToString(*val) : ""; | |
79 str += ", "; | |
80 } | |
81 return str; | |
82 } | |
83 | |
84 template <class T> | |
85 static std::string VectorToString(const std::vector<T>& vals) { | |
86 std::ostringstream ost; | |
87 ost << "["; | |
88 for (size_t i = 0; i < vals.size(); ++i) { | |
89 if (i > 0) { | |
90 ost << ", "; | |
91 } | |
92 ost << vals[i].ToString(); | |
93 } | |
94 ost << "]"; | |
95 return ost.str(); | |
96 } | |
97 | |
98 // Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine. | |
99 // Used to be flags, but that makes it hard to selectively apply options. | |
100 // We are moving all of the setting of options to structs like this, | |
101 // but some things currently still use flags. | |
102 struct AudioOptions { | |
103 void SetAll(const AudioOptions& change) { | |
104 SetFrom(&echo_cancellation, change.echo_cancellation); | |
105 SetFrom(&auto_gain_control, change.auto_gain_control); | |
106 SetFrom(&noise_suppression, change.noise_suppression); | |
107 SetFrom(&highpass_filter, change.highpass_filter); | |
108 SetFrom(&stereo_swapping, change.stereo_swapping); | |
109 SetFrom(&audio_jitter_buffer_max_packets, | |
110 change.audio_jitter_buffer_max_packets); | |
111 SetFrom(&audio_jitter_buffer_fast_accelerate, | |
112 change.audio_jitter_buffer_fast_accelerate); | |
113 SetFrom(&typing_detection, change.typing_detection); | |
114 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise); | |
115 SetFrom(&conference_mode, change.conference_mode); | |
116 SetFrom(&adjust_agc_delta, change.adjust_agc_delta); | |
117 SetFrom(&experimental_agc, change.experimental_agc); | |
118 SetFrom(&extended_filter_aec, change.extended_filter_aec); | |
119 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec); | |
120 SetFrom(&experimental_ns, change.experimental_ns); | |
121 SetFrom(&aec_dump, change.aec_dump); | |
122 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov); | |
123 SetFrom(&tx_agc_digital_compression_gain, | |
124 change.tx_agc_digital_compression_gain); | |
125 SetFrom(&tx_agc_limiter, change.tx_agc_limiter); | |
126 SetFrom(&recording_sample_rate, change.recording_sample_rate); | |
127 SetFrom(&playout_sample_rate, change.playout_sample_rate); | |
128 SetFrom(&dscp, change.dscp); | |
129 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe); | |
130 } | |
131 | |
132 bool operator==(const AudioOptions& o) const { | |
133 return echo_cancellation == o.echo_cancellation && | |
134 auto_gain_control == o.auto_gain_control && | |
135 noise_suppression == o.noise_suppression && | |
136 highpass_filter == o.highpass_filter && | |
137 stereo_swapping == o.stereo_swapping && | |
138 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets && | |
139 audio_jitter_buffer_fast_accelerate == | |
140 o.audio_jitter_buffer_fast_accelerate && | |
141 typing_detection == o.typing_detection && | |
142 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise && | |
143 conference_mode == o.conference_mode && | |
144 experimental_agc == o.experimental_agc && | |
145 extended_filter_aec == o.extended_filter_aec && | |
146 delay_agnostic_aec == o.delay_agnostic_aec && | |
147 experimental_ns == o.experimental_ns && | |
148 adjust_agc_delta == o.adjust_agc_delta && | |
149 aec_dump == o.aec_dump && | |
150 tx_agc_target_dbov == o.tx_agc_target_dbov && | |
151 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain && | |
152 tx_agc_limiter == o.tx_agc_limiter && | |
153 recording_sample_rate == o.recording_sample_rate && | |
154 playout_sample_rate == o.playout_sample_rate && | |
155 dscp == o.dscp && | |
156 combined_audio_video_bwe == o.combined_audio_video_bwe; | |
157 } | |
158 | |
159 std::string ToString() const { | |
160 std::ostringstream ost; | |
161 ost << "AudioOptions {"; | |
162 ost << ToStringIfSet("aec", echo_cancellation); | |
163 ost << ToStringIfSet("agc", auto_gain_control); | |
164 ost << ToStringIfSet("ns", noise_suppression); | |
165 ost << ToStringIfSet("hf", highpass_filter); | |
166 ost << ToStringIfSet("swap", stereo_swapping); | |
167 ost << ToStringIfSet("audio_jitter_buffer_max_packets", | |
168 audio_jitter_buffer_max_packets); | |
169 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate", | |
170 audio_jitter_buffer_fast_accelerate); | |
171 ost << ToStringIfSet("typing", typing_detection); | |
172 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise); | |
173 ost << ToStringIfSet("conference", conference_mode); | |
174 ost << ToStringIfSet("agc_delta", adjust_agc_delta); | |
175 ost << ToStringIfSet("experimental_agc", experimental_agc); | |
176 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec); | |
177 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec); | |
178 ost << ToStringIfSet("experimental_ns", experimental_ns); | |
179 ost << ToStringIfSet("aec_dump", aec_dump); | |
180 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov); | |
181 ost << ToStringIfSet("tx_agc_digital_compression_gain", | |
182 tx_agc_digital_compression_gain); | |
183 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter); | |
184 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate); | |
185 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate); | |
186 ost << ToStringIfSet("dscp", dscp); | |
187 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe); | |
188 ost << "}"; | |
189 return ost.str(); | |
190 } | |
191 | |
192 // Audio processing that attempts to filter away the output signal from | |
193 // later inbound pickup. | |
194 rtc::Optional<bool> echo_cancellation; | |
195 // Audio processing to adjust the sensitivity of the local mic dynamically. | |
196 rtc::Optional<bool> auto_gain_control; | |
197 // Audio processing to filter out background noise. | |
198 rtc::Optional<bool> noise_suppression; | |
199 // Audio processing to remove background noise of lower frequencies. | |
200 rtc::Optional<bool> highpass_filter; | |
201 // Audio processing to swap the left and right channels. | |
202 rtc::Optional<bool> stereo_swapping; | |
203 // Audio receiver jitter buffer (NetEq) max capacity in number of packets. | |
204 rtc::Optional<int> audio_jitter_buffer_max_packets; | |
205 // Audio receiver jitter buffer (NetEq) fast accelerate mode. | |
206 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate; | |
207 // Audio processing to detect typing. | |
208 rtc::Optional<bool> typing_detection; | |
209 rtc::Optional<bool> aecm_generate_comfort_noise; | |
210 rtc::Optional<bool> conference_mode; | |
211 rtc::Optional<int> adjust_agc_delta; | |
212 rtc::Optional<bool> experimental_agc; | |
213 rtc::Optional<bool> extended_filter_aec; | |
214 rtc::Optional<bool> delay_agnostic_aec; | |
215 rtc::Optional<bool> experimental_ns; | |
216 rtc::Optional<bool> aec_dump; | |
217 // Note that tx_agc_* only applies to non-experimental AGC. | |
218 rtc::Optional<uint16_t> tx_agc_target_dbov; | |
219 rtc::Optional<uint16_t> tx_agc_digital_compression_gain; | |
220 rtc::Optional<bool> tx_agc_limiter; | |
221 rtc::Optional<uint32_t> recording_sample_rate; | |
222 rtc::Optional<uint32_t> playout_sample_rate; | |
223 // Set DSCP value for packet sent from audio channel. | |
224 rtc::Optional<bool> dscp; | |
225 // Enable combined audio+bandwidth BWE. | |
226 rtc::Optional<bool> combined_audio_video_bwe; | |
227 | |
228 private: | |
229 template <typename T> | |
230 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) { | |
231 if (o) { | |
232 *s = o; | |
233 } | |
234 } | |
235 }; | |
236 | |
237 // Options that can be applied to a VideoMediaChannel or a VideoMediaEngine. | |
238 // Used to be flags, but that makes it hard to selectively apply options. | |
239 // We are moving all of the setting of options to structs like this, | |
240 // but some things currently still use flags. | |
241 struct VideoOptions { | |
242 void SetAll(const VideoOptions& change) { | |
243 SetFrom(&video_noise_reduction, change.video_noise_reduction); | |
244 SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection); | |
245 SetFrom(&conference_mode, change.conference_mode); | |
246 SetFrom(&dscp, change.dscp); | |
247 SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate); | |
248 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps); | |
249 SetFrom(&disable_prerenderer_smoothing, | |
250 change.disable_prerenderer_smoothing); | |
251 } | |
252 | |
253 bool operator==(const VideoOptions& o) const { | |
254 return video_noise_reduction == o.video_noise_reduction && | |
255 cpu_overuse_detection == o.cpu_overuse_detection && | |
256 conference_mode == o.conference_mode && | |
257 dscp == o.dscp && | |
258 suspend_below_min_bitrate == o.suspend_below_min_bitrate && | |
259 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps && | |
260 disable_prerenderer_smoothing == o.disable_prerenderer_smoothing; | |
261 } | |
262 | |
263 std::string ToString() const { | |
264 std::ostringstream ost; | |
265 ost << "VideoOptions {"; | |
266 ost << ToStringIfSet("noise reduction", video_noise_reduction); | |
267 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection); | |
268 ost << ToStringIfSet("conference mode", conference_mode); | |
269 ost << ToStringIfSet("dscp", dscp); | |
270 ost << ToStringIfSet("suspend below min bitrate", | |
271 suspend_below_min_bitrate); | |
272 ost << ToStringIfSet("screencast min bitrate kbps", | |
273 screencast_min_bitrate_kbps); | |
274 ost << "}"; | |
275 return ost.str(); | |
276 } | |
277 | |
278 // Enable denoising? This flag comes from the getUserMedia | |
279 // constraint 'googNoiseReduction', and WebRtcVideoEngine2 passes it | |
280 // on to the codec options. Disabled by default. | |
281 rtc::Optional<bool> video_noise_reduction; | |
282 // Enable WebRTC Cpu Overuse Detection. This flag comes from the | |
283 // PeerConnection constraint 'googCpuOveruseDetection' and is | |
284 // checked in WebRtcVideoChannel2::OnLoadUpdate, where it's passed | |
285 // to VideoCapturer::video_adapter()->OnCpuResolutionRequest. | |
286 rtc::Optional<bool> cpu_overuse_detection; | |
287 // Use conference mode? This flag comes from the remote | |
288 // description's SDP line 'a=x-google-flag:conference', copied over | |
289 // by VideoChannel::SetRemoteContent_w, and ultimately used by | |
290 // conference mode screencast logic in | |
291 // WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig. | |
292 // The special screencast behaviour is disabled by default. | |
293 rtc::Optional<bool> conference_mode; | |
294 // Set DSCP value for packet sent from video channel. This flag | |
295 // comes from the PeerConnection constraint 'googDscp' and, | |
296 // WebRtcVideoChannel2::SetOptions checks it before calling | |
297 // MediaChannel::SetDscp. If enabled, rtc::DSCP_AF41 is used. If | |
298 // disabled, which is the default, rtc::DSCP_DEFAULT is used. | |
299 rtc::Optional<bool> dscp; | |
300 // Enable WebRTC suspension of video. No video frames will be sent | |
301 // when the bitrate is below the configured minimum bitrate. This | |
302 // flag comes from the PeerConnection constraint | |
303 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel2 copies it | |
304 // to VideoSendStream::Config::suspend_below_min_bitrate. | |
305 rtc::Optional<bool> suspend_below_min_bitrate; | |
306 // Force screencast to use a minimum bitrate. This flag comes from | |
307 // the PeerConnection constraint 'googScreencastMinBitrate'. It is | |
308 // copied to the encoder config by WebRtcVideoChannel2. | |
309 rtc::Optional<int> screencast_min_bitrate_kbps; | |
310 // Set to true if the renderer has an algorithm of frame selection. | |
311 // If the value is true, then WebRTC will hand over a frame as soon as | |
312 // possible without delay, and rendering smoothness is completely the duty | |
313 // of the renderer; | |
314 // If the value is false, then WebRTC is responsible to delay frame release | |
315 // in order to increase rendering smoothness. | |
316 // | |
317 // This flag comes from PeerConnection's RtcConfiguration, but is | |
318 // currently only set by the command line flag | |
319 // 'disable-rtc-smoothness-algorithm'. | |
320 // WebRtcVideoChannel2::AddRecvStream copies it to the created | |
321 // WebRtcVideoReceiveStream, where it is returned by the | |
322 // SmoothsRenderedFrames method. This method is used by the | |
323 // VideoReceiveStream, where the value is passed on to the | |
324 // IncomingVideoStream constructor. | |
325 rtc::Optional<bool> disable_prerenderer_smoothing; | |
326 | |
327 private: | |
328 template <typename T> | |
329 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) { | |
330 if (o) { | |
331 *s = o; | |
332 } | |
333 } | |
334 }; | |
335 | |
336 struct RtpHeaderExtension { | |
337 RtpHeaderExtension() : id(0) {} | |
338 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {} | |
339 | |
340 bool operator==(const RtpHeaderExtension& ext) const { | |
341 // id is a reserved word in objective-c. Therefore the id attribute has to | |
342 // be a fully qualified name in order to compile on IOS. | |
343 return this->id == ext.id && | |
344 uri == ext.uri; | |
345 } | |
346 | |
347 std::string ToString() const { | |
348 std::ostringstream ost; | |
349 ost << "{"; | |
350 ost << "uri: " << uri; | |
351 ost << ", id: " << id; | |
352 ost << "}"; | |
353 return ost.str(); | |
354 } | |
355 | |
356 std::string uri; | |
357 int id; | |
358 // TODO(juberti): SendRecv direction; | |
359 }; | |
360 | |
361 // Returns the named header extension if found among all extensions, NULL | |
362 // otherwise. | |
363 inline const RtpHeaderExtension* FindHeaderExtension( | |
364 const std::vector<RtpHeaderExtension>& extensions, | |
365 const std::string& name) { | |
366 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin(); | |
367 it != extensions.end(); ++it) { | |
368 if (it->uri == name) | |
369 return &(*it); | |
370 } | |
371 return NULL; | |
372 } | |
373 | |
374 class MediaChannel : public sigslot::has_slots<> { | |
375 public: | |
376 class NetworkInterface { | |
377 public: | |
378 enum SocketType { ST_RTP, ST_RTCP }; | |
379 virtual bool SendPacket(rtc::Buffer* packet, | |
380 const rtc::PacketOptions& options) = 0; | |
381 virtual bool SendRtcp(rtc::Buffer* packet, | |
382 const rtc::PacketOptions& options) = 0; | |
383 virtual int SetOption(SocketType type, rtc::Socket::Option opt, | |
384 int option) = 0; | |
385 virtual ~NetworkInterface() {} | |
386 }; | |
387 | |
388 MediaChannel() : network_interface_(NULL) {} | |
389 virtual ~MediaChannel() {} | |
390 | |
391 // Sets the abstract interface class for sending RTP/RTCP data. | |
392 virtual void SetInterface(NetworkInterface *iface) { | |
393 rtc::CritScope cs(&network_interface_crit_); | |
394 network_interface_ = iface; | |
395 } | |
396 | |
397 // Called when a RTP packet is received. | |
398 virtual void OnPacketReceived(rtc::Buffer* packet, | |
399 const rtc::PacketTime& packet_time) = 0; | |
400 // Called when a RTCP packet is received. | |
401 virtual void OnRtcpReceived(rtc::Buffer* packet, | |
402 const rtc::PacketTime& packet_time) = 0; | |
403 // Called when the socket's ability to send has changed. | |
404 virtual void OnReadyToSend(bool ready) = 0; | |
405 // Creates a new outgoing media stream with SSRCs and CNAME as described | |
406 // by sp. | |
407 virtual bool AddSendStream(const StreamParams& sp) = 0; | |
408 // Removes an outgoing media stream. | |
409 // ssrc must be the first SSRC of the media stream if the stream uses | |
410 // multiple SSRCs. | |
411 virtual bool RemoveSendStream(uint32_t ssrc) = 0; | |
412 // Creates a new incoming media stream with SSRCs and CNAME as described | |
413 // by sp. | |
414 virtual bool AddRecvStream(const StreamParams& sp) = 0; | |
415 // Removes an incoming media stream. | |
416 // ssrc must be the first SSRC of the media stream if the stream uses | |
417 // multiple SSRCs. | |
418 virtual bool RemoveRecvStream(uint32_t ssrc) = 0; | |
419 | |
420 // Returns the absoulte sendtime extension id value from media channel. | |
421 virtual int GetRtpSendTimeExtnId() const { | |
422 return -1; | |
423 } | |
424 | |
425 // Base method to send packet using NetworkInterface. | |
426 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) { | |
427 return DoSendPacket(packet, false, options); | |
428 } | |
429 | |
430 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) { | |
431 return DoSendPacket(packet, true, options); | |
432 } | |
433 | |
434 int SetOption(NetworkInterface::SocketType type, | |
435 rtc::Socket::Option opt, | |
436 int option) { | |
437 rtc::CritScope cs(&network_interface_crit_); | |
438 if (!network_interface_) | |
439 return -1; | |
440 | |
441 return network_interface_->SetOption(type, opt, option); | |
442 } | |
443 | |
444 protected: | |
445 // This method sets DSCP |value| on both RTP and RTCP channels. | |
446 int SetDscp(rtc::DiffServCodePoint value) { | |
447 int ret; | |
448 ret = SetOption(NetworkInterface::ST_RTP, | |
449 rtc::Socket::OPT_DSCP, | |
450 value); | |
451 if (ret == 0) { | |
452 ret = SetOption(NetworkInterface::ST_RTCP, | |
453 rtc::Socket::OPT_DSCP, | |
454 value); | |
455 } | |
456 return ret; | |
457 } | |
458 | |
459 private: | |
460 bool DoSendPacket(rtc::Buffer* packet, | |
461 bool rtcp, | |
462 const rtc::PacketOptions& options) { | |
463 rtc::CritScope cs(&network_interface_crit_); | |
464 if (!network_interface_) | |
465 return false; | |
466 | |
467 return (!rtcp) ? network_interface_->SendPacket(packet, options) | |
468 : network_interface_->SendRtcp(packet, options); | |
469 } | |
470 | |
471 // |network_interface_| can be accessed from the worker_thread and | |
472 // from any MediaEngine threads. This critical section is to protect accessing | |
473 // of network_interface_ object. | |
474 rtc::CriticalSection network_interface_crit_; | |
475 NetworkInterface* network_interface_; | |
476 }; | |
477 | |
478 enum SendFlags { | |
479 SEND_NOTHING, | |
480 SEND_MICROPHONE | |
481 }; | |
482 | |
483 // The stats information is structured as follows: | |
484 // Media are represented by either MediaSenderInfo or MediaReceiverInfo. | |
485 // Media contains a vector of SSRC infos that are exclusively used by this | |
486 // media. (SSRCs shared between media streams can't be represented.) | |
487 | |
488 // Information about an SSRC. | |
489 // This data may be locally recorded, or received in an RTCP SR or RR. | |
490 struct SsrcSenderInfo { | |
491 SsrcSenderInfo() | |
492 : ssrc(0), | |
493 timestamp(0) { | |
494 } | |
495 uint32_t ssrc; | |
496 double timestamp; // NTP timestamp, represented as seconds since epoch. | |
497 }; | |
498 | |
499 struct SsrcReceiverInfo { | |
500 SsrcReceiverInfo() | |
501 : ssrc(0), | |
502 timestamp(0) { | |
503 } | |
504 uint32_t ssrc; | |
505 double timestamp; | |
506 }; | |
507 | |
508 struct MediaSenderInfo { | |
509 MediaSenderInfo() | |
510 : bytes_sent(0), | |
511 packets_sent(0), | |
512 packets_lost(0), | |
513 fraction_lost(0.0), | |
514 rtt_ms(0) { | |
515 } | |
516 void add_ssrc(const SsrcSenderInfo& stat) { | |
517 local_stats.push_back(stat); | |
518 } | |
519 // Temporary utility function for call sites that only provide SSRC. | |
520 // As more info is added into SsrcSenderInfo, this function should go away. | |
521 void add_ssrc(uint32_t ssrc) { | |
522 SsrcSenderInfo stat; | |
523 stat.ssrc = ssrc; | |
524 add_ssrc(stat); | |
525 } | |
526 // Utility accessor for clients that are only interested in ssrc numbers. | |
527 std::vector<uint32_t> ssrcs() const { | |
528 std::vector<uint32_t> retval; | |
529 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin(); | |
530 it != local_stats.end(); ++it) { | |
531 retval.push_back(it->ssrc); | |
532 } | |
533 return retval; | |
534 } | |
535 // Utility accessor for clients that make the assumption only one ssrc | |
536 // exists per media. | |
537 // This will eventually go away. | |
538 uint32_t ssrc() const { | |
539 if (local_stats.size() > 0) { | |
540 return local_stats[0].ssrc; | |
541 } else { | |
542 return 0; | |
543 } | |
544 } | |
545 int64_t bytes_sent; | |
546 int packets_sent; | |
547 int packets_lost; | |
548 float fraction_lost; | |
549 int64_t rtt_ms; | |
550 std::string codec_name; | |
551 std::vector<SsrcSenderInfo> local_stats; | |
552 std::vector<SsrcReceiverInfo> remote_stats; | |
553 }; | |
554 | |
555 template<class T> | |
556 struct VariableInfo { | |
557 VariableInfo() | |
558 : min_val(), | |
559 mean(0.0), | |
560 max_val(), | |
561 variance(0.0) { | |
562 } | |
563 T min_val; | |
564 double mean; | |
565 T max_val; | |
566 double variance; | |
567 }; | |
568 | |
569 struct MediaReceiverInfo { | |
570 MediaReceiverInfo() | |
571 : bytes_rcvd(0), | |
572 packets_rcvd(0), | |
573 packets_lost(0), | |
574 fraction_lost(0.0) { | |
575 } | |
576 void add_ssrc(const SsrcReceiverInfo& stat) { | |
577 local_stats.push_back(stat); | |
578 } | |
579 // Temporary utility function for call sites that only provide SSRC. | |
580 // As more info is added into SsrcSenderInfo, this function should go away. | |
581 void add_ssrc(uint32_t ssrc) { | |
582 SsrcReceiverInfo stat; | |
583 stat.ssrc = ssrc; | |
584 add_ssrc(stat); | |
585 } | |
586 std::vector<uint32_t> ssrcs() const { | |
587 std::vector<uint32_t> retval; | |
588 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin(); | |
589 it != local_stats.end(); ++it) { | |
590 retval.push_back(it->ssrc); | |
591 } | |
592 return retval; | |
593 } | |
594 // Utility accessor for clients that make the assumption only one ssrc | |
595 // exists per media. | |
596 // This will eventually go away. | |
597 uint32_t ssrc() const { | |
598 if (local_stats.size() > 0) { | |
599 return local_stats[0].ssrc; | |
600 } else { | |
601 return 0; | |
602 } | |
603 } | |
604 | |
605 int64_t bytes_rcvd; | |
606 int packets_rcvd; | |
607 int packets_lost; | |
608 float fraction_lost; | |
609 std::string codec_name; | |
610 std::vector<SsrcReceiverInfo> local_stats; | |
611 std::vector<SsrcSenderInfo> remote_stats; | |
612 }; | |
613 | |
614 struct VoiceSenderInfo : public MediaSenderInfo { | |
615 VoiceSenderInfo() | |
616 : ext_seqnum(0), | |
617 jitter_ms(0), | |
618 audio_level(0), | |
619 aec_quality_min(0.0), | |
620 echo_delay_median_ms(0), | |
621 echo_delay_std_ms(0), | |
622 echo_return_loss(0), | |
623 echo_return_loss_enhancement(0), | |
624 typing_noise_detected(false) { | |
625 } | |
626 | |
627 int ext_seqnum; | |
628 int jitter_ms; | |
629 int audio_level; | |
630 float aec_quality_min; | |
631 int echo_delay_median_ms; | |
632 int echo_delay_std_ms; | |
633 int echo_return_loss; | |
634 int echo_return_loss_enhancement; | |
635 bool typing_noise_detected; | |
636 }; | |
637 | |
638 struct VoiceReceiverInfo : public MediaReceiverInfo { | |
639 VoiceReceiverInfo() | |
640 : ext_seqnum(0), | |
641 jitter_ms(0), | |
642 jitter_buffer_ms(0), | |
643 jitter_buffer_preferred_ms(0), | |
644 delay_estimate_ms(0), | |
645 audio_level(0), | |
646 expand_rate(0), | |
647 speech_expand_rate(0), | |
648 secondary_decoded_rate(0), | |
649 accelerate_rate(0), | |
650 preemptive_expand_rate(0), | |
651 decoding_calls_to_silence_generator(0), | |
652 decoding_calls_to_neteq(0), | |
653 decoding_normal(0), | |
654 decoding_plc(0), | |
655 decoding_cng(0), | |
656 decoding_plc_cng(0), | |
657 capture_start_ntp_time_ms(-1) {} | |
658 | |
659 int ext_seqnum; | |
660 int jitter_ms; | |
661 int jitter_buffer_ms; | |
662 int jitter_buffer_preferred_ms; | |
663 int delay_estimate_ms; | |
664 int audio_level; | |
665 // fraction of synthesized audio inserted through expansion. | |
666 float expand_rate; | |
667 // fraction of synthesized speech inserted through expansion. | |
668 float speech_expand_rate; | |
669 // fraction of data out of secondary decoding, including FEC and RED. | |
670 float secondary_decoded_rate; | |
671 // Fraction of data removed through time compression. | |
672 float accelerate_rate; | |
673 // Fraction of data inserted through time stretching. | |
674 float preemptive_expand_rate; | |
675 int decoding_calls_to_silence_generator; | |
676 int decoding_calls_to_neteq; | |
677 int decoding_normal; | |
678 int decoding_plc; | |
679 int decoding_cng; | |
680 int decoding_plc_cng; | |
681 // Estimated capture start time in NTP time in ms. | |
682 int64_t capture_start_ntp_time_ms; | |
683 }; | |
684 | |
685 struct VideoSenderInfo : public MediaSenderInfo { | |
686 VideoSenderInfo() | |
687 : packets_cached(0), | |
688 firs_rcvd(0), | |
689 plis_rcvd(0), | |
690 nacks_rcvd(0), | |
691 input_frame_width(0), | |
692 input_frame_height(0), | |
693 send_frame_width(0), | |
694 send_frame_height(0), | |
695 framerate_input(0), | |
696 framerate_sent(0), | |
697 nominal_bitrate(0), | |
698 preferred_bitrate(0), | |
699 adapt_reason(0), | |
700 adapt_changes(0), | |
701 avg_encode_ms(0), | |
702 encode_usage_percent(0) { | |
703 } | |
704 | |
705 std::vector<SsrcGroup> ssrc_groups; | |
706 std::string encoder_implementation_name; | |
707 int packets_cached; | |
708 int firs_rcvd; | |
709 int plis_rcvd; | |
710 int nacks_rcvd; | |
711 int input_frame_width; | |
712 int input_frame_height; | |
713 int send_frame_width; | |
714 int send_frame_height; | |
715 int framerate_input; | |
716 int framerate_sent; | |
717 int nominal_bitrate; | |
718 int preferred_bitrate; | |
719 int adapt_reason; | |
720 int adapt_changes; | |
721 int avg_encode_ms; | |
722 int encode_usage_percent; | |
723 VariableInfo<int> adapt_frame_drops; | |
724 VariableInfo<int> effects_frame_drops; | |
725 VariableInfo<double> capturer_frame_time; | |
726 }; | |
727 | |
728 struct VideoReceiverInfo : public MediaReceiverInfo { | |
729 VideoReceiverInfo() | |
730 : packets_concealed(0), | |
731 firs_sent(0), | |
732 plis_sent(0), | |
733 nacks_sent(0), | |
734 frame_width(0), | |
735 frame_height(0), | |
736 framerate_rcvd(0), | |
737 framerate_decoded(0), | |
738 framerate_output(0), | |
739 framerate_render_input(0), | |
740 framerate_render_output(0), | |
741 decode_ms(0), | |
742 max_decode_ms(0), | |
743 jitter_buffer_ms(0), | |
744 min_playout_delay_ms(0), | |
745 render_delay_ms(0), | |
746 target_delay_ms(0), | |
747 current_delay_ms(0), | |
748 capture_start_ntp_time_ms(-1) { | |
749 } | |
750 | |
751 std::vector<SsrcGroup> ssrc_groups; | |
752 std::string decoder_implementation_name; | |
753 int packets_concealed; | |
754 int firs_sent; | |
755 int plis_sent; | |
756 int nacks_sent; | |
757 int frame_width; | |
758 int frame_height; | |
759 int framerate_rcvd; | |
760 int framerate_decoded; | |
761 int framerate_output; | |
762 // Framerate as sent to the renderer. | |
763 int framerate_render_input; | |
764 // Framerate that the renderer reports. | |
765 int framerate_render_output; | |
766 | |
767 // All stats below are gathered per-VideoReceiver, but some will be correlated | |
768 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC | |
769 // structures, reflect this in the new layout. | |
770 | |
771 // Current frame decode latency. | |
772 int decode_ms; | |
773 // Maximum observed frame decode latency. | |
774 int max_decode_ms; | |
775 // Jitter (network-related) latency. | |
776 int jitter_buffer_ms; | |
777 // Requested minimum playout latency. | |
778 int min_playout_delay_ms; | |
779 // Requested latency to account for rendering delay. | |
780 int render_delay_ms; | |
781 // Target overall delay: network+decode+render, accounting for | |
782 // min_playout_delay_ms. | |
783 int target_delay_ms; | |
784 // Current overall delay, possibly ramping towards target_delay_ms. | |
785 int current_delay_ms; | |
786 | |
787 // Estimated capture start time in NTP time in ms. | |
788 int64_t capture_start_ntp_time_ms; | |
789 }; | |
790 | |
791 struct DataSenderInfo : public MediaSenderInfo { | |
792 DataSenderInfo() | |
793 : ssrc(0) { | |
794 } | |
795 | |
796 uint32_t ssrc; | |
797 }; | |
798 | |
799 struct DataReceiverInfo : public MediaReceiverInfo { | |
800 DataReceiverInfo() | |
801 : ssrc(0) { | |
802 } | |
803 | |
804 uint32_t ssrc; | |
805 }; | |
806 | |
807 struct BandwidthEstimationInfo { | |
808 BandwidthEstimationInfo() | |
809 : available_send_bandwidth(0), | |
810 available_recv_bandwidth(0), | |
811 target_enc_bitrate(0), | |
812 actual_enc_bitrate(0), | |
813 retransmit_bitrate(0), | |
814 transmit_bitrate(0), | |
815 bucket_delay(0) { | |
816 } | |
817 | |
818 int available_send_bandwidth; | |
819 int available_recv_bandwidth; | |
820 int target_enc_bitrate; | |
821 int actual_enc_bitrate; | |
822 int retransmit_bitrate; | |
823 int transmit_bitrate; | |
824 int64_t bucket_delay; | |
825 }; | |
826 | |
827 struct VoiceMediaInfo { | |
828 void Clear() { | |
829 senders.clear(); | |
830 receivers.clear(); | |
831 } | |
832 std::vector<VoiceSenderInfo> senders; | |
833 std::vector<VoiceReceiverInfo> receivers; | |
834 }; | |
835 | |
836 struct VideoMediaInfo { | |
837 void Clear() { | |
838 senders.clear(); | |
839 receivers.clear(); | |
840 bw_estimations.clear(); | |
841 } | |
842 std::vector<VideoSenderInfo> senders; | |
843 std::vector<VideoReceiverInfo> receivers; | |
844 std::vector<BandwidthEstimationInfo> bw_estimations; | |
845 }; | |
846 | |
847 struct DataMediaInfo { | |
848 void Clear() { | |
849 senders.clear(); | |
850 receivers.clear(); | |
851 } | |
852 std::vector<DataSenderInfo> senders; | |
853 std::vector<DataReceiverInfo> receivers; | |
854 }; | |
855 | |
856 struct RtcpParameters { | |
857 bool reduced_size = false; | |
858 }; | |
859 | |
860 template <class Codec> | |
861 struct RtpParameters { | |
862 virtual std::string ToString() const { | |
863 std::ostringstream ost; | |
864 ost << "{"; | |
865 ost << "codecs: " << VectorToString(codecs) << ", "; | |
866 ost << "extensions: " << VectorToString(extensions); | |
867 ost << "}"; | |
868 return ost.str(); | |
869 } | |
870 | |
871 std::vector<Codec> codecs; | |
872 std::vector<RtpHeaderExtension> extensions; | |
873 // TODO(pthatcher): Add streams. | |
874 RtcpParameters rtcp; | |
875 }; | |
876 | |
877 template <class Codec, class Options> | |
878 struct RtpSendParameters : RtpParameters<Codec> { | |
879 std::string ToString() const override { | |
880 std::ostringstream ost; | |
881 ost << "{"; | |
882 ost << "codecs: " << VectorToString(this->codecs) << ", "; | |
883 ost << "extensions: " << VectorToString(this->extensions) << ", "; | |
884 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", "; | |
885 ost << "options: " << options.ToString(); | |
886 ost << "}"; | |
887 return ost.str(); | |
888 } | |
889 | |
890 int max_bandwidth_bps = -1; | |
891 Options options; | |
892 }; | |
893 | |
894 struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> { | |
895 }; | |
896 | |
897 struct AudioRecvParameters : RtpParameters<AudioCodec> { | |
898 }; | |
899 | |
900 class VoiceMediaChannel : public MediaChannel { | |
901 public: | |
902 enum Error { | |
903 ERROR_NONE = 0, // No error. | |
904 ERROR_OTHER, // Other errors. | |
905 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic. | |
906 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS. | |
907 ERROR_REC_DEVICE_SILENT, // No background noise picked up. | |
908 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping. | |
909 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active. | |
910 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors. | |
911 ERROR_REC_SRTP_ERROR, // Generic SRTP failure. | |
912 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets. | |
913 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected. | |
914 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout. | |
915 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS. | |
916 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active. | |
917 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing. | |
918 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure. | |
919 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets. | |
920 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected. | |
921 }; | |
922 | |
923 VoiceMediaChannel() {} | |
924 virtual ~VoiceMediaChannel() {} | |
925 virtual bool SetSendParameters(const AudioSendParameters& params) = 0; | |
926 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0; | |
927 // Starts or stops playout of received audio. | |
928 virtual bool SetPlayout(bool playout) = 0; | |
929 // Starts or stops sending (and potentially capture) of local audio. | |
930 virtual bool SetSend(SendFlags flag) = 0; | |
931 // Configure stream for sending. | |
932 virtual bool SetAudioSend(uint32_t ssrc, | |
933 bool enable, | |
934 const AudioOptions* options, | |
935 AudioRenderer* renderer) = 0; | |
936 // Gets current energy levels for all incoming streams. | |
937 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0; | |
938 // Get the current energy level of the stream sent to the speaker. | |
939 virtual int GetOutputLevel() = 0; | |
940 // Get the time in milliseconds since last recorded keystroke, or negative. | |
941 virtual int GetTimeSinceLastTyping() = 0; | |
942 // Temporarily exposed field for tuning typing detect options. | |
943 virtual void SetTypingDetectionParameters(int time_window, | |
944 int cost_per_typing, int reporting_threshold, int penalty_decay, | |
945 int type_event_delay) = 0; | |
946 // Set speaker output volume of the specified ssrc. | |
947 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0; | |
948 // Returns if the telephone-event has been negotiated. | |
949 virtual bool CanInsertDtmf() = 0; | |
950 // Send a DTMF |event|. The DTMF out-of-band signal will be used. | |
951 // The |ssrc| should be either 0 or a valid send stream ssrc. | |
952 // The valid value for the |event| are 0 to 15 which corresponding to | |
953 // DTMF event 0-9, *, #, A-D. | |
954 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0; | |
955 // Gets quality stats for the channel. | |
956 virtual bool GetStats(VoiceMediaInfo* info) = 0; | |
957 | |
958 virtual void SetRawAudioSink( | |
959 uint32_t ssrc, | |
960 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) = 0; | |
961 }; | |
962 | |
963 struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> { | |
964 }; | |
965 | |
966 struct VideoRecvParameters : RtpParameters<VideoCodec> { | |
967 }; | |
968 | |
969 class VideoMediaChannel : public MediaChannel { | |
970 public: | |
971 enum Error { | |
972 ERROR_NONE = 0, // No error. | |
973 ERROR_OTHER, // Other errors. | |
974 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera. | |
975 ERROR_REC_DEVICE_NO_DEVICE, // No camera. | |
976 ERROR_REC_DEVICE_IN_USE, // Device is in already use. | |
977 ERROR_REC_DEVICE_REMOVED, // Device is removed. | |
978 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure. | |
979 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets. | |
980 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore. | |
981 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure. | |
982 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets. | |
983 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected. | |
984 }; | |
985 | |
986 VideoMediaChannel() {} | |
987 virtual ~VideoMediaChannel() {} | |
988 | |
989 virtual bool SetSendParameters(const VideoSendParameters& params) = 0; | |
990 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0; | |
991 // Gets the currently set codecs/payload types to be used for outgoing media. | |
992 virtual bool GetSendCodec(VideoCodec* send_codec) = 0; | |
993 // Starts or stops transmission (and potentially capture) of local video. | |
994 virtual bool SetSend(bool send) = 0; | |
995 // Configure stream for sending. | |
996 virtual bool SetVideoSend(uint32_t ssrc, | |
997 bool enable, | |
998 const VideoOptions* options) = 0; | |
999 // Sets the sink object to be used for the specified stream. | |
1000 // If SSRC is 0, the renderer is used for the 'default' stream. | |
1001 virtual bool SetSink(uint32_t ssrc, | |
1002 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) = 0; | |
1003 // If |ssrc| is 0, replace the default capturer (engine capturer) with | |
1004 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC. | |
1005 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0; | |
1006 // Gets quality stats for the channel. | |
1007 virtual bool GetStats(VideoMediaInfo* info) = 0; | |
1008 }; | |
1009 | |
1010 enum DataMessageType { | |
1011 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID | |
1012 // values. | |
1013 DMT_NONE = 0, | |
1014 DMT_CONTROL = 1, | |
1015 DMT_BINARY = 2, | |
1016 DMT_TEXT = 3, | |
1017 }; | |
1018 | |
1019 // Info about data received in DataMediaChannel. For use in | |
1020 // DataMediaChannel::SignalDataReceived and in all of the signals that | |
1021 // signal fires, on up the chain. | |
1022 struct ReceiveDataParams { | |
1023 // The in-packet stream indentifier. | |
1024 // For SCTP, this is really SID, not SSRC. | |
1025 uint32_t ssrc; | |
1026 // The type of message (binary, text, or control). | |
1027 DataMessageType type; | |
1028 // A per-stream value incremented per packet in the stream. | |
1029 int seq_num; | |
1030 // A per-stream value monotonically increasing with time. | |
1031 int timestamp; | |
1032 | |
1033 ReceiveDataParams() : | |
1034 ssrc(0), | |
1035 type(DMT_TEXT), | |
1036 seq_num(0), | |
1037 timestamp(0) { | |
1038 } | |
1039 }; | |
1040 | |
1041 struct SendDataParams { | |
1042 // The in-packet stream indentifier. | |
1043 // For SCTP, this is really SID, not SSRC. | |
1044 uint32_t ssrc; | |
1045 // The type of message (binary, text, or control). | |
1046 DataMessageType type; | |
1047 | |
1048 // For SCTP, whether to send messages flagged as ordered or not. | |
1049 // If false, messages can be received out of order. | |
1050 bool ordered; | |
1051 // For SCTP, whether the messages are sent reliably or not. | |
1052 // If false, messages may be lost. | |
1053 bool reliable; | |
1054 // For SCTP, if reliable == false, provide partial reliability by | |
1055 // resending up to this many times. Either count or millis | |
1056 // is supported, not both at the same time. | |
1057 int max_rtx_count; | |
1058 // For SCTP, if reliable == false, provide partial reliability by | |
1059 // resending for up to this many milliseconds. Either count or millis | |
1060 // is supported, not both at the same time. | |
1061 int max_rtx_ms; | |
1062 | |
1063 SendDataParams() : | |
1064 ssrc(0), | |
1065 type(DMT_TEXT), | |
1066 // TODO(pthatcher): Make these true by default? | |
1067 ordered(false), | |
1068 reliable(false), | |
1069 max_rtx_count(0), | |
1070 max_rtx_ms(0) { | |
1071 } | |
1072 }; | |
1073 | |
1074 enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK }; | |
1075 | |
1076 struct DataOptions { | |
1077 std::string ToString() const { | |
1078 return "{}"; | |
1079 } | |
1080 }; | |
1081 | |
1082 struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> { | |
1083 std::string ToString() const { | |
1084 std::ostringstream ost; | |
1085 // Options and extensions aren't used. | |
1086 ost << "{"; | |
1087 ost << "codecs: " << VectorToString(codecs) << ", "; | |
1088 ost << "max_bandwidth_bps: " << max_bandwidth_bps; | |
1089 ost << "}"; | |
1090 return ost.str(); | |
1091 } | |
1092 }; | |
1093 | |
1094 struct DataRecvParameters : RtpParameters<DataCodec> { | |
1095 }; | |
1096 | |
1097 class DataMediaChannel : public MediaChannel { | |
1098 public: | |
1099 enum Error { | |
1100 ERROR_NONE = 0, // No error. | |
1101 ERROR_OTHER, // Other errors. | |
1102 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure. | |
1103 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets. | |
1104 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure. | |
1105 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets. | |
1106 ERROR_RECV_SRTP_REPLAY, // Packet replay detected. | |
1107 }; | |
1108 | |
1109 virtual ~DataMediaChannel() {} | |
1110 | |
1111 virtual bool SetSendParameters(const DataSendParameters& params) = 0; | |
1112 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0; | |
1113 | |
1114 // TODO(pthatcher): Implement this. | |
1115 virtual bool GetStats(DataMediaInfo* info) { return true; } | |
1116 | |
1117 virtual bool SetSend(bool send) = 0; | |
1118 virtual bool SetReceive(bool receive) = 0; | |
1119 | |
1120 virtual bool SendData( | |
1121 const SendDataParams& params, | |
1122 const rtc::Buffer& payload, | |
1123 SendDataResult* result = NULL) = 0; | |
1124 // Signals when data is received (params, data, len) | |
1125 sigslot::signal3<const ReceiveDataParams&, | |
1126 const char*, | |
1127 size_t> SignalDataReceived; | |
1128 // Signal when the media channel is ready to send the stream. Arguments are: | |
1129 // writable(bool) | |
1130 sigslot::signal1<bool> SignalReadyToSend; | |
1131 // Signal for notifying that the remote side has closed the DataChannel. | |
1132 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; | |
1133 }; | |
1134 | |
1135 } // namespace cricket | |
1136 | |
1137 #endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_ | |
OLD | NEW |