OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 // clock for the RTP timestamps. (This is according to the RFC, which states | 31 // clock for the RTP timestamps. (This is according to the RFC, which states |
32 // that it is RECOMMENDED to use the same clock frequency for FlexFEC as for | 32 // that it is RECOMMENDED to use the same clock frequency for FlexFEC as for |
33 // the protected media stream.) | 33 // the protected media stream.) |
34 // The constant converts from clock millisecond timestamps to the 90 kHz | 34 // The constant converts from clock millisecond timestamps to the 90 kHz |
35 // RTP timestamp. | 35 // RTP timestamp. |
36 const int kMsToRtpTimestamp = kVideoPayloadTypeFrequency / 1000; | 36 const int kMsToRtpTimestamp = kVideoPayloadTypeFrequency / 1000; |
37 | 37 |
38 // How often to log the generated FEC packets to the text log. | 38 // How often to log the generated FEC packets to the text log. |
39 constexpr int64_t kPacketLogIntervalMs = 10000; | 39 constexpr int64_t kPacketLogIntervalMs = 10000; |
40 | 40 |
| 41 RtpHeaderExtensionMap RegisterBweExtensions( |
| 42 const std::vector<RtpExtension>& rtp_header_extensions) { |
| 43 RtpHeaderExtensionMap map; |
| 44 for (const auto& extension : rtp_header_extensions) { |
| 45 if (extension.uri == TransportSequenceNumber::kUri) { |
| 46 map.Register<TransportSequenceNumber>(extension.id); |
| 47 } else if (extension.uri == AbsoluteSendTime::kUri) { |
| 48 map.Register<AbsoluteSendTime>(extension.id); |
| 49 } else if (extension.uri == TransmissionOffset::kUri) { |
| 50 map.Register<TransmissionOffset>(extension.id); |
| 51 } else { |
| 52 LOG(LS_INFO) << "FlexfecSender only supports RTP header extensions for " |
| 53 << "BWE, so the extension " << extension.ToString() |
| 54 << " will not be used."; |
| 55 } |
| 56 } |
| 57 return map; |
| 58 } |
| 59 |
41 } // namespace | 60 } // namespace |
42 | 61 |
43 FlexfecSender::FlexfecSender( | 62 FlexfecSender::FlexfecSender( |
44 int payload_type, | 63 int payload_type, |
45 uint32_t ssrc, | 64 uint32_t ssrc, |
46 uint32_t protected_media_ssrc, | 65 uint32_t protected_media_ssrc, |
47 const std::vector<RtpExtension>& rtp_header_extensions, | 66 const std::vector<RtpExtension>& rtp_header_extensions, |
48 Clock* clock) | 67 Clock* clock) |
49 : clock_(clock), | 68 : clock_(clock), |
50 random_(clock_->TimeInMicroseconds()), | 69 random_(clock_->TimeInMicroseconds()), |
51 last_generated_packet_ms_(-1), | 70 last_generated_packet_ms_(-1), |
52 payload_type_(payload_type), | 71 payload_type_(payload_type), |
53 // Initialize the timestamp offset and RTP sequence numbers randomly. | 72 // Initialize the timestamp offset and RTP sequence numbers randomly. |
54 // (This is not intended to be cryptographically strong.) | 73 // (This is not intended to be cryptographically strong.) |
55 timestamp_offset_(random_.Rand<uint32_t>()), | 74 timestamp_offset_(random_.Rand<uint32_t>()), |
56 ssrc_(ssrc), | 75 ssrc_(ssrc), |
57 protected_media_ssrc_(protected_media_ssrc), | 76 protected_media_ssrc_(protected_media_ssrc), |
58 seq_num_(random_.Rand(1, kMaxInitRtpSeqNumber)), | 77 seq_num_(random_.Rand(1, kMaxInitRtpSeqNumber)), |
59 ulpfec_generator_(ForwardErrorCorrection::CreateFlexfec()), | 78 ulpfec_generator_(ForwardErrorCorrection::CreateFlexfec()), |
60 rtp_header_extension_map_() { | 79 rtp_header_extension_map_(RegisterBweExtensions(rtp_header_extensions)) { |
61 // This object should not have been instantiated if FlexFEC is disabled. | 80 // This object should not have been instantiated if FlexFEC is disabled. |
62 RTC_DCHECK_GE(payload_type, 0); | 81 RTC_DCHECK_GE(payload_type, 0); |
63 RTC_DCHECK_LE(payload_type, 127); | 82 RTC_DCHECK_LE(payload_type, 127); |
64 | 83 |
65 // It's OK to create this object on a different thread/task queue than | 84 // It's OK to create this object on a different thread/task queue than |
66 // the one used during main operation. | 85 // the one used during main operation. |
67 sequence_checker_.Detach(); | 86 sequence_checker_.Detach(); |
68 | |
69 // Register RTP header extensions for BWE. | |
70 for (const auto& extension : rtp_header_extensions) { | |
71 if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | |
72 rtp_header_extension_map_.Register(kRtpExtensionTransportSequenceNumber, | |
73 extension.id); | |
74 } else if (extension.uri == RtpExtension::kAbsSendTimeUri) { | |
75 rtp_header_extension_map_.Register(kRtpExtensionAbsoluteSendTime, | |
76 extension.id); | |
77 } else if (extension.uri == RtpExtension::kTimestampOffsetUri) { | |
78 rtp_header_extension_map_.Register(kRtpExtensionTransmissionTimeOffset, | |
79 extension.id); | |
80 } else { | |
81 LOG(LS_WARNING) << "RTP header extension with id: " << extension.id | |
82 << ", uri: " << extension.uri | |
83 << ", is unsupported by FlexfecSender."; | |
84 } | |
85 } | |
86 } | 87 } |
87 | 88 |
88 FlexfecSender::~FlexfecSender() = default; | 89 FlexfecSender::~FlexfecSender() = default; |
89 | 90 |
90 // We are reusing the implementation from UlpfecGenerator for SetFecParameters, | 91 // We are reusing the implementation from UlpfecGenerator for SetFecParameters, |
91 // AddRtpPacketAndGenerateFec, and FecAvailable. | 92 // AddRtpPacketAndGenerateFec, and FecAvailable. |
92 void FlexfecSender::SetFecParameters(const FecProtectionParams& params) { | 93 void FlexfecSender::SetFecParameters(const FecProtectionParams& params) { |
93 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 94 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); |
94 ulpfec_generator_.SetFecParameters(params); | 95 ulpfec_generator_.SetFecParameters(params); |
95 } | 96 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 now_ms - last_generated_packet_ms_ > kPacketLogIntervalMs) { | 152 now_ms - last_generated_packet_ms_ > kPacketLogIntervalMs) { |
152 LOG(LS_INFO) << "Generated " << fec_packets_to_send.size() | 153 LOG(LS_INFO) << "Generated " << fec_packets_to_send.size() |
153 << " FlexFEC packets with payload type: " << payload_type_ | 154 << " FlexFEC packets with payload type: " << payload_type_ |
154 << " and SSRC: " << ssrc_ << "."; | 155 << " and SSRC: " << ssrc_ << "."; |
155 last_generated_packet_ms_ = now_ms; | 156 last_generated_packet_ms_ = now_ms; |
156 } | 157 } |
157 | 158 |
158 return fec_packets_to_send; | 159 return fec_packets_to_send; |
159 } | 160 } |
160 | 161 |
| 162 // The overhead is BWE RTP header extensions and FlexFEC header. |
161 size_t FlexfecSender::MaxPacketOverhead() const { | 163 size_t FlexfecSender::MaxPacketOverhead() const { |
162 return kFlexfecMaxHeaderSize; | 164 return rtp_header_extension_map_.GetTotalLengthInBytes() + |
| 165 kFlexfecMaxHeaderSize; |
163 } | 166 } |
164 | 167 |
165 } // namespace webrtc | 168 } // namespace webrtc |
OLD | NEW |