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 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 // side to cause recreation of the stream. | 849 // side to cause recreation of the stream. |
850 before[i].codec.preference = 0; | 850 before[i].codec.preference = 0; |
851 after[i].codec.preference = 0; | 851 after[i].codec.preference = 0; |
852 if (before[i] != after[i]) { | 852 if (before[i] != after[i]) { |
853 return true; | 853 return true; |
854 } | 854 } |
855 } | 855 } |
856 return false; | 856 return false; |
857 } | 857 } |
858 | 858 |
859 bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) { | 859 bool WebRtcVideoChannel2::SetSendParameters( |
860 const VideoSendParameters& send_params) { | |
860 // TODO(pbos): Refactor this to only recreate the send streams once | 861 // TODO(pbos): Refactor this to only recreate the send streams once |
861 // instead of 4 times. | 862 // instead of 4 times. |
862 return (SetSendCodecs(params.codecs) && | 863 if (!SetSendCodecs(send_params.codecs) || |
863 SetSendRtpHeaderExtensions(params.extensions) && | 864 !SetSendRtpHeaderExtensions(send_params.extensions) || |
864 SetMaxSendBandwidth(params.max_bandwidth_bps) && | 865 !SetMaxSendBandwidth(send_params.max_bandwidth_bps) || |
865 SetOptions(params.options)); | 866 !SetOptions(send_params.options)) { |
867 return false; | |
868 } | |
869 if (send_params_.rtcp.reduced_size != send_params.rtcp.reduced_size) { | |
870 rtc::CritScope stream_lock(&stream_crit_); | |
871 for (auto& kv : send_streams_) { | |
872 kv.second->SetSendParameters(send_params); | |
Taylor Brandstetter
2015/10/23 17:16:32
Here, I could have made a new method, "SetSendRedu
pthatcher1
2015/11/23 21:59:06
Yeah, we want everything to go in SetSendParameter
| |
873 } | |
874 } | |
875 send_params_ = send_params; | |
876 return true; | |
866 } | 877 } |
867 | 878 |
868 bool WebRtcVideoChannel2::SetRecvParameters(const VideoRecvParameters& params) { | 879 bool WebRtcVideoChannel2::SetRecvParameters( |
880 const VideoRecvParameters& recv_params) { | |
869 // TODO(pbos): Refactor this to only recreate the recv streams once | 881 // TODO(pbos): Refactor this to only recreate the recv streams once |
870 // instead of twice. | 882 // instead of twice. |
871 return (SetRecvCodecs(params.codecs) && | 883 if (!SetRecvCodecs(recv_params.codecs) || |
872 SetRecvRtpHeaderExtensions(params.extensions)); | 884 !SetRecvRtpHeaderExtensions(recv_params.extensions)) { |
885 return false; | |
886 } | |
887 if (recv_params_.rtcp.reduced_size != recv_params.rtcp.reduced_size) { | |
888 rtc::CritScope stream_lock(&stream_crit_); | |
889 for (auto& kv : receive_streams_) { | |
890 kv.second->SetRecvParameters(recv_params); | |
891 } | |
892 } | |
893 recv_params_ = recv_params; | |
894 return true; | |
873 } | 895 } |
874 | 896 |
875 std::string WebRtcVideoChannel2::CodecSettingsVectorToString( | 897 std::string WebRtcVideoChannel2::CodecSettingsVectorToString( |
876 const std::vector<VideoCodecSettings>& codecs) { | 898 const std::vector<VideoCodecSettings>& codecs) { |
877 std::stringstream out; | 899 std::stringstream out; |
878 out << '{'; | 900 out << '{'; |
879 for (size_t i = 0; i < codecs.size(); ++i) { | 901 for (size_t i = 0; i < codecs.size(); ++i) { |
880 out << codecs[i].codec.ToString(); | 902 out << codecs[i].codec.ToString(); |
881 if (i != codecs.size() - 1) { | 903 if (i != codecs.size() - 1) { |
882 out << ", "; | 904 out << ", "; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 | 1103 |
1082 if (!ValidateSendSsrcAvailability(sp)) | 1104 if (!ValidateSendSsrcAvailability(sp)) |
1083 return false; | 1105 return false; |
1084 | 1106 |
1085 for (uint32_t used_ssrc : sp.ssrcs) | 1107 for (uint32_t used_ssrc : sp.ssrcs) |
1086 send_ssrcs_.insert(used_ssrc); | 1108 send_ssrcs_.insert(used_ssrc); |
1087 | 1109 |
1088 webrtc::VideoSendStream::Config config(this); | 1110 webrtc::VideoSendStream::Config config(this); |
1089 config.overuse_callback = this; | 1111 config.overuse_callback = this; |
1090 | 1112 |
1091 WebRtcVideoSendStream* stream = | 1113 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( |
1092 new WebRtcVideoSendStream(call_, | 1114 call_, sp, config, external_encoder_factory_, options_, |
1093 sp, | 1115 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, |
1094 config, | 1116 send_params_); |
1095 external_encoder_factory_, | |
1096 options_, | |
1097 bitrate_config_.max_bitrate_bps, | |
1098 send_codec_, | |
1099 send_rtp_extensions_); | |
1100 | 1117 |
1101 uint32_t ssrc = sp.first_ssrc(); | 1118 uint32_t ssrc = sp.first_ssrc(); |
1102 RTC_DCHECK(ssrc != 0); | 1119 RTC_DCHECK(ssrc != 0); |
1103 send_streams_[ssrc] = stream; | 1120 send_streams_[ssrc] = stream; |
1104 | 1121 |
1105 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { | 1122 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
1106 rtcp_receiver_report_ssrc_ = ssrc; | 1123 rtcp_receiver_report_ssrc_ = ssrc; |
1107 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 1124 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
1108 "a send stream."; | 1125 "a send stream."; |
1109 for (auto& kv : receive_streams_) | 1126 for (auto& kv : receive_streams_) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1233 | 1250 |
1234 void WebRtcVideoChannel2::ConfigureReceiverRtp( | 1251 void WebRtcVideoChannel2::ConfigureReceiverRtp( |
1235 webrtc::VideoReceiveStream::Config* config, | 1252 webrtc::VideoReceiveStream::Config* config, |
1236 const StreamParams& sp) const { | 1253 const StreamParams& sp) const { |
1237 uint32_t ssrc = sp.first_ssrc(); | 1254 uint32_t ssrc = sp.first_ssrc(); |
1238 | 1255 |
1239 config->rtp.remote_ssrc = ssrc; | 1256 config->rtp.remote_ssrc = ssrc; |
1240 config->rtp.local_ssrc = rtcp_receiver_report_ssrc_; | 1257 config->rtp.local_ssrc = rtcp_receiver_report_ssrc_; |
1241 | 1258 |
1242 config->rtp.extensions = recv_rtp_extensions_; | 1259 config->rtp.extensions = recv_rtp_extensions_; |
1260 config->rtp.rtcp_mode = recv_params_.rtcp.reduced_size | |
1261 ? webrtc::RtcpMode::kReducedSize | |
1262 : webrtc::RtcpMode::kCompound; | |
1243 | 1263 |
1244 // TODO(pbos): This protection is against setting the same local ssrc as | 1264 // TODO(pbos): This protection is against setting the same local ssrc as |
1245 // remote which is not permitted by the lower-level API. RTCP requires a | 1265 // remote which is not permitted by the lower-level API. RTCP requires a |
1246 // corresponding sender SSRC. Figure out what to do when we don't have | 1266 // corresponding sender SSRC. Figure out what to do when we don't have |
1247 // (receive-only) or know a good local SSRC. | 1267 // (receive-only) or know a good local SSRC. |
1248 if (config->rtp.remote_ssrc == config->rtp.local_ssrc) { | 1268 if (config->rtp.remote_ssrc == config->rtp.local_ssrc) { |
1249 if (config->rtp.local_ssrc != kDefaultRtcpReceiverReportSsrc) { | 1269 if (config->rtp.local_ssrc != kDefaultRtcpReceiverReportSsrc) { |
1250 config->rtp.local_ssrc = kDefaultRtcpReceiverReportSsrc; | 1270 config->rtp.local_ssrc = kDefaultRtcpReceiverReportSsrc; |
1251 } else { | 1271 } else { |
1252 config->rtp.local_ssrc = kDefaultRtcpReceiverReportSsrc + 1; | 1272 config->rtp.local_ssrc = kDefaultRtcpReceiverReportSsrc + 1; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 } | 1744 } |
1725 | 1745 |
1726 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1746 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1727 webrtc::Call* call, | 1747 webrtc::Call* call, |
1728 const StreamParams& sp, | 1748 const StreamParams& sp, |
1729 const webrtc::VideoSendStream::Config& config, | 1749 const webrtc::VideoSendStream::Config& config, |
1730 WebRtcVideoEncoderFactory* external_encoder_factory, | 1750 WebRtcVideoEncoderFactory* external_encoder_factory, |
1731 const VideoOptions& options, | 1751 const VideoOptions& options, |
1732 int max_bitrate_bps, | 1752 int max_bitrate_bps, |
1733 const Settable<VideoCodecSettings>& codec_settings, | 1753 const Settable<VideoCodecSettings>& codec_settings, |
1734 const std::vector<webrtc::RtpExtension>& rtp_extensions) | 1754 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1755 // TODO(pbos): Don't duplicate information between send_params, | |
1756 // rtp_extensions, options, etc. | |
1757 const VideoSendParameters& send_params) | |
1735 : ssrcs_(sp.ssrcs), | 1758 : ssrcs_(sp.ssrcs), |
1736 ssrc_groups_(sp.ssrc_groups), | 1759 ssrc_groups_(sp.ssrc_groups), |
1737 call_(call), | 1760 call_(call), |
1738 external_encoder_factory_(external_encoder_factory), | 1761 external_encoder_factory_(external_encoder_factory), |
1739 stream_(NULL), | 1762 stream_(NULL), |
1740 parameters_(config, options, max_bitrate_bps, codec_settings), | 1763 parameters_(config, options, max_bitrate_bps, codec_settings), |
1741 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), | 1764 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), |
1742 capturer_(NULL), | 1765 capturer_(NULL), |
1743 sending_(false), | 1766 sending_(false), |
1744 muted_(false), | 1767 muted_(false), |
1745 old_adapt_changes_(0), | 1768 old_adapt_changes_(0), |
1746 first_frame_timestamp_ms_(0), | 1769 first_frame_timestamp_ms_(0), |
1747 last_frame_timestamp_ms_(0) { | 1770 last_frame_timestamp_ms_(0) { |
1748 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1771 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1749 | 1772 |
1750 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1773 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1751 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1774 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1752 ¶meters_.config.rtp.rtx.ssrcs); | 1775 ¶meters_.config.rtp.rtx.ssrcs); |
1753 parameters_.config.rtp.c_name = sp.cname; | 1776 parameters_.config.rtp.c_name = sp.cname; |
1754 parameters_.config.rtp.extensions = rtp_extensions; | 1777 parameters_.config.rtp.extensions = rtp_extensions; |
1778 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | |
1779 ? webrtc::RtcpMode::kReducedSize | |
1780 : webrtc::RtcpMode::kCompound; | |
1755 | 1781 |
1756 VideoCodecSettings params; | 1782 VideoCodecSettings params; |
1757 if (codec_settings.Get(¶ms)) { | 1783 if (codec_settings.Get(¶ms)) { |
1758 SetCodec(params); | 1784 SetCodec(params); |
1759 } | 1785 } |
1760 } | 1786 } |
1761 | 1787 |
1762 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1788 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1763 DisconnectCapturer(); | 1789 DisconnectCapturer(); |
1764 if (stream_ != NULL) { | 1790 if (stream_ != NULL) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2061 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions( | 2087 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions( |
2062 const std::vector<webrtc::RtpExtension>& rtp_extensions) { | 2088 const std::vector<webrtc::RtpExtension>& rtp_extensions) { |
2063 rtc::CritScope cs(&lock_); | 2089 rtc::CritScope cs(&lock_); |
2064 parameters_.config.rtp.extensions = rtp_extensions; | 2090 parameters_.config.rtp.extensions = rtp_extensions; |
2065 if (stream_ != nullptr) { | 2091 if (stream_ != nullptr) { |
2066 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetRtpExtensions"; | 2092 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetRtpExtensions"; |
2067 RecreateWebRtcStream(); | 2093 RecreateWebRtcStream(); |
2068 } | 2094 } |
2069 } | 2095 } |
2070 | 2096 |
2097 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters( | |
2098 const VideoSendParameters& send_params) { | |
2099 rtc::CritScope cs(&lock_); | |
pthatcher1
2015/10/23 20:40:01
Should we do another check to see if it's changed
Taylor Brandstetter
2015/11/11 19:42:40
For the other methods, only WebRtcVideoChannel2 ch
| |
2100 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | |
2101 ? webrtc::RtcpMode::kReducedSize | |
2102 : webrtc::RtcpMode::kCompound; | |
2103 if (stream_ != nullptr) { | |
2104 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; | |
2105 RecreateWebRtcStream(); | |
2106 } | |
2107 } | |
2108 | |
2071 webrtc::VideoEncoderConfig | 2109 webrtc::VideoEncoderConfig |
2072 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 2110 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
2073 const Dimensions& dimensions, | 2111 const Dimensions& dimensions, |
2074 const VideoCodec& codec) const { | 2112 const VideoCodec& codec) const { |
2075 webrtc::VideoEncoderConfig encoder_config; | 2113 webrtc::VideoEncoderConfig encoder_config; |
2076 if (dimensions.is_screencast) { | 2114 if (dimensions.is_screencast) { |
2077 int screencast_min_bitrate_kbps; | 2115 int screencast_min_bitrate_kbps; |
2078 parameters_.options.screencast_min_bitrate.Get( | 2116 parameters_.options.screencast_min_bitrate.Get( |
2079 &screencast_min_bitrate_kbps); | 2117 &screencast_min_bitrate_kbps); |
2080 encoder_config.min_transmit_bitrate_bps = | 2118 encoder_config.min_transmit_bitrate_bps = |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2492 RecreateWebRtcStream(); | 2530 RecreateWebRtcStream(); |
2493 } | 2531 } |
2494 | 2532 |
2495 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRtpExtensions( | 2533 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRtpExtensions( |
2496 const std::vector<webrtc::RtpExtension>& extensions) { | 2534 const std::vector<webrtc::RtpExtension>& extensions) { |
2497 config_.rtp.extensions = extensions; | 2535 config_.rtp.extensions = extensions; |
2498 LOG(LS_INFO) << "RecreateWebRtcStream (recv) because of SetRtpExtensions"; | 2536 LOG(LS_INFO) << "RecreateWebRtcStream (recv) because of SetRtpExtensions"; |
2499 RecreateWebRtcStream(); | 2537 RecreateWebRtcStream(); |
2500 } | 2538 } |
2501 | 2539 |
2540 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRecvParameters( | |
2541 const VideoRecvParameters& recv_params) { | |
2542 config_.rtp.rtcp_mode = recv_params.rtcp.reduced_size | |
2543 ? webrtc::RtcpMode::kReducedSize | |
2544 : webrtc::RtcpMode::kCompound; | |
2545 LOG(LS_INFO) << "RecreateWebRtcStream (recv) because of SetRecvParameters"; | |
2546 RecreateWebRtcStream(); | |
2547 } | |
2548 | |
2502 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::RecreateWebRtcStream() { | 2549 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::RecreateWebRtcStream() { |
2503 if (stream_ != NULL) { | 2550 if (stream_ != NULL) { |
2504 call_->DestroyVideoReceiveStream(stream_); | 2551 call_->DestroyVideoReceiveStream(stream_); |
2505 } | 2552 } |
2506 stream_ = call_->CreateVideoReceiveStream(config_); | 2553 stream_ = call_->CreateVideoReceiveStream(config_); |
2507 stream_->Start(); | 2554 stream_->Start(); |
2508 } | 2555 } |
2509 | 2556 |
2510 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::ClearDecoders( | 2557 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::ClearDecoders( |
2511 std::vector<AllocatedDecoder>* allocated_decoders) { | 2558 std::vector<AllocatedDecoder>* allocated_decoders) { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2744 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2791 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2745 } | 2792 } |
2746 } | 2793 } |
2747 | 2794 |
2748 return video_codecs; | 2795 return video_codecs; |
2749 } | 2796 } |
2750 | 2797 |
2751 } // namespace cricket | 2798 } // namespace cricket |
2752 | 2799 |
2753 #endif // HAVE_WEBRTC_VIDEO | 2800 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |