Lines Matching +full:pcm +full:- +full:sync +full:- +full:mode
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
6 * Digital Audio (PCM) abstract layer
8 * Abramo Bagnara <abramo@alsa-project.org>
21 #define snd_pcm_substream_chip(substream) ((substream)->private_data)
22 #define snd_pcm_chip(pcm) ((pcm)->private_data) argument
86 #define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
106 #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
132 #define SNDRV_PCM_RATE_KNOT (1U<<31) /* supports more non-continuous rates */
160 // available bit count in most significant bit. It's for the case of so-called 'left-justified' or
161 // `right-padding` sample which has less width than 32 bit.
257 struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
259 struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
269 return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK]; in constrs_mask()
275 return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]; in constrs_interval()
311 * userspace-provided audio timestamp config to kernel,
323 config->type_requested = data & 0xF; in snd_pcm_unpack_audio_tstamp_config()
324 config->report_delay = (data >> 4) & 1; in snd_pcm_unpack_audio_tstamp_config()
328 * kernel-provided audio timestamp report to user-space
332 /* 6 of max 16 bits used for bit-fields */
350 tmp = report->accuracy_report; in snd_pcm_pack_audio_tstamp_report()
352 tmp |= report->actual_type; in snd_pcm_pack_audio_tstamp_report()
354 tmp |= report->valid; in snd_pcm_pack_audio_tstamp_report()
356 *data &= 0xffff; /* zero-clear MSBs */ in snd_pcm_pack_audio_tstamp_report()
358 *accuracy = report->accuracy; in snd_pcm_pack_audio_tstamp_report()
363 /* -- Status -- */
368 bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */
376 u64 hw_ptr_wrap; /* offset for hw_ptr due to boundary wrap-around */
378 /* -- HW params -- */
379 snd_pcm_access_t access; /* access mode */
396 /* -- SW params; see struct snd_pcm_sw_params for comments -- */
405 /* internal data of auto-silencer */
409 bool std_sync_id; /* hardware synchronization - standard per card ID */
411 /* -- mmap -- */
415 /* -- locking / scheduling -- */
416 snd_pcm_uframes_t twake; /* do transfer (!poll) wakeup if non-zero */
424 /* -- private section -- */
428 /* -- hardware description -- */
432 /* -- timer -- */
436 /* -- DMA -- */
442 unsigned int buffer_changed:1; /* buffer allocation changed; set only in managed mode */
444 /* -- audio timestamp config -- */
450 /* -- OSS things -- */
465 struct snd_pcm *pcm; member
467 void *private_data; /* copied from pcm->private_data */
475 /* -- hardware operations -- */
477 /* -- runtime information -- */
479 /* -- timer section -- */
483 /* -- next substream -- */
485 /* -- linked substreams -- */
489 /* -- assigned files -- */
496 /* -- OSS things -- */
510 #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
515 struct snd_pcm *pcm; member
516 /* -- substreams -- */
521 /* -- OSS things -- */
530 struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
547 void (*private_free) (struct snd_pcm *pcm);
548 bool internal; /* pcm is for internal use only */
549 bool nonatomic; /* whole PCM operations are in non-atomic context */
568 int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
572 int (*n_register) (struct snd_pcm * pcm);
573 int (*n_disconnect) (struct snd_pcm * pcm);
574 int (*n_unregister) (struct snd_pcm * pcm);
594 int snd_pcm_suspend_all(struct snd_pcm *pcm);
596 static inline int snd_pcm_suspend_all(struct snd_pcm *pcm) in snd_pcm_suspend_all() argument
602 int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
605 int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
623 * PCM library
627 * snd_pcm_stream_linked - Check whether the substream is linked with others
634 return substream->group != &substream->self_group; in snd_pcm_stream_linked()
645 * snd_pcm_stream_lock_irqsave - Lock the PCM stream
646 * @substream: PCM substream
649 * This locks the PCM stream like snd_pcm_stream_lock() but with the local
662 * snd_pcm_stream_lock_irqsave_nested - Single-nested PCM stream locking
663 * @substream: PCM substream
666 * This locks the PCM stream like snd_pcm_stream_lock_irqsave() but with
667 * the single-depth lockdep subclass.
677 snd_pcm_stream_lock(_T->lock),
678 snd_pcm_stream_unlock(_T->lock))
680 snd_pcm_stream_lock_irq(_T->lock),
681 snd_pcm_stream_unlock_irq(_T->lock))
683 snd_pcm_stream_lock_irqsave(_T->lock, _T->flags),
684 snd_pcm_stream_unlock_irqrestore(_T->lock, _T->flags),
688 * snd_pcm_group_for_each_entry - iterate over the linked substreams
697 list_for_each_entry(s, &substream->group->substreams, link_list)
705 * snd_pcm_running - Check whether the substream is in a running state
713 return (substream->runtime->state == SNDRV_PCM_STATE_RUNNING || in snd_pcm_running()
714 (substream->runtime->state == SNDRV_PCM_STATE_DRAINING && in snd_pcm_running()
715 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)); in snd_pcm_running()
719 * __snd_pcm_set_state - Change the current PCM state
720 * @runtime: PCM runtime to set
728 runtime->state = state; in __snd_pcm_set_state()
729 runtime->status->state = state; /* copy for mmap */ in __snd_pcm_set_state()
733 * bytes_to_samples - Unit conversion of the size from bytes to samples
734 * @runtime: PCM runtime instance
741 return size * 8 / runtime->sample_bits; in bytes_to_samples()
745 * bytes_to_frames - Unit conversion of the size from bytes to frames
746 * @runtime: PCM runtime instance
753 return size * 8 / runtime->frame_bits; in bytes_to_frames()
757 * samples_to_bytes - Unit conversion of the size from samples to bytes
758 * @runtime: PCM runtime instance
765 return size * runtime->sample_bits / 8; in samples_to_bytes()
769 * frames_to_bytes - Unit conversion of the size from frames to bytes
770 * @runtime: PCM runtime instance
777 return size * runtime->frame_bits / 8; in frames_to_bytes()
781 * frame_aligned - Check whether the byte size is aligned to frames
782 * @runtime: PCM runtime instance
789 return bytes % runtime->byte_align == 0; in frame_aligned()
793 * snd_pcm_lib_buffer_bytes - Get the buffer size of the current PCM in bytes
794 * @substream: PCM substream
800 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_lib_buffer_bytes()
801 return frames_to_bytes(runtime, runtime->buffer_size); in snd_pcm_lib_buffer_bytes()
805 * snd_pcm_lib_period_bytes - Get the period size of the current PCM in bytes
806 * @substream: PCM substream
812 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_lib_period_bytes()
813 return frames_to_bytes(runtime, runtime->period_size); in snd_pcm_lib_period_bytes()
817 * snd_pcm_playback_avail - Get the available (writable) space for playback
818 * @runtime: PCM runtime instance
820 * Result is between 0 ... (boundary - 1)
826 …snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_… in snd_pcm_playback_avail()
828 avail += runtime->boundary; in snd_pcm_playback_avail()
829 else if ((snd_pcm_uframes_t) avail >= runtime->boundary) in snd_pcm_playback_avail()
830 avail -= runtime->boundary; in snd_pcm_playback_avail()
835 * snd_pcm_capture_avail - Get the available (readable) space for capture
836 * @runtime: PCM runtime instance
838 * Result is between 0 ... (boundary - 1)
844 snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr; in snd_pcm_capture_avail()
846 avail += runtime->boundary; in snd_pcm_capture_avail()
851 * snd_pcm_playback_hw_avail - Get the queued space for playback
852 * @runtime: PCM runtime instance
858 return runtime->buffer_size - snd_pcm_playback_avail(runtime); in snd_pcm_playback_hw_avail()
862 * snd_pcm_capture_hw_avail - Get the free space for capture
863 * @runtime: PCM runtime instance
869 return runtime->buffer_size - snd_pcm_capture_avail(runtime); in snd_pcm_capture_hw_avail()
873 * snd_pcm_playback_ready - check whether the playback buffer is available
874 * @substream: the pcm substream instance
878 * Return: Non-zero if available, or zero if not.
882 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_playback_ready()
883 return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min; in snd_pcm_playback_ready()
887 * snd_pcm_capture_ready - check whether the capture buffer is available
888 * @substream: the pcm substream instance
892 * Return: Non-zero if available, or zero if not.
896 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_capture_ready()
897 return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min; in snd_pcm_capture_ready()
901 * snd_pcm_playback_data - check whether any data exists on the playback buffer
902 * @substream: the pcm substream instance
906 * Return: Non-zero if any data exists, or zero if not. If stop_threshold
907 * is bigger or equal to boundary, then this function returns always non-zero.
911 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_playback_data()
913 if (runtime->stop_threshold >= runtime->boundary) in snd_pcm_playback_data()
915 return snd_pcm_playback_avail(runtime) < runtime->buffer_size; in snd_pcm_playback_data()
919 * snd_pcm_playback_empty - check whether the playback buffer is empty
920 * @substream: the pcm substream instance
924 * Return: Non-zero if empty, or zero if not.
928 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_playback_empty()
929 return snd_pcm_playback_avail(runtime) >= runtime->buffer_size; in snd_pcm_playback_empty()
933 * snd_pcm_capture_empty - check whether the capture buffer is empty
934 * @substream: the pcm substream instance
938 * Return: Non-zero if empty, or zero if not.
942 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_capture_empty()
947 * snd_pcm_trigger_done - Mark the master substream
948 * @substream: the pcm substream instance
952 * supports the single-shot operation, the driver calls this in the loop
963 substream->runtime->trigger_master = master; in snd_pcm_trigger_done()
981 return ¶ms->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK]; in hw_param_mask()
987 return ¶ms->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]; in hw_param_interval()
993 return ¶ms->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK]; in hw_param_mask_c()
999 return ¶ms->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]; in hw_param_interval_c()
1003 * params_channels - Get the number of channels from the hw params
1010 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_CHANNELS)->min; in params_channels()
1014 * params_rate - Get the sample rate from the hw params
1021 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_RATE)->min; in params_rate()
1025 * params_period_size - Get the period size (in frames) from the hw params
1032 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min; in params_period_size()
1036 * params_periods - Get the number of periods from the hw params
1043 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIODS)->min; in params_periods()
1047 * params_buffer_size - Get the buffer size (in frames) from the hw params
1054 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min; in params_buffer_size()
1058 * params_buffer_bytes - Get the buffer size (in bytes) from the hw params
1065 return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min; in params_buffer_bytes()
1123 * snd_pcm_hw_constraint_single() - Constrain parameter to a single value
1124 * @runtime: PCM runtime instance
1143 #if 0 /* just for kernel-doc */
1145 * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
1148 * Return: 1 if the given PCM format is CPU-endian, 0 if
1164 void snd_pcm_set_ops(struct snd_pcm * pcm, int direction,
1169 * snd_pcm_set_sync - set the PCM sync id
1170 * @substream: the pcm substream
1172 * Use the default PCM sync identifier for the specific card.
1176 substream->runtime->std_sync_id = true; in snd_pcm_set_sync()
1247 return snd_pcm_hw_limit_rates(&runtime->hw); in snd_pcm_limit_hw_rates()
1258 * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer
1259 * @substream: PCM substream to set
1262 * Copy the buffer information to runtime->dma_buffer when @bufp is non-NULL.
1268 struct snd_pcm_runtime *runtime = substream->runtime; in snd_pcm_set_runtime_buffer()
1270 runtime->dma_buffer_p = bufp; in snd_pcm_set_runtime_buffer()
1271 runtime->dma_area = bufp->area; in snd_pcm_set_runtime_buffer()
1272 runtime->dma_addr = bufp->addr; in snd_pcm_set_runtime_buffer()
1273 runtime->dma_bytes = bufp->bytes; in snd_pcm_set_runtime_buffer()
1275 runtime->dma_buffer_p = NULL; in snd_pcm_set_runtime_buffer()
1276 runtime->dma_area = NULL; in snd_pcm_set_runtime_buffer()
1277 runtime->dma_addr = 0; in snd_pcm_set_runtime_buffer()
1278 runtime->dma_bytes = 0; in snd_pcm_set_runtime_buffer()
1283 * snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode
1284 * @runtime: PCM runtime instance
1290 switch (runtime->tstamp_type) { in snd_pcm_gettime()
1308 void snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
1312 void snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
1320 int snd_pcm_set_managed_buffer_all(struct snd_pcm *pcm, int type,
1325 * snd_pcm_set_fixed_buffer - Preallocate and set up the fixed size PCM buffer
1326 * @substream: the pcm substream instance
1329 * @size: the requested pre-allocation size in bytes
1331 * This is a variant of snd_pcm_set_managed_buffer(), but this pre-allocates
1332 * only the given sized buffer and doesn't allow re-allocation nor dynamic
1334 * The function may return -ENOMEM error, hence the caller must check it.
1346 * snd_pcm_set_fixed_buffer_all - Preallocate and set up the fixed size PCM buffer
1347 * @pcm: the pcm instance
1350 * @size: the requested pre-allocation size in bytes
1353 * all substream. If any of allocation fails, it returns -ENOMEM, hence the
1359 snd_pcm_set_fixed_buffer_all(struct snd_pcm *pcm, int type, in snd_pcm_set_fixed_buffer_all() argument
1362 return snd_pcm_set_managed_buffer_all(pcm, type, data, size, 0); in snd_pcm_set_fixed_buffer_all()
1365 #define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
1368 * snd_pcm_sgbuf_get_addr - Get the DMA address at the corresponding offset
1369 * @substream: PCM substream
1381 * snd_pcm_sgbuf_get_chunk_size - Compute the max size that fits within the
1383 * @substream: PCM substream
1398 /* mmap for io-memory area */
1408 * snd_pcm_limit_isa_dma_size - Get the max size fitting with ISA DMA transfer
1429 * snd_pcm_direction_name - Get a string naming the direction of a stream
1443 * snd_pcm_stream_str - Get a string naming the direction of a stream
1444 * @substream: the pcm substream instance
1450 return snd_pcm_direction_name(substream->stream); in snd_pcm_stream_str()
1454 * PCM channel-mapping control API
1464 struct snd_pcm *pcm; /* assigned PCM instance */ member
1474 * snd_pcm_chmap_substream - get the PCM substream assigned to the given chmap info
1478 * Return: the matched PCM substream, or NULL if not found
1484 for (s = info->pcm->streams[info->stream].substream; s; s = s->next) in snd_pcm_chmap_substream()
1485 if (s->number == idx) in snd_pcm_chmap_substream()
1490 /* ALSA-standard channel maps (RL/RR prior to C/LFE) */
1500 int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
1507 * pcm_format_to_bits - Strong-typed conversion of pcm_format to bitwise
1508 * @pcm_format: PCM format
1510 * Return: 64bit mask corresponding to the given PCM format
1518 * pcm_for_each_format - helper to iterate for each format type
1527 #define pcm_err(pcm, fmt, args...) \ argument
1528 dev_err((pcm)->card->dev, fmt, ##args)
1529 #define pcm_warn(pcm, fmt, args...) \ argument
1530 dev_warn((pcm)->card->dev, fmt, ##args)
1531 #define pcm_dbg(pcm, fmt, args...) \ argument
1532 dev_dbg((pcm)->card->dev, fmt, ##args)
1554 …__u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspac…
1555 s64 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */
1560 unsigned char reserved[52-4*sizeof(s64)]; /* must be filled with zero */
1579 u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */
1580 s32 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */
1585 unsigned char reserved[52-4*sizeof(s32)]; /* must be filled with zero */