Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1132)

Side by Side Diff: talk/media/webrtc/webrtcvideoengine2.cc

Issue 1561073006: Consolidate SetSendParameters into one setter. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove duplicate SetOptions code Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (!rtx_ssrcs.empty() && primary_ssrcs.size() != rtx_ssrcs.size()) { 236 if (!rtx_ssrcs.empty() && primary_ssrcs.size() != rtx_ssrcs.size()) {
237 LOG(LS_ERROR) 237 LOG(LS_ERROR)
238 << "RTX SSRCs exist, but don't cover all SSRCs (unsupported): " 238 << "RTX SSRCs exist, but don't cover all SSRCs (unsupported): "
239 << sp.ToString(); 239 << sp.ToString();
240 return false; 240 return false;
241 } 241 }
242 242
243 return true; 243 return true;
244 } 244 }
245 245
246 inline const webrtc::RtpExtension* FindHeaderExtension( 246 inline bool ContainsHeaderExtension(
247 const std::vector<webrtc::RtpExtension>& extensions, 247 const std::vector<webrtc::RtpExtension>& extensions,
248 const std::string& name) { 248 const std::string& name) {
249 for (const auto& kv : extensions) { 249 for (const auto& kv : extensions) {
250 if (kv.name == name) { 250 if (kv.name == name) {
251 return &kv; 251 return true;
252 } 252 }
253 } 253 }
254 return NULL; 254 return false;
255 } 255 }
256 256
257 // Merges two fec configs and logs an error if a conflict arises 257 // Merges two fec configs and logs an error if a conflict arises
258 // such that merging in different order would trigger a different output. 258 // such that merging in different order would trigger a different output.
259 static void MergeFecConfig(const webrtc::FecConfig& other, 259 static void MergeFecConfig(const webrtc::FecConfig& other,
260 webrtc::FecConfig* output) { 260 webrtc::FecConfig* output) {
261 if (other.ulpfec_payload_type != -1) { 261 if (other.ulpfec_payload_type != -1) {
262 if (output->ulpfec_payload_type != -1 && 262 if (output->ulpfec_payload_type != -1 &&
263 output->ulpfec_payload_type != other.ulpfec_payload_type) { 263 output->ulpfec_payload_type != other.ulpfec_payload_type) {
264 LOG(LS_WARNING) << "Conflict merging ulpfec_payload_type configs: " 264 LOG(LS_WARNING) << "Conflict merging ulpfec_payload_type configs: "
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 encoder_factory->codecs())) { 540 encoder_factory->codecs())) {
541 simulcast_encoder_factory_.reset( 541 simulcast_encoder_factory_.reset(
542 new WebRtcSimulcastEncoderFactory(encoder_factory)); 542 new WebRtcSimulcastEncoderFactory(encoder_factory));
543 encoder_factory = simulcast_encoder_factory_.get(); 543 encoder_factory = simulcast_encoder_factory_.get();
544 } 544 }
545 external_encoder_factory_ = encoder_factory; 545 external_encoder_factory_ = encoder_factory;
546 546
547 video_codecs_ = GetSupportedCodecs(); 547 video_codecs_ = GetSupportedCodecs();
548 } 548 }
549 549
550 bool WebRtcVideoEngine2::EnableTimedRender() {
551 // TODO(pbos): Figure out whether this can be removed.
552 return true;
553 }
554
555 // Checks to see whether we comprehend and could receive a particular codec 550 // Checks to see whether we comprehend and could receive a particular codec
556 bool WebRtcVideoEngine2::FindCodec(const VideoCodec& in) { 551 bool WebRtcVideoEngine2::FindCodec(const VideoCodec& in) {
557 // TODO(pbos): Probe encoder factory to figure out that the codec is supported 552 // TODO(pbos): Probe encoder factory to figure out that the codec is supported
558 // if supported by the encoder factory. Add a corresponding test that fails 553 // if supported by the encoder factory. Add a corresponding test that fails
559 // with this code (that doesn't ask the factory). 554 // with this code (that doesn't ask the factory).
560 for (size_t j = 0; j < video_codecs_.size(); ++j) { 555 for (size_t j = 0; j < video_codecs_.size(); ++j) {
561 VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0); 556 VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0);
562 if (codec.Matches(in)) { 557 if (codec.Matches(in)) {
563 return true; 558 return true;
564 } 559 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // side to cause recreation of the stream. 698 // side to cause recreation of the stream.
704 before[i].codec.preference = 0; 699 before[i].codec.preference = 0;
705 after[i].codec.preference = 0; 700 after[i].codec.preference = 0;
706 if (before[i] != after[i]) { 701 if (before[i] != after[i]) {
707 return true; 702 return true;
708 } 703 }
709 } 704 }
710 return false; 705 return false;
711 } 706 }
712 707
708 bool WebRtcVideoChannel2::GetChangedSendParameters(
709 const VideoSendParameters& params,
710 ChangedSendParameters* changed_params) const {
711 if (!ValidateCodecFormats(params.codecs) ||
712 !ValidateRtpExtensions(params.extensions)) {
713 return false;
714 }
715
716 // ==== SEND CODEC ====
717 const std::vector<VideoCodecSettings> supported_codecs =
718 FilterSupportedCodecs(MapCodecs(params.codecs));
719
720 if (supported_codecs.empty()) {
721 LOG(LS_ERROR) << "No video codecs supported.";
722 return false;
723 }
724
725 if (!send_codec_ || supported_codecs.front() != *send_codec_) {
726 // Send codec has changed.
727 changed_params->codec =
728 rtc::Optional<VideoCodecSettings>(supported_codecs.front());
729 }
730
731 // ==== RTP HEADER EXTENSIONS ====
732 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions(
733 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true);
734 if (send_rtp_extensions_ != filtered_extensions) {
735 changed_params->rtp_header_extensions =
736 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions);
737 }
738
739 // ==== MAX BITRATE ====
740 if (params.max_bandwidth_bps != bitrate_config_.max_bitrate_bps &&
741 params.max_bandwidth_bps >= 0) {
742 // 0 uncaps max bitrate (-1).
743 changed_params->max_bandwidth_bps = rtc::Optional<int>(
744 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps);
745 }
746
747 // ==== OPTIONS ====
748 // TODO(pbos): Require VideoSendParameters to contain a full set of options
749 // and check if params.options != options_ instead of applying a delta.
750 VideoOptions old_options = options_;
Taylor Brandstetter 2016/01/21 23:47:16 I don't think you need "old_options", we can just
pbos-webrtc 2016/01/26 16:57:49 Done.
751 VideoOptions new_options = options_;
752 new_options.SetAll(params.options);
753 if (!(new_options == old_options)) {
754 changed_params->options = rtc::Optional<VideoOptions>(new_options);
755 }
756
757 changed_params->rtcp_mode = params.rtcp.reduced_size
758 ? webrtc::RtcpMode::kReducedSize
759 : webrtc::RtcpMode::kCompound;
760
761 return true;
762 }
763
713 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { 764 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) {
714 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters"); 765 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters");
715 LOG(LS_INFO) << "SetSendParameters: " << params.ToString(); 766 LOG(LS_INFO) << "SetSendParameters: " << params.ToString();
716 // TODO(pbos): Refactor this to only recreate the send streams once 767 ChangedSendParameters changed_params;
717 // instead of 4 times. 768 if (!GetChangedSendParameters(params, &changed_params)) {
718 if (!SetSendCodecs(params.codecs) ||
719 !SetSendRtpHeaderExtensions(params.extensions) ||
720 !SetMaxSendBandwidth(params.max_bandwidth_bps) ||
721 !SetOptions(params.options)) {
722 return false; 769 return false;
723 } 770 }
724 if (send_params_.rtcp.reduced_size != params.rtcp.reduced_size) { 771
772 bool bitrate_config_changed = false;
773
774 bool codec_set = false;
775 if (changed_params.codec) {
776 const VideoCodecSettings& codec_settings = *changed_params.codec;
777 send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings);
778 VideoCodec codec = codec_settings.codec;
779 codec_set = true;
780
781 LOG(LS_INFO) << "Using codec: " << codec.ToString();
782 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean
783 // that we change the min/max of bandwidth estimation. Reevaluate this.
784 int bitrate_kbps;
Taylor Brandstetter 2016/01/21 23:47:16 Since this method is already pretty huge, I would
pbos-webrtc 2016/01/26 16:57:49 Done.
785 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) &&
786 bitrate_kbps > 0) {
787 bitrate_config_.min_bitrate_bps = bitrate_kbps * 1000;
788 } else {
789 bitrate_config_.min_bitrate_bps = 0;
790 }
791 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) &&
792 bitrate_kbps > 0) {
793 bitrate_config_.start_bitrate_bps = bitrate_kbps * 1000;
794 } else {
795 // Do not reconfigure start bitrate unless it's specified and positive.
796 bitrate_config_.start_bitrate_bps = -1;
797 }
798 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) &&
799 bitrate_kbps > 0) {
800 bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000;
801 } else {
802 bitrate_config_.max_bitrate_bps = -1;
803 }
804 bitrate_config_changed = true;
805 }
806
807 if (changed_params.rtp_header_extensions) {
808 send_rtp_extensions_ = *changed_params.rtp_header_extensions;
809 }
810
811 if (changed_params.max_bandwidth_bps) {
812 // TODO(pbos): Figure out whether b=AS means max bitrate for this
813 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in
814 // which case this should not set a Call::BitrateConfig but rather
815 // reconfigure
Taylor Brandstetter 2016/01/21 23:47:16 nit: move "// all senders." up a line.
pbos-webrtc 2016/01/26 16:57:49 Done.
816 // all senders.
817 int max_bitrate_bps = *changed_params.max_bandwidth_bps;
818 bitrate_config_.start_bitrate_bps = -1;
819 bitrate_config_.max_bitrate_bps = max_bitrate_bps;
820 if (max_bitrate_bps > 0 &&
821 bitrate_config_.min_bitrate_bps > max_bitrate_bps) {
822 bitrate_config_.min_bitrate_bps = max_bitrate_bps;
823 }
824 bitrate_config_changed = true;
825 }
826
827 if (bitrate_config_changed) {
828 call_->SetBitrateConfig(bitrate_config_);
829 }
830
831 if (changed_params.options) {
832 options_.SetAll(*changed_params.options);
833 {
834 rtc::CritScope lock(&capturer_crit_);
835 if (options_.cpu_overuse_detection)
Taylor Brandstetter 2016/01/21 23:47:16 nit: add {}
pbos-webrtc 2016/01/26 16:57:49 Done.
836 signal_cpu_adaptation_ = *options_.cpu_overuse_detection;
837 }
838 rtc::DiffServCodePoint dscp =
839 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT;
840 MediaChannel::SetDscp(dscp);
841 }
842
843 {
725 rtc::CritScope stream_lock(&stream_crit_); 844 rtc::CritScope stream_lock(&stream_crit_);
726 for (auto& kv : send_streams_) { 845 for (auto& kv : send_streams_) {
727 kv.second->SetSendParameters(params); 846 kv.second->SetSendParameters(changed_params);
847 }
848 if (codec_set) {
Taylor Brandstetter 2016/01/21 23:47:16 Instead of "codec_set", can you just use "if (chan
pbos-webrtc 2016/01/26 16:57:49 Done.
849 // Update receive feedback parameters from new codec.
850 LOG(LS_INFO)
851 << "SetFeedbackOptions on all the receive streams because the send "
852 "codec has changed.";
853 for (auto& kv : receive_streams_) {
854 RTC_DCHECK(kv.second != nullptr);
855 kv.second->SetFeedbackParameters(HasNack(send_codec_->codec),
856 HasRemb(send_codec_->codec),
857 HasTransportCc(send_codec_->codec));
858 }
728 } 859 }
729 } 860 }
730 send_params_ = params; 861 send_params_ = params;
731 return true; 862 return true;
732 } 863 }
733 864
734 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) { 865 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) {
735 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvParameters"); 866 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvParameters");
736 LOG(LS_INFO) << "SetRecvParameters: " << params.ToString(); 867 LOG(LS_INFO) << "SetRecvParameters: " << params.ToString();
737 // TODO(pbos): Refactor this to only recreate the recv streams once 868 // TODO(pbos): Refactor this to only recreate the recv streams once
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 rtc::CritScope stream_lock(&stream_crit_); 931 rtc::CritScope stream_lock(&stream_crit_);
801 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = 932 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it =
802 receive_streams_.begin(); 933 receive_streams_.begin();
803 it != receive_streams_.end(); ++it) { 934 it != receive_streams_.end(); ++it) {
804 it->second->SetRecvCodecs(recv_codecs_); 935 it->second->SetRecvCodecs(recv_codecs_);
805 } 936 }
806 937
807 return true; 938 return true;
808 } 939 }
809 940
810 bool WebRtcVideoChannel2::SetSendCodecs(const std::vector<VideoCodec>& codecs) { 941 void WebRtcVideoChannel2::SetSendCodec(
Taylor Brandstetter 2016/01/21 23:47:16 What's the purpose of this method?
pbos-webrtc 2016/01/26 16:57:49 Moved over in this patchset, removed. Thanks.
811 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendCodecs"); 942 const VideoCodecSettings& codec_settings) {}
812 LOG(LS_INFO) << "SetSendCodecs: " << CodecVectorToString(codecs);
813 if (!ValidateCodecFormats(codecs)) {
814 return false;
815 }
816
817 const std::vector<VideoCodecSettings> supported_codecs =
818 FilterSupportedCodecs(MapCodecs(codecs));
819
820 if (supported_codecs.empty()) {
821 LOG(LS_ERROR) << "No video codecs supported.";
822 return false;
823 }
824
825 LOG(LS_INFO) << "Using codec: " << supported_codecs.front().codec.ToString();
826
827 if (send_codec_ && supported_codecs.front() == *send_codec_) {
828 LOG(LS_INFO) << "Ignore call to SetSendCodecs because first supported "
829 "codec hasn't changed.";
830 // Using same codec, avoid reconfiguring.
831 return true;
832 }
833
834 send_codec_ = rtc::Optional<WebRtcVideoChannel2::VideoCodecSettings>(
835 supported_codecs.front());
836
837 rtc::CritScope stream_lock(&stream_crit_);
838 LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different "
839 "first supported codec.";
840 for (auto& kv : send_streams_) {
841 RTC_DCHECK(kv.second != nullptr);
842 kv.second->SetCodec(supported_codecs.front());
843 }
844 LOG(LS_INFO)
845 << "SetFeedbackOptions on all the receive streams because the send "
846 "codec has changed.";
847 for (auto& kv : receive_streams_) {
848 RTC_DCHECK(kv.second != nullptr);
849 kv.second->SetFeedbackParameters(
850 HasNack(supported_codecs.front().codec),
851 HasRemb(supported_codecs.front().codec),
852 HasTransportCc(supported_codecs.front().codec));
853 }
854
855 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean that
856 // we change the min/max of bandwidth estimation. Reevaluate this.
857 VideoCodec codec = supported_codecs.front().codec;
858 int bitrate_kbps;
859 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) &&
860 bitrate_kbps > 0) {
861 bitrate_config_.min_bitrate_bps = bitrate_kbps * 1000;
862 } else {
863 bitrate_config_.min_bitrate_bps = 0;
864 }
865 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) &&
866 bitrate_kbps > 0) {
867 bitrate_config_.start_bitrate_bps = bitrate_kbps * 1000;
868 } else {
869 // Do not reconfigure start bitrate unless it's specified and positive.
870 bitrate_config_.start_bitrate_bps = -1;
871 }
872 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) &&
873 bitrate_kbps > 0) {
874 bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000;
875 } else {
876 bitrate_config_.max_bitrate_bps = -1;
877 }
878 call_->SetBitrateConfig(bitrate_config_);
879
880 return true;
881 }
882 943
883 bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { 944 bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) {
884 if (!send_codec_) { 945 if (!send_codec_) {
885 LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; 946 LOG(LS_VERBOSE) << "GetSendCodec: No send codec set.";
886 return false; 947 return false;
887 } 948 }
888 *codec = send_codec_->codec; 949 *codec = send_codec_->codec;
889 return true; 950 return true;
890 } 951 }
891 952
(...skipping 18 matching lines...) Expand all
910 StartAllSendStreams(); 971 StartAllSendStreams();
911 } else { 972 } else {
912 StopAllSendStreams(); 973 StopAllSendStreams();
913 } 974 }
914 sending_ = send; 975 sending_ = send;
915 return true; 976 return true;
916 } 977 }
917 978
918 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable, 979 bool WebRtcVideoChannel2::SetVideoSend(uint32_t ssrc, bool enable,
919 const VideoOptions* options) { 980 const VideoOptions* options) {
981 TRACE_EVENT0("webrtc", "SetVideoSend");
982 LOG(LS_INFO) << "SetVideoSend (ssrc= " << ssrc << ", enable = " << enable
983 << "options: " << (options ? options->ToString() : "nullptr")
984 << ").";
985
920 // TODO(solenberg): The state change should be fully rolled back if any one of 986 // TODO(solenberg): The state change should be fully rolled back if any one of
921 // these calls fail. 987 // these calls fail.
922 if (!MuteStream(ssrc, !enable)) { 988 if (!MuteStream(ssrc, !enable)) {
923 return false; 989 return false;
924 } 990 }
925 if (enable && options) { 991 if (enable && options) {
926 return SetOptions(*options); 992 VideoSendParameters new_params = send_params_;
927 } else { 993 new_params.options.SetAll(*options);
928 return true; 994 SetSendParameters(send_params_);
929 } 995 }
996 return true;
930 } 997 }
931 998
932 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( 999 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability(
933 const StreamParams& sp) const { 1000 const StreamParams& sp) const {
934 for (uint32_t ssrc: sp.ssrcs) { 1001 for (uint32_t ssrc: sp.ssrcs) {
935 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { 1002 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) {
936 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; 1003 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists.";
937 return false; 1004 return false;
938 } 1005 }
939 } 1006 }
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 if (send_streams_.find(ssrc) == send_streams_.end()) { 1326 if (send_streams_.find(ssrc) == send_streams_.end()) {
1260 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; 1327 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
1261 return false; 1328 return false;
1262 } 1329 }
1263 if (!send_streams_[ssrc]->SetCapturer(capturer)) { 1330 if (!send_streams_[ssrc]->SetCapturer(capturer)) {
1264 return false; 1331 return false;
1265 } 1332 }
1266 } 1333 }
1267 1334
1268 if (capturer) { 1335 if (capturer) {
1269 capturer->SetApplyRotation( 1336 capturer->SetApplyRotation(!ContainsHeaderExtension(
1270 !FindHeaderExtension(send_rtp_extensions_, 1337 send_rtp_extensions_, kRtpVideoRotationHeaderExtension));
1271 kRtpVideoRotationHeaderExtension));
1272 } 1338 }
1273 { 1339 {
1274 rtc::CritScope lock(&capturer_crit_); 1340 rtc::CritScope lock(&capturer_crit_);
1275 capturers_[ssrc] = capturer; 1341 capturers_[ssrc] = capturer;
1276 } 1342 }
1277 return true; 1343 return true;
1278 } 1344 }
1279 1345
1280 bool WebRtcVideoChannel2::SendIntraFrame() { 1346 bool WebRtcVideoChannel2::SendIntraFrame() {
1281 // TODO(pbos): Implement. 1347 // TODO(pbos): Implement.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 1464
1399 rtc::CritScope stream_lock(&stream_crit_); 1465 rtc::CritScope stream_lock(&stream_crit_);
1400 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = 1466 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it =
1401 receive_streams_.begin(); 1467 receive_streams_.begin();
1402 it != receive_streams_.end(); ++it) { 1468 it != receive_streams_.end(); ++it) {
1403 it->second->SetRtpExtensions(recv_rtp_extensions_); 1469 it->second->SetRtpExtensions(recv_rtp_extensions_);
1404 } 1470 }
1405 return true; 1471 return true;
1406 } 1472 }
1407 1473
1408 bool WebRtcVideoChannel2::SetSendRtpHeaderExtensions( 1474 // TODO(pbos): Remove SetOptions in favor of SetSendParameters.
1409 const std::vector<RtpHeaderExtension>& extensions) { 1475 void WebRtcVideoChannel2::SetOptions(const VideoOptions& options) {
1410 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendRtpHeaderExtensions"); 1476 VideoSendParameters new_params = send_params_;
1411 if (!ValidateRtpExtensions(extensions)) { 1477 new_params.options.SetAll(options);
1412 return false; 1478 SetSendParameters(send_params_);
1413 }
1414 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions(
1415 extensions, webrtc::RtpExtension::IsSupportedForVideo, true);
1416 if (send_rtp_extensions_ == filtered_extensions) {
1417 LOG(LS_INFO) << "Ignoring call to SetRecvRtpHeaderExtensions because "
1418 "header extensions haven't changed.";
1419 return true;
1420 }
1421 send_rtp_extensions_.swap(filtered_extensions);
1422
1423 const webrtc::RtpExtension* cvo_extension = FindHeaderExtension(
1424 send_rtp_extensions_, kRtpVideoRotationHeaderExtension);
1425
1426 rtc::CritScope stream_lock(&stream_crit_);
1427 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it =
1428 send_streams_.begin();
1429 it != send_streams_.end(); ++it) {
1430 it->second->SetRtpExtensions(send_rtp_extensions_);
1431 it->second->SetApplyRotation(!cvo_extension);
1432 }
1433 return true;
1434 }
1435
1436 // Counter-intuitively this method doesn't only set global bitrate caps but also
1437 // per-stream codec max bitrates. This is to permit SetMaxSendBitrate (b=AS) to
1438 // raise bitrates above the 2000k default bitrate cap.
1439 bool WebRtcVideoChannel2::SetMaxSendBandwidth(int max_bitrate_bps) {
1440 // TODO(pbos): Figure out whether b=AS means max bitrate for this
1441 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in
1442 // which case this should not set a Call::BitrateConfig but rather reconfigure
1443 // all senders.
1444 LOG(LS_INFO) << "SetMaxSendBandwidth: " << max_bitrate_bps << "bps.";
1445 if (max_bitrate_bps == bitrate_config_.max_bitrate_bps)
1446 return true;
1447
1448 if (max_bitrate_bps < 0) {
1449 // Option not set.
1450 return true;
1451 }
1452 if (max_bitrate_bps == 0) {
1453 // Unsetting max bitrate.
1454 max_bitrate_bps = -1;
1455 }
1456 bitrate_config_.start_bitrate_bps = -1;
1457 bitrate_config_.max_bitrate_bps = max_bitrate_bps;
1458 if (max_bitrate_bps > 0 &&
1459 bitrate_config_.min_bitrate_bps > max_bitrate_bps) {
1460 bitrate_config_.min_bitrate_bps = max_bitrate_bps;
1461 }
1462 call_->SetBitrateConfig(bitrate_config_);
1463 rtc::CritScope stream_lock(&stream_crit_);
1464 for (auto& kv : send_streams_)
1465 kv.second->SetMaxBitrateBps(max_bitrate_bps);
1466 return true;
1467 }
1468
1469 bool WebRtcVideoChannel2::SetOptions(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 {
1479 rtc::CritScope lock(&capturer_crit_);
1480 if (options_.cpu_overuse_detection)
1481 signal_cpu_adaptation_ = *options_.cpu_overuse_detection;
1482 }
1483 rtc::DiffServCodePoint dscp =
1484 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT;
1485 MediaChannel::SetDscp(dscp);
1486 rtc::CritScope stream_lock(&stream_crit_);
1487 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it =
1488 send_streams_.begin();
1489 it != send_streams_.end(); ++it) {
1490 it->second->SetOptions(options_);
1491 }
1492 return true;
1493 } 1479 }
1494 1480
1495 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { 1481 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) {
1496 MediaChannel::SetInterface(iface); 1482 MediaChannel::SetInterface(iface);
1497 // Set the RTP recv/send buffer to a bigger size 1483 // Set the RTP recv/send buffer to a bigger size
1498 MediaChannel::SetOption(NetworkInterface::ST_RTP, 1484 MediaChannel::SetOption(NetworkInterface::ST_RTP,
1499 rtc::Socket::OPT_RCVBUF, 1485 rtc::Socket::OPT_RCVBUF,
1500 kVideoRtpBufferSize); 1486 kVideoRtpBufferSize);
1501 1487
1502 // Speculative change to increase the outbound socket buffer size. 1488 // Speculative change to increase the outbound socket buffer size.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 const std::vector<webrtc::RtpExtension>& rtp_extensions, 1591 const std::vector<webrtc::RtpExtension>& rtp_extensions,
1606 // TODO(deadbeef): Don't duplicate information between send_params, 1592 // TODO(deadbeef): Don't duplicate information between send_params,
1607 // rtp_extensions, options, etc. 1593 // rtp_extensions, options, etc.
1608 const VideoSendParameters& send_params) 1594 const VideoSendParameters& send_params)
1609 : ssrcs_(sp.ssrcs), 1595 : ssrcs_(sp.ssrcs),
1610 ssrc_groups_(sp.ssrc_groups), 1596 ssrc_groups_(sp.ssrc_groups),
1611 call_(call), 1597 call_(call),
1612 external_encoder_factory_(external_encoder_factory), 1598 external_encoder_factory_(external_encoder_factory),
1613 stream_(NULL), 1599 stream_(NULL),
1614 parameters_(config, options, max_bitrate_bps, codec_settings), 1600 parameters_(config, options, max_bitrate_bps, codec_settings),
1601 reconfigure_encoder_(false),
Taylor Brandstetter 2016/01/21 23:47:16 nit: Can initialize this to false in the header fi
pbos-webrtc 2016/01/26 16:57:49 If so I'd like to do that for all members, maybe i
1615 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), 1602 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false),
1616 capturer_(NULL), 1603 capturer_(NULL),
1617 sending_(false), 1604 sending_(false),
1618 muted_(false), 1605 muted_(false),
1619 old_adapt_changes_(0), 1606 old_adapt_changes_(0),
1620 first_frame_timestamp_ms_(0), 1607 first_frame_timestamp_ms_(0),
1621 last_frame_timestamp_ms_(0) { 1608 last_frame_timestamp_ms_(0) {
1622 parameters_.config.rtp.max_packet_size = kVideoMtu; 1609 parameters_.config.rtp.max_packet_size = kVideoMtu;
1623 1610
1624 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1611 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
1625 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, 1612 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs,
1626 &parameters_.config.rtp.rtx.ssrcs); 1613 &parameters_.config.rtp.rtx.ssrcs);
1627 parameters_.config.rtp.c_name = sp.cname; 1614 parameters_.config.rtp.c_name = sp.cname;
1628 parameters_.config.rtp.extensions = rtp_extensions; 1615 parameters_.config.rtp.extensions = rtp_extensions;
1629 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1616 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size
1630 ? webrtc::RtcpMode::kReducedSize 1617 ? webrtc::RtcpMode::kReducedSize
1631 : webrtc::RtcpMode::kCompound; 1618 : webrtc::RtcpMode::kCompound;
1632 1619
1633 if (codec_settings) { 1620 if (codec_settings) {
1634 SetCodec(*codec_settings); 1621 SetCodecAndOptions(*codec_settings, parameters_.options);
1635 } 1622 }
1636 } 1623 }
1637 1624
1638 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { 1625 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() {
1639 DisconnectCapturer(); 1626 DisconnectCapturer();
1640 if (stream_ != NULL) { 1627 if (stream_ != NULL) {
1641 call_->DestroyVideoSendStream(stream_); 1628 call_->DestroyVideoSendStream(stream_);
1642 } 1629 }
1643 DestroyVideoEncoder(&allocated_encoder_); 1630 DestroyVideoEncoder(&allocated_encoder_);
1644 } 1631 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 } 1725 }
1739 1726
1740 capturer_ = capturer; 1727 capturer_ = capturer;
1741 } 1728 }
1742 // Lock cannot be held while connecting the capturer to prevent lock-order 1729 // Lock cannot be held while connecting the capturer to prevent lock-order
1743 // violations. 1730 // violations.
1744 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); 1731 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame);
1745 return true; 1732 return true;
1746 } 1733 }
1747 1734
1735 // TODO(pbos): Apply this on the VideoAdapter instead!
1748 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( 1736 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat(
1749 const VideoFormat& format) { 1737 const VideoFormat& format) {
1750 if ((format.width == 0 || format.height == 0) && 1738 if ((format.width == 0 || format.height == 0) &&
1751 format.width != format.height) { 1739 format.width != format.height) {
1752 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " 1740 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not "
1753 "both, 0x0 drops frames)."; 1741 "both, 0x0 drops frames).";
1754 return false; 1742 return false;
1755 } 1743 }
1756 1744
1757 rtc::CritScope cs(&lock_); 1745 rtc::CritScope cs(&lock_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 } 1778 }
1791 capturer->SignalVideoFrame.disconnect(this); 1779 capturer->SignalVideoFrame.disconnect(this);
1792 return true; 1780 return true;
1793 } 1781 }
1794 1782
1795 const std::vector<uint32_t>& 1783 const std::vector<uint32_t>&
1796 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { 1784 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
1797 return ssrcs_; 1785 return ssrcs_;
1798 } 1786 }
1799 1787
1800 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetApplyRotation(
1801 bool apply_rotation) {
1802 rtc::CritScope cs(&lock_);
1803 if (capturer_ == NULL)
1804 return;
1805
1806 capturer_->SetApplyRotation(apply_rotation);
1807 }
1808
1809 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( 1788 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions(
1810 const VideoOptions& options) { 1789 const VideoOptions& options) {
1811 rtc::CritScope cs(&lock_); 1790 rtc::CritScope cs(&lock_);
1812 if (parameters_.codec_settings) { 1791 if (parameters_.codec_settings) {
1813 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" 1792 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options="
1814 << options.ToString(); 1793 << options.ToString();
1815 SetCodecAndOptions(*parameters_.codec_settings, options); 1794 SetCodecAndOptions(*parameters_.codec_settings, options);
1816 } else { 1795 } else {
1817 parameters_.options = options; 1796 parameters_.options = options;
1818 } 1797 }
1819 } 1798 }
1820 1799
1821 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec(
1822 const VideoCodecSettings& codec_settings) {
1823 rtc::CritScope cs(&lock_);
1824 LOG(LS_INFO) << "SetCodecAndOptions because of SetCodec.";
1825 SetCodecAndOptions(codec_settings, parameters_.options);
1826 }
1827
1828 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) { 1800 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) {
1829 if (CodecNamesEq(name, kVp8CodecName)) { 1801 if (CodecNamesEq(name, kVp8CodecName)) {
1830 return webrtc::kVideoCodecVP8; 1802 return webrtc::kVideoCodecVP8;
1831 } else if (CodecNamesEq(name, kVp9CodecName)) { 1803 } else if (CodecNamesEq(name, kVp9CodecName)) {
1832 return webrtc::kVideoCodecVP9; 1804 return webrtc::kVideoCodecVP9;
1833 } else if (CodecNamesEq(name, kH264CodecName)) { 1805 } else if (CodecNamesEq(name, kH264CodecName)) {
1834 return webrtc::kVideoCodecH264; 1806 return webrtc::kVideoCodecH264;
1835 } 1807 }
1836 return webrtc::kVideoCodecUnknown; 1808 return webrtc::kVideoCodecUnknown;
1837 } 1809 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); 1849 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder);
1878 } 1850 }
1879 delete encoder->encoder; 1851 delete encoder->encoder;
1880 } 1852 }
1881 1853
1882 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( 1854 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions(
1883 const VideoCodecSettings& codec_settings, 1855 const VideoCodecSettings& codec_settings,
1884 const VideoOptions& options) { 1856 const VideoOptions& options) {
1885 parameters_.encoder_config = 1857 parameters_.encoder_config =
1886 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); 1858 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec);
1887 if (parameters_.encoder_config.streams.empty()) 1859 RTC_DCHECK(!parameters_.encoder_config.streams.empty());
1888 return;
1889 1860
1890 format_ = VideoFormat(codec_settings.codec.width, 1861 format_ = VideoFormat(codec_settings.codec.width,
1891 codec_settings.codec.height, 1862 codec_settings.codec.height,
1892 VideoFormat::FpsToInterval(30), 1863 VideoFormat::FpsToInterval(30),
1893 FOURCC_I420); 1864 FOURCC_I420);
1894 1865
1895 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); 1866 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec);
1896 parameters_.config.encoder_settings.encoder = new_encoder.encoder; 1867 parameters_.config.encoder_settings.encoder = new_encoder.encoder;
1897 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; 1868 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name;
1898 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; 1869 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id;
(...skipping 29 matching lines...) Expand all
1928 LOG(LS_INFO) 1899 LOG(LS_INFO)
1929 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" 1900 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options="
1930 << options.ToString(); 1901 << options.ToString();
1931 RecreateWebRtcStream(); 1902 RecreateWebRtcStream();
1932 if (allocated_encoder_.encoder != new_encoder.encoder) { 1903 if (allocated_encoder_.encoder != new_encoder.encoder) {
1933 DestroyVideoEncoder(&allocated_encoder_); 1904 DestroyVideoEncoder(&allocated_encoder_);
1934 allocated_encoder_ = new_encoder; 1905 allocated_encoder_ = new_encoder;
1935 } 1906 }
1936 } 1907 }
1937 1908
1938 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions(
1939 const std::vector<webrtc::RtpExtension>& rtp_extensions) {
1940 rtc::CritScope cs(&lock_);
1941 parameters_.config.rtp.extensions = rtp_extensions;
1942 if (stream_ != nullptr) {
1943 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetRtpExtensions";
1944 RecreateWebRtcStream();
1945 }
1946 }
1947
1948 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters( 1909 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters(
1949 const VideoSendParameters& send_params) { 1910 const ChangedSendParameters& params) {
1950 rtc::CritScope cs(&lock_); 1911 rtc::CritScope cs(&lock_);
1951 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1912 // |recreate_stream| means construction-time parameters have changed and the
1952 ? webrtc::RtcpMode::kReducedSize 1913 // sending stream needs to be reset with the new config.
1953 : webrtc::RtcpMode::kCompound; 1914 bool recreate_stream = false;
1954 if (stream_ != nullptr) { 1915 if (parameters_.config.rtp.rtcp_mode != params.rtcp_mode) {
1916 parameters_.config.rtp.rtcp_mode = params.rtcp_mode;
1917 recreate_stream = true;
1918 }
1919 if (params.rtp_header_extensions) {
1920 parameters_.config.rtp.extensions = *params.rtp_header_extensions;
1921 if (capturer_) {
1922 capturer_->SetApplyRotation(!ContainsHeaderExtension(
1923 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension));
1924 }
1925 recreate_stream = true;
1926 }
1927 if (params.max_bandwidth_bps) {
1928 // Max bitrate has changed, reconfigure encoder settings on the next frame
1929 // or stream recreation.
1930 parameters_.max_bitrate_bps = *params.max_bandwidth_bps;
1931 reconfigure_encoder_ = true;
Taylor Brandstetter 2016/01/21 23:47:16 Maybe rename this to something like "pending_recon
pbos-webrtc 2016/01/26 16:57:49 pending_encoder_reconfiguration_ done.
1932 }
1933 // Set codecs and options.
1934 if (params.codec) {
1935 SetCodecAndOptions(*params.codec,
1936 params.options ? *params.options : parameters_.options);
1937 recreate_stream = false;
Taylor Brandstetter 2016/01/21 23:47:16 Instead of resetting recreate_stream to false, you
pbos-webrtc 2016/01/26 16:57:49 Done.
1938 } else if (params.options) {
1939 // Reconfigure if codecs are already set.
1940 if (parameters_.codec_settings) {
1941 SetCodecAndOptions(*parameters_.codec_settings, *params.options);
1942 recreate_stream = false;
Taylor Brandstetter 2016/01/21 23:47:16 Same here.
pbos-webrtc 2016/01/26 16:57:49 Done.
1943 } else {
1944 parameters_.options = *params.options;
1945 }
1946 }
1947 if (recreate_stream) {
1955 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; 1948 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters";
1956 RecreateWebRtcStream(); 1949 RecreateWebRtcStream();
1957 } 1950 }
1958 } 1951 }
1959 1952
1960 webrtc::VideoEncoderConfig 1953 webrtc::VideoEncoderConfig
1961 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( 1954 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig(
1962 const Dimensions& dimensions, 1955 const Dimensions& dimensions,
1963 const VideoCodec& codec) const { 1956 const VideoCodec& codec) const {
1964 webrtc::VideoEncoderConfig encoder_config; 1957 webrtc::VideoEncoderConfig encoder_config;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 config.tl0_bitrate_kbps * 1000); 2009 config.tl0_bitrate_kbps * 1000);
2017 } 2010 }
2018 return encoder_config; 2011 return encoder_config;
2019 } 2012 }
2020 2013
2021 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( 2014 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions(
2022 int width, 2015 int width,
2023 int height, 2016 int height,
2024 bool is_screencast) { 2017 bool is_screencast) {
2025 if (last_dimensions_.width == width && last_dimensions_.height == height && 2018 if (last_dimensions_.width == width && last_dimensions_.height == height &&
2026 last_dimensions_.is_screencast == is_screencast) { 2019 last_dimensions_.is_screencast == is_screencast &&
2020 !reconfigure_encoder_) {
2027 // Configured using the same parameters, do not reconfigure. 2021 // Configured using the same parameters, do not reconfigure.
2028 return; 2022 return;
2029 } 2023 }
2030 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height 2024 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height
2031 << (is_screencast ? " (screencast)" : " (not screencast)"); 2025 << (is_screencast ? " (screencast)" : " (not screencast)");
2032 2026
2033 last_dimensions_.width = width; 2027 last_dimensions_.width = width;
2034 last_dimensions_.height = height; 2028 last_dimensions_.height = height;
2035 last_dimensions_.is_screencast = is_screencast; 2029 last_dimensions_.is_screencast = is_screencast;
2036 2030
2037 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); 2031 RTC_DCHECK(!parameters_.encoder_config.streams.empty());
2038 2032
2039 RTC_CHECK(parameters_.codec_settings); 2033 RTC_CHECK(parameters_.codec_settings);
2040 VideoCodecSettings codec_settings = *parameters_.codec_settings; 2034 VideoCodecSettings codec_settings = *parameters_.codec_settings;
2041 2035
2042 webrtc::VideoEncoderConfig encoder_config = 2036 webrtc::VideoEncoderConfig encoder_config =
2043 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); 2037 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec);
2044 2038
2045 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( 2039 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings(
2046 codec_settings.codec, parameters_.options, is_screencast); 2040 codec_settings.codec, parameters_.options, is_screencast);
2047 2041
2048 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); 2042 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config);
2049 2043
2050 encoder_config.encoder_specific_settings = NULL; 2044 encoder_config.encoder_specific_settings = NULL;
2045 reconfigure_encoder_ = false;
2051 2046
2052 if (!stream_reconfigured) { 2047 if (!stream_reconfigured) {
2053 LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " 2048 LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: "
2054 << width << "x" << height; 2049 << width << "x" << height;
2055 return; 2050 return;
2056 } 2051 }
2057 2052
2058 parameters_.encoder_config = encoder_config; 2053 parameters_.encoder_config = encoder_config;
2059 } 2054 }
2060 2055
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2177 for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it = 2172 for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it =
2178 stats.substreams.begin(); 2173 stats.substreams.begin();
2179 it != stats.substreams.end(); ++it) { 2174 it != stats.substreams.end(); ++it) {
2180 bwe_info->transmit_bitrate += it->second.total_bitrate_bps; 2175 bwe_info->transmit_bitrate += it->second.total_bitrate_bps;
2181 bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps; 2176 bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps;
2182 } 2177 }
2183 bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps; 2178 bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps;
2184 bwe_info->actual_enc_bitrate += stats.media_bitrate_bps; 2179 bwe_info->actual_enc_bitrate += stats.media_bitrate_bps;
2185 } 2180 }
2186 2181
2187 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetMaxBitrateBps(
2188 int max_bitrate_bps) {
2189 rtc::CritScope cs(&lock_);
2190 parameters_.max_bitrate_bps = max_bitrate_bps;
2191
2192 // No need to reconfigure if the stream hasn't been configured yet.
2193 if (parameters_.encoder_config.streams.empty())
2194 return;
2195
2196 // Force a stream reconfigure to set the new max bitrate.
2197 int width = last_dimensions_.width;
2198 last_dimensions_.width = 0;
2199 SetDimensions(width, last_dimensions_.height, last_dimensions_.is_screencast);
2200 }
2201
2202 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { 2182 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() {
2203 if (stream_ != NULL) { 2183 if (stream_ != NULL) {
2204 call_->DestroyVideoSendStream(stream_); 2184 call_->DestroyVideoSendStream(stream_);
2205 } 2185 }
2206 2186
2207 RTC_CHECK(parameters_.codec_settings); 2187 RTC_CHECK(parameters_.codec_settings);
2208 parameters_.encoder_config.encoder_specific_settings = 2188 parameters_.encoder_config.encoder_specific_settings =
2209 ConfigureVideoEncoderSettings( 2189 ConfigureVideoEncoderSettings(
2210 parameters_.codec_settings->codec, parameters_.options, 2190 parameters_.codec_settings->codec, parameters_.options,
2211 parameters_.encoder_config.content_type == 2191 parameters_.encoder_config.content_type ==
2212 webrtc::VideoEncoderConfig::ContentType::kScreen); 2192 webrtc::VideoEncoderConfig::ContentType::kScreen);
2213 2193
2214 webrtc::VideoSendStream::Config config = parameters_.config; 2194 webrtc::VideoSendStream::Config config = parameters_.config;
2215 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { 2195 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) {
2216 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " 2196 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX "
2217 "payload type the set codec. Ignoring RTX."; 2197 "payload type the set codec. Ignoring RTX.";
2218 config.rtp.rtx.ssrcs.clear(); 2198 config.rtp.rtx.ssrcs.clear();
2219 } 2199 }
2220 stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config); 2200 stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config);
2221 2201
2222 parameters_.encoder_config.encoder_specific_settings = NULL; 2202 parameters_.encoder_config.encoder_specific_settings = NULL;
2203 reconfigure_encoder_ = false;
2223 2204
2224 if (sending_) { 2205 if (sending_) {
2225 stream_->Start(); 2206 stream_->Start();
2226 } 2207 }
2227 } 2208 }
2228 2209
2229 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( 2210 WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream(
2230 webrtc::Call* call, 2211 webrtc::Call* call,
2231 const StreamParams& sp, 2212 const StreamParams& sp,
2232 const webrtc::VideoReceiveStream::Config& config, 2213 const webrtc::VideoReceiveStream::Config& config,
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2630 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2650 } 2631 }
2651 } 2632 }
2652 2633
2653 return video_codecs; 2634 return video_codecs;
2654 } 2635 }
2655 2636
2656 } // namespace cricket 2637 } // namespace cricket
2657 2638
2658 #endif // HAVE_WEBRTC_VIDEO 2639 #endif // HAVE_WEBRTC_VIDEO
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvideoengine2.h ('k') | talk/media/webrtc/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698