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

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: 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
« no previous file with comments | « talk/media/webrtc/webrtcvideoengine2.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::FilterSendParameters(
pthatcher1 2016/01/07 21:03:43 I think a better name here would be GetChangedSend
pbos-webrtc 2016/01/20 18:09:03 Done.
709 const VideoSendParameters& params,
710 FilteredSendParameters* out_params) const {
pthatcher1 2016/01/07 21:03:43 And this ChangedSendParameters* changed_params Fi
pbos-webrtc 2016/01/20 18:09:03 Done.
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 out_params->codec = rtc::Optional<VideoCodecSettings>(
728 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 out_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 out_params->max_bandwidth_bps = rtc::Optional<int>(
744 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps);
745 }
746
747 // ==== OPTIONS ====
748
749 VideoOptions old_options = options_;
750 VideoOptions new_options = options_;
751 new_options.SetAll(params.options);
752 if (!(new_options == old_options)) {
pthatcher1 2016/01/07 21:03:43 Can you put a TODO to see if we can just do: if (
pbos-webrtc 2016/01/20 18:09:03 Done.
753 out_params->options = rtc::Optional<VideoOptions>(new_options);
754 }
755
756 out_params->rtcp_mode = params.rtcp.reduced_size
757 ? webrtc::RtcpMode::kReducedSize
758 : webrtc::RtcpMode::kCompound;
759
760 return true;
761 }
762
713 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { 763 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) {
714 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters"); 764 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendParameters");
715 LOG(LS_INFO) << "SetSendParameters: " << params.ToString(); 765 LOG(LS_INFO) << "SetSendParameters: " << params.ToString();
716 // TODO(pbos): Refactor this to only recreate the send streams once 766 FilteredSendParameters filtered_params;
717 // instead of 4 times. 767 if (!FilterSendParameters(params, &filtered_params)) {
718 if (!SetSendCodecs(params.codecs) ||
719 !SetSendRtpHeaderExtensions(params.extensions) ||
720 !SetMaxSendBandwidth(params.max_bandwidth_bps) ||
721 !SetOptions(params.options)) {
722 return false; 768 return false;
723 } 769 }
724 if (send_params_.rtcp.reduced_size != params.rtcp.reduced_size) { 770
771 bool bitrate_config_changed = false;
772
773 bool codec_set = false;
774 if (filtered_params.codec) {
775 const VideoCodecSettings& codec_settings = *filtered_params.codec;
776 send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings);
777 VideoCodec codec = codec_settings.codec;
778 codec_set = true;
779
780 LOG(LS_INFO) << "Using codec: " << codec.ToString();
781 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean
782 // that we change the min/max of bandwidth estimation. Reevaluate this.
783 int bitrate_kbps;
784 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) &&
785 bitrate_kbps > 0) {
786 bitrate_config_.min_bitrate_bps = bitrate_kbps * 1000;
787 } else {
788 bitrate_config_.min_bitrate_bps = 0;
789 }
790 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) &&
791 bitrate_kbps > 0) {
792 bitrate_config_.start_bitrate_bps = bitrate_kbps * 1000;
793 } else {
794 // Do not reconfigure start bitrate unless it's specified and positive.
795 bitrate_config_.start_bitrate_bps = -1;
796 }
797 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) &&
798 bitrate_kbps > 0) {
799 bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000;
800 } else {
801 bitrate_config_.max_bitrate_bps = -1;
802 }
803 bitrate_config_changed = true;
804 }
805
806 if (filtered_params.rtp_header_extensions) {
807 send_rtp_extensions_ = *filtered_params.rtp_header_extensions;
808 }
809
810 if (filtered_params.max_bandwidth_bps) {
811 // TODO(pbos): Figure out whether b=AS means max bitrate for this
812 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in
813 // which case this should not set a Call::BitrateConfig but rather
814 // reconfigure
815 // all senders.
816 int max_bitrate_bps = *filtered_params.max_bandwidth_bps;
817 bitrate_config_.start_bitrate_bps = -1;
818 bitrate_config_.max_bitrate_bps = max_bitrate_bps;
819 if (max_bitrate_bps > 0 &&
820 bitrate_config_.min_bitrate_bps > max_bitrate_bps) {
821 bitrate_config_.min_bitrate_bps = max_bitrate_bps;
822 }
823 bitrate_config_changed = true;
824 }
825
826 if (bitrate_config_changed) {
827 call_->SetBitrateConfig(bitrate_config_);
828 }
829
830 if (filtered_params.options) {
831 options_.SetAll(*filtered_params.options);
832 {
833 rtc::CritScope lock(&capturer_crit_);
834 if (options_.cpu_overuse_detection)
835 signal_cpu_adaptation_ = *options_.cpu_overuse_detection;
836 }
837 rtc::DiffServCodePoint dscp =
838 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT;
839 MediaChannel::SetDscp(dscp);
840 }
841
842 {
725 rtc::CritScope stream_lock(&stream_crit_); 843 rtc::CritScope stream_lock(&stream_crit_);
726 for (auto& kv : send_streams_) { 844 for (auto& kv : send_streams_) {
727 kv.second->SetSendParameters(params); 845 kv.second->SetSendParameters(filtered_params);
846 }
847 if (codec_set) {
848 // Update receive feedback parameters from new codec.
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(HasNack(send_codec_->codec),
855 HasRemb(send_codec_->codec),
856 HasTransportCc(send_codec_->codec));
857 }
728 } 858 }
729 } 859 }
730 send_params_ = params; 860 send_params_ = params;
731 return true; 861 return true;
732 } 862 }
733 863
734 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) { 864 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) {
735 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvParameters"); 865 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvParameters");
736 LOG(LS_INFO) << "SetRecvParameters: " << params.ToString(); 866 LOG(LS_INFO) << "SetRecvParameters: " << params.ToString();
737 // TODO(pbos): Refactor this to only recreate the recv streams once 867 // 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_); 930 rtc::CritScope stream_lock(&stream_crit_);
801 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = 931 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it =
802 receive_streams_.begin(); 932 receive_streams_.begin();
803 it != receive_streams_.end(); ++it) { 933 it != receive_streams_.end(); ++it) {
804 it->second->SetRecvCodecs(recv_codecs_); 934 it->second->SetRecvCodecs(recv_codecs_);
805 } 935 }
806 936
807 return true; 937 return true;
808 } 938 }
809 939
810 bool WebRtcVideoChannel2::SetSendCodecs(const std::vector<VideoCodec>& codecs) { 940 void WebRtcVideoChannel2::SetSendCodec(
811 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendCodecs"); 941 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 } 942 }
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 }
(...skipping 19 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 // TODO(pbos): Provide VideoSendParameters here instead if possible, and
993 // remove SetOptions.
994 SetOptions(*options);
pthatcher1 2016/01/07 21:03:43 If you pulled out most of the logic in SetSendPara
pbos-webrtc 2016/01/20 18:09:04 Done.
995 return true;
927 } else { 996 } else {
928 return true; 997 return true;
929 } 998 }
pthatcher1 2016/01/07 21:03:43 These both return true, so you could probably just
pbos-webrtc 2016/01/20 18:09:04 Yeah that looks dumb. Assuming it has evolved over
930 } 999 }
931 1000
932 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( 1001 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability(
933 const StreamParams& sp) const { 1002 const StreamParams& sp) const {
934 for (uint32_t ssrc: sp.ssrcs) { 1003 for (uint32_t ssrc: sp.ssrcs) {
935 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { 1004 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) {
936 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; 1005 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists.";
937 return false; 1006 return false;
938 } 1007 }
939 } 1008 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; 1329 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
1261 return false; 1330 return false;
1262 } 1331 }
1263 if (!send_streams_[ssrc]->SetCapturer(capturer)) { 1332 if (!send_streams_[ssrc]->SetCapturer(capturer)) {
1264 return false; 1333 return false;
1265 } 1334 }
1266 } 1335 }
1267 1336
1268 if (capturer) { 1337 if (capturer) {
1269 capturer->SetApplyRotation( 1338 capturer->SetApplyRotation(
1270 !FindHeaderExtension(send_rtp_extensions_, 1339 !ContainsHeaderExtension(send_rtp_extensions_,
1271 kRtpVideoRotationHeaderExtension)); 1340 kRtpVideoRotationHeaderExtension));
1272 } 1341 }
1273 { 1342 {
1274 rtc::CritScope lock(&capturer_crit_); 1343 rtc::CritScope lock(&capturer_crit_);
1275 capturers_[ssrc] = capturer; 1344 capturers_[ssrc] = capturer;
1276 } 1345 }
1277 return true; 1346 return true;
1278 } 1347 }
1279 1348
1280 bool WebRtcVideoChannel2::SendIntraFrame() { 1349 bool WebRtcVideoChannel2::SendIntraFrame() {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 1467
1399 rtc::CritScope stream_lock(&stream_crit_); 1468 rtc::CritScope stream_lock(&stream_crit_);
1400 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it = 1469 for (std::map<uint32_t, WebRtcVideoReceiveStream*>::iterator it =
1401 receive_streams_.begin(); 1470 receive_streams_.begin();
1402 it != receive_streams_.end(); ++it) { 1471 it != receive_streams_.end(); ++it) {
1403 it->second->SetRtpExtensions(recv_rtp_extensions_); 1472 it->second->SetRtpExtensions(recv_rtp_extensions_);
1404 } 1473 }
1405 return true; 1474 return true;
1406 } 1475 }
1407 1476
1408 bool WebRtcVideoChannel2::SetSendRtpHeaderExtensions( 1477 // TODO(pbos): Remove SetOptions in favor of SetSendParameters.
1409 const std::vector<RtpHeaderExtension>& extensions) { 1478 void WebRtcVideoChannel2::SetOptions(const VideoOptions& options) {
1410 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendRtpHeaderExtensions");
1411 if (!ValidateRtpExtensions(extensions)) {
1412 return false;
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_; 1479 VideoOptions old_options = options_;
1473 options_.SetAll(options); 1480 options_.SetAll(options);
1474 if (options_ == old_options) { 1481 if (options == old_options) {
1475 // No new options to set. 1482 return;
1476 return true;
1477 } 1483 }
1478 { 1484 {
1479 rtc::CritScope lock(&capturer_crit_); 1485 rtc::CritScope lock(&capturer_crit_);
1480 if (options_.cpu_overuse_detection) 1486 if (options_.cpu_overuse_detection)
1481 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; 1487 signal_cpu_adaptation_ = *options_.cpu_overuse_detection;
1482 } 1488 }
1483 rtc::DiffServCodePoint dscp = 1489 rtc::DiffServCodePoint dscp =
1484 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; 1490 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT;
1485 MediaChannel::SetDscp(dscp); 1491 MediaChannel::SetDscp(dscp);
1486 rtc::CritScope stream_lock(&stream_crit_); 1492 rtc::CritScope stream_lock(&stream_crit_);
1487 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = 1493 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it =
1488 send_streams_.begin(); 1494 send_streams_.begin();
1489 it != send_streams_.end(); ++it) { 1495 it != send_streams_.end(); ++it) {
1490 it->second->SetOptions(options_); 1496 it->second->SetOptions(options_);
1491 } 1497 }
1492 return true;
1493 } 1498 }
1494 1499
1495 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { 1500 void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) {
1496 MediaChannel::SetInterface(iface); 1501 MediaChannel::SetInterface(iface);
1497 // Set the RTP recv/send buffer to a bigger size 1502 // Set the RTP recv/send buffer to a bigger size
1498 MediaChannel::SetOption(NetworkInterface::ST_RTP, 1503 MediaChannel::SetOption(NetworkInterface::ST_RTP,
1499 rtc::Socket::OPT_RCVBUF, 1504 rtc::Socket::OPT_RCVBUF,
1500 kVideoRtpBufferSize); 1505 kVideoRtpBufferSize);
1501 1506
1502 // Speculative change to increase the outbound socket buffer size. 1507 // Speculative change to increase the outbound socket buffer size.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1629 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
1625 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, 1630 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs,
1626 &parameters_.config.rtp.rtx.ssrcs); 1631 &parameters_.config.rtp.rtx.ssrcs);
1627 parameters_.config.rtp.c_name = sp.cname; 1632 parameters_.config.rtp.c_name = sp.cname;
1628 parameters_.config.rtp.extensions = rtp_extensions; 1633 parameters_.config.rtp.extensions = rtp_extensions;
1629 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1634 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size
1630 ? webrtc::RtcpMode::kReducedSize 1635 ? webrtc::RtcpMode::kReducedSize
1631 : webrtc::RtcpMode::kCompound; 1636 : webrtc::RtcpMode::kCompound;
1632 1637
1633 if (codec_settings) { 1638 if (codec_settings) {
1634 SetCodec(*codec_settings); 1639 SetCodecAndOptions(*codec_settings, parameters_.options);
1635 } 1640 }
1636 } 1641 }
1637 1642
1638 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { 1643 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() {
1639 DisconnectCapturer(); 1644 DisconnectCapturer();
1640 if (stream_ != NULL) { 1645 if (stream_ != NULL) {
1641 call_->DestroyVideoSendStream(stream_); 1646 call_->DestroyVideoSendStream(stream_);
1642 } 1647 }
1643 DestroyVideoEncoder(&allocated_encoder_); 1648 DestroyVideoEncoder(&allocated_encoder_);
1644 } 1649 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 } 1743 }
1739 1744
1740 capturer_ = capturer; 1745 capturer_ = capturer;
1741 } 1746 }
1742 // Lock cannot be held while connecting the capturer to prevent lock-order 1747 // Lock cannot be held while connecting the capturer to prevent lock-order
1743 // violations. 1748 // violations.
1744 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); 1749 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame);
1745 return true; 1750 return true;
1746 } 1751 }
1747 1752
1753 // TODO(pbos): Apply this on the VideoAdapter instead!
1748 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( 1754 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat(
1749 const VideoFormat& format) { 1755 const VideoFormat& format) {
1750 if ((format.width == 0 || format.height == 0) && 1756 if ((format.width == 0 || format.height == 0) &&
1751 format.width != format.height) { 1757 format.width != format.height) {
1752 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " 1758 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not "
1753 "both, 0x0 drops frames)."; 1759 "both, 0x0 drops frames).";
1754 return false; 1760 return false;
1755 } 1761 }
1756 1762
1757 rtc::CritScope cs(&lock_); 1763 rtc::CritScope cs(&lock_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 } 1796 }
1791 capturer->SignalVideoFrame.disconnect(this); 1797 capturer->SignalVideoFrame.disconnect(this);
1792 return true; 1798 return true;
1793 } 1799 }
1794 1800
1795 const std::vector<uint32_t>& 1801 const std::vector<uint32_t>&
1796 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { 1802 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
1797 return ssrcs_; 1803 return ssrcs_;
1798 } 1804 }
1799 1805
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( 1806 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions(
pthatcher1 2016/01/08 00:34:57 By the way, as far as I can tell, this is only use
pbos-webrtc 2016/01/20 18:09:04 Acknowledged.
1810 const VideoOptions& options) { 1807 const VideoOptions& options) {
1811 rtc::CritScope cs(&lock_); 1808 rtc::CritScope cs(&lock_);
1812 if (parameters_.codec_settings) { 1809 if (parameters_.codec_settings) {
1813 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" 1810 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options="
1814 << options.ToString(); 1811 << options.ToString();
1815 SetCodecAndOptions(*parameters_.codec_settings, options); 1812 SetCodecAndOptions(*parameters_.codec_settings, options);
1816 } else { 1813 } else {
1817 parameters_.options = options; 1814 parameters_.options = options;
1818 } 1815 }
1819 } 1816 }
1820 1817
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) { 1818 webrtc::VideoCodecType CodecTypeFromName(const std::string& name) {
1829 if (CodecNamesEq(name, kVp8CodecName)) { 1819 if (CodecNamesEq(name, kVp8CodecName)) {
1830 return webrtc::kVideoCodecVP8; 1820 return webrtc::kVideoCodecVP8;
1831 } else if (CodecNamesEq(name, kVp9CodecName)) { 1821 } else if (CodecNamesEq(name, kVp9CodecName)) {
1832 return webrtc::kVideoCodecVP9; 1822 return webrtc::kVideoCodecVP9;
1833 } else if (CodecNamesEq(name, kH264CodecName)) { 1823 } else if (CodecNamesEq(name, kH264CodecName)) {
1834 return webrtc::kVideoCodecH264; 1824 return webrtc::kVideoCodecH264;
1835 } 1825 }
1836 return webrtc::kVideoCodecUnknown; 1826 return webrtc::kVideoCodecUnknown;
1837 } 1827 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); 1867 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder);
1878 } 1868 }
1879 delete encoder->encoder; 1869 delete encoder->encoder;
1880 } 1870 }
1881 1871
1882 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( 1872 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions(
1883 const VideoCodecSettings& codec_settings, 1873 const VideoCodecSettings& codec_settings,
1884 const VideoOptions& options) { 1874 const VideoOptions& options) {
1885 parameters_.encoder_config = 1875 parameters_.encoder_config =
1886 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); 1876 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec);
1887 if (parameters_.encoder_config.streams.empty()) 1877 RTC_DCHECK(!parameters_.encoder_config.streams.empty());
1888 return;
1889 1878
1890 format_ = VideoFormat(codec_settings.codec.width, 1879 format_ = VideoFormat(codec_settings.codec.width,
1891 codec_settings.codec.height, 1880 codec_settings.codec.height,
1892 VideoFormat::FpsToInterval(30), 1881 VideoFormat::FpsToInterval(30),
1893 FOURCC_I420); 1882 FOURCC_I420);
1894 1883
1895 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); 1884 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec);
1896 parameters_.config.encoder_settings.encoder = new_encoder.encoder; 1885 parameters_.config.encoder_settings.encoder = new_encoder.encoder;
1897 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; 1886 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name;
1898 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; 1887 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id;
(...skipping 29 matching lines...) Expand all
1928 LOG(LS_INFO) 1917 LOG(LS_INFO)
1929 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" 1918 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options="
1930 << options.ToString(); 1919 << options.ToString();
1931 RecreateWebRtcStream(); 1920 RecreateWebRtcStream();
1932 if (allocated_encoder_.encoder != new_encoder.encoder) { 1921 if (allocated_encoder_.encoder != new_encoder.encoder) {
1933 DestroyVideoEncoder(&allocated_encoder_); 1922 DestroyVideoEncoder(&allocated_encoder_);
1934 allocated_encoder_ = new_encoder; 1923 allocated_encoder_ = new_encoder;
1935 } 1924 }
1936 } 1925 }
1937 1926
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( 1927 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters(
1949 const VideoSendParameters& send_params) { 1928 const FilteredSendParameters& params) {
1950 rtc::CritScope cs(&lock_); 1929 rtc::CritScope cs(&lock_);
1951 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1930 bool needs_restart = false;
1952 ? webrtc::RtcpMode::kReducedSize 1931 bool force_reconfigure = false;
pthatcher1 2016/01/07 21:03:43 needs_restart means "RecreateWebRtcStream();" forc
pbos-webrtc 2016/01/20 18:09:04 Done.
1953 : webrtc::RtcpMode::kCompound; 1932 if (parameters_.config.rtp.rtcp_mode != params.rtcp_mode) {
1954 if (stream_ != nullptr) { 1933 parameters_.config.rtp.rtcp_mode = params.rtcp_mode;
1934 needs_restart = true;
1935 }
1936 if (params.rtp_header_extensions) {
1937 parameters_.config.rtp.extensions = *params.rtp_header_extensions;
1938 if (capturer_) {
1939 capturer_->SetApplyRotation(!ContainsHeaderExtension(
1940 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension));
1941 }
1942 needs_restart = true;
1943 }
1944 if (params.max_bandwidth_bps) {
1945 parameters_.max_bitrate_bps = *params.max_bandwidth_bps;
1946 if (!parameters_.encoder_config.streams.empty() && stream_ != nullptr) {
1947 // Already running, force a stream reconfigure to set the new max bitrate.
1948 // TODO(pbos): Just have it reconfigure on the next frame instead. Do this
1949 // before submitting.
1950 force_reconfigure = true;
1951 }
1952 }
1953 if (force_reconfigure) {
1954 int width = last_dimensions_.width;
1955 last_dimensions_.width = 0;
1956 SetDimensions(width, last_dimensions_.height,
1957 last_dimensions_.is_screencast);
1958 }
pthatcher1 2016/01/07 21:03:43 If you're going to recreate the stream later, do y
pbos-webrtc 2016/01/20 18:09:04 Nope, I don't. Made this lazy and reinitialize on
1959 // Set codecs and options.
1960 if (params.codec) {
1961 SetCodecAndOptions(*params.codec,
1962 params.options ? *params.options : parameters_.options);
1963 needs_restart = false;
1964 } else if (params.options) {
1965 // Reconfigure if codecs are already set.
1966 if (parameters_.codec_settings) {
1967 SetCodecAndOptions(*parameters_.codec_settings, *params.options);
1968 needs_restart = false;
1969 } else {
1970 parameters_.options = *params.options;
1971 }
1972 }
1973 if (needs_restart) {
1955 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; 1974 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters";
1956 RecreateWebRtcStream(); 1975 RecreateWebRtcStream();
1957 } 1976 }
1958 } 1977 }
1959 1978
1960 webrtc::VideoEncoderConfig 1979 webrtc::VideoEncoderConfig
1961 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( 1980 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig(
1962 const Dimensions& dimensions, 1981 const Dimensions& dimensions,
1963 const VideoCodec& codec) const { 1982 const VideoCodec& codec) const {
1964 webrtc::VideoEncoderConfig encoder_config; 1983 webrtc::VideoEncoderConfig encoder_config;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2177 for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it = 2196 for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it =
2178 stats.substreams.begin(); 2197 stats.substreams.begin();
2179 it != stats.substreams.end(); ++it) { 2198 it != stats.substreams.end(); ++it) {
2180 bwe_info->transmit_bitrate += it->second.total_bitrate_bps; 2199 bwe_info->transmit_bitrate += it->second.total_bitrate_bps;
2181 bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps; 2200 bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps;
2182 } 2201 }
2183 bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps; 2202 bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps;
2184 bwe_info->actual_enc_bitrate += stats.media_bitrate_bps; 2203 bwe_info->actual_enc_bitrate += stats.media_bitrate_bps;
2185 } 2204 }
2186 2205
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() { 2206 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() {
2203 if (stream_ != NULL) { 2207 if (stream_ != NULL) {
2204 call_->DestroyVideoSendStream(stream_); 2208 call_->DestroyVideoSendStream(stream_);
2205 } 2209 }
2206 2210
2207 RTC_CHECK(parameters_.codec_settings); 2211 RTC_CHECK(parameters_.codec_settings);
2208 parameters_.encoder_config.encoder_specific_settings = 2212 parameters_.encoder_config.encoder_specific_settings =
2209 ConfigureVideoEncoderSettings( 2213 ConfigureVideoEncoderSettings(
2210 parameters_.codec_settings->codec, parameters_.options, 2214 parameters_.codec_settings->codec, parameters_.options,
2211 parameters_.encoder_config.content_type == 2215 parameters_.encoder_config.content_type ==
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2667 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2664 } 2668 }
2665 } 2669 }
2666 2670
2667 return video_codecs; 2671 return video_codecs;
2668 } 2672 }
2669 2673
2670 } // namespace cricket 2674 } // namespace cricket
2671 2675
2672 #endif // HAVE_WEBRTC_VIDEO 2676 #endif // HAVE_WEBRTC_VIDEO
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvideoengine2.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698