Skip to content

Commit

Permalink
fix(rtp) attempt at using the pu64QPCPosition packet capture timestam…
Browse files Browse the repository at this point in the history
…p value from Windows GetBuffer(), but didn't quite figure out the way to pass it in the packet queue
  • Loading branch information
andygrundman committed Jan 10, 2025
1 parent 3ce1061 commit 0767e00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace audio {

using buffer_t = util::buffer_t<std::uint8_t>;
using packet_t = std::pair<void *, buffer_t>;
// XXX maybe change to this for adding packet_timestamp
// using packet_t = std::tuple<void *, buffer_t, std::uint64_t>;
using audio_ctx_ref_t = safe::shared_t<audio_ctx_t>::ptr_t;

void
Expand Down
6 changes: 5 additions & 1 deletion src/platform/windows/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -668,6 +671,7 @@ namespace platf::audio {
util::buffer_t<float> sample_buf;
float *sample_buf_pos;
int channels;
std::uint64_t packet_timestamp;

HANDLE mmcss_task_handle = NULL;
};
Expand Down
13 changes: 11 additions & 2 deletions src/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::uint32_t>(
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>(
// 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<std::uint32_t>(session->audio.avRiKeyId + sequenceNumber);
Expand Down

0 comments on commit 0767e00

Please sign in to comment.