diff options
author | Takashi Iwai <tiwai@suse.de> | 2017-05-19 14:16:44 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2017-05-21 02:58:30 -0400 |
commit | e0327a0f214154b517fa2b325acd8d42736ac95b (patch) | |
tree | e58812594b993f30c4b56c47e458c29e0710f814 | |
parent | f839cc1cbd29f2160ef4e621b920e254cc84133a (diff) |
ALSA: pcm: Simplify forward/rewind codes
Factor out the common codes in snd_pcm_*_forward() and *_rewind()
functions to simplify the codes. No functional changes.
Reviewd-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/core/pcm_native.c | 118 |
1 files changed, 50 insertions, 68 deletions
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 93bd2c662c1d..ecde57afa45a 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c | |||
@@ -2455,34 +2455,58 @@ static int do_pcm_hwsync(struct snd_pcm_substream *substream) | |||
2455 | } | 2455 | } |
2456 | } | 2456 | } |
2457 | 2457 | ||
2458 | /* increase the appl_ptr; returns the processed frames */ | ||
2459 | static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream, | ||
2460 | snd_pcm_uframes_t frames, | ||
2461 | snd_pcm_sframes_t avail) | ||
2462 | { | ||
2463 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
2464 | snd_pcm_sframes_t appl_ptr; | ||
2465 | |||
2466 | if (avail <= 0) | ||
2467 | return 0; | ||
2468 | if (frames > (snd_pcm_uframes_t)avail) | ||
2469 | frames = avail; | ||
2470 | appl_ptr = runtime->control->appl_ptr + frames; | ||
2471 | if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) | ||
2472 | appl_ptr -= runtime->boundary; | ||
2473 | runtime->control->appl_ptr = appl_ptr; | ||
2474 | return frames; | ||
2475 | } | ||
2476 | |||
2477 | /* decrease the appl_ptr; returns the processed frames */ | ||
2478 | static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream, | ||
2479 | snd_pcm_uframes_t frames, | ||
2480 | snd_pcm_sframes_t avail) | ||
2481 | { | ||
2482 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
2483 | snd_pcm_sframes_t appl_ptr; | ||
2484 | |||
2485 | if (avail <= 0) | ||
2486 | return 0; | ||
2487 | if (frames > (snd_pcm_uframes_t)avail) | ||
2488 | frames = avail; | ||
2489 | appl_ptr = runtime->control->appl_ptr - frames; | ||
2490 | if (appl_ptr < 0) | ||
2491 | appl_ptr += runtime->boundary; | ||
2492 | runtime->control->appl_ptr = appl_ptr; | ||
2493 | return frames; | ||
2494 | } | ||
2495 | |||
2458 | static snd_pcm_sframes_t snd_pcm_playback_rewind(struct snd_pcm_substream *substream, | 2496 | static snd_pcm_sframes_t snd_pcm_playback_rewind(struct snd_pcm_substream *substream, |
2459 | snd_pcm_uframes_t frames) | 2497 | snd_pcm_uframes_t frames) |
2460 | { | 2498 | { |
2461 | struct snd_pcm_runtime *runtime = substream->runtime; | 2499 | struct snd_pcm_runtime *runtime = substream->runtime; |
2462 | snd_pcm_sframes_t appl_ptr; | ||
2463 | snd_pcm_sframes_t ret; | 2500 | snd_pcm_sframes_t ret; |
2464 | snd_pcm_sframes_t hw_avail; | ||
2465 | 2501 | ||
2466 | if (frames == 0) | 2502 | if (frames == 0) |
2467 | return 0; | 2503 | return 0; |
2468 | 2504 | ||
2469 | snd_pcm_stream_lock_irq(substream); | 2505 | snd_pcm_stream_lock_irq(substream); |
2470 | ret = do_pcm_hwsync(substream); | 2506 | ret = do_pcm_hwsync(substream); |
2471 | if (ret < 0) | 2507 | if (!ret) |
2472 | goto __end; | 2508 | ret = rewind_appl_ptr(substream, frames, |
2473 | hw_avail = snd_pcm_playback_hw_avail(runtime); | 2509 | snd_pcm_playback_hw_avail(runtime)); |
2474 | if (hw_avail <= 0) { | ||
2475 | ret = 0; | ||
2476 | goto __end; | ||
2477 | } | ||
2478 | if (frames > (snd_pcm_uframes_t)hw_avail) | ||
2479 | frames = hw_avail; | ||
2480 | appl_ptr = runtime->control->appl_ptr - frames; | ||
2481 | if (appl_ptr < 0) | ||
2482 | appl_ptr += runtime->boundary; | ||
2483 | runtime->control->appl_ptr = appl_ptr; | ||
2484 | ret = frames; | ||
2485 | __end: | ||
2486 | snd_pcm_stream_unlock_irq(substream); | 2510 | snd_pcm_stream_unlock_irq(substream); |
2487 | return ret; | 2511 | return ret; |
2488 | } | 2512 | } |
@@ -2491,30 +2515,16 @@ static snd_pcm_sframes_t snd_pcm_capture_rewind(struct snd_pcm_substream *substr | |||
2491 | snd_pcm_uframes_t frames) | 2515 | snd_pcm_uframes_t frames) |
2492 | { | 2516 | { |
2493 | struct snd_pcm_runtime *runtime = substream->runtime; | 2517 | struct snd_pcm_runtime *runtime = substream->runtime; |
2494 | snd_pcm_sframes_t appl_ptr; | ||
2495 | snd_pcm_sframes_t ret; | 2518 | snd_pcm_sframes_t ret; |
2496 | snd_pcm_sframes_t hw_avail; | ||
2497 | 2519 | ||
2498 | if (frames == 0) | 2520 | if (frames == 0) |
2499 | return 0; | 2521 | return 0; |
2500 | 2522 | ||
2501 | snd_pcm_stream_lock_irq(substream); | 2523 | snd_pcm_stream_lock_irq(substream); |
2502 | ret = do_pcm_hwsync(substream); | 2524 | ret = do_pcm_hwsync(substream); |
2503 | if (ret < 0) | 2525 | if (!ret) |
2504 | goto __end; | 2526 | ret = rewind_appl_ptr(substream, frames, |
2505 | hw_avail = snd_pcm_capture_hw_avail(runtime); | 2527 | snd_pcm_capture_hw_avail(runtime)); |
2506 | if (hw_avail <= 0) { | ||
2507 | ret = 0; | ||
2508 | goto __end; | ||
2509 | } | ||
2510 | if (frames > (snd_pcm_uframes_t)hw_avail) | ||
2511 | frames = hw_avail; | ||
2512 | appl_ptr = runtime->control->appl_ptr - frames; | ||
2513 | if (appl_ptr < 0) | ||
2514 | appl_ptr += runtime->boundary; | ||
2515 | runtime->control->appl_ptr = appl_ptr; | ||
2516 | ret = frames; | ||
2517 | __end: | ||
2518 | snd_pcm_stream_unlock_irq(substream); | 2528 | snd_pcm_stream_unlock_irq(substream); |
2519 | return ret; | 2529 | return ret; |
2520 | } | 2530 | } |
@@ -2523,30 +2533,16 @@ static snd_pcm_sframes_t snd_pcm_playback_forward(struct snd_pcm_substream *subs | |||
2523 | snd_pcm_uframes_t frames) | 2533 | snd_pcm_uframes_t frames) |
2524 | { | 2534 | { |
2525 | struct snd_pcm_runtime *runtime = substream->runtime; | 2535 | struct snd_pcm_runtime *runtime = substream->runtime; |
2526 | snd_pcm_sframes_t appl_ptr; | ||
2527 | snd_pcm_sframes_t ret; | 2536 | snd_pcm_sframes_t ret; |
2528 | snd_pcm_sframes_t avail; | ||
2529 | 2537 | ||
2530 | if (frames == 0) | 2538 | if (frames == 0) |
2531 | return 0; | 2539 | return 0; |
2532 | 2540 | ||
2533 | snd_pcm_stream_lock_irq(substream); | 2541 | snd_pcm_stream_lock_irq(substream); |
2534 | ret = do_pcm_hwsync(substream); | 2542 | ret = do_pcm_hwsync(substream); |
2535 | if (ret < 0) | 2543 | if (!ret) |
2536 | goto __end; | 2544 | ret = forward_appl_ptr(substream, frames, |
2537 | avail = snd_pcm_playback_avail(runtime); | 2545 | snd_pcm_playback_avail(runtime)); |
2538 | if (avail <= 0) { | ||
2539 | ret = 0; | ||
2540 | goto __end; | ||
2541 | } | ||
2542 | if (frames > (snd_pcm_uframes_t)avail) | ||
2543 | frames = avail; | ||
2544 | appl_ptr = runtime->control->appl_ptr + frames; | ||
2545 | if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) | ||
2546 | appl_ptr -= runtime->boundary; | ||
2547 | runtime->control->appl_ptr = appl_ptr; | ||
2548 | ret = frames; | ||
2549 | __end: | ||
2550 | snd_pcm_stream_unlock_irq(substream); | 2546 | snd_pcm_stream_unlock_irq(substream); |
2551 | return ret; | 2547 | return ret; |
2552 | } | 2548 | } |
@@ -2555,30 +2551,16 @@ static snd_pcm_sframes_t snd_pcm_capture_forward(struct snd_pcm_substream *subst | |||
2555 | snd_pcm_uframes_t frames) | 2551 | snd_pcm_uframes_t frames) |
2556 | { | 2552 | { |
2557 | struct snd_pcm_runtime *runtime = substream->runtime; | 2553 | struct snd_pcm_runtime *runtime = substream->runtime; |
2558 | snd_pcm_sframes_t appl_ptr; | ||
2559 | snd_pcm_sframes_t ret; | 2554 | snd_pcm_sframes_t ret; |
2560 | snd_pcm_sframes_t avail; | ||
2561 | 2555 | ||
2562 | if (frames == 0) | 2556 | if (frames == 0) |
2563 | return 0; | 2557 | return 0; |
2564 | 2558 | ||
2565 | snd_pcm_stream_lock_irq(substream); | 2559 | snd_pcm_stream_lock_irq(substream); |
2566 | ret = do_pcm_hwsync(substream); | 2560 | ret = do_pcm_hwsync(substream); |
2567 | if (ret < 0) | 2561 | if (!ret) |
2568 | goto __end; | 2562 | ret = forward_appl_ptr(substream, frames, |
2569 | avail = snd_pcm_capture_avail(runtime); | 2563 | snd_pcm_capture_avail(runtime)); |
2570 | if (avail <= 0) { | ||
2571 | ret = 0; | ||
2572 | goto __end; | ||
2573 | } | ||
2574 | if (frames > (snd_pcm_uframes_t)avail) | ||
2575 | frames = avail; | ||
2576 | appl_ptr = runtime->control->appl_ptr + frames; | ||
2577 | if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) | ||
2578 | appl_ptr -= runtime->boundary; | ||
2579 | runtime->control->appl_ptr = appl_ptr; | ||
2580 | ret = frames; | ||
2581 | __end: | ||
2582 | snd_pcm_stream_unlock_irq(substream); | 2564 | snd_pcm_stream_unlock_irq(substream); |
2583 | return ret; | 2565 | return ret; |
2584 | } | 2566 | } |