| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 void Destroy(webrtc::VideoEncoder* encoder) override { | 72 void Destroy(webrtc::VideoEncoder* encoder) override { |
| 73 return factory_->DestroyVideoEncoder(encoder); | 73 return factory_->DestroyVideoEncoder(encoder); |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 cricket::WebRtcVideoEncoderFactory* const factory_; | 77 cricket::WebRtcVideoEncoderFactory* const factory_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 webrtc::Call::Config::BitrateConfig GetBitrateConfigForCodec( |
| 81 const VideoCodec& codec) { |
| 82 webrtc::Call::Config::BitrateConfig config; |
| 83 int bitrate_kbps; |
| 84 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) && |
| 85 bitrate_kbps > 0) { |
| 86 config.min_bitrate_bps = bitrate_kbps * 1000; |
| 87 } else { |
| 88 config.min_bitrate_bps = 0; |
| 89 } |
| 90 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) && |
| 91 bitrate_kbps > 0) { |
| 92 config.start_bitrate_bps = bitrate_kbps * 1000; |
| 93 } else { |
| 94 // Do not reconfigure start bitrate unless it's specified and positive. |
| 95 config.start_bitrate_bps = -1; |
| 96 } |
| 97 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) && |
| 98 bitrate_kbps > 0) { |
| 99 config.max_bitrate_bps = bitrate_kbps * 1000; |
| 100 } else { |
| 101 config.max_bitrate_bps = -1; |
| 102 } |
| 103 return config; |
| 104 } |
| 105 |
| 80 // An encoder factory that wraps Create requests for simulcastable codec types | 106 // An encoder factory that wraps Create requests for simulcastable codec types |
| 81 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type | 107 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type |
| 82 // requests are just passed through to the contained encoder factory. | 108 // requests are just passed through to the contained encoder factory. |
| 83 class WebRtcSimulcastEncoderFactory | 109 class WebRtcSimulcastEncoderFactory |
| 84 : public cricket::WebRtcVideoEncoderFactory { | 110 : public cricket::WebRtcVideoEncoderFactory { |
| 85 public: | 111 public: |
| 86 // WebRtcSimulcastEncoderFactory doesn't take ownership of |factory|, which is | 112 // WebRtcSimulcastEncoderFactory doesn't take ownership of |factory|, which is |
| 87 // owned by e.g. PeerConnectionFactory. | 113 // owned by e.g. PeerConnectionFactory. |
| 88 explicit WebRtcSimulcastEncoderFactory( | 114 explicit WebRtcSimulcastEncoderFactory( |
| 89 cricket::WebRtcVideoEncoderFactory* factory) | 115 cricket::WebRtcVideoEncoderFactory* factory) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 if (!rtx_ssrcs.empty() && primary_ssrcs.size() != rtx_ssrcs.size()) { | 262 if (!rtx_ssrcs.empty() && primary_ssrcs.size() != rtx_ssrcs.size()) { |
| 237 LOG(LS_ERROR) | 263 LOG(LS_ERROR) |
| 238 << "RTX SSRCs exist, but don't cover all SSRCs (unsupported): " | 264 << "RTX SSRCs exist, but don't cover all SSRCs (unsupported): " |
| 239 << sp.ToString(); | 265 << sp.ToString(); |
| 240 return false; | 266 return false; |
| 241 } | 267 } |
| 242 | 268 |
| 243 return true; | 269 return true; |
| 244 } | 270 } |
| 245 | 271 |
| 246 inline const webrtc::RtpExtension* FindHeaderExtension( | 272 inline bool ContainsHeaderExtension( |
| 247 const std::vector<webrtc::RtpExtension>& extensions, | 273 const std::vector<webrtc::RtpExtension>& extensions, |
| 248 const std::string& name) { | 274 const std::string& name) { |
| 249 for (const auto& kv : extensions) { | 275 for (const auto& kv : extensions) { |
| 250 if (kv.name == name) { | 276 if (kv.name == name) { |
| 251 return &kv; | 277 return true; |
| 252 } | 278 } |
| 253 } | 279 } |
| 254 return NULL; | 280 return false; |
| 255 } | 281 } |
| 256 | 282 |
| 257 // Merges two fec configs and logs an error if a conflict arises | 283 // Merges two fec configs and logs an error if a conflict arises |
| 258 // such that merging in different order would trigger a different output. | 284 // such that merging in different order would trigger a different output. |
| 259 static void MergeFecConfig(const webrtc::FecConfig& other, | 285 static void MergeFecConfig(const webrtc::FecConfig& other, |
| 260 webrtc::FecConfig* output) { | 286 webrtc::FecConfig* output) { |
| 261 if (other.ulpfec_payload_type != -1) { | 287 if (other.ulpfec_payload_type != -1) { |
| 262 if (output->ulpfec_payload_type != -1 && | 288 if (output->ulpfec_payload_type != -1 && |
| 263 output->ulpfec_payload_type != other.ulpfec_payload_type) { | 289 output->ulpfec_payload_type != other.ulpfec_payload_type) { |
| 264 LOG(LS_WARNING) << "Conflict merging ulpfec_payload_type configs: " | 290 LOG(LS_WARNING) << "Conflict merging ulpfec_payload_type configs: " |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 encoder_factory->codecs())) { | 571 encoder_factory->codecs())) { |
| 546 simulcast_encoder_factory_.reset( | 572 simulcast_encoder_factory_.reset( |
| 547 new WebRtcSimulcastEncoderFactory(encoder_factory)); | 573 new WebRtcSimulcastEncoderFactory(encoder_factory)); |
| 548 encoder_factory = simulcast_encoder_factory_.get(); | 574 encoder_factory = simulcast_encoder_factory_.get(); |
| 549 } | 575 } |
| 550 external_encoder_factory_ = encoder_factory; | 576 external_encoder_factory_ = encoder_factory; |
| 551 | 577 |
| 552 video_codecs_ = GetSupportedCodecs(); | 578 video_codecs_ = GetSupportedCodecs(); |
| 553 } | 579 } |
| 554 | 580 |
| 555 bool WebRtcVideoEngine2::EnableTimedRender() { | |
| 556 // TODO(pbos): Figure out whether this can be removed. | |
| 557 return true; | |
| 558 } | |
| 559 | |
| 560 // Checks to see whether we comprehend and could receive a particular codec | 581 // Checks to see whether we comprehend and could receive a particular codec |
| 561 bool WebRtcVideoEngine2::FindCodec(const VideoCodec& in) { | 582 bool WebRtcVideoEngine2::FindCodec(const VideoCodec& in) { |
| 562 // TODO(pbos): Probe encoder factory to figure out that the codec is supported | 583 // TODO(pbos): Probe encoder factory to figure out that the codec is supported |
| 563 // if supported by the encoder factory. Add a corresponding test that fails | 584 // if supported by the encoder factory. Add a corresponding test that fails |
| 564 // with this code (that doesn't ask the factory). | 585 // with this code (that doesn't ask the factory). |
| 565 for (size_t j = 0; j < video_codecs_.size(); ++j) { | 586 for (size_t j = 0; j < video_codecs_.size(); ++j) { |
| 566 VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0); | 587 VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0); |
| 567 if (codec.Matches(in)) { | 588 if (codec.Matches(in)) { |
| 568 return true; | 589 return true; |
| 569 } | 590 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 // side to cause recreation of the stream. | 729 // side to cause recreation of the stream. |
| 709 before[i].codec.preference = 0; | 730 before[i].codec.preference = 0; |
| 710 after[i].codec.preference = 0; | 731 after[i].codec.preference = 0; |
| 711 if (before[i] != after[i]) { | 732 if (before[i] != after[i]) { |
| 712 return true; | 733 return true; |
| 713 } | 734 } |
| 714 } | 735 } |
| 715 return false; | 736 return false; |
| 716 } | 737 } |
| 717 | 738 |
| 739 bool WebRtcVideoChannel2::GetChangedSendParameters( |
| 740 const VideoSendParameters& params, |
| 741 ChangedSendParameters* changed_params) const { |
| 742 if (!ValidateCodecFormats(params.codecs) || |
| 743 !ValidateRtpExtensions(params.extensions)) { |
| 744 return false; |
| 745 } |
| 746 |
| 747 // ==== SEND CODEC ==== |
| 748 const std::vector<VideoCodecSettings> supported_codecs = |
| 749 FilterSupportedCodecs(MapCodecs(params.codecs)); |
| 750 |
| 751 if (supported_codecs.empty()) { |
| 752 LOG(LS_ERROR) << "No video codecs supported."; |
| 753 return false; |
| 754 } |
| 755 |
| 756 if (!send_codec_ || supported_codecs.front() != *send_codec_) { |
| 757 // Send codec has changed. |
| 758 changed_params->codec = |
| 759 rtc::Optional<VideoCodecSettings>(supported_codecs.front()); |
| 760 } |
| 761 |
| 762 // ==== RTP HEADER EXTENSIONS ==== |
| 763 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( |
| 764 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); |
| 765 if (send_rtp_extensions_ != filtered_extensions) { |
| 766 changed_params->rtp_header_extensions = |
| 767 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); |
| 768 } |
| 769 |
| 770 // ==== MAX BITRATE ==== |
| 771 if (params.max_bandwidth_bps != bitrate_config_.max_bitrate_bps && |
| 772 params.max_bandwidth_bps >= 0) { |
| 773 // 0 uncaps max bitrate (-1). |
| 774 changed_params->max_bandwidth_bps = rtc::Optional<int>( |
| 775 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps); |
| 776 } |
| 777 |
| 778 // ==== OPTIONS ==== |
| 779 // TODO(pbos): Require VideoSendParameters to contain a full set of options |
| 780 // and check if params.options != options_ instead of applying a delta. |
| 781 VideoOptions new_options = options_; |
| 782 new_options.SetAll(params.options); |
| 783 if (!(new_options == options_)) { |
| 784 changed_params->options = rtc::Optional<VideoOptions>(new_options); |
| 785 } |
| 786 |
| 787 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) { |
| 788 changed_params->rtcp_mode = rtc::Optional<webrtc::RtcpMode>( |
| 789 params.rtcp.reduced_size ? webrtc::RtcpMode::kReducedSize |
| 790 : webrtc::RtcpMode::kCompound); |
| 791 } |
| 792 |
| 793 return true; |
| 794 } |
| 795 |
| 718 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { | 796 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { |
| 719 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters"); | 797 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters"); |
| 720 LOG(LS_INFO) << "SetSendParameters: " << params.ToString(); | 798 LOG(LS_INFO) << "SetSendParameters: " << params.ToString(); |
| 721 // TODO(pbos): Refactor this to only recreate the send streams once | 799 ChangedSendParameters changed_params; |
| 722 // instead of 4 times. | 800 if (!GetChangedSendParameters(params, &changed_params)) { |
| 723 if (!SetSendCodecs(params.codecs) || | |
| 724 !SetSendRtpHeaderExtensions(params.extensions) || | |
| 725 !SetMaxSendBandwidth(params.max_bandwidth_bps) || | |
| 726 !SetOptions(params.options)) { | |
| 727 return false; | 801 return false; |
| 728 } | 802 } |
| 729 if (send_params_.rtcp.reduced_size != params.rtcp.reduced_size) { | 803 |
| 804 bool bitrate_config_changed = false; |
| 805 |
| 806 if (changed_params.codec) { |
| 807 const VideoCodecSettings& codec_settings = *changed_params.codec; |
| 808 send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings); |
| 809 |
| 810 LOG(LS_INFO) << "Using codec: " << codec_settings.codec.ToString(); |
| 811 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean |
| 812 // that we change the min/max of bandwidth estimation. Reevaluate this. |
| 813 bitrate_config_ = GetBitrateConfigForCodec(codec_settings.codec); |
| 814 bitrate_config_changed = true; |
| 815 } |
| 816 |
| 817 if (changed_params.rtp_header_extensions) { |
| 818 send_rtp_extensions_ = *changed_params.rtp_header_extensions; |
| 819 } |
| 820 |
| 821 if (changed_params.max_bandwidth_bps) { |
| 822 // TODO(pbos): Figure out whether b=AS means max bitrate for this |
| 823 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in |
| 824 // which case this should not set a Call::BitrateConfig but rather |
| 825 // reconfigure all senders. |
| 826 int max_bitrate_bps = *changed_params.max_bandwidth_bps; |
| 827 bitrate_config_.start_bitrate_bps = -1; |
| 828 bitrate_config_.max_bitrate_bps = max_bitrate_bps; |
| 829 if (max_bitrate_bps > 0 && |
| 830 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { |
| 831 bitrate_config_.min_bitrate_bps = max_bitrate_bps; |
| 832 } |
| 833 bitrate_config_changed = true; |
| 834 } |
| 835 |
| 836 if (bitrate_config_changed) { |
| 837 call_->SetBitrateConfig(bitrate_config_); |
| 838 } |
| 839 |
| 840 if (changed_params.options) { |
| 841 options_.SetAll(*changed_params.options); |
| 842 { |
| 843 rtc::CritScope lock(&capturer_crit_); |
| 844 if (options_.cpu_overuse_detection) { |
| 845 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; |
| 846 } |
| 847 } |
| 848 rtc::DiffServCodePoint dscp = |
| 849 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; |
| 850 MediaChannel::SetDscp(dscp); |
| 851 } |
| 852 |
| 853 { |
| 730 rtc::CritScope stream_lock(&stream_crit_); | 854 rtc::CritScope stream_lock(&stream_crit_); |
| 731 for (auto& kv : send_streams_) { | 855 for (auto& kv : send_streams_) { |
| 732 kv.second->SetSendParameters(params); | 856 kv.second->SetSendParameters(changed_params); |
| 857 } |
| 858 if (changed_params.codec) { |
| 859 // Update receive feedback parameters from new codec. |
| 860 LOG(LS_INFO) |
| 861 << "SetFeedbackOptions on all the receive streams because the send " |
| 862 "codec has changed."; |
| 863 for (auto& kv : receive_streams_) { |
| 864 RTC_DCHECK(kv.second != nullptr); |
| 865 kv.second->SetFeedbackParameters(HasNack(send_codec_->codec), |
| 866 HasRemb(send_codec_->codec), |
| 867 HasTransportCc(send_codec_->codec)); |
| 868 } |
| 733 } | 869 } |
| 734 } | 870 } |
| 735 send_params_ = params; | 871 send_params_ = params; |
| 736 return true; | 872 return true; |
| 737 } | 873 } |
| 738 | 874 |
| 739 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) { | 875 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) { |
| 740 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvParameters"); | 876 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvParameters"); |
| 741 LOG(LS_INFO) << "SetRecvParameters: " << params.ToString(); | 877 LOG(LS_INFO) << "SetRecvParameters: " << params.ToString(); |
| 742 // TODO(pbos): Refactor this to only recreate the recv streams once | 878 // TODO(pbos): Refactor this to only recreate the recv streams once |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 rtc::CritScope stream_lock(&stream_crit_); | 941 rtc::CritScope stream_lock(&stream_crit_); |
| 806 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = | 942 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = |
| 807 receive_streams_.begin(); | 943 receive_streams_.begin(); |
| 808 it != receive_streams_.end(); ++it) { | 944 it != receive_streams_.end(); ++it) { |
| 809 it->second->SetRecvCodecs(recv_codecs_); | 945 it->second->SetRecvCodecs(recv_codecs_); |
| 810 } | 946 } |
| 811 | 947 |
| 812 return true; | 948 return true; |
| 813 } | 949 } |
| 814 | 950 |
| 815 bool WebRtcVideoChannel2::SetSendCodecs(const std::vector<VideoCodec>& codecs) { | |
| 816 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendCodecs"); | |
| 817 LOG(LS_INFO) << "SetSendCodecs: " << CodecVectorToString(codecs); | |
| 818 if (!ValidateCodecFormats(codecs)) { | |
| 819 return false; | |
| 820 } | |
| 821 | |
| 822 const std::vector<VideoCodecSettings> supported_codecs = | |
| 823 FilterSupportedCodecs(MapCodecs(codecs)); | |
| 824 | |
| 825 if (supported_codecs.empty()) { | |
| 826 LOG(LS_ERROR) << "No video codecs supported."; | |
| 827 return false; | |
| 828 } | |
| 829 | |
| 830 LOG(LS_INFO) << "Using codec: " << supported_codecs.front().codec.ToString(); | |
| 831 | |
| 832 if (send_codec_ && supported_codecs.front() == *send_codec_) { | |
| 833 LOG(LS_INFO) << "Ignore call to SetSendCodecs because first supported " | |
| 834 "codec hasn't changed."; | |
| 835 // Using same codec, avoid reconfiguring. | |
| 836 return true; | |
| 837 } | |
| 838 | |
| 839 send_codec_ = rtc::Optional<WebRtcVideoChannel2::VideoCodecSettings>( | |
| 840 supported_codecs.front()); | |
| 841 | |
| 842 rtc::CritScope stream_lock(&stream_crit_); | |
| 843 LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different " | |
| 844 "first supported codec."; | |
| 845 for (auto& kv : send_streams_) { | |
| 846 RTC_DCHECK(kv.second != nullptr); | |
| 847 kv.second->SetCodec(supported_codecs.front()); | |
| 848 } | |
| 849 LOG(LS_INFO) | |
| 850 << "SetFeedbackOptions on all the receive streams because the send " | |
| 851 "codec has changed."; | |
| 852 for (auto& kv : receive_streams_) { | |
| 853 RTC_DCHECK(kv.second != nullptr); | |
| 854 kv.second->SetFeedbackParameters( | |
| 855 HasNack(supported_codecs.front().codec), | |
| 856 HasRemb(supported_codecs.front().codec), | |
| 857 HasTransportCc(supported_codecs.front().codec)); | |
| 858 } | |
| 859 | |
| 860 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean that | |
| 861 // we change the min/max of bandwidth estimation. Reevaluate this. | |
| 862 VideoCodec codec = supported_codecs.front().codec; | |
| 863 int bitrate_kbps; | |
| 864 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) && | |
| 865 bitrate_kbps > 0) { | |
| 866 bitrate_config_.min_bitrate_bps = bitrate_kbps * 1000; | |
| 867 } else { | |
| 868 bitrate_config_.min_bitrate_bps = 0; | |
| 869 } | |
| 870 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) && | |
| 871 bitrate_kbps > 0) { | |
| 872 bitrate_config_.start_bitrate_bps = bitrate_kbps * 1000; | |
| 873 } else { | |
| 874 // Do not reconfigure start bitrate unless it's specified and positive. | |
| 875 bitrate_config_.start_bitrate_bps = -1; | |
| 876 } | |
| 877 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) && | |
| 878 bitrate_kbps > 0) { | |
| 879 bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000; | |
| 880 } else { | |
| 881 bitrate_config_.max_bitrate_bps = -1; | |
| 882 } | |
| 883 call_->SetBitrateConfig(bitrate_config_); | |
| 884 | |
| 885 return true; | |
| 886 } | |
| 887 | |
| 888 bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { | 951 bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { |
| 889 if (!send_codec_) { | 952 if (!send_codec_) { |
| 890 LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; | 953 LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; |
| 891 return false; | 954 return false; |
| 892 } | 955 } |
| 893 *codec = send_codec_->codec; | 956 *codec = send_codec_->codec; |
| 894 return true; | 957 return true; |
| 895 } | 958 } |
| 896 | 959 |
| 897 bool WebRtcVideoChannel2::SetSendStreamFormat(uint32_t ssrc, | 960 bool WebRtcVideoChannel2::SetSendStreamFormat(uint32_t ssrc, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 915 StartAllSendStreams(); | 978 StartAllSendStreams(); |
| 916 } else { | 979 } else { |
| 917 StopAllSendStreams(); | 980 StopAllSendStreams(); |
| 918 } | 981 } |
| 919 sending_ = send; | 982 sending_ = send; |
| 920 return true; | 983 return true; |
| 921 } | 984 } |
| 922 | 985 |
| 923 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, | 986 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, |
| 924 const VideoOptions* options) { | 987 const VideoOptions* options) { |
| 988 TRACE_EVENT0("webrtc", "SetVideoSend"); |
| 989 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable |
| 990 << "options: " << (options ? options->ToString() : "nullptr") |
| 991 << ")."; |
| 992 |
| 925 // TODO(solenberg): The state change should be fully rolled back if any one of | 993 // TODO(solenberg): The state change should be fully rolled back if any one of |
| 926 // these calls fail. | 994 // these calls fail. |
| 927 if (!MuteStream(ssrc, !enable)) { | 995 if (!MuteStream(ssrc, !enable)) { |
| 928 return false; | 996 return false; |
| 929 } | 997 } |
| 930 if (enable && options) { | 998 if (enable && options) { |
| 931 return SetOptions(*options); | 999 VideoSendParameters new_params = send_params_; |
| 932 } else { | 1000 new_params.options.SetAll(*options); |
| 933 return true; | 1001 SetSendParameters(send_params_); |
| 934 } | 1002 } |
| 1003 return true; |
| 935 } | 1004 } |
| 936 | 1005 |
| 937 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 1006 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
| 938 const StreamParams& sp) const { | 1007 const StreamParams& sp) const { |
| 939 for (uint32_t ssrc: sp.ssrcs) { | 1008 for (uint32_t ssrc: sp.ssrcs) { |
| 940 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 1009 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
| 941 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; | 1010 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; |
| 942 return false; | 1011 return false; |
| 943 } | 1012 } |
| 944 } | 1013 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 if (send_streams_.find(ssrc) == send_streams_.end()) { | 1317 if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 1249 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1318 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
| 1250 return false; | 1319 return false; |
| 1251 } | 1320 } |
| 1252 if (!send_streams_[ssrc]->SetCapturer(capturer)) { | 1321 if (!send_streams_[ssrc]->SetCapturer(capturer)) { |
| 1253 return false; | 1322 return false; |
| 1254 } | 1323 } |
| 1255 } | 1324 } |
| 1256 | 1325 |
| 1257 if (capturer) { | 1326 if (capturer) { |
| 1258 capturer->SetApplyRotation( | 1327 capturer->SetApplyRotation(!ContainsHeaderExtension( |
| 1259 !FindHeaderExtension(send_rtp_extensions_, | 1328 send_rtp_extensions_, kRtpVideoRotationHeaderExtension)); |
| 1260 kRtpVideoRotationHeaderExtension)); | |
| 1261 } | 1329 } |
| 1262 { | 1330 { |
| 1263 rtc::CritScope lock(&capturer_crit_); | 1331 rtc::CritScope lock(&capturer_crit_); |
| 1264 capturers_[ssrc] = capturer; | 1332 capturers_[ssrc] = capturer; |
| 1265 } | 1333 } |
| 1266 return true; | 1334 return true; |
| 1267 } | 1335 } |
| 1268 | 1336 |
| 1269 bool WebRtcVideoChannel2::SendIntraFrame() { | 1337 bool WebRtcVideoChannel2::SendIntraFrame() { |
| 1270 // TODO(pbos): Implement. | 1338 // TODO(pbos): Implement. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 | 1455 |
| 1388 rtc::CritScope stream_lock(&stream_crit_); | 1456 rtc::CritScope stream_lock(&stream_crit_); |
| 1389 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = | 1457 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = |
| 1390 receive_streams_.begin(); | 1458 receive_streams_.begin(); |
| 1391 it != receive_streams_.end(); ++it) { | 1459 it != receive_streams_.end(); ++it) { |
| 1392 it->second->SetRtpExtensions(recv_rtp_extensions_); | 1460 it->second->SetRtpExtensions(recv_rtp_extensions_); |
| 1393 } | 1461 } |
| 1394 return true; | 1462 return true; |
| 1395 } | 1463 } |
| 1396 | 1464 |
| 1397 bool WebRtcVideoChannel2::SetSendRtpHeaderExtensions( | 1465 // TODO(pbos): Remove SetOptions in favor of SetSendParameters. |
| 1398 const std::vector<RtpHeaderExtension>& extensions) { | 1466 void WebRtcVideoChannel2::SetOptions(const VideoOptions& options) { |
| 1399 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendRtpHeaderExtensions"); | 1467 VideoSendParameters new_params = send_params_; |
| 1400 if (!ValidateRtpExtensions(extensions)) { | 1468 new_params.options.SetAll(options); |
| 1401 return false; | 1469 SetSendParameters(send_params_); |
| 1402 } | |
| 1403 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( | |
| 1404 extensions, webrtc::RtpExtension::IsSupportedForVideo, true); | |
| 1405 if (send_rtp_extensions_ == filtered_extensions) { | |
| 1406 LOG(LS_INFO) << "Ignoring call to SetRecvRtpHeaderExtensions because " | |
| 1407 "header extensions haven't changed."; | |
| 1408 return true; | |
| 1409 } | |
| 1410 send_rtp_extensions_.swap(filtered_extensions); | |
| 1411 | |
| 1412 const webrtc::RtpExtension* cvo_extension = FindHeaderExtension( | |
| 1413 send_rtp_extensions_, kRtpVideoRotationHeaderExtension); | |
| 1414 | |
| 1415 rtc::CritScope stream_lock(&stream_crit_); | |
| 1416 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = | |
| 1417 send_streams_.begin(); | |
| 1418 it != send_streams_.end(); ++it) { | |
| 1419 it->second->SetRtpExtensions(send_rtp_extensions_); | |
| 1420 it->second->SetApplyRotation(!cvo_extension); | |
| 1421 } | |
| 1422 return true; | |
| 1423 } | |
| 1424 | |
| 1425 // Counter-intuitively this method doesn't only set global bitrate caps but also | |
| 1426 // per-stream codec max bitrates. This is to permit SetMaxSendBitrate (b=AS) to | |
| 1427 // raise bitrates above the 2000k default bitrate cap. | |
| 1428 bool WebRtcVideoChannel2::SetMaxSendBandwidth(int max_bitrate_bps) { | |
| 1429 // TODO(pbos): Figure out whether b=AS means max bitrate for this | |
| 1430 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in | |
| 1431 // which case this should not set a Call::BitrateConfig but rather reconfigure | |
| 1432 // all senders. | |
| 1433 LOG(LS_INFO) << "SetMaxSendBandwidth: " << max_bitrate_bps << "bps."; | |
| 1434 if (max_bitrate_bps == bitrate_config_.max_bitrate_bps) | |
| 1435 return true; | |
| 1436 | |
| 1437 if (max_bitrate_bps < 0) { | |
| 1438 // Option not set. | |
| 1439 return true; | |
| 1440 } | |
| 1441 if (max_bitrate_bps == 0) { | |
| 1442 // Unsetting max bitrate. | |
| 1443 max_bitrate_bps = -1; | |
| 1444 } | |
| 1445 bitrate_config_.start_bitrate_bps = -1; | |
| 1446 bitrate_config_.max_bitrate_bps = max_bitrate_bps; | |
| 1447 if (max_bitrate_bps > 0 && | |
| 1448 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { | |
| 1449 bitrate_config_.min_bitrate_bps = max_bitrate_bps; | |
| 1450 } | |
| 1451 call_->SetBitrateConfig(bitrate_config_); | |
| 1452 rtc::CritScope stream_lock(&stream_crit_); | |
| 1453 for (auto& kv : send_streams_) | |
| 1454 kv.second->SetMaxBitrateBps(max_bitrate_bps); | |
| 1455 return true; | |
| 1456 } | |
| 1457 | |
| 1458 bool WebRtcVideoChannel2::SetOptions(const VideoOptions& options) { | |
| 1459 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetOptions"); | |
| 1460 LOG(LS_INFO) << "SetOptions: " << options.ToString(); | |
| 1461 VideoOptions old_options = options_; | |
| 1462 options_.SetAll(options); | |
| 1463 if (options_ == old_options) { | |
| 1464 // No new options to set. | |
| 1465 return true; | |
| 1466 } | |
| 1467 { | |
| 1468 rtc::CritScope lock(&capturer_crit_); | |
| 1469 if (options_.cpu_overuse_detection) | |
| 1470 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; | |
| 1471 } | |
| 1472 rtc::DiffServCodePoint dscp = | |
| 1473 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; | |
| 1474 MediaChannel::SetDscp(dscp); | |
| 1475 rtc::CritScope stream_lock(&stream_crit_); | |
| 1476 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = | |
| 1477 send_streams_.begin(); | |
| 1478 it != send_streams_.end(); ++it) { | |
| 1479 it->second->SetOptions(options_); | |
| 1480 } | |
| 1481 return true; | |
| 1482 } | 1470 } |
| 1483 | 1471 |
| 1484 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { | 1472 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { |
| 1485 MediaChannel::SetInterface(iface); | 1473 MediaChannel::SetInterface(iface); |
| 1486 // Set the RTP recv/send buffer to a bigger size | 1474 // Set the RTP recv/send buffer to a bigger size |
| 1487 MediaChannel::SetOption(NetworkInterface::ST_RTP, | 1475 MediaChannel::SetOption(NetworkInterface::ST_RTP, |
| 1488 rtc::Socket::OPT_RCVBUF, | 1476 rtc::Socket::OPT_RCVBUF, |
| 1489 kVideoRtpBufferSize); | 1477 kVideoRtpBufferSize); |
| 1490 | 1478 |
| 1491 // Speculative change to increase the outbound socket buffer size. | 1479 // Speculative change to increase the outbound socket buffer size. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1582 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
| 1595 // TODO(deadbeef): Don't duplicate information between send_params, | 1583 // TODO(deadbeef): Don't duplicate information between send_params, |
| 1596 // rtp_extensions, options, etc. | 1584 // rtp_extensions, options, etc. |
| 1597 const VideoSendParameters& send_params) | 1585 const VideoSendParameters& send_params) |
| 1598 : ssrcs_(sp.ssrcs), | 1586 : ssrcs_(sp.ssrcs), |
| 1599 ssrc_groups_(sp.ssrc_groups), | 1587 ssrc_groups_(sp.ssrc_groups), |
| 1600 call_(call), | 1588 call_(call), |
| 1601 external_encoder_factory_(external_encoder_factory), | 1589 external_encoder_factory_(external_encoder_factory), |
| 1602 stream_(NULL), | 1590 stream_(NULL), |
| 1603 parameters_(config, options, max_bitrate_bps, codec_settings), | 1591 parameters_(config, options, max_bitrate_bps, codec_settings), |
| 1592 pending_encoder_reconfiguration_(false), |
| 1604 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), | 1593 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), |
| 1605 capturer_(NULL), | 1594 capturer_(NULL), |
| 1606 sending_(false), | 1595 sending_(false), |
| 1607 muted_(false), | 1596 muted_(false), |
| 1608 old_adapt_changes_(0), | 1597 old_adapt_changes_(0), |
| 1609 first_frame_timestamp_ms_(0), | 1598 first_frame_timestamp_ms_(0), |
| 1610 last_frame_timestamp_ms_(0) { | 1599 last_frame_timestamp_ms_(0) { |
| 1611 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1600 parameters_.config.rtp.max_packet_size = kVideoMtu; |
| 1612 | 1601 |
| 1613 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1602 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
| 1614 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1603 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
| 1615 ¶meters_.config.rtp.rtx.ssrcs); | 1604 ¶meters_.config.rtp.rtx.ssrcs); |
| 1616 parameters_.config.rtp.c_name = sp.cname; | 1605 parameters_.config.rtp.c_name = sp.cname; |
| 1617 parameters_.config.rtp.extensions = rtp_extensions; | 1606 parameters_.config.rtp.extensions = rtp_extensions; |
| 1618 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1607 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |
| 1619 ? webrtc::RtcpMode::kReducedSize | 1608 ? webrtc::RtcpMode::kReducedSize |
| 1620 : webrtc::RtcpMode::kCompound; | 1609 : webrtc::RtcpMode::kCompound; |
| 1621 | 1610 |
| 1622 if (codec_settings) { | 1611 if (codec_settings) { |
| 1623 SetCodec(*codec_settings); | 1612 SetCodecAndOptions(*codec_settings, parameters_.options); |
| 1624 } | 1613 } |
| 1625 } | 1614 } |
| 1626 | 1615 |
| 1627 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1616 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
| 1628 DisconnectCapturer(); | 1617 DisconnectCapturer(); |
| 1629 if (stream_ != NULL) { | 1618 if (stream_ != NULL) { |
| 1630 call_->DestroyVideoSendStream(stream_); | 1619 call_->DestroyVideoSendStream(stream_); |
| 1631 } | 1620 } |
| 1632 DestroyVideoEncoder(&allocated_encoder_); | 1621 DestroyVideoEncoder(&allocated_encoder_); |
| 1633 } | 1622 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 } | 1716 } |
| 1728 | 1717 |
| 1729 capturer_ = capturer; | 1718 capturer_ = capturer; |
| 1730 } | 1719 } |
| 1731 // Lock cannot be held while connecting the capturer to prevent lock-order | 1720 // Lock cannot be held while connecting the capturer to prevent lock-order |
| 1732 // violations. | 1721 // violations. |
| 1733 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); | 1722 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); |
| 1734 return true; | 1723 return true; |
| 1735 } | 1724 } |
| 1736 | 1725 |
| 1726 // TODO(pbos): Apply this on the VideoAdapter instead! |
| 1737 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( | 1727 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( |
| 1738 const VideoFormat& format) { | 1728 const VideoFormat& format) { |
| 1739 if ((format.width == 0 || format.height == 0) && | 1729 if ((format.width == 0 || format.height == 0) && |
| 1740 format.width != format.height) { | 1730 format.width != format.height) { |
| 1741 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " | 1731 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " |
| 1742 "both, 0x0 drops frames)."; | 1732 "both, 0x0 drops frames)."; |
| 1743 return false; | 1733 return false; |
| 1744 } | 1734 } |
| 1745 | 1735 |
| 1746 rtc::CritScope cs(&lock_); | 1736 rtc::CritScope cs(&lock_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 } | 1769 } |
| 1780 capturer->SignalVideoFrame.disconnect(this); | 1770 capturer->SignalVideoFrame.disconnect(this); |
| 1781 return true; | 1771 return true; |
| 1782 } | 1772 } |
| 1783 | 1773 |
| 1784 const std::vector<uint32_t>& | 1774 const std::vector<uint32_t>& |
| 1785 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1775 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| 1786 return ssrcs_; | 1776 return ssrcs_; |
| 1787 } | 1777 } |
| 1788 | 1778 |
| 1789 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetApplyRotation( | |
| 1790 bool apply_rotation) { | |
| 1791 rtc::CritScope cs(&lock_); | |
| 1792 if (capturer_ == NULL) | |
| 1793 return; | |
| 1794 | |
| 1795 capturer_->SetApplyRotation(apply_rotation); | |
| 1796 } | |
| 1797 | |
| 1798 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1779 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
| 1799 const VideoOptions& options) { | 1780 const VideoOptions& options) { |
| 1800 rtc::CritScope cs(&lock_); | 1781 rtc::CritScope cs(&lock_); |
| 1801 if (parameters_.codec_settings) { | 1782 if (parameters_.codec_settings) { |
| 1802 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" | 1783 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" |
| 1803 << options.ToString(); | 1784 << options.ToString(); |
| 1804 SetCodecAndOptions(*parameters_.codec_settings, options); | 1785 SetCodecAndOptions(*parameters_.codec_settings, options); |
| 1805 } else { | 1786 } else { |
| 1806 parameters_.options = options; | 1787 parameters_.options = options; |
| 1807 } | 1788 } |
| 1808 } | 1789 } |
| 1809 | 1790 |
| 1810 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( | |
| 1811 const VideoCodecSettings& codec_settings) { | |
| 1812 rtc::CritScope cs(&lock_); | |
| 1813 LOG(LS_INFO) << "SetCodecAndOptions because of SetCodec."; | |
| 1814 SetCodecAndOptions(codec_settings, parameters_.options); | |
| 1815 } | |
| 1816 | |
| 1817 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) { | 1791 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) { |
| 1818 if (CodecNamesEq(name, kVp8CodecName)) { | 1792 if (CodecNamesEq(name, kVp8CodecName)) { |
| 1819 return webrtc::kVideoCodecVP8; | 1793 return webrtc::kVideoCodecVP8; |
| 1820 } else if (CodecNamesEq(name, kVp9CodecName)) { | 1794 } else if (CodecNamesEq(name, kVp9CodecName)) { |
| 1821 return webrtc::kVideoCodecVP9; | 1795 return webrtc::kVideoCodecVP9; |
| 1822 } else if (CodecNamesEq(name, kH264CodecName)) { | 1796 } else if (CodecNamesEq(name, kH264CodecName)) { |
| 1823 return webrtc::kVideoCodecH264; | 1797 return webrtc::kVideoCodecH264; |
| 1824 } | 1798 } |
| 1825 return webrtc::kVideoCodecUnknown; | 1799 return webrtc::kVideoCodecUnknown; |
| 1826 } | 1800 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); | 1840 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); |
| 1867 } | 1841 } |
| 1868 delete encoder->encoder; | 1842 delete encoder->encoder; |
| 1869 } | 1843 } |
| 1870 | 1844 |
| 1871 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( | 1845 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( |
| 1872 const VideoCodecSettings& codec_settings, | 1846 const VideoCodecSettings& codec_settings, |
| 1873 const VideoOptions& options) { | 1847 const VideoOptions& options) { |
| 1874 parameters_.encoder_config = | 1848 parameters_.encoder_config = |
| 1875 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); | 1849 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
| 1876 if (parameters_.encoder_config.streams.empty()) | 1850 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |
| 1877 return; | |
| 1878 | 1851 |
| 1879 format_ = VideoFormat(codec_settings.codec.width, | 1852 format_ = VideoFormat(codec_settings.codec.width, |
| 1880 codec_settings.codec.height, | 1853 codec_settings.codec.height, |
| 1881 VideoFormat::FpsToInterval(30), | 1854 VideoFormat::FpsToInterval(30), |
| 1882 FOURCC_I420); | 1855 FOURCC_I420); |
| 1883 | 1856 |
| 1884 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); | 1857 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); |
| 1885 parameters_.config.encoder_settings.encoder = new_encoder.encoder; | 1858 parameters_.config.encoder_settings.encoder = new_encoder.encoder; |
| 1886 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; | 1859 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; |
| 1887 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; | 1860 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1917 LOG(LS_INFO) | 1890 LOG(LS_INFO) |
| 1918 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" | 1891 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" |
| 1919 << options.ToString(); | 1892 << options.ToString(); |
| 1920 RecreateWebRtcStream(); | 1893 RecreateWebRtcStream(); |
| 1921 if (allocated_encoder_.encoder != new_encoder.encoder) { | 1894 if (allocated_encoder_.encoder != new_encoder.encoder) { |
| 1922 DestroyVideoEncoder(&allocated_encoder_); | 1895 DestroyVideoEncoder(&allocated_encoder_); |
| 1923 allocated_encoder_ = new_encoder; | 1896 allocated_encoder_ = new_encoder; |
| 1924 } | 1897 } |
| 1925 } | 1898 } |
| 1926 | 1899 |
| 1927 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions( | |
| 1928 const std::vector<webrtc::RtpExtension>& rtp_extensions) { | |
| 1929 rtc::CritScope cs(&lock_); | |
| 1930 parameters_.config.rtp.extensions = rtp_extensions; | |
| 1931 if (stream_ != nullptr) { | |
| 1932 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetRtpExtensions"; | |
| 1933 RecreateWebRtcStream(); | |
| 1934 } | |
| 1935 } | |
| 1936 | |
| 1937 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters( | 1900 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters( |
| 1938 const VideoSendParameters& send_params) { | 1901 const ChangedSendParameters& params) { |
| 1939 rtc::CritScope cs(&lock_); | 1902 rtc::CritScope cs(&lock_); |
| 1940 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1903 // |recreate_stream| means construction-time parameters have changed and the |
| 1941 ? webrtc::RtcpMode::kReducedSize | 1904 // sending stream needs to be reset with the new config. |
| 1942 : webrtc::RtcpMode::kCompound; | 1905 bool recreate_stream = false; |
| 1943 if (stream_ != nullptr) { | 1906 if (params.rtcp_mode) { |
| 1907 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; |
| 1908 recreate_stream = true; |
| 1909 } |
| 1910 if (params.rtp_header_extensions) { |
| 1911 parameters_.config.rtp.extensions = *params.rtp_header_extensions; |
| 1912 if (capturer_) { |
| 1913 capturer_->SetApplyRotation(!ContainsHeaderExtension( |
| 1914 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension)); |
| 1915 } |
| 1916 recreate_stream = true; |
| 1917 } |
| 1918 if (params.max_bandwidth_bps) { |
| 1919 // Max bitrate has changed, reconfigure encoder settings on the next frame |
| 1920 // or stream recreation. |
| 1921 parameters_.max_bitrate_bps = *params.max_bandwidth_bps; |
| 1922 pending_encoder_reconfiguration_ = true; |
| 1923 } |
| 1924 // Set codecs and options. |
| 1925 if (params.codec) { |
| 1926 SetCodecAndOptions(*params.codec, |
| 1927 params.options ? *params.options : parameters_.options); |
| 1928 return; |
| 1929 } else if (params.options) { |
| 1930 // Reconfigure if codecs are already set. |
| 1931 if (parameters_.codec_settings) { |
| 1932 SetCodecAndOptions(*parameters_.codec_settings, *params.options); |
| 1933 return; |
| 1934 } else { |
| 1935 parameters_.options = *params.options; |
| 1936 } |
| 1937 } |
| 1938 if (recreate_stream) { |
| 1944 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1939 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; |
| 1945 RecreateWebRtcStream(); | 1940 RecreateWebRtcStream(); |
| 1946 } | 1941 } |
| 1947 } | 1942 } |
| 1948 | 1943 |
| 1949 webrtc::VideoEncoderConfig | 1944 webrtc::VideoEncoderConfig |
| 1950 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 1945 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| 1951 const Dimensions& dimensions, | 1946 const Dimensions& dimensions, |
| 1952 const VideoCodec& codec) const { | 1947 const VideoCodec& codec) const { |
| 1953 webrtc::VideoEncoderConfig encoder_config; | 1948 webrtc::VideoEncoderConfig encoder_config; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 config.tl0_bitrate_kbps * 1000); | 2000 config.tl0_bitrate_kbps * 1000); |
| 2006 } | 2001 } |
| 2007 return encoder_config; | 2002 return encoder_config; |
| 2008 } | 2003 } |
| 2009 | 2004 |
| 2010 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( | 2005 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( |
| 2011 int width, | 2006 int width, |
| 2012 int height, | 2007 int height, |
| 2013 bool is_screencast) { | 2008 bool is_screencast) { |
| 2014 if (last_dimensions_.width == width && last_dimensions_.height == height && | 2009 if (last_dimensions_.width == width && last_dimensions_.height == height && |
| 2015 last_dimensions_.is_screencast == is_screencast) { | 2010 last_dimensions_.is_screencast == is_screencast && |
| 2011 !pending_encoder_reconfiguration_) { |
| 2016 // Configured using the same parameters, do not reconfigure. | 2012 // Configured using the same parameters, do not reconfigure. |
| 2017 return; | 2013 return; |
| 2018 } | 2014 } |
| 2019 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height | 2015 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height |
| 2020 << (is_screencast ? " (screencast)" : " (not screencast)"); | 2016 << (is_screencast ? " (screencast)" : " (not screencast)"); |
| 2021 | 2017 |
| 2022 last_dimensions_.width = width; | 2018 last_dimensions_.width = width; |
| 2023 last_dimensions_.height = height; | 2019 last_dimensions_.height = height; |
| 2024 last_dimensions_.is_screencast = is_screencast; | 2020 last_dimensions_.is_screencast = is_screencast; |
| 2025 | 2021 |
| 2026 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); | 2022 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |
| 2027 | 2023 |
| 2028 RTC_CHECK(parameters_.codec_settings); | 2024 RTC_CHECK(parameters_.codec_settings); |
| 2029 VideoCodecSettings codec_settings = *parameters_.codec_settings; | 2025 VideoCodecSettings codec_settings = *parameters_.codec_settings; |
| 2030 | 2026 |
| 2031 webrtc::VideoEncoderConfig encoder_config = | 2027 webrtc::VideoEncoderConfig encoder_config = |
| 2032 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); | 2028 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
| 2033 | 2029 |
| 2034 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( | 2030 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( |
| 2035 codec_settings.codec, parameters_.options, is_screencast); | 2031 codec_settings.codec, parameters_.options, is_screencast); |
| 2036 | 2032 |
| 2037 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); | 2033 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); |
| 2038 | 2034 |
| 2039 encoder_config.encoder_specific_settings = NULL; | 2035 encoder_config.encoder_specific_settings = NULL; |
| 2036 pending_encoder_reconfiguration_ = false; |
| 2040 | 2037 |
| 2041 if (!stream_reconfigured) { | 2038 if (!stream_reconfigured) { |
| 2042 LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " | 2039 LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " |
| 2043 << width << "x" << height; | 2040 << width << "x" << height; |
| 2044 return; | 2041 return; |
| 2045 } | 2042 } |
| 2046 | 2043 |
| 2047 parameters_.encoder_config = encoder_config; | 2044 parameters_.encoder_config = encoder_config; |
| 2048 } | 2045 } |
| 2049 | 2046 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2166 for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it = | 2163 for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it = |
| 2167 stats.substreams.begin(); | 2164 stats.substreams.begin(); |
| 2168 it != stats.substreams.end(); ++it) { | 2165 it != stats.substreams.end(); ++it) { |
| 2169 bwe_info->transmit_bitrate += it->second.total_bitrate_bps; | 2166 bwe_info->transmit_bitrate += it->second.total_bitrate_bps; |
| 2170 bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps; | 2167 bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps; |
| 2171 } | 2168 } |
| 2172 bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps; | 2169 bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps; |
| 2173 bwe_info->actual_enc_bitrate += stats.media_bitrate_bps; | 2170 bwe_info->actual_enc_bitrate += stats.media_bitrate_bps; |
| 2174 } | 2171 } |
| 2175 | 2172 |
| 2176 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetMaxBitrateBps( | |
| 2177 int max_bitrate_bps) { | |
| 2178 rtc::CritScope cs(&lock_); | |
| 2179 parameters_.max_bitrate_bps = max_bitrate_bps; | |
| 2180 | |
| 2181 // No need to reconfigure if the stream hasn't been configured yet. | |
| 2182 if (parameters_.encoder_config.streams.empty()) | |
| 2183 return; | |
| 2184 | |
| 2185 // Force a stream reconfigure to set the new max bitrate. | |
| 2186 int width = last_dimensions_.width; | |
| 2187 last_dimensions_.width = 0; | |
| 2188 SetDimensions(width, last_dimensions_.height, last_dimensions_.is_screencast); | |
| 2189 } | |
| 2190 | |
| 2191 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { | 2173 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { |
| 2192 if (stream_ != NULL) { | 2174 if (stream_ != NULL) { |
| 2193 call_->DestroyVideoSendStream(stream_); | 2175 call_->DestroyVideoSendStream(stream_); |
| 2194 } | 2176 } |
| 2195 | 2177 |
| 2196 RTC_CHECK(parameters_.codec_settings); | 2178 RTC_CHECK(parameters_.codec_settings); |
| 2197 parameters_.encoder_config.encoder_specific_settings = | 2179 parameters_.encoder_config.encoder_specific_settings = |
| 2198 ConfigureVideoEncoderSettings( | 2180 ConfigureVideoEncoderSettings( |
| 2199 parameters_.codec_settings->codec, parameters_.options, | 2181 parameters_.codec_settings->codec, parameters_.options, |
| 2200 parameters_.encoder_config.content_type == | 2182 parameters_.encoder_config.content_type == |
| 2201 webrtc::VideoEncoderConfig::ContentType::kScreen); | 2183 webrtc::VideoEncoderConfig::ContentType::kScreen); |
| 2202 | 2184 |
| 2203 webrtc::VideoSendStream::Config config = parameters_.config; | 2185 webrtc::VideoSendStream::Config config = parameters_.config; |
| 2204 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { | 2186 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { |
| 2205 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " | 2187 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " |
| 2206 "payload type the set codec. Ignoring RTX."; | 2188 "payload type the set codec. Ignoring RTX."; |
| 2207 config.rtp.rtx.ssrcs.clear(); | 2189 config.rtp.rtx.ssrcs.clear(); |
| 2208 } | 2190 } |
| 2209 stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config); | 2191 stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config); |
| 2210 | 2192 |
| 2211 parameters_.encoder_config.encoder_specific_settings = NULL; | 2193 parameters_.encoder_config.encoder_specific_settings = NULL; |
| 2194 pending_encoder_reconfiguration_ = false; |
| 2212 | 2195 |
| 2213 if (sending_) { | 2196 if (sending_) { |
| 2214 stream_->Start(); | 2197 stream_->Start(); |
| 2215 } | 2198 } |
| 2216 } | 2199 } |
| 2217 | 2200 |
| 2218 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( | 2201 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( |
| 2219 webrtc::Call* call, | 2202 webrtc::Call* call, |
| 2220 const StreamParams& sp, | 2203 const StreamParams& sp, |
| 2221 const webrtc::VideoReceiveStream::Config& config, | 2204 const webrtc::VideoReceiveStream::Config& config, |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2631 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2614 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2632 } | 2615 } |
| 2633 } | 2616 } |
| 2634 | 2617 |
| 2635 return video_codecs; | 2618 return video_codecs; |
| 2636 } | 2619 } |
| 2637 | 2620 |
| 2638 } // namespace cricket | 2621 } // namespace cricket |
| 2639 | 2622 |
| 2640 #endif // HAVE_WEBRTC_VIDEO | 2623 #endif // HAVE_WEBRTC_VIDEO |
| OLD | NEW |