include/sound/pcm-indirect.h
Source file repositories/reference/linux-study-clean/include/sound/pcm-indirect.h
File Facts
- System
- Linux kernel
- Corpus path
include/sound/pcm-indirect.h- Extension
.h- Size
- 5303 bytes
- Lines
- 181
- Domain
- Driver Families
- Bucket
- include/sound
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sound/pcm.h
Detected Declarations
struct snd_pcm_indirectfunction snd_pcm_indirect_playback_transferfunction snd_pcm_indirect_playback_pointerfunction snd_pcm_indirect_capture_transferfunction snd_pcm_indirect_capture_pointer
Annotated Snippet
struct snd_pcm_indirect {
unsigned int hw_buffer_size; /* Byte size of hardware buffer */
unsigned int hw_queue_size; /* Max queue size of hw buffer (0 = buffer size) */
unsigned int hw_data; /* Offset to next dst (or src) in hw ring buffer */
unsigned int hw_io; /* Ring buffer hw pointer */
int hw_ready; /* Bytes ready for play (or captured) in hw ring buffer */
unsigned int sw_buffer_size; /* Byte size of software buffer */
unsigned int sw_data; /* Offset to next dst (or src) in sw ring buffer */
unsigned int sw_io; /* Current software pointer in bytes */
int sw_ready; /* Bytes ready to be transferred to/from hw */
snd_pcm_uframes_t appl_ptr; /* Last seen appl_ptr */
};
typedef void (*snd_pcm_indirect_copy_t)(struct snd_pcm_substream *substream,
struct snd_pcm_indirect *rec, size_t bytes);
/*
* helper function for playback ack callback
*/
static inline int
snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream,
struct snd_pcm_indirect *rec,
snd_pcm_indirect_copy_t copy)
{
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_uframes_t appl_ptr = runtime->control->appl_ptr;
snd_pcm_sframes_t diff = appl_ptr - rec->appl_ptr;
int qsize;
if (diff) {
if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2))
diff += runtime->boundary;
if (diff < 0)
return -EPIPE;
rec->sw_ready += (int)frames_to_bytes(runtime, diff);
rec->appl_ptr = appl_ptr;
}
qsize = rec->hw_queue_size ? rec->hw_queue_size : rec->hw_buffer_size;
while (rec->hw_ready < qsize && rec->sw_ready > 0) {
unsigned int hw_to_end = rec->hw_buffer_size - rec->hw_data;
unsigned int sw_to_end = rec->sw_buffer_size - rec->sw_data;
unsigned int bytes = qsize - rec->hw_ready;
if (rec->sw_ready < (int)bytes)
bytes = rec->sw_ready;
if (hw_to_end < bytes)
bytes = hw_to_end;
if (sw_to_end < bytes)
bytes = sw_to_end;
if (! bytes)
break;
copy(substream, rec, bytes);
rec->hw_data += bytes;
if (rec->hw_data == rec->hw_buffer_size)
rec->hw_data = 0;
rec->sw_data += bytes;
if (rec->sw_data == rec->sw_buffer_size)
rec->sw_data = 0;
rec->hw_ready += bytes;
rec->sw_ready -= bytes;
}
return 0;
}
/*
* helper function for playback pointer callback
* ptr = current byte pointer
*/
static inline snd_pcm_uframes_t
snd_pcm_indirect_playback_pointer(struct snd_pcm_substream *substream,
struct snd_pcm_indirect *rec, unsigned int ptr)
{
int bytes = ptr - rec->hw_io;
int err;
if (bytes < 0)
bytes += rec->hw_buffer_size;
rec->hw_io = ptr;
rec->hw_ready -= bytes;
rec->sw_io += bytes;
if (rec->sw_io >= rec->sw_buffer_size)
rec->sw_io -= rec->sw_buffer_size;
if (substream->ops->ack) {
err = substream->ops->ack(substream);
if (err == -EPIPE)
return SNDRV_PCM_POS_XRUN;
}
return bytes_to_frames(substream->runtime, rec->sw_io);
}
Annotation
- Immediate include surface: `sound/pcm.h`.
- Detected declarations: `struct snd_pcm_indirect`, `function snd_pcm_indirect_playback_transfer`, `function snd_pcm_indirect_playback_pointer`, `function snd_pcm_indirect_capture_transfer`, `function snd_pcm_indirect_capture_pointer`.
- Atlas domain: Driver Families / include/sound.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.