core: introduce pa_{sink_input|source_output}_fail_move()
authorLennart Poettering <lennart@poettering.net>
Fri, 14 Aug 2009 22:03:50 +0000 (00:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 Aug 2009 22:03:50 +0000 (00:03 +0200)
src/pulsecore/sink-input.c
src/pulsecore/sink-input.h
src/pulsecore/sink.c
src/pulsecore/source-output.c
src/pulsecore/source-output.h
src/pulsecore/source.c

index 1f67d0f..3a9915f 100644 (file)
@@ -1318,6 +1318,24 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
 }
 
 /* Called from main context */
+void pa_sink_input_fail_move(pa_sink_input *i) {
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_ctl_context();
+    pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+    pa_assert(!i->sink);
+
+    /* Check if someone wants this sink input? */
+    if (pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FAIL], i) == PA_HOOK_STOP)
+        return;
+
+    if (i->moving)
+        i->moving(i, NULL);
+
+    pa_sink_input_kill(i);
+}
+
+/* Called from main context */
 int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
     int r;
 
@@ -1341,6 +1359,7 @@ int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
     }
 
     if ((r = pa_sink_input_finish_move(i, dest, save)) < 0) {
+        pa_sink_input_fail_move(i);
         pa_sink_input_unref(i);
         return r;
     }
index cd424e8..9088d6a 100644 (file)
@@ -159,7 +159,9 @@ struct pa_sink_input {
     /* If non-NULL called whenever the sink input is moved to a new
      * sink. Called from main context after the sink input has been
      * detached from the old sink and before it has been attached to
-     * the new sink. */
+     * the new sink. If dest is NULL the move was executed in two
+     * phases and the second one failed; the stream will be destroyed
+     * after this call. */
     void (*moving) (pa_sink_input *i, pa_sink *dest);   /* may be NULL */
 
     /* Supposed to unlink and destroy this stream. Called from main
@@ -337,6 +339,7 @@ pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest); /* may thi
  * new sink */
 int pa_sink_input_start_move(pa_sink_input *i);
 int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save);
+void pa_sink_input_fail_move(pa_sink_input *i);
 
 pa_sink_input_state_t pa_sink_input_get_state(pa_sink_input *i);
 
index edcf5bd..65c6374 100644 (file)
@@ -649,7 +649,7 @@ void pa_sink_move_all_finish(pa_sink *s, pa_queue *q, pa_bool_t save) {
 
     while ((i = PA_SINK_INPUT(pa_queue_pop(q)))) {
         if (pa_sink_input_finish_move(i, s, save) < 0)
-            pa_sink_input_kill(i);
+            pa_sink_input_fail_move(i);
 
         pa_sink_input_unref(i);
     }
@@ -665,10 +665,8 @@ void pa_sink_move_all_fail(pa_queue *q) {
     pa_assert(q);
 
     while ((i = PA_SINK_INPUT(pa_queue_pop(q)))) {
-        if (pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FAIL], i) == PA_HOOK_OK) {
-            pa_sink_input_kill(i);
-            pa_sink_input_unref(i);
-        }
+        pa_sink_input_fail_move(i);
+        pa_sink_input_unref(i);
     }
 
     pa_queue_free(q, NULL, NULL);
index 5d79dbb..8cb361c 100644 (file)
@@ -847,6 +847,24 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t
 }
 
 /* Called from main context */
+void pa_source_output_fail_move(pa_source_output *o) {
+
+    pa_source_output_assert_ref(o);
+    pa_assert_ctl_context();
+    pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
+    pa_assert(!o->source);
+
+    /* Check if someone wants this source output? */
+    if (pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FAIL], o) == PA_HOOK_STOP)
+        return;
+
+    if (o->moving)
+        o->moving(o, NULL);
+
+    pa_source_output_kill(o);
+}
+
+/* Called from main context */
 int pa_source_output_move_to(pa_source_output *o, pa_source *dest, pa_bool_t save) {
     int r;
 
@@ -870,6 +888,7 @@ int pa_source_output_move_to(pa_source_output *o, pa_source *dest, pa_bool_t sav
     }
 
     if ((r = pa_source_output_finish_move(o, dest, save)) < 0) {
+        pa_source_output_fail_move(o);
         pa_source_output_unref(o);
         return r;
     }
index 4bf88ca..6e3475a 100644 (file)
@@ -127,7 +127,9 @@ struct pa_source_output {
     /* If non-NULL called whenever the source output is moved to a new
      * source. Called from main context after the stream was detached
      * from the old source and before it is attached to the new
-     * source. */
+     * source. If dest is NULL the move was executed in two
+     * phases and the second one failed; the stream will be destroyed
+     * after this call. */
     void (*moving) (pa_source_output *o, pa_source *dest);   /* may be NULL */
 
     /* Supposed to unlink and destroy this stream. Called from main
@@ -262,6 +264,7 @@ int pa_source_output_move_to(pa_source_output *o, pa_source *dest, pa_bool_t sav
  * new source */
 int pa_source_output_start_move(pa_source_output *o);
 int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t save);
+void pa_source_output_fail_move(pa_source_output *o);
 
 #define pa_source_output_get_state(o) ((o)->state)
 
index 97a20b9..5731663 100644 (file)
@@ -574,7 +574,7 @@ void pa_source_move_all_finish(pa_source *s, pa_queue *q, pa_bool_t save) {
 
     while ((o = PA_SOURCE_OUTPUT(pa_queue_pop(q)))) {
         if (pa_source_output_finish_move(o, s, save) < 0)
-            pa_source_output_kill(o);
+            pa_source_output_fail_move(o);
 
         pa_source_output_unref(o);
     }
@@ -590,10 +590,8 @@ void pa_source_move_all_fail(pa_queue *q) {
     pa_assert(q);
 
     while ((o = PA_SOURCE_OUTPUT(pa_queue_pop(q)))) {
-        if (pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FAIL], o) == PA_HOOK_OK) {
-            pa_source_output_kill(o);
-            pa_source_output_unref(o);
-        }
+        pa_source_output_fail_move(o);
+        pa_source_output_unref(o);
     }
 
     pa_queue_free(q, NULL, NULL);