OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/video/video_send_stream.h" | 10 #include "webrtc/video/video_send_stream.h" |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 encoded_image, codec_specific_info->codecType); | 935 encoded_image, codec_specific_info->codecType); |
936 RTC_DCHECK(ok); | 936 RTC_DCHECK(ok); |
937 } | 937 } |
938 } | 938 } |
939 | 939 |
940 return result; | 940 return result; |
941 } | 941 } |
942 | 942 |
943 void VideoSendStreamImpl::ConfigureProtection() { | 943 void VideoSendStreamImpl::ConfigureProtection() { |
944 RTC_DCHECK_RUN_ON(worker_queue_); | 944 RTC_DCHECK_RUN_ON(worker_queue_); |
945 // Enable NACK, FEC or both. | 945 |
946 const bool enable_protection_nack = config_->rtp.nack.rtp_history_ms > 0; | 946 const bool nack_enabled = config_->rtp.nack.rtp_history_ms > 0; |
947 const int red_payload_type = config_->rtp.ulpfec.red_payload_type; | 947 int red_payload_type = config_->rtp.ulpfec.red_payload_type; |
948 int ulpfec_payload_type = config_->rtp.ulpfec.ulpfec_payload_type; | 948 int ulpfec_payload_type = config_->rtp.ulpfec.ulpfec_payload_type; |
| 949 |
| 950 // Shorthands. |
| 951 auto IsRedEnabled = [&]() { return red_payload_type >= 0; }; |
| 952 auto IsUlpfecEnabled = [&]() { return ulpfec_payload_type >= 0; }; |
| 953 auto DisableUlpfec = [&]() { ulpfec_payload_type = -1; }; |
| 954 |
949 // Payload types without picture ID cannot determine that a stream is complete | 955 // Payload types without picture ID cannot determine that a stream is complete |
950 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is | 956 // without retransmitting FEC, so using ULPFEC + NACK for H.264 (for instance) |
951 // a waste of bandwidth since FEC packets still have to be transmitted. Note | 957 // is a waste of bandwidth since FEC packets still have to be transmitted. |
952 // that this is not the case with FLEXFEC. | 958 // Note that this is not the case with FlexFEC. |
953 if (enable_protection_nack && | 959 if (nack_enabled && IsUlpfecEnabled() && |
954 !PayloadTypeSupportsSkippingFecPackets( | 960 !PayloadTypeSupportsSkippingFecPackets( |
955 config_->encoder_settings.payload_name)) { | 961 config_->encoder_settings.payload_name)) { |
956 LOG(LS_WARNING) << "Transmitting payload type without picture ID using" | 962 LOG(LS_WARNING) |
957 "NACK+FEC is a waste of bandwidth since FEC packets " | 963 << "Transmitting payload type without picture ID using " |
958 "also have to be retransmitted. Disabling FEC."; | 964 "NACK+ULPFEC is a waste of bandwidth since ULPFEC packets " |
959 ulpfec_payload_type = -1; | 965 "also have to be retransmitted. Disabling ULPFEC."; |
| 966 DisableUlpfec(); |
960 } | 967 } |
961 | 968 |
962 // TODO(brandtr): Remove the workaround described below. | 969 // Verify payload types. |
963 // | 970 // |
964 // In theory, we should enable RED if and only if ULPFEC is also enabled, | 971 // Due to how old receivers work, we need to always send RED if it has been |
965 // and vice versa. (We only support ULPFEC over RED, not multiplexed in any | 972 // negotiated. This is a remnant of an old RED/RTX workaround, see |
966 // other way.) However, due to the RED/RTX workaround introduced here: | 973 // https://codereview.webrtc.org/2469093003. |
967 // https://codereview.webrtc.org/1649493004, we need to send media over RED | 974 // TODO(brandtr): This change went into M56, so we can remove it in ~M59. |
968 // (even if ULPFEC is disabled), whenever RED has been negotiated in the SDP. | 975 // At that time, we can disable RED whenever ULPFEC is disabled, as there is |
969 // This is due to the associated payload type is hardcoded to be RED in the | 976 // no point in using RED without ULPFEC. |
970 // receiver, whenever RED appears in the SDP. If we would not send media over | 977 if (IsRedEnabled()) { |
971 // RED in this case, the RTX receiver would recover retransmitted packets | |
972 // using the wrong payload type. | |
973 | |
974 // Verify validity of provided payload types. | |
975 if (red_payload_type != -1) { | |
976 RTC_DCHECK_GE(red_payload_type, 0); | 978 RTC_DCHECK_GE(red_payload_type, 0); |
977 RTC_DCHECK_LE(red_payload_type, 127); | 979 RTC_DCHECK_LE(red_payload_type, 127); |
978 } | 980 } |
979 if (ulpfec_payload_type != -1) { | 981 if (IsUlpfecEnabled()) { |
980 RTC_DCHECK_GE(ulpfec_payload_type, 0); | 982 RTC_DCHECK_GE(ulpfec_payload_type, 0); |
981 RTC_DCHECK_LE(ulpfec_payload_type, 127); | 983 RTC_DCHECK_LE(ulpfec_payload_type, 127); |
| 984 if (!IsRedEnabled()) { |
| 985 LOG(LS_WARNING) |
| 986 << "ULPFEC is enabled but RED is disabled. Disabling ULPFEC."; |
| 987 DisableUlpfec(); |
| 988 } |
982 } | 989 } |
983 | 990 |
984 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 991 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
985 // Set NACK. | 992 // Set NACK. |
986 rtp_rtcp->SetStorePacketsStatus( | 993 rtp_rtcp->SetStorePacketsStatus( |
987 enable_protection_nack || congestion_controller_->pacer(), | 994 nack_enabled || congestion_controller_->pacer(), |
988 kMinSendSidePacketHistorySize); | 995 kMinSendSidePacketHistorySize); |
989 // Set FEC. | 996 // Set RED/ULPFEC information. |
990 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 997 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
991 rtp_rtcp->SetUlpfecConfig(red_payload_type, ulpfec_payload_type); | 998 rtp_rtcp->SetUlpfecConfig(red_payload_type, ulpfec_payload_type); |
992 } | 999 } |
993 } | 1000 } |
994 | 1001 |
995 const bool enable_protection_fec = (ulpfec_payload_type != -1); | 1002 protection_bitrate_calculator_.SetProtectionMethod(IsUlpfecEnabled(), |
996 protection_bitrate_calculator_.SetProtectionMethod(enable_protection_fec, | 1003 nack_enabled); |
997 enable_protection_nack); | |
998 } | 1004 } |
999 | 1005 |
1000 void VideoSendStreamImpl::ConfigureSsrcs() { | 1006 void VideoSendStreamImpl::ConfigureSsrcs() { |
1001 RTC_DCHECK_RUN_ON(worker_queue_); | 1007 RTC_DCHECK_RUN_ON(worker_queue_); |
1002 // Configure regular SSRCs. | 1008 // Configure regular SSRCs. |
1003 for (size_t i = 0; i < config_->rtp.ssrcs.size(); ++i) { | 1009 for (size_t i = 0; i < config_->rtp.ssrcs.size(); ++i) { |
1004 uint32_t ssrc = config_->rtp.ssrcs[i]; | 1010 uint32_t ssrc = config_->rtp.ssrcs[i]; |
1005 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; | 1011 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; |
1006 rtp_rtcp->SetSSRC(ssrc); | 1012 rtp_rtcp->SetSSRC(ssrc); |
1007 | 1013 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 } | 1139 } |
1134 | 1140 |
1135 void VideoSendStreamImpl::SetTransportOverhead( | 1141 void VideoSendStreamImpl::SetTransportOverhead( |
1136 int transport_overhead_per_packet) { | 1142 int transport_overhead_per_packet) { |
1137 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 1143 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
1138 rtp_rtcp->SetTransportOverhead(transport_overhead_per_packet); | 1144 rtp_rtcp->SetTransportOverhead(transport_overhead_per_packet); |
1139 } | 1145 } |
1140 | 1146 |
1141 } // namespace internal | 1147 } // namespace internal |
1142 } // namespace webrtc | 1148 } // namespace webrtc |
OLD | NEW |