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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // (This is not intended to be cryptographically strong.) | 73 // (This is not intended to be cryptographically strong.) |
74 timestamp_offset_(random_.Rand<uint32_t>()), | 74 timestamp_offset_(random_.Rand<uint32_t>()), |
75 ssrc_(ssrc), | 75 ssrc_(ssrc), |
76 protected_media_ssrc_(protected_media_ssrc), | 76 protected_media_ssrc_(protected_media_ssrc), |
77 seq_num_(random_.Rand(1, kMaxInitRtpSeqNumber)), | 77 seq_num_(random_.Rand(1, kMaxInitRtpSeqNumber)), |
78 ulpfec_generator_(ForwardErrorCorrection::CreateFlexfec()), | 78 ulpfec_generator_(ForwardErrorCorrection::CreateFlexfec()), |
79 rtp_header_extension_map_(RegisterBweExtensions(rtp_header_extensions)) { | 79 rtp_header_extension_map_(RegisterBweExtensions(rtp_header_extensions)) { |
80 // This object should not have been instantiated if FlexFEC is disabled. | 80 // This object should not have been instantiated if FlexFEC is disabled. |
81 RTC_DCHECK_GE(payload_type, 0); | 81 RTC_DCHECK_GE(payload_type, 0); |
82 RTC_DCHECK_LE(payload_type, 127); | 82 RTC_DCHECK_LE(payload_type, 127); |
83 | |
84 // It's OK to create this object on a different thread/task queue than | |
85 // the one used during main operation. | |
86 sequence_checker_.Detach(); | |
87 } | 83 } |
88 | 84 |
89 FlexfecSender::~FlexfecSender() = default; | 85 FlexfecSender::~FlexfecSender() = default; |
90 | 86 |
91 // We are reusing the implementation from UlpfecGenerator for SetFecParameters, | 87 // We are reusing the implementation from UlpfecGenerator for SetFecParameters, |
92 // AddRtpPacketAndGenerateFec, and FecAvailable. | 88 // AddRtpPacketAndGenerateFec, and FecAvailable. |
93 void FlexfecSender::SetFecParameters(const FecProtectionParams& params) { | 89 void FlexfecSender::SetFecParameters(const FecProtectionParams& params) { |
94 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 90 rtc::CritScope cs(&crit_sect_); |
95 ulpfec_generator_.SetFecParameters(params); | 91 ulpfec_generator_.SetFecParameters(params); |
96 } | 92 } |
97 | 93 |
98 bool FlexfecSender::AddRtpPacketAndGenerateFec( | 94 bool FlexfecSender::AddRtpPacketAndGenerateFec( |
99 const RtpPacketToSend& packet) { | 95 const RtpPacketToSend& packet) { |
100 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 96 rtc::CritScope cs(&crit_sect_); |
101 // TODO(brandtr): Generalize this SSRC check when we support multistream | 97 // TODO(brandtr): Generalize this SSRC check when we support multistream |
102 // protection. | 98 // protection. |
103 RTC_DCHECK_EQ(packet.Ssrc(), protected_media_ssrc_); | 99 RTC_DCHECK_EQ(packet.Ssrc(), protected_media_ssrc_); |
104 return ulpfec_generator_.AddRtpPacketAndGenerateFec( | 100 return ulpfec_generator_.AddRtpPacketAndGenerateFec( |
105 packet.data(), packet.payload_size(), packet.headers_size()) == 0; | 101 packet.data(), packet.payload_size(), packet.headers_size()) == 0; |
106 } | 102 } |
107 | 103 |
108 bool FlexfecSender::FecAvailable() const { | 104 bool FlexfecSender::FecAvailable() const { |
109 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 105 rtc::CritScope cs(&crit_sect_); |
110 return ulpfec_generator_.FecAvailable(); | 106 return ulpfec_generator_.FecAvailable(); |
111 } | 107 } |
112 | 108 |
113 std::vector<std::unique_ptr<RtpPacketToSend>> | 109 std::vector<std::unique_ptr<RtpPacketToSend>> |
114 FlexfecSender::GetFecPackets() { | 110 FlexfecSender::GetFecPackets() { |
115 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 111 rtc::CritScope cs(&crit_sect_); |
116 | 112 |
117 std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets_to_send; | 113 std::vector<std::unique_ptr<RtpPacketToSend>> fec_packets_to_send; |
118 fec_packets_to_send.reserve(ulpfec_generator_.generated_fec_packets_.size()); | 114 fec_packets_to_send.reserve(ulpfec_generator_.generated_fec_packets_.size()); |
119 for (const auto& fec_packet : ulpfec_generator_.generated_fec_packets_) { | 115 for (const auto& fec_packet : ulpfec_generator_.generated_fec_packets_) { |
120 std::unique_ptr<RtpPacketToSend> fec_packet_to_send( | 116 std::unique_ptr<RtpPacketToSend> fec_packet_to_send( |
121 new RtpPacketToSend(&rtp_header_extension_map_)); | 117 new RtpPacketToSend(&rtp_header_extension_map_)); |
122 | 118 |
123 // RTP header. | 119 // RTP header. |
124 fec_packet_to_send->SetMarker(false); | 120 fec_packet_to_send->SetMarker(false); |
125 fec_packet_to_send->SetPayloadType(payload_type_); | 121 fec_packet_to_send->SetPayloadType(payload_type_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 return fec_packets_to_send; | 155 return fec_packets_to_send; |
160 } | 156 } |
161 | 157 |
162 // The overhead is BWE RTP header extensions and FlexFEC header. | 158 // The overhead is BWE RTP header extensions and FlexFEC header. |
163 size_t FlexfecSender::MaxPacketOverhead() const { | 159 size_t FlexfecSender::MaxPacketOverhead() const { |
164 return rtp_header_extension_map_.GetTotalLengthInBytes() + | 160 return rtp_header_extension_map_.GetTotalLengthInBytes() + |
165 kFlexfecMaxHeaderSize; | 161 kFlexfecMaxHeaderSize; |
166 } | 162 } |
167 | 163 |
168 } // namespace webrtc | 164 } // namespace webrtc |
OLD | NEW |