History

ALSA: compress_offload: Add 64-bit safe timestamp infrastructure

The copied_total field in struct snd_compr_tstamp is a 32-bit value that can overflow on long-running high-bitrate streams, leading to incorrect calculations for buffer availablility. This patch adds a 64-bit safe timestamping mechanism. A new UAPI struct, snd_compr_tstamp64, is added which uses 64-bit types for byte counters. The relevant ops structures across the ASoC and core compress code are updated to use this new struct. ASoC drivers are updated to use u64 counters. Internal timestamps being u64 now, a compatibility function is added to convert the 64-bit timestamp back to the 32-bit format for legacy ioctl callers.

Joris Verhaegen committed 1 year ago

Commit 2c92e2f1 parent cbd676824 files · +125 −72Browse files

Showing the changes to include/uapi (1 of 24 files). Show all

Unified · Split

include/uapi/sound/compress_offload.h+19−0
@@ -56,6 +56,25 @@ struct snd_compr_tstamp { · 55 unmodified lines
56 __u32 sampling_rate;56 __u32 sampling_rate;
57} __attribute__((packed, aligned(4)));57} __attribute__((packed, aligned(4)));
58 58
59/**
60 * struct snd_compr_tstamp64 - timestamp descriptor with fields in 64 bit
61 * @byte_offset: Byte offset in ring buffer to DSP
62 * @copied_total: Total number of bytes copied from/to ring buffer to/by DSP
63 * @pcm_frames: Frames decoded or encoded by DSP. This field will evolve by
64 * large steps and should only be used to monitor encoding/decoding
65 * progress. It shall not be used for timing estimates.
66 * @pcm_io_frames: Frames rendered or received by DSP into a mixer or an audio
67 * output/input. This field should be used for A/V sync or time estimates.
68 * @sampling_rate: sampling rate of audio
69 */
70struct snd_compr_tstamp64 {
71 __u32 byte_offset;
72 __u64 copied_total;
73 __u64 pcm_frames;
74 __u64 pcm_io_frames;
75 __u32 sampling_rate;
76} __attribute__((packed, aligned(4)));
77
59/**78/**
60 * struct snd_compr_avail - avail descriptor79 * struct snd_compr_avail - avail descriptor
61 * @avail: Number of bytes available in ring buffer for writing/reading80 * @avail: Number of bytes available in ring buffer for writing/reading