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
161 struct snd_compr_metadata *metadata);161 struct snd_compr_metadata *metadata);
162 int (*trigger)(struct snd_compr_stream *stream, int cmd);162 int (*trigger)(struct snd_compr_stream *stream, int cmd);
163 int (*pointer)(struct snd_compr_stream *stream,163 int (*pointer)(struct snd_compr_stream *stream,
164 struct snd_compr_tstamp *tstamp);164 struct snd_compr_tstamp64 *tstamp);
165 int (*copy)(struct snd_compr_stream *stream, char __user *buf,165 int (*copy)(struct snd_compr_stream *stream, char __user *buf,
166 size_t count);166 size_t count);
167 int (*mmap)(struct snd_compr_stream *stream,167 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
47 struct snd_compr_stream *stream, int cmd);47 struct snd_compr_stream *stream, int cmd);
48 int (*pointer)(struct snd_soc_component *component,48 int (*pointer)(struct snd_soc_component *component,
49 struct snd_compr_stream *stream,49 struct snd_compr_stream *stream,
50 struct snd_compr_tstamp *tstamp);50 struct snd_compr_tstamp64 *tstamp);
51 int (*copy)(struct snd_soc_component *component,51 int (*copy)(struct snd_soc_component *component,
52 struct snd_compr_stream *stream, char __user *buf,52 struct snd_compr_stream *stream, char __user *buf,
53 size_t count);53 size_t count);
@@ -498,7 +498,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, · 444 unmodified lines
498 struct snd_compr_codec_caps *codec);498 struct snd_compr_codec_caps *codec);
499int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);499int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
500int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,500int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
501 struct snd_compr_tstamp *tstamp);501 struct snd_compr_tstamp64 *tstamp);
502int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,502int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
503 char __user *buf, size_t count);503 char __user *buf, size_t count);
504int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,504int 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
256 size_t bytes);256 size_t bytes);
257int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,257int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
258 struct snd_compr_stream *cstream,258 struct snd_compr_stream *cstream,
259 struct snd_compr_tstamp *tstamp);259 struct snd_compr_tstamp64 *tstamp);
260int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,260int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
261 struct snd_compr_stream *cstream,261 struct snd_compr_stream *cstream,
262 struct snd_compr_metadata *metadata);262 struct snd_compr_metadata *metadata);
@@ -383,8 +383,9 @@ struct snd_soc_cdai_ops { · 120 unmodified lines
383 struct snd_compr_metadata *, struct snd_soc_dai *);383 struct snd_compr_metadata *, struct snd_soc_dai *);
384 int (*trigger)(struct snd_compr_stream *, int,384 int (*trigger)(struct snd_compr_stream *, int,
385 struct snd_soc_dai *);385 struct snd_soc_dai *);
386 int (*pointer)(struct snd_compr_stream *,386 int (*pointer)(struct snd_compr_stream *stream,
387 struct snd_compr_tstamp *, struct snd_soc_dai *);387 struct snd_compr_tstamp64 *tstamp,
388 struct snd_soc_dai *dai);
388 int (*ack)(struct snd_compr_stream *, size_t,389 int (*ack)(struct snd_compr_stream *, size_t,
389 struct snd_soc_dai *);390 struct snd_soc_dai *);
390};391};
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

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