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 (4 of 24 files). Show all

Unified · Split

4 files
  1. include/sound/compress_driver.h +1 −1
  2. include/sound/soc-component.h +2 −2
  3. include/sound/soc-dai.h +4 −3
  4. include/uapi/sound/compress_offload.h +19 −0
include/sound/compress_driver.h+1−1
@@ -161,7 +161,7 @@ struct snd_compr_ops { · 160 unmodified lines
161161 struct snd_compr_metadata *metadata);
162162 int (*trigger)(struct snd_compr_stream *stream, int cmd);
163163 int (*pointer)(struct snd_compr_stream *stream,
164− struct snd_compr_tstamp *tstamp);
164+ struct snd_compr_tstamp64 *tstamp);
165165 int (*copy)(struct snd_compr_stream *stream, char __user *buf,
166166 size_t count);
167167 int (*mmap)(struct snd_compr_stream *stream,
include/sound/soc-component.h+2−2
@@ -47,7 +47,7 @@ struct snd_compress_ops { · 46 unmodified lines
4747 struct snd_compr_stream *stream, int cmd);
4848 int (*pointer)(struct snd_soc_component *component,
4949 struct snd_compr_stream *stream,
50− struct snd_compr_tstamp *tstamp);
50+ struct snd_compr_tstamp64 *tstamp);
5151 int (*copy)(struct snd_soc_component *component,
5252 struct snd_compr_stream *stream, char __user *buf,
5353 size_t count);
@@ -498,7 +498,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, · 444 unmodified lines
498498 struct snd_compr_codec_caps *codec);
499499 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
500500 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
501− struct snd_compr_tstamp *tstamp);
501+ struct snd_compr_tstamp64 *tstamp);
502502 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
503503 char __user *buf, size_t count);
504504 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
include/sound/soc-dai.h+4−3
@@ -256,7 +256,7 @@ int snd_soc_dai_compr_ack(struct snd_soc_dai *dai, · 255 unmodified lines
256256 size_t bytes);
257257 int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
258258 struct snd_compr_stream *cstream,
259− struct snd_compr_tstamp *tstamp);
259+ struct snd_compr_tstamp64 *tstamp);
260260 int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
261261 struct snd_compr_stream *cstream,
262262 struct snd_compr_metadata *metadata);
@@ -383,8 +383,9 @@ struct snd_soc_cdai_ops { · 120 unmodified lines
383383 struct snd_compr_metadata *, struct snd_soc_dai *);
384384 int (*trigger)(struct snd_compr_stream *, int,
385385 struct snd_soc_dai *);
386− int (*pointer)(struct snd_compr_stream *,
387− struct snd_compr_tstamp *, struct snd_soc_dai *);
386+ int (*pointer)(struct snd_compr_stream *stream,
387+ struct snd_compr_tstamp64 *tstamp,
388+ struct snd_soc_dai *dai);
388389 int (*ack)(struct snd_compr_stream *, size_t,
389390 struct snd_soc_dai *);
390391 };
include/uapi/sound/compress_offload.h+19−0
@@ -56,6 +56,25 @@ struct snd_compr_tstamp { · 55 unmodified lines
5656 __u32 sampling_rate;
5757 } __attribute__((packed, aligned(4)));
5858
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+ */
70+struct 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+
5978 /**
6079 * struct snd_compr_avail - avail descriptor
6180 * @avail: Number of bytes available in ring buffer for writing/reading

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t