chiark / gitweb /
disorder-playrtp now releases its lock around activate/deactivate
authorRichard Kettlewell <rjk@greenend.org.uk>
Fri, 13 Mar 2009 21:05:44 +0000 (21:05 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Fri, 13 Mar 2009 21:05:44 +0000 (21:05 +0000)
calls.  This necessary since deactivate may block if a sample
collection callback is still running (in this case it will be blocked
indefinitely).  It actually happens with the Core Audio backend but it
could apply to other APIs too.

clients/playrtp.c
lib/uaudio.h

index 96474376520193efdb6418dddd33e3d26d537ca8..92cbb75e87525bd4867e5363d015693bebc75309 100644 (file)
@@ -763,7 +763,9 @@ int main(int argc, char **argv) {
     info("Playing...");
     next_timestamp = pheap_first(&packets)->timestamp;
     active = 1;
     info("Playing...");
     next_timestamp = pheap_first(&packets)->timestamp;
     active = 1;
+    pthread_mutex_unlock(&lock);
     backend->activate();
     backend->activate();
+    pthread_mutex_lock(&lock);
     /* Wait until the buffer empties out */
     while(nsamples >= minbuffer
          || (nsamples > 0
     /* Wait until the buffer empties out */
     while(nsamples >= minbuffer
          || (nsamples > 0
@@ -771,7 +773,9 @@ int main(int argc, char **argv) {
       pthread_cond_wait(&cond, &lock);
     }
     /* Stop playing for a bit until the buffer re-fills */
       pthread_cond_wait(&cond, &lock);
     }
     /* Stop playing for a bit until the buffer re-fills */
+    pthread_mutex_unlock(&lock);
     backend->deactivate();
     backend->deactivate();
+    pthread_mutex_lock(&lock);
     active = 0;
     /* Go back round */
   }
     active = 0;
     /* Go back round */
   }
index aa686d0c37638e042274e724d6ed455700301b95..e79639384578e2c53b8299d81cbd85e040920e27 100644 (file)
@@ -34,6 +34,15 @@ extern size_t uaudio_sample_size;
  * @param max_samples How many samples to supply
  * @param userdata As passed to uaudio_open()
  * @return Number of samples filled
  * @param max_samples How many samples to supply
  * @param userdata As passed to uaudio_open()
  * @return Number of samples filled
+ *
+ * This function should not block if possible (better to fill the buffer with
+ * 0s) and should definitely not block indefinitely.  This great caution with
+ * any locks or syscalls!  In particular avoid it taking a lock that may be
+ * held while any of the @ref uaudio members are called.
+ *
+ * If it's more convenient, it's OK to return less than the maximum number of
+ * samples (including 0) provided you expect to be called again for more
+ * samples immediately.
  */
 typedef size_t uaudio_callback(void *buffer,
                                size_t max_samples,
  */
 typedef size_t uaudio_callback(void *buffer,
                                size_t max_samples,