Skip to content

Commit 5227584

Browse files
DanilChapovalovWebRTC LUCI CQ
authored andcommitted
Use Timestamp type instead of int64_t in Flexfec classes
Bug: webrtc:13757 Change-Id: Ideafea65adb827b5457de22a04e3235cda3ffd5c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/301260 Commit-Queue: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Auto-Submit: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39948}
1 parent b035dcc commit 5227584

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

modules/rtp_rtcp/include/flexfec_receiver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <memory>
1717

1818
#include "api/sequence_checker.h"
19+
#include "api/units/timestamp.h"
1920
#include "modules/rtp_rtcp/include/recovered_packet_receiver.h"
2021
#include "modules/rtp_rtcp/source/forward_error_correction.h"
2122
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
@@ -67,7 +68,8 @@ class FlexfecReceiver {
6768

6869
// Logging and stats.
6970
Clock* const clock_;
70-
int64_t last_recovered_packet_ms_ RTC_GUARDED_BY(sequence_checker_);
71+
Timestamp last_recovered_packet_ RTC_GUARDED_BY(sequence_checker_) =
72+
Timestamp::MinusInfinity();
7173
FecPacketCounter packet_counter_ RTC_GUARDED_BY(sequence_checker_);
7274

7375
RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;

modules/rtp_rtcp/include/flexfec_sender.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "absl/strings/string_view.h"
1919
#include "api/array_view.h"
2020
#include "api/rtp_parameters.h"
21+
#include "api/units/timestamp.h"
2122
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
2223
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
2324
#include "modules/rtp_rtcp/source/rtp_header_extension_size.h"
@@ -77,7 +78,7 @@ class FlexfecSender : public VideoFecGenerator {
7778
// Utility.
7879
Clock* const clock_;
7980
Random random_;
80-
int64_t last_generated_packet_ms_;
81+
Timestamp last_generated_packet_ = Timestamp::MinusInfinity();
8182

8283
// Config.
8384
const int payload_type_;

modules/rtp_rtcp/source/flexfec_receiver.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "api/array_view.h"
1616
#include "api/scoped_refptr.h"
17+
#include "api/units/time_delta.h"
18+
#include "api/units/timestamp.h"
1719
#include "rtc_base/checks.h"
1820
#include "rtc_base/logging.h"
1921

@@ -25,7 +27,7 @@ namespace {
2527
constexpr size_t kMinFlexfecHeaderSize = 20;
2628

2729
// How often to log the recovered packets to the text log.
28-
constexpr int kPacketLogIntervalMs = 10000;
30+
constexpr TimeDelta kPacketLogInterval = TimeDelta::Seconds(10);
2931

3032
} // namespace
3133

@@ -48,8 +50,7 @@ FlexfecReceiver::FlexfecReceiver(
4850
erasure_code_(
4951
ForwardErrorCorrection::CreateFlexfec(ssrc, protected_media_ssrc)),
5052
recovered_packet_receiver_(recovered_packet_receiver),
51-
clock_(clock),
52-
last_recovered_packet_ms_(-1) {
53+
clock_(clock) {
5354
// It's OK to create this object on a different thread/task queue than
5455
// the one used during main operation.
5556
sequence_checker_.Detach();
@@ -173,9 +174,9 @@ void FlexfecReceiver::ProcessReceivedPacket(
173174
recovered_packet_receiver_->OnRecoveredPacket(parsed_packet);
174175

175176
// Periodically log the incoming packets at LS_INFO.
176-
int64_t now_ms = clock_->TimeInMilliseconds();
177+
Timestamp now = clock_->CurrentTime();
177178
bool should_log_periodically =
178-
now_ms - last_recovered_packet_ms_ > kPacketLogIntervalMs;
179+
now - last_recovered_packet_ > kPacketLogInterval;
179180
if (RTC_LOG_CHECK_LEVEL(LS_VERBOSE) || should_log_periodically) {
180181
rtc::LoggingSeverity level =
181182
should_log_periodically ? rtc::LS_INFO : rtc::LS_VERBOSE;
@@ -185,7 +186,7 @@ void FlexfecReceiver::ProcessReceivedPacket(
185186
<< recovered_packet->pkt->data.size()
186187
<< " from FlexFEC stream with SSRC: " << ssrc_;
187188
if (should_log_periodically) {
188-
last_recovered_packet_ms_ = now_ms;
189+
last_recovered_packet_ = now;
189190
}
190191
}
191192
}

modules/rtp_rtcp/source/flexfec_sender.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <utility>
1717

1818
#include "absl/strings/string_view.h"
19+
#include "api/units/time_delta.h"
20+
#include "api/units/timestamp.h"
1921
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
2022
#include "modules/rtp_rtcp/source/forward_error_correction.h"
2123
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
@@ -42,7 +44,7 @@ constexpr size_t kFlexfecMaxHeaderSize = 32;
4244
const int kMsToRtpTimestamp = kVideoPayloadTypeFrequency / 1000;
4345

4446
// How often to log the generated FEC packets to the text log.
45-
constexpr int64_t kPacketLogIntervalMs = 10000;
47+
constexpr TimeDelta kPacketLogInterval = TimeDelta::Seconds(10);
4648

4749
RtpHeaderExtensionMap RegisterSupportedExtensions(
4850
const std::vector<RtpExtension>& rtp_header_extensions) {
@@ -79,7 +81,6 @@ FlexfecSender::FlexfecSender(
7981
Clock* clock)
8082
: clock_(clock),
8183
random_(clock_->TimeInMicroseconds()),
82-
last_generated_packet_ms_(-1),
8384
payload_type_(payload_type),
8485
// Reset RTP state if this is not the first time we are operating.
8586
// Otherwise, randomize the initial timestamp offset and RTP sequence
@@ -168,17 +169,17 @@ std::vector<std::unique_ptr<RtpPacketToSend>> FlexfecSender::GetFecPackets() {
168169
ulpfec_generator_.ResetState();
169170
}
170171

171-
int64_t now_ms = clock_->TimeInMilliseconds();
172+
Timestamp now = clock_->CurrentTime();
172173
if (!fec_packets_to_send.empty() &&
173-
now_ms - last_generated_packet_ms_ > kPacketLogIntervalMs) {
174+
now - last_generated_packet_ > kPacketLogInterval) {
174175
RTC_LOG(LS_VERBOSE) << "Generated " << fec_packets_to_send.size()
175176
<< " FlexFEC packets with payload type: "
176177
<< payload_type_ << " and SSRC: " << ssrc_ << ".";
177-
last_generated_packet_ms_ = now_ms;
178+
last_generated_packet_ = now;
178179
}
179180

180181
MutexLock lock(&mutex_);
181-
fec_bitrate_.Update(total_fec_data_bytes, now_ms);
182+
fec_bitrate_.Update(total_fec_data_bytes, now.ms());
182183

183184
return fec_packets_to_send;
184185
}

0 commit comments

Comments
 (0)