blob: 441fbff391f90ded3642bebb346bfbf48d024495 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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/base/basictypes.h"
35#include "talk/base/buffer.h"
36#include "talk/base/logging.h"
37#include "talk/base/sigslot.h"
38#include "talk/base/socket.h"
39#include "talk/base/window.h"
40#include "talk/media/base/codec.h"
41#include "talk/media/base/constants.h"
42#include "talk/media/base/streamparams.h"
43// TODO(juberti): re-evaluate this include
44#include "talk/session/media/audiomonitor.h"
45
46namespace talk_base {
47class Buffer;
48class RateLimiter;
49class Timing;
50}
51
52namespace cricket {
53
54class AudioRenderer;
55struct RtpHeader;
56class ScreencastId;
57struct VideoFormat;
58class VideoCapturer;
59class VideoRenderer;
60
61const int kMinRtpHeaderExtensionId = 1;
62const int kMaxRtpHeaderExtensionId = 255;
63const int kScreencastDefaultFps = 5;
64
65// Used in AudioOptions and VideoOptions to signify "unset" values.
66template <class T>
67class Settable {
68 public:
69 Settable() : set_(false), val_() {}
70 explicit Settable(T val) : set_(true), val_(val) {}
71
72 bool IsSet() const {
73 return set_;
74 }
75
76 bool Get(T* out) const {
77 *out = val_;
78 return set_;
79 }
80
81 T GetWithDefaultIfUnset(const T& default_value) const {
82 return set_ ? val_ : default_value;
83 }
84
85 virtual void Set(T val) {
86 set_ = true;
87 val_ = val;
88 }
89
90 void Clear() {
91 Set(T());
92 set_ = false;
93 }
94
95 void SetFrom(const Settable<T>& o) {
96 // Set this value based on the value of o, iff o is set. If this value is
97 // set and o is unset, the current value will be unchanged.
98 T val;
99 if (o.Get(&val)) {
100 Set(val);
101 }
102 }
103
104 std::string ToString() const {
105 return set_ ? talk_base::ToString(val_) : "";
106 }
107
108 bool operator==(const Settable<T>& o) const {
109 // Equal if both are unset with any value or both set with the same value.
110 return (set_ == o.set_) && (!set_ || (val_ == o.val_));
111 }
112
113 bool operator!=(const Settable<T>& o) const {
114 return !operator==(o);
115 }
116
117 protected:
118 void InitializeValue(const T &val) {
119 val_ = val;
120 }
121
122 private:
123 bool set_;
124 T val_;
125};
126
127class SettablePercent : public Settable<float> {
128 public:
129 virtual void Set(float val) {
130 if (val < 0) {
131 val = 0;
132 }
133 if (val > 1.0) {
134 val = 1.0;
135 }
136 Settable<float>::Set(val);
137 }
138};
139
140template <class T>
141static std::string ToStringIfSet(const char* key, const Settable<T>& val) {
142 std::string str;
143 if (val.IsSet()) {
144 str = key;
145 str += ": ";
146 str += val.ToString();
147 str += ", ";
148 }
149 return str;
150}
151
152// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
153// Used to be flags, but that makes it hard to selectively apply options.
154// We are moving all of the setting of options to structs like this,
155// but some things currently still use flags.
156struct AudioOptions {
157 void SetAll(const AudioOptions& change) {
158 echo_cancellation.SetFrom(change.echo_cancellation);
159 auto_gain_control.SetFrom(change.auto_gain_control);
160 noise_suppression.SetFrom(change.noise_suppression);
161 highpass_filter.SetFrom(change.highpass_filter);
162 stereo_swapping.SetFrom(change.stereo_swapping);
163 typing_detection.SetFrom(change.typing_detection);
164 conference_mode.SetFrom(change.conference_mode);
165 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
166 experimental_agc.SetFrom(change.experimental_agc);
167 experimental_aec.SetFrom(change.experimental_aec);
168 aec_dump.SetFrom(change.aec_dump);
169 }
170
171 bool operator==(const AudioOptions& o) const {
172 return echo_cancellation == o.echo_cancellation &&
173 auto_gain_control == o.auto_gain_control &&
174 noise_suppression == o.noise_suppression &&
175 highpass_filter == o.highpass_filter &&
176 stereo_swapping == o.stereo_swapping &&
177 typing_detection == o.typing_detection &&
178 conference_mode == o.conference_mode &&
179 experimental_agc == o.experimental_agc &&
180 experimental_aec == o.experimental_aec &&
181 adjust_agc_delta == o.adjust_agc_delta &&
182 aec_dump == o.aec_dump;
183 }
184
185 std::string ToString() const {
186 std::ostringstream ost;
187 ost << "AudioOptions {";
188 ost << ToStringIfSet("aec", echo_cancellation);
189 ost << ToStringIfSet("agc", auto_gain_control);
190 ost << ToStringIfSet("ns", noise_suppression);
191 ost << ToStringIfSet("hf", highpass_filter);
192 ost << ToStringIfSet("swap", stereo_swapping);
193 ost << ToStringIfSet("typing", typing_detection);
194 ost << ToStringIfSet("conference", conference_mode);
195 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
196 ost << ToStringIfSet("experimental_agc", experimental_agc);
197 ost << ToStringIfSet("experimental_aec", experimental_aec);
198 ost << ToStringIfSet("aec_dump", aec_dump);
199 ost << "}";
200 return ost.str();
201 }
202
203 // Audio processing that attempts to filter away the output signal from
204 // later inbound pickup.
205 Settable<bool> echo_cancellation;
206 // Audio processing to adjust the sensitivity of the local mic dynamically.
207 Settable<bool> auto_gain_control;
208 // Audio processing to filter out background noise.
209 Settable<bool> noise_suppression;
210 // Audio processing to remove background noise of lower frequencies.
211 Settable<bool> highpass_filter;
212 // Audio processing to swap the left and right channels.
213 Settable<bool> stereo_swapping;
214 // Audio processing to detect typing.
215 Settable<bool> typing_detection;
216 Settable<bool> conference_mode;
217 Settable<int> adjust_agc_delta;
218 Settable<bool> experimental_agc;
219 Settable<bool> experimental_aec;
220 Settable<bool> aec_dump;
221};
222
223// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
224// Used to be flags, but that makes it hard to selectively apply options.
225// We are moving all of the setting of options to structs like this,
226// but some things currently still use flags.
227struct VideoOptions {
228 VideoOptions() {
229 process_adaptation_threshhold.Set(kProcessCpuThreshold);
230 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
231 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
232 }
233
234 void SetAll(const VideoOptions& change) {
235 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
236 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
237 adapt_view_switch.SetFrom(change.adapt_view_switch);
238 video_noise_reduction.SetFrom(change.video_noise_reduction);
239 video_three_layers.SetFrom(change.video_three_layers);
240 video_enable_camera_list.SetFrom(change.video_enable_camera_list);
241 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
242 video_high_bitrate.SetFrom(change.video_high_bitrate);
243 video_watermark.SetFrom(change.video_watermark);
244 video_temporal_layer_screencast.SetFrom(
245 change.video_temporal_layer_screencast);
246 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
247 conference_mode.SetFrom(change.conference_mode);
248 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
249 system_low_adaptation_threshhold.SetFrom(
250 change.system_low_adaptation_threshhold);
251 system_high_adaptation_threshhold.SetFrom(
252 change.system_high_adaptation_threshhold);
253 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
254 }
255
256 bool operator==(const VideoOptions& o) const {
257 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
258 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
259 adapt_view_switch == o.adapt_view_switch &&
260 video_noise_reduction == o.video_noise_reduction &&
261 video_three_layers == o.video_three_layers &&
262 video_enable_camera_list == o.video_enable_camera_list &&
263 video_one_layer_screencast == o.video_one_layer_screencast &&
264 video_high_bitrate == o.video_high_bitrate &&
265 video_watermark == o.video_watermark &&
266 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
267 video_leaky_bucket == o.video_leaky_bucket &&
268 conference_mode == o.conference_mode &&
269 process_adaptation_threshhold == o.process_adaptation_threshhold &&
270 system_low_adaptation_threshhold ==
271 o.system_low_adaptation_threshhold &&
272 system_high_adaptation_threshhold ==
273 o.system_high_adaptation_threshhold &&
274 buffered_mode_latency == o.buffered_mode_latency;
275 }
276
277 std::string ToString() const {
278 std::ostringstream ost;
279 ost << "VideoOptions {";
280 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
281 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
282 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
283 ost << ToStringIfSet("noise reduction", video_noise_reduction);
284 ost << ToStringIfSet("3 layers", video_three_layers);
285 ost << ToStringIfSet("camera list", video_enable_camera_list);
286 ost << ToStringIfSet("1 layer screencast",
287 video_one_layer_screencast);
288 ost << ToStringIfSet("high bitrate", video_high_bitrate);
289 ost << ToStringIfSet("watermark", video_watermark);
290 ost << ToStringIfSet("video temporal layer screencast",
291 video_temporal_layer_screencast);
292 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
293 ost << ToStringIfSet("conference mode", conference_mode);
294 ost << ToStringIfSet("process", process_adaptation_threshhold);
295 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
296 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
297 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
298 ost << "}";
299 return ost.str();
300 }
301
302 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
303 Settable<bool> adapt_input_to_encoder;
304 // Enable CPU adaptation?
305 Settable<bool> adapt_input_to_cpu_usage;
306 // Enable Adapt View Switch?
307 Settable<bool> adapt_view_switch;
308 // Enable denoising?
309 Settable<bool> video_noise_reduction;
310 // Experimental: Enable multi layer?
311 Settable<bool> video_three_layers;
312 // Experimental: Enable camera list?
313 Settable<bool> video_enable_camera_list;
314 // Experimental: Enable one layer screencast?
315 Settable<bool> video_one_layer_screencast;
316 // Experimental: Enable WebRtc higher bitrate?
317 Settable<bool> video_high_bitrate;
318 // Experimental: Add watermark to the rendered video image.
319 Settable<bool> video_watermark;
320 // Experimental: Enable WebRTC layered screencast.
321 Settable<bool> video_temporal_layer_screencast;
322 // Enable WebRTC leaky bucket when sending media packets.
323 Settable<bool> video_leaky_bucket;
324 // Use conference mode?
325 Settable<bool> conference_mode;
326 // Threshhold for process cpu adaptation. (Process limit)
327 SettablePercent process_adaptation_threshhold;
328 // Low threshhold for cpu adaptation. (Adapt up)
329 SettablePercent system_low_adaptation_threshhold;
330 // High threshhold for cpu adaptation. (Adapt down)
331 SettablePercent system_high_adaptation_threshhold;
332 // Specify buffered mode latency in milliseconds.
333 Settable<int> buffered_mode_latency;
334};
335
336// A class for playing out soundclips.
337class SoundclipMedia {
338 public:
339 enum SoundclipFlags {
340 SF_LOOP = 1,
341 };
342
343 virtual ~SoundclipMedia() {}
344
345 // Plays a sound out to the speakers with the given audio stream. The stream
346 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
347 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
348 // Returns whether it was successful.
349 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
350};
351
352struct RtpHeaderExtension {
353 RtpHeaderExtension() : id(0) {}
354 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
355 std::string uri;
356 int id;
357 // TODO(juberti): SendRecv direction;
358
359 bool operator==(const RtpHeaderExtension& ext) const {
360 // id is a reserved word in objective-c. Therefore the id attribute has to
361 // be a fully qualified name in order to compile on IOS.
362 return this->id == ext.id &&
363 uri == ext.uri;
364 }
365};
366
367// Returns the named header extension if found among all extensions, NULL
368// otherwise.
369inline const RtpHeaderExtension* FindHeaderExtension(
370 const std::vector<RtpHeaderExtension>& extensions,
371 const std::string& name) {
372 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
373 it != extensions.end(); ++it) {
374 if (it->uri == name)
375 return &(*it);
376 }
377 return NULL;
378}
379
380enum MediaChannelOptions {
381 // Tune the stream for conference mode.
382 OPT_CONFERENCE = 0x0001
383};
384
385enum VoiceMediaChannelOptions {
386 // Tune the audio stream for vcs with different target levels.
387 OPT_AGC_MINUS_10DB = 0x80000000
388};
389
390// DTMF flags to control if a DTMF tone should be played and/or sent.
391enum DtmfFlags {
392 DF_PLAY = 0x01,
393 DF_SEND = 0x02,
394};
395
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396class MediaChannel : public sigslot::has_slots<> {
397 public:
398 class NetworkInterface {
399 public:
400 enum SocketType { ST_RTP, ST_RTCP };
401 virtual bool SendPacket(talk_base::Buffer* packet) = 0;
402 virtual bool SendRtcp(talk_base::Buffer* packet) = 0;
403 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
404 int option) = 0;
405 virtual ~NetworkInterface() {}
406 };
407
408 MediaChannel() : network_interface_(NULL) {}
409 virtual ~MediaChannel() {}
410
411 // Gets/sets the abstract inteface class for sending RTP/RTCP data.
412 NetworkInterface *network_interface() { return network_interface_; }
413 virtual void SetInterface(NetworkInterface *iface) {
414 network_interface_ = iface;
415 }
416
417 // Called when a RTP packet is received.
418 virtual void OnPacketReceived(talk_base::Buffer* packet) = 0;
419 // Called when a RTCP packet is received.
420 virtual void OnRtcpReceived(talk_base::Buffer* packet) = 0;
421 // Called when the socket's ability to send has changed.
422 virtual void OnReadyToSend(bool ready) = 0;
423 // Creates a new outgoing media stream with SSRCs and CNAME as described
424 // by sp.
425 virtual bool AddSendStream(const StreamParams& sp) = 0;
426 // Removes an outgoing media stream.
427 // ssrc must be the first SSRC of the media stream if the stream uses
428 // multiple SSRCs.
429 virtual bool RemoveSendStream(uint32 ssrc) = 0;
430 // Creates a new incoming media stream with SSRCs and CNAME as described
431 // by sp.
432 virtual bool AddRecvStream(const StreamParams& sp) = 0;
433 // Removes an incoming media stream.
434 // ssrc must be the first SSRC of the media stream if the stream uses
435 // multiple SSRCs.
436 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
437
438 // Mutes the channel.
439 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
440
441 // Sets the RTP extension headers and IDs to use when sending RTP.
442 virtual bool SetRecvRtpHeaderExtensions(
443 const std::vector<RtpHeaderExtension>& extensions) = 0;
444 virtual bool SetSendRtpHeaderExtensions(
445 const std::vector<RtpHeaderExtension>& extensions) = 0;
446 // Sets the rate control to use when sending data.
447 virtual bool SetSendBandwidth(bool autobw, int bps) = 0;
448
449 protected:
450 NetworkInterface *network_interface_;
451};
452
453enum SendFlags {
454 SEND_NOTHING,
455 SEND_RINGBACKTONE,
456 SEND_MICROPHONE
457};
458
459struct VoiceSenderInfo {
460 VoiceSenderInfo()
461 : ssrc(0),
462 bytes_sent(0),
463 packets_sent(0),
464 packets_lost(0),
465 fraction_lost(0.0),
466 ext_seqnum(0),
467 rtt_ms(0),
468 jitter_ms(0),
469 audio_level(0),
470 aec_quality_min(0.0),
471 echo_delay_median_ms(0),
472 echo_delay_std_ms(0),
473 echo_return_loss(0),
474 echo_return_loss_enhancement(0) {
475 }
476
477 uint32 ssrc;
478 std::string codec_name;
479 int64 bytes_sent;
480 int packets_sent;
481 int packets_lost;
482 float fraction_lost;
483 int ext_seqnum;
484 int rtt_ms;
485 int jitter_ms;
486 int audio_level;
487 float aec_quality_min;
488 int echo_delay_median_ms;
489 int echo_delay_std_ms;
490 int echo_return_loss;
491 int echo_return_loss_enhancement;
492};
493
494struct VoiceReceiverInfo {
495 VoiceReceiverInfo()
496 : ssrc(0),
497 bytes_rcvd(0),
498 packets_rcvd(0),
499 packets_lost(0),
500 fraction_lost(0.0),
501 ext_seqnum(0),
502 jitter_ms(0),
503 jitter_buffer_ms(0),
504 jitter_buffer_preferred_ms(0),
505 delay_estimate_ms(0),
506 audio_level(0),
507 expand_rate(0) {
508 }
509
510 uint32 ssrc;
511 int64 bytes_rcvd;
512 int packets_rcvd;
513 int packets_lost;
514 float fraction_lost;
515 int ext_seqnum;
516 int jitter_ms;
517 int jitter_buffer_ms;
518 int jitter_buffer_preferred_ms;
519 int delay_estimate_ms;
520 int audio_level;
521 // fraction of synthesized speech inserted through pre-emptive expansion
522 float expand_rate;
523};
524
525struct VideoSenderInfo {
526 VideoSenderInfo()
527 : bytes_sent(0),
528 packets_sent(0),
529 packets_cached(0),
530 packets_lost(0),
531 fraction_lost(0.0),
532 firs_rcvd(0),
533 nacks_rcvd(0),
534 rtt_ms(0),
535 frame_width(0),
536 frame_height(0),
537 framerate_input(0),
538 framerate_sent(0),
539 nominal_bitrate(0),
540 preferred_bitrate(0),
541 adapt_reason(0) {
542 }
543
544 std::vector<uint32> ssrcs;
545 std::vector<SsrcGroup> ssrc_groups;
546 std::string codec_name;
547 int64 bytes_sent;
548 int packets_sent;
549 int packets_cached;
550 int packets_lost;
551 float fraction_lost;
552 int firs_rcvd;
553 int nacks_rcvd;
554 int rtt_ms;
555 int frame_width;
556 int frame_height;
557 int framerate_input;
558 int framerate_sent;
559 int nominal_bitrate;
560 int preferred_bitrate;
561 int adapt_reason;
562};
563
564struct VideoReceiverInfo {
565 VideoReceiverInfo()
566 : bytes_rcvd(0),
567 packets_rcvd(0),
568 packets_lost(0),
569 packets_concealed(0),
570 fraction_lost(0.0),
571 firs_sent(0),
572 nacks_sent(0),
573 frame_width(0),
574 frame_height(0),
575 framerate_rcvd(0),
576 framerate_decoded(0),
577 framerate_output(0),
578 framerate_render_input(0),
579 framerate_render_output(0) {
580 }
581
582 std::vector<uint32> ssrcs;
583 std::vector<SsrcGroup> ssrc_groups;
584 int64 bytes_rcvd;
585 // vector<int> layer_bytes_rcvd;
586 int packets_rcvd;
587 int packets_lost;
588 int packets_concealed;
589 float fraction_lost;
590 int firs_sent;
591 int nacks_sent;
592 int frame_width;
593 int frame_height;
594 int framerate_rcvd;
595 int framerate_decoded;
596 int framerate_output;
597 // Framerate as sent to the renderer.
598 int framerate_render_input;
599 // Framerate that the renderer reports.
600 int framerate_render_output;
601};
602
603struct DataSenderInfo {
604 DataSenderInfo()
605 : ssrc(0),
606 bytes_sent(0),
607 packets_sent(0) {
608 }
609
610 uint32 ssrc;
611 std::string codec_name;
612 int64 bytes_sent;
613 int packets_sent;
614};
615
616struct DataReceiverInfo {
617 DataReceiverInfo()
618 : ssrc(0),
619 bytes_rcvd(0),
620 packets_rcvd(0) {
621 }
622
623 uint32 ssrc;
624 int64 bytes_rcvd;
625 int packets_rcvd;
626};
627
628struct BandwidthEstimationInfo {
629 BandwidthEstimationInfo()
630 : available_send_bandwidth(0),
631 available_recv_bandwidth(0),
632 target_enc_bitrate(0),
633 actual_enc_bitrate(0),
634 retransmit_bitrate(0),
635 transmit_bitrate(0),
636 bucket_delay(0) {
637 }
638
639 int available_send_bandwidth;
640 int available_recv_bandwidth;
641 int target_enc_bitrate;
642 int actual_enc_bitrate;
643 int retransmit_bitrate;
644 int transmit_bitrate;
645 int bucket_delay;
646};
647
648struct VoiceMediaInfo {
649 void Clear() {
650 senders.clear();
651 receivers.clear();
652 }
653 std::vector<VoiceSenderInfo> senders;
654 std::vector<VoiceReceiverInfo> receivers;
655};
656
657struct VideoMediaInfo {
658 void Clear() {
659 senders.clear();
660 receivers.clear();
661 bw_estimations.clear();
662 }
663 std::vector<VideoSenderInfo> senders;
664 std::vector<VideoReceiverInfo> receivers;
665 std::vector<BandwidthEstimationInfo> bw_estimations;
666};
667
668struct DataMediaInfo {
669 void Clear() {
670 senders.clear();
671 receivers.clear();
672 }
673 std::vector<DataSenderInfo> senders;
674 std::vector<DataReceiverInfo> receivers;
675};
676
677class VoiceMediaChannel : public MediaChannel {
678 public:
679 enum Error {
680 ERROR_NONE = 0, // No error.
681 ERROR_OTHER, // Other errors.
682 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
683 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
684 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
685 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
686 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
687 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
688 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
689 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
690 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
691 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
692 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
693 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
694 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
695 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
696 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
697 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
698 };
699
700 VoiceMediaChannel() {}
701 virtual ~VoiceMediaChannel() {}
702 // Sets the codecs/payload types to be used for incoming media.
703 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
704 // Sets the codecs/payload types to be used for outgoing media.
705 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
706 // Starts or stops playout of received audio.
707 virtual bool SetPlayout(bool playout) = 0;
708 // Starts or stops sending (and potentially capture) of local audio.
709 virtual bool SetSend(SendFlags flag) = 0;
710 // Sets the renderer object to be used for the specified audio stream.
711 virtual bool SetRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
712 // Gets current energy levels for all incoming streams.
713 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
714 // Get the current energy level of the stream sent to the speaker.
715 virtual int GetOutputLevel() = 0;
716 // Get the time in milliseconds since last recorded keystroke, or negative.
717 virtual int GetTimeSinceLastTyping() = 0;
718 // Temporarily exposed field for tuning typing detect options.
719 virtual void SetTypingDetectionParameters(int time_window,
720 int cost_per_typing, int reporting_threshold, int penalty_decay,
721 int type_event_delay) = 0;
722 // Set left and right scale for speaker output volume of the specified ssrc.
723 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
724 // Get left and right scale for speaker output volume of the specified ssrc.
725 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
726 // Specifies a ringback tone to be played during call setup.
727 virtual bool SetRingbackTone(const char *buf, int len) = 0;
728 // Plays or stops the aforementioned ringback tone
729 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
730 // Returns if the telephone-event has been negotiated.
731 virtual bool CanInsertDtmf() { return false; }
732 // Send and/or play a DTMF |event| according to the |flags|.
733 // The DTMF out-of-band signal will be used on sending.
734 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000735 // The valid value for the |event| are 0 to 15 which corresponding to
736 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
738 // Gets quality stats for the channel.
739 virtual bool GetStats(VoiceMediaInfo* info) = 0;
740 // Gets last reported error for this media channel.
741 virtual void GetLastMediaError(uint32* ssrc,
742 VoiceMediaChannel::Error* error) {
743 ASSERT(error != NULL);
744 *error = ERROR_NONE;
745 }
746 // Sets the media options to use.
747 virtual bool SetOptions(const AudioOptions& options) = 0;
748 virtual bool GetOptions(AudioOptions* options) const = 0;
749
750 // Signal errors from MediaChannel. Arguments are:
751 // ssrc(uint32), and error(VoiceMediaChannel::Error).
752 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
753};
754
755class VideoMediaChannel : public MediaChannel {
756 public:
757 enum Error {
758 ERROR_NONE = 0, // No error.
759 ERROR_OTHER, // Other errors.
760 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
761 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
762 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
763 ERROR_REC_DEVICE_REMOVED, // Device is removed.
764 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
765 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
766 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
767 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
768 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
769 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
770 };
771
772 VideoMediaChannel() : renderer_(NULL) {}
773 virtual ~VideoMediaChannel() {}
774 // Sets the codecs/payload types to be used for incoming media.
775 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
776 // Sets the codecs/payload types to be used for outgoing media.
777 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
778 // Gets the currently set codecs/payload types to be used for outgoing media.
779 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
780 // Sets the format of a specified outgoing stream.
781 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
782 // Starts or stops playout of received video.
783 virtual bool SetRender(bool render) = 0;
784 // Starts or stops transmission (and potentially capture) of local video.
785 virtual bool SetSend(bool send) = 0;
786 // Sets the renderer object to be used for the specified stream.
787 // If SSRC is 0, the renderer is used for the 'default' stream.
788 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
789 // If |ssrc| is 0, replace the default capturer (engine capturer) with
790 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
791 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
792 // Gets quality stats for the channel.
793 virtual bool GetStats(VideoMediaInfo* info) = 0;
794
795 // Send an intra frame to the receivers.
796 virtual bool SendIntraFrame() = 0;
797 // Reuqest each of the remote senders to send an intra frame.
798 virtual bool RequestIntraFrame() = 0;
799 // Sets the media options to use.
800 virtual bool SetOptions(const VideoOptions& options) = 0;
801 virtual bool GetOptions(VideoOptions* options) const = 0;
802 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
803
804 // Signal errors from MediaChannel. Arguments are:
805 // ssrc(uint32), and error(VideoMediaChannel::Error).
806 sigslot::signal2<uint32, Error> SignalMediaError;
807
808 protected:
809 VideoRenderer *renderer_;
810};
811
812enum DataMessageType {
813 // TODO(pthatcher): Make this enum match the SCTP PPIDs that WebRTC uses?
814 DMT_CONTROL = 0,
815 DMT_BINARY = 1,
816 DMT_TEXT = 2,
817};
818
819// Info about data received in DataMediaChannel. For use in
820// DataMediaChannel::SignalDataReceived and in all of the signals that
821// signal fires, on up the chain.
822struct ReceiveDataParams {
823 // The in-packet stream indentifier.
824 // For SCTP, this is really SID, not SSRC.
825 uint32 ssrc;
826 // The type of message (binary, text, or control).
827 DataMessageType type;
828 // A per-stream value incremented per packet in the stream.
829 int seq_num;
830 // A per-stream value monotonically increasing with time.
831 int timestamp;
832
833 ReceiveDataParams() :
834 ssrc(0),
835 type(DMT_TEXT),
836 seq_num(0),
837 timestamp(0) {
838 }
839};
840
841struct SendDataParams {
842 // The in-packet stream indentifier.
843 // For SCTP, this is really SID, not SSRC.
844 uint32 ssrc;
845 // The type of message (binary, text, or control).
846 DataMessageType type;
847
848 // For SCTP, whether to send messages flagged as ordered or not.
849 // If false, messages can be received out of order.
850 bool ordered;
851 // For SCTP, whether the messages are sent reliably or not.
852 // If false, messages may be lost.
853 bool reliable;
854 // For SCTP, if reliable == false, provide partial reliability by
855 // resending up to this many times. Either count or millis
856 // is supported, not both at the same time.
857 int max_rtx_count;
858 // For SCTP, if reliable == false, provide partial reliability by
859 // resending for up to this many milliseconds. Either count or millis
860 // is supported, not both at the same time.
861 int max_rtx_ms;
862
863 SendDataParams() :
864 ssrc(0),
865 type(DMT_TEXT),
866 // TODO(pthatcher): Make these true by default?
867 ordered(false),
868 reliable(false),
869 max_rtx_count(0),
870 max_rtx_ms(0) {
871 }
872};
873
874enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
875
876class DataMediaChannel : public MediaChannel {
877 public:
878 enum Error {
879 ERROR_NONE = 0, // No error.
880 ERROR_OTHER, // Other errors.
881 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
882 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
883 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
884 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
885 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
886 };
887
888 virtual ~DataMediaChannel() {}
889
890 virtual bool SetSendBandwidth(bool autobw, int bps) = 0;
891 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
892 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
893 virtual bool SetRecvRtpHeaderExtensions(
894 const std::vector<RtpHeaderExtension>& extensions) = 0;
895 virtual bool SetSendRtpHeaderExtensions(
896 const std::vector<RtpHeaderExtension>& extensions) = 0;
897 virtual bool AddSendStream(const StreamParams& sp) = 0;
898 virtual bool RemoveSendStream(uint32 ssrc) = 0;
899 virtual bool AddRecvStream(const StreamParams& sp) = 0;
900 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
901 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
902 // TODO(pthatcher): Implement this.
903 virtual bool GetStats(DataMediaInfo* info) { return true; }
904
905 virtual bool SetSend(bool send) = 0;
906 virtual bool SetReceive(bool receive) = 0;
907 virtual void OnPacketReceived(talk_base::Buffer* packet) = 0;
908 virtual void OnRtcpReceived(talk_base::Buffer* packet) = 0;
909
910 virtual bool SendData(
911 const SendDataParams& params,
912 const talk_base::Buffer& payload,
913 SendDataResult* result = NULL) = 0;
914 // Signals when data is received (params, data, len)
915 sigslot::signal3<const ReceiveDataParams&,
916 const char*,
917 size_t> SignalDataReceived;
918 // Signal errors from MediaChannel. Arguments are:
919 // ssrc(uint32), and error(DataMediaChannel::Error).
920 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
921};
922
923} // namespace cricket
924
925#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_