Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 webrtc::Call* call, | 615 webrtc::Call* call, |
| 616 const VideoOptions& options, | 616 const VideoOptions& options, |
| 617 const std::vector<VideoCodec>& recv_codecs, | 617 const std::vector<VideoCodec>& recv_codecs, |
| 618 WebRtcVideoEncoderFactory* external_encoder_factory, | 618 WebRtcVideoEncoderFactory* external_encoder_factory, |
| 619 WebRtcVideoDecoderFactory* external_decoder_factory) | 619 WebRtcVideoDecoderFactory* external_decoder_factory) |
| 620 : call_(call), | 620 : call_(call), |
| 621 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), | 621 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
| 622 external_encoder_factory_(external_encoder_factory), | 622 external_encoder_factory_(external_encoder_factory), |
| 623 external_decoder_factory_(external_decoder_factory) { | 623 external_decoder_factory_(external_decoder_factory) { |
| 624 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 624 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 625 SetDefaultOptions(); | 625 |
| 626 options_.SetAll(options); | 626 signal_cpu_adaptation_ = options.cpu_overuse_detection.value_or(true); |
| 627 if (options_.cpu_overuse_detection) | |
| 628 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; | |
| 629 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; | 627 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
| 630 sending_ = false; | 628 sending_ = false; |
| 631 default_send_ssrc_ = 0; | 629 default_send_ssrc_ = 0; |
| 632 SetRecvCodecs(recv_codecs); | 630 SetRecvCodecs(recv_codecs); |
| 633 } | 631 } |
| 634 | 632 |
| 635 void WebRtcVideoChannel2::SetDefaultOptions() { | 633 void WebRtcVideoChannel2::SetDefaultOptions(VideoOptions *options) { |
| 636 options_.cpu_overuse_detection = rtc::Optional<bool>(true); | 634 options->cpu_overuse_detection = rtc::Optional<bool>(true); |
| 637 options_.dscp = rtc::Optional<bool>(false); | 635 options->dscp = rtc::Optional<bool>(false); |
| 638 options_.suspend_below_min_bitrate = rtc::Optional<bool>(false); | 636 options->suspend_below_min_bitrate = rtc::Optional<bool>(false); |
| 639 options_.screencast_min_bitrate = rtc::Optional<int>(0); | 637 options->screencast_min_bitrate = rtc::Optional<int>(0); |
| 640 } | 638 } |
| 641 | 639 |
| 642 WebRtcVideoChannel2::~WebRtcVideoChannel2() { | 640 WebRtcVideoChannel2::~WebRtcVideoChannel2() { |
| 643 for (auto& kv : send_streams_) | 641 for (auto& kv : send_streams_) |
| 644 delete kv.second; | 642 delete kv.second; |
| 645 for (auto& kv : receive_streams_) | 643 for (auto& kv : receive_streams_) |
| 646 delete kv.second; | 644 delete kv.second; |
| 647 } | 645 } |
| 648 | 646 |
| 649 bool WebRtcVideoChannel2::CodecIsExternallySupported( | 647 bool WebRtcVideoChannel2::CodecIsExternallySupported( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 return false; | 708 return false; |
| 711 } | 709 } |
| 712 | 710 |
| 713 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { | 711 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { |
| 714 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters"); | 712 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters"); |
| 715 LOG(LS_INFO) << "SetSendParameters: " << params.ToString(); | 713 LOG(LS_INFO) << "SetSendParameters: " << params.ToString(); |
| 716 // TODO(pbos): Refactor this to only recreate the send streams once | 714 // TODO(pbos): Refactor this to only recreate the send streams once |
| 717 // instead of 4 times. | 715 // instead of 4 times. |
| 718 if (!SetSendCodecs(params.codecs) || | 716 if (!SetSendCodecs(params.codecs) || |
| 719 !SetSendRtpHeaderExtensions(params.extensions) || | 717 !SetSendRtpHeaderExtensions(params.extensions) || |
| 720 !SetMaxSendBandwidth(params.max_bandwidth_bps) || | 718 !SetMaxSendBandwidth(params.max_bandwidth_bps)) { |
| 721 !SetOptions(params.options)) { | |
| 722 return false; | 719 return false; |
| 723 } | 720 } |
| 721 SetSharedOptions(params.options); | |
| 724 if (send_params_.rtcp.reduced_size != params.rtcp.reduced_size) { | 722 if (send_params_.rtcp.reduced_size != params.rtcp.reduced_size) { |
| 725 rtc::CritScope stream_lock(&stream_crit_); | 723 rtc::CritScope stream_lock(&stream_crit_); |
| 726 for (auto& kv : send_streams_) { | 724 for (auto& kv : send_streams_) { |
| 727 kv.second->SetSendParameters(params); | 725 kv.second->SetSendParameters(params); |
| 728 } | 726 } |
| 729 } | 727 } |
| 730 send_params_ = params; | 728 send_params_ = params; |
| 731 return true; | 729 return true; |
| 732 } | 730 } |
| 733 | 731 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 } | 914 } |
| 917 | 915 |
| 918 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, | 916 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, |
| 919 const VideoOptions* options) { | 917 const VideoOptions* options) { |
| 920 // TODO(solenberg): The state change should be fully rolled back if any one of | 918 // TODO(solenberg): The state change should be fully rolled back if any one of |
| 921 // these calls fail. | 919 // these calls fail. |
| 922 if (!MuteStream(ssrc, !enable)) { | 920 if (!MuteStream(ssrc, !enable)) { |
| 923 return false; | 921 return false; |
| 924 } | 922 } |
| 925 if (enable && options) { | 923 if (enable && options) { |
| 926 return SetOptions(*options); | 924 return SetOptions(ssrc, *options); |
| 927 } else { | 925 } else { |
| 928 return true; | 926 return true; |
| 929 } | 927 } |
| 930 } | 928 } |
| 931 | 929 |
| 932 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 930 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
| 933 const StreamParams& sp) const { | 931 const StreamParams& sp) const { |
| 934 for (uint32_t ssrc: sp.ssrcs) { | 932 for (uint32_t ssrc: sp.ssrcs) { |
| 935 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 933 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
| 936 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; | 934 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 961 | 959 |
| 962 if (!ValidateSendSsrcAvailability(sp)) | 960 if (!ValidateSendSsrcAvailability(sp)) |
| 963 return false; | 961 return false; |
| 964 | 962 |
| 965 for (uint32_t used_ssrc : sp.ssrcs) | 963 for (uint32_t used_ssrc : sp.ssrcs) |
| 966 send_ssrcs_.insert(used_ssrc); | 964 send_ssrcs_.insert(used_ssrc); |
| 967 | 965 |
| 968 webrtc::VideoSendStream::Config config(this); | 966 webrtc::VideoSendStream::Config config(this); |
| 969 config.overuse_callback = this; | 967 config.overuse_callback = this; |
| 970 | 968 |
| 969 // Initial options | |
| 970 VideoOptions options; | |
| 971 SetDefaultOptions(&options); | |
| 972 | |
| 971 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( | 973 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( |
| 972 call_, sp, config, external_encoder_factory_, options_, | 974 call_, sp, config, external_encoder_factory_, options, |
| 973 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, | 975 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, |
| 974 send_params_); | 976 send_params_); |
| 975 | 977 |
| 976 uint32_t ssrc = sp.first_ssrc(); | 978 uint32_t ssrc = sp.first_ssrc(); |
| 977 RTC_DCHECK(ssrc != 0); | 979 RTC_DCHECK(ssrc != 0); |
| 978 send_streams_[ssrc] = stream; | 980 send_streams_[ssrc] = stream; |
| 979 | 981 |
| 980 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { | 982 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
| 981 rtcp_receiver_report_ssrc_ = ssrc; | 983 rtcp_receiver_report_ssrc_ = ssrc; |
| 982 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 984 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 | 1094 |
| 1093 // Set up A/V sync group based on sync label. | 1095 // Set up A/V sync group based on sync label. |
| 1094 config.sync_group = sp.sync_label; | 1096 config.sync_group = sp.sync_label; |
| 1095 | 1097 |
| 1096 config.rtp.remb = send_codec_ ? HasRemb(send_codec_->codec) : false; | 1098 config.rtp.remb = send_codec_ ? HasRemb(send_codec_->codec) : false; |
| 1097 config.rtp.transport_cc = | 1099 config.rtp.transport_cc = |
| 1098 send_codec_ ? HasTransportCc(send_codec_->codec) : false; | 1100 send_codec_ ? HasTransportCc(send_codec_->codec) : false; |
| 1099 | 1101 |
| 1100 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( | 1102 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( |
| 1101 call_, sp, config, external_decoder_factory_, default_stream, | 1103 call_, sp, config, external_decoder_factory_, default_stream, |
| 1102 recv_codecs_, options_.disable_prerenderer_smoothing.value_or(false)); | 1104 recv_codecs_, |
| 1105 // TODO(nisse): Used to pass | |
|
pbos-webrtc
2016/01/28 14:55:44
This should be const on construction, this needs t
| |
| 1106 // options_.disable_prerenderer_smoothing.value_or(false), | |
| 1107 // unclear if it needs to be configurable here, but there's no | |
| 1108 // other method to change it. | |
| 1109 false); | |
| 1103 | 1110 |
| 1104 return true; | 1111 return true; |
| 1105 } | 1112 } |
| 1106 | 1113 |
| 1107 void WebRtcVideoChannel2::ConfigureReceiverRtp( | 1114 void WebRtcVideoChannel2::ConfigureReceiverRtp( |
| 1108 webrtc::VideoReceiveStream::Config* config, | 1115 webrtc::VideoReceiveStream::Config* config, |
| 1109 const StreamParams& sp) const { | 1116 const StreamParams& sp) const { |
| 1110 uint32_t ssrc = sp.first_ssrc(); | 1117 uint32_t ssrc = sp.first_ssrc(); |
| 1111 | 1118 |
| 1112 config->rtp.remote_ssrc = ssrc; | 1119 config->rtp.remote_ssrc = ssrc; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1459 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { | 1466 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { |
| 1460 bitrate_config_.min_bitrate_bps = max_bitrate_bps; | 1467 bitrate_config_.min_bitrate_bps = max_bitrate_bps; |
| 1461 } | 1468 } |
| 1462 call_->SetBitrateConfig(bitrate_config_); | 1469 call_->SetBitrateConfig(bitrate_config_); |
| 1463 rtc::CritScope stream_lock(&stream_crit_); | 1470 rtc::CritScope stream_lock(&stream_crit_); |
| 1464 for (auto& kv : send_streams_) | 1471 for (auto& kv : send_streams_) |
| 1465 kv.second->SetMaxBitrateBps(max_bitrate_bps); | 1472 kv.second->SetMaxBitrateBps(max_bitrate_bps); |
| 1466 return true; | 1473 return true; |
| 1467 } | 1474 } |
| 1468 | 1475 |
| 1469 bool WebRtcVideoChannel2::SetOptions(const VideoOptions& options) { | 1476 void WebRtcVideoChannel2::SetSharedOptions(const VideoOptions& options) { |
| 1470 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetOptions"); | |
| 1471 LOG(LS_INFO) << "SetOptions: " << options.ToString(); | |
| 1472 VideoOptions old_options = options_; | |
| 1473 options_.SetAll(options); | |
| 1474 if (options_ == old_options) { | |
| 1475 // No new options to set. | |
| 1476 return true; | |
| 1477 } | |
| 1478 { | 1477 { |
| 1479 rtc::CritScope lock(&capturer_crit_); | 1478 rtc::CritScope lock(&capturer_crit_); |
| 1480 if (options_.cpu_overuse_detection) | 1479 if (options.cpu_overuse_detection) |
| 1481 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; | 1480 signal_cpu_adaptation_ = *options.cpu_overuse_detection; |
| 1482 } | 1481 } |
| 1483 rtc::DiffServCodePoint dscp = | 1482 rtc::DiffServCodePoint dscp = |
| 1484 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; | 1483 options.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; |
| 1485 MediaChannel::SetDscp(dscp); | 1484 MediaChannel::SetDscp(dscp); |
| 1485 } | |
| 1486 | |
| 1487 bool WebRtcVideoChannel2::SetOptions(uint32_t ssrc, | |
| 1488 const VideoOptions& options) { | |
| 1489 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetOptions"); | |
| 1490 LOG(LS_INFO) << "SetOptions: ssrc " << ssrc << ": " << options.ToString(); | |
| 1491 SetSharedOptions(options); | |
| 1492 | |
| 1486 rtc::CritScope stream_lock(&stream_crit_); | 1493 rtc::CritScope stream_lock(&stream_crit_); |
| 1487 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = | 1494 if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 1488 send_streams_.begin(); | 1495 return false; |
| 1489 it != send_streams_.end(); ++it) { | |
| 1490 it->second->SetOptions(options_); | |
| 1491 } | 1496 } |
| 1497 send_streams_[ssrc]->SetOptions(options); | |
| 1498 | |
| 1492 return true; | 1499 return true; |
| 1493 } | 1500 } |
| 1494 | 1501 |
| 1495 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { | 1502 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { |
| 1496 MediaChannel::SetInterface(iface); | 1503 MediaChannel::SetInterface(iface); |
| 1497 // Set the RTP recv/send buffer to a bigger size | 1504 // Set the RTP recv/send buffer to a bigger size |
| 1498 MediaChannel::SetOption(NetworkInterface::ST_RTP, | 1505 MediaChannel::SetOption(NetworkInterface::ST_RTP, |
| 1499 rtc::Socket::OPT_RCVBUF, | 1506 rtc::Socket::OPT_RCVBUF, |
| 1500 kVideoRtpBufferSize); | 1507 kVideoRtpBufferSize); |
| 1501 | 1508 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1801 bool apply_rotation) { | 1808 bool apply_rotation) { |
| 1802 rtc::CritScope cs(&lock_); | 1809 rtc::CritScope cs(&lock_); |
| 1803 if (capturer_ == NULL) | 1810 if (capturer_ == NULL) |
| 1804 return; | 1811 return; |
| 1805 | 1812 |
| 1806 capturer_->SetApplyRotation(apply_rotation); | 1813 capturer_->SetApplyRotation(apply_rotation); |
| 1807 } | 1814 } |
| 1808 | 1815 |
| 1809 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1816 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
| 1810 const VideoOptions& options) { | 1817 const VideoOptions& options) { |
| 1818 | |
| 1811 rtc::CritScope cs(&lock_); | 1819 rtc::CritScope cs(&lock_); |
| 1812 if (parameters_.codec_settings) { | 1820 if (parameters_.codec_settings) { |
| 1813 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" | 1821 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" |
| 1814 << options.ToString(); | 1822 << options.ToString(); |
| 1815 SetCodecAndOptions(*parameters_.codec_settings, options); | 1823 SetCodecAndOptions(*parameters_.codec_settings, options); |
| 1816 } else { | 1824 } else { |
| 1817 parameters_.options = options; | 1825 parameters_.options = options; |
| 1818 } | 1826 } |
| 1819 } | 1827 } |
| 1820 | 1828 |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2649 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2657 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2650 } | 2658 } |
| 2651 } | 2659 } |
| 2652 | 2660 |
| 2653 return video_codecs; | 2661 return video_codecs; |
| 2654 } | 2662 } |
| 2655 | 2663 |
| 2656 } // namespace cricket | 2664 } // namespace cricket |
| 2657 | 2665 |
| 2658 #endif // HAVE_WEBRTC_VIDEO | 2666 #endif // HAVE_WEBRTC_VIDEO |
| OLD | NEW |