Prevent warnings from timestamp aligner used in AudioDeviceBuffer

The logcat is spammed with warnings from timestamp aligner.
This CL make a workaround to use the timestamp aligner to get capture times,
without generating the warnings.

Bug: webrtc:14970
Change-Id: Idab4b298e0484a57841a214db9440f9ac6faaa4d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/296324
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Olov Brändström <brandstrom@google.com>
Cr-Commit-Position: refs/heads/main@{#39486}
This commit is contained in:
Olov Brändström 2023-03-06 14:15:37 +01:00 committed by Rashad Sookram
parent 3f71b5a8b3
commit 7bf1cd341a
4 changed files with 33 additions and 6 deletions

View file

@ -248,11 +248,28 @@ int32_t AudioDeviceBuffer::SetRecordedBuffer(
}
if (capture_timestamp_ns) {
capture_timestamp_ns_ =
rtc::kNumNanosecsPerMicrosec *
timestamp_aligner_.TranslateTimestamp(
*capture_timestamp_ns / rtc::kNumNanosecsPerMicrosec,
rtc::TimeMicros());
int64_t align_offsync_estimation_time = rtc::TimeMicros();
if (align_offsync_estimation_time -
rtc::TimestampAligner::kMinFrameIntervalUs >
align_offsync_estimation_time_) {
align_offsync_estimation_time_ = align_offsync_estimation_time;
capture_timestamp_ns_ =
rtc::kNumNanosecsPerMicrosec *
timestamp_aligner_.TranslateTimestamp(
*capture_timestamp_ns / rtc::kNumNanosecsPerMicrosec,
align_offsync_estimation_time);
} else {
// The Timestamp aligner is designed to prevent timestamps that are too
// similar, and produces warnings if it is called to often. We do not care
// about that here, so we do this workaround. If we where to call the
// aligner within a millisecond, we instead call this, that do not update
// the clock offset estimation. This get us timestamps without generating
// warnings, but could generate two timestamps within a millisecond.
capture_timestamp_ns_ =
rtc::kNumNanosecsPerMicrosec *
timestamp_aligner_.TranslateTimestamp(*capture_timestamp_ns /
rtc::kNumNanosecsPerMicrosec);
}
}
// Derive a new level value twice per second and check if it is non-zero.
int16_t max_abs = 0;

View file

@ -196,6 +196,10 @@ class AudioDeviceBuffer {
// Capture timestamp.
absl::optional<int64_t> capture_timestamp_ns_;
// The last time the Timestamp Aligner was used to estimate clock offset
// between system clock and capture time from audio.
// This is used to prevent estimating the clock offset too often.
absl::optional<int64_t> align_offsync_estimation_time_;
// Counts number of times LogStats() has been called.
size_t num_stat_reports_ RTC_GUARDED_BY(task_queue_);

View file

@ -112,7 +112,6 @@ int64_t TimestampAligner::UpdateOffset(int64_t capturer_time_us,
int64_t TimestampAligner::ClipTimestamp(int64_t filtered_time_us,
int64_t system_time_us) {
const int64_t kMinFrameIntervalUs = rtc::kNumMicrosecsPerMillisec;
// Clip to make sure we don't produce timestamps in the future.
int64_t time_us = filtered_time_us - clip_bias_us_;
if (time_us > system_time_us) {

View file

@ -14,6 +14,7 @@
#include <stdint.h>
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/time_utils.h"
namespace rtc {
@ -38,6 +39,12 @@ class RTC_EXPORT TimestampAligner {
TimestampAligner& operator=(const TimestampAligner&) = delete;
public:
// Minimum difference of two timestamps generated by
// "TranslateTimestamp(int64_t capturer_time_us, int64_t system_time_us)"
// This avoids the caller from getting two timestamps with the same
// millisecond.
static constexpr int64_t kMinFrameIntervalUs = rtc::kNumMicrosecsPerMillisec;
// Translates timestamps of a capture system to the same timescale as is used
// by rtc::TimeMicros(). `capturer_time_us` is assumed to be accurate, but
// with an unknown epoch and clock drift. `system_time_us` is