Make WebRtcAudioRecord save timestamps
Add timestamps to audio_record_jni DataIsRecorded() function, and make WebRtcAudioRecord find and send the time stamp to that function. This CL is an continuation of https://webrtc-review.googlesource.com/c/src/+/249085 Bug: webrtc:13609 Change-Id: I63ab89f1215893cbe1d11d9d8948f5639fc5cdfe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249951 Reviewed-by: Xavier Lepaul <xalep@webrtc.org> Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Reviewed-by: Minyue Li <minyue@google.com> Commit-Queue: Olov Brändström <brandstrom@google.com> Cr-Commit-Position: refs/heads/main@{#35933}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
98d26df5b7
commit
092d776b7b
@ -17,6 +17,7 @@ import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.AudioRecordingConfiguration;
|
||||
import android.media.AudioTimestamp;
|
||||
import android.media.MediaRecorder.AudioSource;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
@ -130,6 +131,10 @@ class WebRtcAudioRecord {
|
||||
doAudioRecordStateCallback(AUDIO_RECORD_START);
|
||||
|
||||
long lastTime = System.nanoTime();
|
||||
AudioTimestamp audioTimestamp = null;
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
audioTimestamp = new AudioTimestamp();
|
||||
}
|
||||
while (keepAlive) {
|
||||
int bytesRead = audioRecord.read(byteBuffer, byteBuffer.capacity());
|
||||
if (bytesRead == byteBuffer.capacity()) {
|
||||
@ -141,7 +146,14 @@ class WebRtcAudioRecord {
|
||||
// failed to join this thread. To be a bit safer, try to avoid calling any native methods
|
||||
// in case they've been unregistered after stopRecording() returned.
|
||||
if (keepAlive) {
|
||||
nativeDataIsRecorded(nativeAudioRecord, bytesRead);
|
||||
long captureTimeNs = 0;
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if (audioRecord.getTimestamp(audioTimestamp, AudioTimestamp.TIMEBASE_MONOTONIC)
|
||||
== AudioRecord.SUCCESS) {
|
||||
captureTimeNs = audioTimestamp.nanoTime;
|
||||
}
|
||||
}
|
||||
nativeDataIsRecorded(nativeAudioRecord, bytesRead, captureTimeNs);
|
||||
}
|
||||
if (audioSamplesReadyCallback != null) {
|
||||
// Copy the entire byte buffer array. The start of the byteBuffer is not necessarily
|
||||
@ -489,7 +501,8 @@ class WebRtcAudioRecord {
|
||||
|
||||
private native void nativeCacheDirectBufferAddress(
|
||||
long nativeAudioRecordJni, ByteBuffer byteBuffer);
|
||||
private native void nativeDataIsRecorded(long nativeAudioRecordJni, int bytes);
|
||||
private native void nativeDataIsRecorded(
|
||||
long nativeAudioRecordJni, int bytes, long captureTimestampNs);
|
||||
|
||||
// Sets all recorded samples to zero if `mute` is true, i.e., ensures that
|
||||
// the microphone is muted.
|
||||
|
||||
@ -245,14 +245,15 @@ void AudioRecordJni::CacheDirectBufferAddress(
|
||||
// the thread is 'AudioRecordThread'.
|
||||
void AudioRecordJni::DataIsRecorded(JNIEnv* env,
|
||||
const JavaParamRef<jobject>& j_caller,
|
||||
int length) {
|
||||
int length,
|
||||
int64_t capture_timestamp_ns) {
|
||||
RTC_DCHECK(thread_checker_java_.IsCurrent());
|
||||
if (!audio_device_buffer_) {
|
||||
RTC_LOG(LS_ERROR) << "AttachAudioBuffer has not been called";
|
||||
return;
|
||||
}
|
||||
audio_device_buffer_->SetRecordedBuffer(direct_buffer_address_,
|
||||
frames_per_buffer_);
|
||||
audio_device_buffer_->SetRecordedBuffer(
|
||||
direct_buffer_address_, frames_per_buffer_, capture_timestamp_ns);
|
||||
// We provide one (combined) fixed delay estimate for the APM and use the
|
||||
// `playDelayMs` parameter only. Components like the AEC only sees the sum
|
||||
// of `playDelayMs` and `recDelayMs`, hence the distributions does not matter.
|
||||
|
||||
@ -90,7 +90,8 @@ class AudioRecordJni : public AudioInput {
|
||||
// the thread is 'AudioRecordThread'.
|
||||
void DataIsRecorded(JNIEnv* env,
|
||||
const JavaParamRef<jobject>& j_caller,
|
||||
int length);
|
||||
int length,
|
||||
int64_t capture_timestamp_ns);
|
||||
|
||||
private:
|
||||
// Stores thread ID in constructor.
|
||||
|
||||
Reference in New Issue
Block a user