Make capture timestamp optional in ADM.
This is to avoid using 0 as a default value. Also fix a bug in audio_device_buffer where the timestamp aligner used the wrong input timestamp. Bug: webrtc:13609 Change-Id: I00016e68ab50d052990c2b9f80aa1e2d7e167b93 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291118 Reviewed-by: Olov Brändström <brandstrom@google.com> Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39177}
This commit is contained in:
parent
6e627290bf
commit
22821deb38
@ -107,35 +107,35 @@ AudioTransportImpl::~AudioTransportImpl() {}
|
||||
|
||||
int32_t AudioTransportImpl::RecordedDataIsAvailable(
|
||||
const void* audio_data,
|
||||
const size_t number_of_frames,
|
||||
const size_t bytes_per_sample,
|
||||
const size_t number_of_channels,
|
||||
const uint32_t sample_rate,
|
||||
const uint32_t audio_delay_milliseconds,
|
||||
const int32_t clock_drift,
|
||||
const uint32_t volume,
|
||||
const bool key_pressed,
|
||||
size_t number_of_frames,
|
||||
size_t bytes_per_sample,
|
||||
size_t number_of_channels,
|
||||
uint32_t sample_rate,
|
||||
uint32_t audio_delay_milliseconds,
|
||||
int32_t clock_drift,
|
||||
uint32_t volume,
|
||||
bool key_pressed,
|
||||
uint32_t& new_mic_volume) { // NOLINT: to avoid changing APIs
|
||||
return RecordedDataIsAvailable(
|
||||
audio_data, number_of_frames, bytes_per_sample, number_of_channels,
|
||||
sample_rate, audio_delay_milliseconds, clock_drift, volume, key_pressed,
|
||||
new_mic_volume, /* estimated_capture_time_ns */ 0);
|
||||
new_mic_volume, /*estimated_capture_time_ns=*/absl::nullopt);
|
||||
}
|
||||
|
||||
// Not used in Chromium. Process captured audio and distribute to all sending
|
||||
// streams, and try to do this at the lowest possible sample rate.
|
||||
int32_t AudioTransportImpl::RecordedDataIsAvailable(
|
||||
const void* audio_data,
|
||||
const size_t number_of_frames,
|
||||
const size_t bytes_per_sample,
|
||||
const size_t number_of_channels,
|
||||
const uint32_t sample_rate,
|
||||
const uint32_t audio_delay_milliseconds,
|
||||
const int32_t /*clock_drift*/,
|
||||
const uint32_t /*volume*/,
|
||||
const bool key_pressed,
|
||||
size_t number_of_frames,
|
||||
size_t bytes_per_sample,
|
||||
size_t number_of_channels,
|
||||
uint32_t sample_rate,
|
||||
uint32_t audio_delay_milliseconds,
|
||||
int32_t /*clock_drift*/,
|
||||
uint32_t /*volume*/,
|
||||
bool key_pressed,
|
||||
uint32_t& /*new_mic_volume*/,
|
||||
const int64_t
|
||||
absl::optional<int64_t>
|
||||
estimated_capture_time_ns) { // NOLINT: to avoid changing APIs
|
||||
RTC_DCHECK(audio_data);
|
||||
RTC_DCHECK_GE(number_of_channels, 1);
|
||||
@ -166,8 +166,11 @@ int32_t AudioTransportImpl::RecordedDataIsAvailable(
|
||||
ProcessCaptureFrame(audio_delay_milliseconds, key_pressed,
|
||||
swap_stereo_channels, audio_processing_,
|
||||
audio_frame.get());
|
||||
audio_frame->set_absolute_capture_timestamp_ms(estimated_capture_time_ns /
|
||||
|
||||
if (estimated_capture_time_ns) {
|
||||
audio_frame->set_absolute_capture_timestamp_ms(*estimated_capture_time_ns /
|
||||
1000000);
|
||||
}
|
||||
|
||||
RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0);
|
||||
if (async_audio_processing_)
|
||||
|
||||
@ -52,7 +52,8 @@ class AudioTransportImpl : public AudioTransport {
|
||||
bool keyPressed,
|
||||
uint32_t& newMicLevel) override;
|
||||
|
||||
int32_t RecordedDataIsAvailable(const void* audioSamples,
|
||||
int32_t RecordedDataIsAvailable(
|
||||
const void* audioSamples,
|
||||
size_t nSamples,
|
||||
size_t nBytesPerSample,
|
||||
size_t nChannels,
|
||||
@ -62,7 +63,7 @@ class AudioTransportImpl : public AudioTransport {
|
||||
uint32_t currentMicLevel,
|
||||
bool keyPressed,
|
||||
uint32_t& newMicLevel,
|
||||
int64_t estimated_capture_time_ns) override;
|
||||
absl::optional<int64_t> estimated_capture_time_ns) override;
|
||||
|
||||
int32_t NeedMorePlayData(size_t nSamples,
|
||||
size_t nBytesPerSample,
|
||||
|
||||
@ -55,7 +55,6 @@ AudioDeviceBuffer::AudioDeviceBuffer(TaskQueueFactory* task_queue_factory)
|
||||
typing_status_(false),
|
||||
play_delay_ms_(0),
|
||||
rec_delay_ms_(0),
|
||||
capture_timestamp_ns_(0),
|
||||
num_stat_reports_(0),
|
||||
last_timer_task_time_(0),
|
||||
rec_stat_count_(0),
|
||||
@ -231,12 +230,13 @@ void AudioDeviceBuffer::SetVQEData(int play_delay_ms, int rec_delay_ms) {
|
||||
|
||||
int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audio_buffer,
|
||||
size_t samples_per_channel) {
|
||||
return SetRecordedBuffer(audio_buffer, samples_per_channel, 0);
|
||||
return SetRecordedBuffer(audio_buffer, samples_per_channel, absl::nullopt);
|
||||
}
|
||||
|
||||
int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audio_buffer,
|
||||
int32_t AudioDeviceBuffer::SetRecordedBuffer(
|
||||
const void* audio_buffer,
|
||||
size_t samples_per_channel,
|
||||
int64_t capture_timestamp_ns) {
|
||||
absl::optional<int64_t> capture_timestamp_ns) {
|
||||
// Copy the complete input buffer to the local buffer.
|
||||
const size_t old_size = rec_buffer_.size();
|
||||
rec_buffer_.SetData(static_cast<const int16_t*>(audio_buffer),
|
||||
@ -247,17 +247,13 @@ int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audio_buffer,
|
||||
RTC_LOG(LS_INFO) << "Size of recording buffer: " << rec_buffer_.size();
|
||||
}
|
||||
|
||||
// If the timestamp is less then or equal to zero, it's not valid and are
|
||||
// ignored. If we do antimestamp alignment on them they might accidentally
|
||||
// become greater then zero, and will be handled as if they were a correct
|
||||
// timestamp.
|
||||
if (capture_timestamp_ns) {
|
||||
capture_timestamp_ns_ =
|
||||
(capture_timestamp_ns > 0)
|
||||
? rtc::kNumNanosecsPerMicrosec *
|
||||
rtc::kNumNanosecsPerMicrosec *
|
||||
timestamp_aligner_.TranslateTimestamp(
|
||||
capture_timestamp_ns_ / rtc::kNumNanosecsPerMicrosec,
|
||||
rtc::TimeMicros())
|
||||
: capture_timestamp_ns;
|
||||
*capture_timestamp_ns / rtc::kNumNanosecsPerMicrosec,
|
||||
rtc::TimeMicros());
|
||||
}
|
||||
// Derive a new level value twice per second and check if it is non-zero.
|
||||
int16_t max_abs = 0;
|
||||
RTC_DCHECK_LT(rec_stat_count_, 50);
|
||||
|
||||
@ -102,9 +102,10 @@ class AudioDeviceBuffer {
|
||||
virtual int32_t SetRecordedBuffer(const void* audio_buffer,
|
||||
size_t samples_per_channel);
|
||||
|
||||
virtual int32_t SetRecordedBuffer(const void* audio_buffer,
|
||||
virtual int32_t SetRecordedBuffer(
|
||||
const void* audio_buffer,
|
||||
size_t samples_per_channel,
|
||||
int64_t capture_timestamp_ns);
|
||||
absl::optional<int64_t> capture_timestamp_ns);
|
||||
virtual void SetVQEData(int play_delay_ms, int rec_delay_ms);
|
||||
virtual int32_t DeliverRecordedData();
|
||||
uint32_t NewMicLevel() const;
|
||||
@ -194,7 +195,7 @@ class AudioDeviceBuffer {
|
||||
int rec_delay_ms_;
|
||||
|
||||
// Capture timestamp.
|
||||
int64_t capture_timestamp_ns_;
|
||||
absl::optional<int64_t> capture_timestamp_ns_;
|
||||
|
||||
// Counts number of times LogStats() has been called.
|
||||
size_t num_stat_reports_ RTC_GUARDED_BY(task_queue_);
|
||||
|
||||
@ -55,14 +55,15 @@ class ADMWrapper : public AudioDeviceModule, public AudioTransport {
|
||||
uint32_t currentMicLevel,
|
||||
bool keyPressed,
|
||||
uint32_t& newMicLevel) override {
|
||||
return RecordedDataIsAvailable(audioSamples, nSamples, nBytesPerSample,
|
||||
nChannels, samples_per_sec, total_delay_ms,
|
||||
clockDrift, currentMicLevel, keyPressed,
|
||||
newMicLevel, /*capture_timestamp_ns*/ 0);
|
||||
return RecordedDataIsAvailable(
|
||||
audioSamples, nSamples, nBytesPerSample, nChannels, samples_per_sec,
|
||||
total_delay_ms, clockDrift, currentMicLevel, keyPressed, newMicLevel,
|
||||
/*capture_timestamp_ns=*/absl::nullopt);
|
||||
}
|
||||
|
||||
// AudioTransport methods overrides.
|
||||
int32_t RecordedDataIsAvailable(const void* audioSamples,
|
||||
int32_t RecordedDataIsAvailable(
|
||||
const void* audioSamples,
|
||||
size_t nSamples,
|
||||
size_t nBytesPerSample,
|
||||
size_t nChannels,
|
||||
@ -72,7 +73,7 @@ class ADMWrapper : public AudioDeviceModule, public AudioTransport {
|
||||
uint32_t currentMicLevel,
|
||||
bool keyPressed,
|
||||
uint32_t& newMicLevel,
|
||||
int64_t capture_timestamp_ns) override {
|
||||
absl::optional<int64_t> capture_timestamp_ns) override {
|
||||
int32_t res = 0;
|
||||
// Capture PCM data of locally captured audio.
|
||||
if (observer_) {
|
||||
|
||||
@ -56,7 +56,7 @@ class AudioTransport {
|
||||
uint32_t currentMicLevel,
|
||||
bool keyPressed,
|
||||
uint32_t& newMicLevel,
|
||||
int64_t estimatedCaptureTimeNS) { // NOLINT
|
||||
absl::optional<int64_t> estimatedCaptureTimeNS) { // NOLINT
|
||||
// TODO(webrtc:13620) Make the default behaver of the new API to behave as
|
||||
// the old API. This can be pure virtual if all uses of the old API is
|
||||
// removed.
|
||||
|
||||
@ -48,7 +48,7 @@ class MockAudioTransport : public AudioTransport {
|
||||
uint32_t currentMicLevel,
|
||||
bool keyPressed,
|
||||
uint32_t& newMicLevel,
|
||||
int64_t estimated_capture_time_ns),
|
||||
absl::optional<int64_t> estimated_capture_time_ns),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(int32_t,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user