From 0767e00b9dd95619fb03e923652527b008813188 Mon Sep 17 00:00:00 2001 From: Andy Grundman Date: Fri, 10 Jan 2025 04:35:15 -0500 Subject: [PATCH] fix(rtp) attempt at using the pu64QPCPosition packet capture timestamp value from Windows GetBuffer(), but didn't quite figure out the way to pass it in the packet queue --- src/audio.h | 2 ++ src/platform/windows/audio.cpp | 6 +++++- src/stream.cpp | 13 +++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/audio.h b/src/audio.h index 927dfdef20b..d28c50fcd44 100644 --- a/src/audio.h +++ b/src/audio.h @@ -69,6 +69,8 @@ namespace audio { using buffer_t = util::buffer_t; using packet_t = std::pair; + // XXX maybe change to this for adding packet_timestamp + // using packet_t = std::tuple; using audio_ctx_ref_t = safe::shared_t::ptr_t; void diff --git a/src/platform/windows/audio.cpp b/src/platform/windows/audio.cpp index 3c401976afc..74fdfdd6fd9 100644 --- a/src/platform/windows/audio.cpp +++ b/src/platform/windows/audio.cpp @@ -572,6 +572,7 @@ namespace platf::audio { // number of samples / number of channels struct block_aligned_t { std::uint32_t audio_sample_size; + std::uint64_t packet_timestamp; } block_aligned; // Check if the default audio device has changed @@ -606,7 +607,8 @@ namespace platf::audio { (BYTE **) &sample_aligned.samples, &block_aligned.audio_sample_size, &buffer_flags, - nullptr, nullptr); + nullptr, + &block_aligned.packet_timestamp); switch (status) { case S_OK: @@ -637,6 +639,7 @@ namespace platf::audio { } sample_buf_pos += n; + packet_timestamp = block_aligned.packet_timestamp; audio_capture->ReleaseBuffer(block_aligned.audio_sample_size); } @@ -668,6 +671,7 @@ namespace platf::audio { util::buffer_t sample_buf; float *sample_buf_pos; int channels; + std::uint64_t packet_timestamp; HANDLE mmcss_task_handle = NULL; }; diff --git a/src/stream.cpp b/src/stream.cpp index 953342cd0f9..991a76a9022 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -1631,14 +1631,23 @@ namespace stream { } TUPLE_2D_REF(channel_data, packet_data, *packet); + // XXX for transporting packet_timestamp? + // TUPLE_3D_REF(channel_data, packet_data, packet_timestamp, *packet); auto session = (session_t *) channel_data; auto sequenceNumber = session->audio.sequenceNumber; // Audio timestamps are in milliseconds and should be AudioPacketDuration (5ms or 10ms) apart + + // XXX fix packet->packet_timestamp + // auto packet_time_point = std::chrono::steady_clock::time_point( + // std::chrono::microseconds(packet->packet_timestamp) + // ); + auto timestamp = static_cast( - std::chrono::duration_cast( + std::chrono::duration_cast( + // std::chrono::steady_clock::now() - packet_time_point std::chrono::steady_clock::now() - session->audio.timestamp_epoch - ).count() / 1000.0 + ).count() ); *(std::uint32_t *) iv.data() = util::endian::big(session->audio.avRiKeyId + sequenceNumber);