]> code.delx.au - pulseaudio/blobdiff - src/modules/module-null-sink.c
modules: Fix resource leak in alsa-card
[pulseaudio] / src / modules / module-null-sink.c
index 10868f5c0c15e25f5d60d0f0a4c38ea2ec133cce..c038b6cf85a8e28af0303e2f1e3ee7a6fca3ab57 100644 (file)
@@ -48,7 +48,7 @@
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_DESCRIPTION(_("Clocked NULL sink"));
 PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_LOAD_ONCE(FALSE);
+PA_MODULE_LOAD_ONCE(false);
 PA_MODULE_USAGE(
         "sink_name=<name of sink> "
         "sink_properties=<properties for the sink> "
@@ -136,11 +136,11 @@ static void process_rewind(struct userdata *u, pa_usec_t now) {
 
     pa_assert(u);
 
-    /* Figure out how much we shall rewind and reset the counter */
     rewind_nbytes = u->sink->thread_info.rewind_nbytes;
-    u->sink->thread_info.rewind_nbytes = 0;
 
-    pa_assert(rewind_nbytes > 0);
+    if (!PA_SINK_IS_OPENED(u->sink->thread_info.state) || rewind_nbytes <= 0)
+        goto do_nothing;
+
     pa_log_debug("Requested to rewind %lu bytes.", (unsigned long) rewind_nbytes);
 
     if (u->timestamp <= now)
@@ -176,7 +176,7 @@ static void process_render(struct userdata *u, pa_usec_t now) {
     queued. Hence: at maximum read this many bytes from the sink
     inputs. */
 
-    /* Fill the buffer up the the latency size */
+    /* Fill the buffer up the latency size */
     while (u->timestamp < now + u->block_usec) {
         pa_memchunk chunk;
 
@@ -207,21 +207,17 @@ static void thread_func(void *userdata) {
     u->timestamp = pa_rtclock_now();
 
     for (;;) {
+        pa_usec_t now = 0;
         int ret;
 
-        /* Render some data and drop it immediately */
-        if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
-            pa_usec_t now;
-
+        if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
             now = pa_rtclock_now();
 
-            if (u->sink->thread_info.rewind_requested) {
-                if (u->sink->thread_info.rewind_nbytes > 0)
-                    process_rewind(u, now);
-                else
-                    pa_sink_process_rewind(u->sink, 0);
-            }
+        if (PA_UNLIKELY(u->sink->thread_info.rewind_requested))
+            process_rewind(u, now);
 
+        /* Render some data and drop it immediately */
+        if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
             if (u->timestamp <= now)
                 process_render(u, now);
 
@@ -230,7 +226,7 @@ static void thread_func(void *userdata) {
             pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
-        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
+        if ((ret = pa_rtpoll_run(u->rtpoll, true)) < 0)
             goto fail;
 
         if (ret == 0)
@@ -315,6 +311,8 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
+    pa_sink_set_latency_range(u->sink, 0, BLOCK_USEC);
+
     pa_sink_put(u->sink);
 
     pa_modargs_free(ma);