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