]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/source-output.c
simplify latency config functions a bit and make them callable in more contexts
[pulseaudio] / src / pulsecore / source-output.c
index d8a2363cff766b0edb8047e83b113e92144633b0..550b6571044dda4573cea6be0173d9cc2bacf12a 100644 (file)
@@ -5,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -87,7 +87,7 @@ static void reset_callbacks(pa_source_output *o) {
     o->attach = NULL;
     o->detach = NULL;
     o->suspend = NULL;
-    o->moved = NULL;
+    o->moving = NULL;
     o->kill = NULL;
     o->get_latency = NULL;
     o->state_change = NULL;
@@ -335,6 +335,8 @@ void pa_source_output_unlink(pa_source_output*o) {
         o->source = NULL;
     }
 
+    pa_core_maybe_vacuum(o->core);
+
     pa_source_output_unref(o);
 }
 
@@ -513,27 +515,13 @@ void pa_source_output_update_max_rewind(pa_source_output *o, size_t nbytes  /* i
         o->update_max_rewind(o, o->thread_info.resampler ? pa_resampler_result(o->thread_info.resampler, nbytes) : nbytes);
 }
 
-/* Called from thread context */
-static pa_usec_t fixup_latency(pa_source *s, pa_usec_t usec) {
-    pa_source_assert_ref(s);
-
-    if (usec == (pa_usec_t) -1)
-        return usec;
-
-    if (s->thread_info.max_latency > 0 && usec > s->thread_info.max_latency)
-        usec = s->thread_info.max_latency;
-
-    if (s->thread_info.min_latency > 0 && usec < s->thread_info.min_latency)
-        usec = s->thread_info.min_latency;
-
-    return usec;
-}
-
 /* Called from thread context */
 pa_usec_t pa_source_output_set_requested_latency_within_thread(pa_source_output *o, pa_usec_t usec) {
     pa_source_output_assert_ref(o);
 
-    usec = fixup_latency(o->source, usec);
+    if (usec != (pa_usec_t) -1)
+        usec = PA_CLAMP(usec, o->source->thread_info.min_latency, o->source->thread_info.max_latency);
+
     o->thread_info.requested_source_latency = usec;
     pa_source_invalidate_requested_latency(o->source);
 
@@ -542,33 +530,42 @@ pa_usec_t pa_source_output_set_requested_latency_within_thread(pa_source_output
 
 /* Called from main context */
 pa_usec_t pa_source_output_set_requested_latency(pa_source_output *o, pa_usec_t usec) {
+    pa_usec_t min_latency, max_latency;
+
     pa_source_output_assert_ref(o);
 
-    if (PA_SOURCE_OUTPUT_IS_LINKED(o->state))
+    if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && o->source) {
         pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
-    else
-        /* If this source output is not realized yet, we have to touch
-         * the thread info data directly */
+        return usec;
+    }
+
+    /* If this source output is not realized yet or is being moved, we
+     * have to touch the thread info data directly */
+
+    pa_source_get_latency_range(o->source, &min_latency, &max_latency);
+
+    if (usec != (pa_usec_t) -1)
+        usec = PA_CLAMP(usec, min_latency, max_latency);
 
-        o->thread_info.requested_source_latency = usec;
+    o->thread_info.requested_source_latency = usec;
 
     return usec;
 }
 
 /* Called from main context */
 pa_usec_t pa_source_output_get_requested_latency(pa_source_output *o) {
-    pa_usec_t usec = 0;
-
     pa_source_output_assert_ref(o);
 
-    if (PA_SOURCE_OUTPUT_IS_LINKED(o->state))
+    if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && o->source) {
+        pa_usec_t usec = 0;
         pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_GET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
-    else
-        /* If this source output is not realized yet, we have to touch
-         * the thread info data directly */
-        usec = o->thread_info.requested_source_latency;
+        return usec;
+    }
 
-    return usec;
+    /* If this source output is not realized yet or is being moved, we
+     * have to touch the thread info data directly */
+
+    return o->thread_info.requested_source_latency;
 }
 
 /* Called from main context */
@@ -747,6 +744,9 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t
     } else
         new_resampler = NULL;
 
+    if (o->moving)
+        o->moving(o);
+
     o->source = dest;
     o->save_source = save;
     pa_idxset_put(o->source->outputs, o, NULL);
@@ -774,14 +774,12 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t
     }
 
     pa_source_update_status(dest);
+
     pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_ADD_OUTPUT, o, 0, NULL) == 0);
 
     pa_log_debug("Successfully moved source output %i to %s.", o->index, dest->name);
 
     /* Notify everyone */
-    if (o->moved)
-        o->moved(o);
-
     pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], o);
     pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);