Lines Matching refs:runtime

37 static inline void update_silence_vars(struct snd_pcm_runtime *runtime,
47 delta += runtime->boundary;
48 if ((snd_pcm_uframes_t)delta < runtime->silence_filled)
49 runtime->silence_filled -= delta;
51 runtime->silence_filled = 0;
52 runtime->silence_start = new_ptr;
57 * runtime->silence_start: starting pointer to silence area
58 * runtime->silence_filled: size filled with silence
59 * runtime->silence_threshold: threshold from application
60 * runtime->silence_size: maximal size from application
62 * when runtime->silence_size >= runtime->boundary - fill processed area with silence immediately
66 struct snd_pcm_runtime *runtime = substream->runtime;
70 if (runtime->silence_size < runtime->boundary) {
72 snd_pcm_uframes_t appl_ptr = READ_ONCE(runtime->control->appl_ptr);
73 update_silence_vars(runtime, runtime->silence_start, appl_ptr);
76 new_hw_ptr = runtime->status->hw_ptr;
80 noise_dist += runtime->boundary;
82 noise_dist += runtime->silence_filled;
83 if (noise_dist >= (snd_pcm_sframes_t) runtime->silence_threshold)
85 frames = runtime->silence_threshold - noise_dist;
86 if (frames > runtime->silence_size)
87 frames = runtime->silence_size;
93 snd_pcm_uframes_t hw_ptr = runtime->status->hw_ptr;
101 snd_pcm_sframes_t avail = runtime->control->appl_ptr - hw_ptr;
103 avail += runtime->boundary;
109 runtime->silence_filled = avail > runtime->buffer_size ? 0 : avail;
110 runtime->silence_start = hw_ptr;
113 update_silence_vars(runtime, hw_ptr, new_hw_ptr);
119 frames = runtime->buffer_size - runtime->silence_filled;
121 if (snd_BUG_ON(frames > runtime->buffer_size))
125 ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size;
127 transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
130 runtime->silence_filled += transfer;
170 struct snd_pcm_runtime *runtime = substream->runtime;
173 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
176 snd_pcm_gettime(runtime, &tstamp);
177 runtime->status->tstamp.tv_sec = tstamp.tv_sec;
178 runtime->status->tstamp.tv_nsec = tstamp.tv_nsec;
207 struct snd_pcm_runtime *runtime)
212 if (avail > runtime->avail_max)
213 runtime->avail_max = avail;
214 if (runtime->state == SNDRV_PCM_STATE_DRAINING) {
215 if (avail >= runtime->buffer_size) {
220 if (avail >= runtime->stop_threshold) {
225 if (runtime->twake) {
226 if (avail >= runtime->twake)
227 wake_up(&runtime->tsleep);
228 } else if (avail >= runtime->control->avail_min)
229 wake_up(&runtime->sleep);
237 struct snd_pcm_runtime *runtime = substream->runtime;
241 if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE)
245 (runtime->audio_tstamp_report.actual_type ==
253 audio_frames = runtime->hw_ptr_wrap + runtime->status->hw_ptr;
255 if (runtime->audio_tstamp_config.report_delay) {
257 audio_frames -= runtime->delay;
259 audio_frames += runtime->delay;
262 runtime->rate);
266 if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec ||
267 runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) {
268 runtime->status->audio_tstamp.tv_sec = audio_tstamp->tv_sec;
269 runtime->status->audio_tstamp.tv_nsec = audio_tstamp->tv_nsec;
270 runtime->status->tstamp.tv_sec = curr_tstamp->tv_sec;
271 runtime->status->tstamp.tv_nsec = curr_tstamp->tv_nsec;
279 snd_pcm_gettime(substream->runtime, &driver_tstamp);
280 runtime->driver_tstamp = driver_tstamp;
286 struct snd_pcm_runtime *runtime = substream->runtime;
296 old_hw_ptr = runtime->status->hw_ptr;
306 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
308 (runtime->audio_tstamp_config.type_requested != SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) {
311 &runtime->audio_tstamp_config,
312 &runtime->audio_tstamp_report);
315 if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)
316 snd_pcm_gettime(runtime, &curr_tstamp);
318 snd_pcm_gettime(runtime, &curr_tstamp);
325 if (pos >= runtime->buffer_size) {
331 name, pos, runtime->buffer_size,
332 runtime->period_size);
336 pos -= pos % runtime->min_align;
338 hw_base = runtime->hw_ptr_base;
343 delta = runtime->hw_ptr_interrupt + runtime->period_size;
346 hdelta = curr_jiffies - runtime->hw_ptr_jiffies;
347 if (hdelta > runtime->hw_ptr_buffer_jiffies/2 + 1) {
348 hw_base += runtime->buffer_size;
349 if (hw_base >= runtime->boundary) {
361 hw_base += runtime->buffer_size;
362 if (hw_base >= runtime->boundary) {
371 delta += runtime->boundary;
373 if (runtime->no_period_wakeup) {
379 jdelta = curr_jiffies - runtime->hw_ptr_jiffies;
380 if (jdelta < runtime->hw_ptr_buffer_jiffies / 2)
382 hdelta = jdelta - delta * HZ / runtime->rate;
383 xrun_threshold = runtime->hw_ptr_buffer_jiffies / 2 + 1;
385 delta += runtime->buffer_size;
386 hw_base += runtime->buffer_size;
387 if (hw_base >= runtime->boundary) {
392 hdelta -= runtime->hw_ptr_buffer_jiffies;
398 if (delta >= runtime->buffer_size + runtime->period_size) {
414 if (runtime->hw.info & SNDRV_PCM_INFO_BATCH)
417 if (hdelta < runtime->delay)
419 hdelta -= runtime->delay;
420 jdelta = curr_jiffies - runtime->hw_ptr_jiffies;
421 if (((hdelta * HZ) / runtime->rate) > jdelta + HZ/100) {
423 (((runtime->period_size * HZ) / runtime->rate)
431 new_hw_ptr += runtime->period_size;
432 if (new_hw_ptr >= runtime->boundary) {
433 new_hw_ptr -= runtime->boundary;
442 (long)runtime->period_size, jdelta,
443 ((hdelta * HZ) / runtime->rate), hw_base,
448 hw_base = new_hw_ptr - (new_hw_ptr % runtime->buffer_size);
451 if (delta > runtime->period_size + runtime->period_size / 2) {
461 if (runtime->status->hw_ptr == new_hw_ptr) {
462 runtime->hw_ptr_jiffies = curr_jiffies;
468 runtime->silence_size > 0)
472 delta = new_hw_ptr - runtime->hw_ptr_interrupt;
474 delta += runtime->boundary;
475 delta -= (snd_pcm_uframes_t)delta % runtime->period_size;
476 runtime->hw_ptr_interrupt += delta;
477 if (runtime->hw_ptr_interrupt >= runtime->boundary)
478 runtime->hw_ptr_interrupt -= runtime->boundary;
480 runtime->hw_ptr_base = hw_base;
481 runtime->status->hw_ptr = new_hw_ptr;
482 runtime->hw_ptr_jiffies = curr_jiffies;
485 runtime->hw_ptr_wrap += runtime->boundary;
490 return snd_pcm_update_state(substream, runtime);
526 struct snd_pcm_runtime *runtime = substream->runtime;
528 runtime->sync.id32[0] = substream->pcm->card->number;
529 runtime->sync.id32[1] = -1;
530 runtime->sync.id32[2] = -1;
531 runtime->sync.id32[3] = -1;
1136 * @runtime: the pcm runtime instance
1145 int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
1150 struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
1191 * @runtime: PCM runtime instance
1199 int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1202 struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
1213 * @runtime: PCM runtime instance
1221 int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1224 struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
1237 * @runtime: PCM runtime instance
1245 int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var)
1247 struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
1254 * @runtime: PCM runtime instance
1264 int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1267 struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
1287 * @runtime: PCM runtime instance
1296 int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
1301 return snd_pcm_hw_rule_add(runtime, cond, var,
1318 * @runtime: PCM runtime instance
1327 int snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime,
1332 return snd_pcm_hw_rule_add(runtime, cond, var,
1355 * @runtime: PCM runtime instance
1362 int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
1367 return snd_pcm_hw_rule_add(runtime, cond, var,
1389 * @runtime: PCM runtime instance
1396 int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
1401 return snd_pcm_hw_rule_add(runtime, cond, var,
1428 * @runtime: PCM runtime instance
1440 int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
1446 return snd_pcm_hw_rule_add(runtime, cond, -1,
1462 * @runtime: PCM runtime instance
1469 int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
1474 return snd_pcm_hw_rule_add(runtime, cond, var,
1494 * @runtime: PCM runtime instance
1500 int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
1504 return snd_pcm_hw_rule_add(runtime, cond, var,
1522 * @runtime: PCM runtime instance
1527 int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
1530 return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE,
1746 struct snd_pcm_runtime *runtime = substream->runtime;
1751 runtime->status->hw_ptr %= runtime->buffer_size;
1753 runtime->status->hw_ptr = 0;
1754 runtime->hw_ptr_wrap = 0;
1763 struct snd_pcm_runtime *runtime = substream->runtime;
1765 if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) {
1769 width = snd_pcm_format_physical_width(runtime->format);
1773 switch (runtime->access) {
1777 info->step = runtime->channels * width;
1782 size_t size = runtime->dma_bytes / runtime->channels;
1802 params->fifo_size = substream->runtime->hw.fifo_size;
1803 if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_FIFO_IN_FRAMES)) {
1840 * snd_pcm_period_elapsed_under_stream_lock() - update the status of runtime for the next period
1847 * The call of function updates the status of runtime with the latest position of audio data
1868 struct snd_pcm_runtime *runtime;
1872 runtime = substream->runtime;
1883 snd_kill_fasync(runtime->fasync, SIGIO, POLL_IN);
1888 * snd_pcm_period_elapsed() - update the status of runtime for the next period by acquiring lock of
1918 struct snd_pcm_runtime *runtime = substream->runtime;
1927 add_wait_queue(&runtime->tsleep, &wait);
1929 if (runtime->no_period_wakeup)
1938 if (runtime->rate) {
1939 long t = runtime->buffer_size * 1100 / runtime->rate;
1960 if (avail >= runtime->twake)
1968 switch (runtime->state) {
1999 remove_wait_queue(&runtime->tsleep, &wait);
2013 static void *get_dma_ptr(struct snd_pcm_runtime *runtime,
2016 return runtime->dma_area + hwoff +
2017 channel * (runtime->dma_bytes / runtime->channels);
2025 if (copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff),
2039 struct snd_pcm_runtime *runtime = substream->runtime;
2047 snd_pcm_format_set_silence(runtime->format,
2048 get_dma_ptr(runtime, channel, hwoff),
2049 bytes_to_samples(runtime, bytes));
2058 if (copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff),
2100 struct snd_pcm_runtime *runtime = substream->runtime;
2103 hwoff = frames_to_bytes(runtime, hwoff);
2104 off = frames_to_bytes(runtime, off);
2105 frames = frames_to_bytes(runtime, frames);
2121 struct snd_pcm_runtime *runtime = substream->runtime;
2122 int channels = runtime->channels;
2130 off = samples_to_bytes(runtime, off);
2131 frames = samples_to_bytes(runtime, frames);
2132 hwoff = samples_to_bytes(runtime, hwoff);
2151 if (substream->runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
2152 substream->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED)
2163 struct snd_pcm_runtime *runtime;
2166 runtime = substream->runtime;
2167 if (snd_BUG_ON(!substream->ops->copy && !runtime->dma_area))
2169 if (runtime->state == SNDRV_PCM_STATE_OPEN)
2174 static int pcm_accessible_state(struct snd_pcm_runtime *runtime)
2176 switch (runtime->state) {
2196 struct snd_pcm_runtime *runtime = substream->runtime;
2197 snd_pcm_uframes_t old_appl_ptr = runtime->control->appl_ptr;
2204 if (appl_ptr >= runtime->boundary)
2209 if (substream->runtime->info & SNDRV_PCM_INFO_NO_REWINDS) {
2212 if (diff > runtime->buffer_size)
2215 if (runtime->boundary + diff > runtime->buffer_size)
2220 runtime->control->appl_ptr = appl_ptr;
2224 runtime->control->appl_ptr = old_appl_ptr;
2241 struct snd_pcm_runtime *runtime = substream->runtime;
2257 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
2258 runtime->channels > 1)
2262 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
2286 err = pcm_accessible_state(runtime);
2290 runtime->twake = runtime->control->avail_min ? : 1;
2291 if (runtime->state == SNDRV_PCM_STATE_RUNNING)
2299 runtime->state == SNDRV_PCM_STATE_PREPARED &&
2300 size >= runtime->start_threshold) {
2313 runtime->state == SNDRV_PCM_STATE_DRAINING) {
2321 runtime->twake = min_t(snd_pcm_uframes_t, size,
2322 runtime->control->avail_min ? : 1);
2330 appl_ptr = READ_ONCE(runtime->control->appl_ptr);
2331 appl_ofs = appl_ptr % runtime->buffer_size;
2332 cont = runtime->buffer_size - appl_ofs;
2339 if (!atomic_inc_unless_negative(&runtime->buffer_accessing)) {
2351 atomic_dec(&runtime->buffer_accessing);
2354 err = pcm_accessible_state(runtime);
2358 if (appl_ptr >= runtime->boundary)
2359 appl_ptr -= runtime->boundary;
2369 runtime->state == SNDRV_PCM_STATE_PREPARED &&
2370 snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
2377 runtime->twake = 0;
2379 snd_pcm_update_state(substream, runtime);
2470 if (!substream->runtime)
2474 if (map->channels == substream->runtime->channels &&