aboutsummaryrefslogtreecommitdiffstats
path: root/main/audacious-plugins/alsa-period-wait.patch
blob: 68527d9a833fbeb6d2ac4d34191716b3bd2d5aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# HG changeset patch
# User John Lindgren <john.lindgren@tds.net>
# Date 1292029591 18000
# Node ID 21ec3fe20e6fdffb5758aa847310944021dda67d
# Parent  eb47af70d029335ac12b4eb7e02d5664069439fa
alsa: Make delay time for poll() workaround depend on period size.
alsa: Fix thread logic.

diff -r eb47af70d029 -r 21ec3fe20e6f src/alsa/alsa.c
--- a/src/alsa/alsa.c	Fri Dec 10 11:47:49 2010 -0500
+++ b/src/alsa/alsa.c	Fri Dec 10 20:06:31 2010 -0500
@@ -79,6 +79,7 @@
 
 static void * alsa_buffer;
 static int alsa_buffer_length, alsa_buffer_data_start, alsa_buffer_data_length;
+static int alsa_period; /* milliseconds */
 
 static int64_t alsa_written; /* frames */
 static char alsa_prebuffer, alsa_paused;
@@ -195,6 +196,9 @@
             continue;
         }
 
+        if (! snd_pcm_bytes_to_frames (alsa_handle, alsa_buffer_data_length))
+            continue;
+
     WAIT:
         pthread_mutex_unlock (& alsa_mutex);
 
@@ -215,7 +219,8 @@
 
         if (workaround && slept)
         {
-            const struct timespec delay = {.tv_sec = 00, .tv_nsec = 100000000};
+            const struct timespec delay = {.tv_sec = 0, .tv_nsec = 600000 *
+             alsa_period};
             nanosleep (& delay, NULL);
         }
         else
@@ -380,14 +385,14 @@
     direction = 0;
     CHECK_NOISY (snd_pcm_hw_params_set_period_time_near, alsa_handle, params,
      & useconds, & direction);
-    int period = useconds / 1000;
+    alsa_period = useconds / 1000;
 
     CHECK_NOISY (snd_pcm_hw_params, alsa_handle, params);
 
     int soft_buffer = MAX (aud_cfg->output_buffer_size / 2,
      aud_cfg->output_buffer_size - hard_buffer);
     AUDDBG ("Buffer: hardware %d ms, software %d ms, period %d ms.\n",
-     hard_buffer, soft_buffer, period);
+     hard_buffer, soft_buffer, alsa_period);
 
     alsa_buffer_length = snd_pcm_frames_to_bytes (alsa_handle, (int64_t)
      soft_buffer * rate / 1000);
@@ -468,6 +473,9 @@
     alsa_buffer_data_length += length;
     alsa_written += snd_pcm_bytes_to_frames (alsa_handle, length);
 
+    if (! alsa_paused)
+        pthread_cond_broadcast (& alsa_cond);
+
     pthread_mutex_unlock (& alsa_mutex);
 }