]> code.delx.au - pulseaudio/commitdiff
add suspend_within_thread() callbacks to pa_sink_input/pa_source_output
authorLennart Poettering <lennart@poettering.net>
Mon, 6 Apr 2009 22:46:20 +0000 (00:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 6 Apr 2009 22:46:20 +0000 (00:46 +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 1fdb3fa6743843a68628ff9804b0aad85b514e30..ad6b9ca71a2f4374ef446b22e56f6323ad9e5183 100644 (file)
@@ -117,6 +117,7 @@ static void reset_callbacks(pa_sink_input *i) {
     i->attach = NULL;
     i->detach = NULL;
     i->suspend = NULL;
+    i->suspend_within_thread = NULL;
     i->moving = NULL;
     i->kill = NULL;
     i->get_latency = NULL;
index 0dd5e9aae407624b536b61f0b628fbb5a3507ed7..6ecb5d73bb0373d6c1e2c402c6ca2430c8587192 100644 (file)
@@ -148,6 +148,10 @@ struct pa_sink_input {
      * to suspends or resumes. Called from main context */
     void (*suspend) (pa_sink_input *i, pa_bool_t b);   /* may be NULL */
 
+    /* If non-NULL called whenever the sink this input is attached
+     * to suspends or resumes. Called from IO context */
+    void (*suspend_within_thread) (pa_sink_input *i, pa_bool_t b);   /* may be NULL */
+
     /* 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
index a0f0ea7e6a82205bb4907b252700b16657f876e1..a5226320cc0b931238ba5538ee4d79440fd88bcb 100644 (file)
@@ -1585,7 +1585,11 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
         case PA_SINK_MESSAGE_GET_MUTE:
             return 0;
 
-        case PA_SINK_MESSAGE_SET_STATE:
+        case PA_SINK_MESSAGE_SET_STATE: {
+
+            pa_bool_t suspend_change =
+                (s->thread_info.state == PA_SINK_SUSPENDED && PA_SINK_IS_OPENED(PA_PTR_TO_UINT(userdata))) ||
+                (PA_SINK_IS_OPENED(s->thread_info.state) && PA_PTR_TO_UINT(userdata) == PA_SINK_SUSPENDED);
 
             s->thread_info.state = PA_PTR_TO_UINT(userdata);
 
@@ -1594,7 +1598,17 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
                 s->thread_info.rewind_requested = FALSE;
             }
 
+            if (suspend_change) {
+                pa_sink_input *i;
+                void *state = NULL;
+
+                while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL)))
+                    if (i->suspend_within_thread)
+                        i->suspend_within_thread(i, s->thread_info.state == PA_SINK_SUSPENDED);
+            }
+
             return 0;
+        }
 
         case PA_SINK_MESSAGE_DETACH:
 
index 1c37be932cb12af1f5a063cedb937d7530f93ac3..8918b43101d9628be0996c60b1d9df337cf716af 100644 (file)
@@ -87,6 +87,7 @@ static void reset_callbacks(pa_source_output *o) {
     o->attach = NULL;
     o->detach = NULL;
     o->suspend = NULL;
+    o->suspend_within_thread = NULL;
     o->moving = NULL;
     o->kill = NULL;
     o->get_latency = NULL;
index 9f5f7744120feadc4c4896089f8dad50bbe5c13d..9824e160d1dbbf2120682fb2686e876bf8d9db29 100644 (file)
@@ -120,6 +120,10 @@ struct pa_source_output {
      * to suspends or resumes. Called from main context */
     void (*suspend) (pa_source_output *o, pa_bool_t b);   /* may be NULL */
 
+    /* If non-NULL called whenever the source this output is attached
+     * to suspends or resumes. Called from IO context */
+    void (*suspend_within_thread) (pa_source_output *o, pa_bool_t b);   /* may be NULL */
+
     /* 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
index 252e23abe8edcd9d851c77826db0fb0a2e25f8a5..b85d6e12ed069a8291935d93e37e5f535def09a0 100644 (file)
@@ -933,9 +933,26 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
         case PA_SOURCE_MESSAGE_GET_MUTE:
             return 0;
 
-        case PA_SOURCE_MESSAGE_SET_STATE:
+        case PA_SOURCE_MESSAGE_SET_STATE: {
+
+            pa_bool_t suspend_change =
+                (s->thread_info.state == PA_SOURCE_SUSPENDED && PA_SOURCE_IS_OPENED(PA_PTR_TO_UINT(userdata))) ||
+                (PA_SOURCE_IS_OPENED(s->thread_info.state) && PA_PTR_TO_UINT(userdata) == PA_SOURCE_SUSPENDED);
+
             s->thread_info.state = PA_PTR_TO_UINT(userdata);
+
+            if (suspend_change) {
+                pa_source_output *o;
+                void *state = NULL;
+
+                while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL)))
+                    if (o->suspend_within_thread)
+                        o->suspend_within_thread(o, s->thread_info.state == PA_SOURCE_SUSPENDED);
+            }
+
+
             return 0;
+        }
 
         case PA_SOURCE_MESSAGE_DETACH:
 
@@ -1217,7 +1234,7 @@ void pa_source_get_latency_range(pa_source *s, pa_usec_t *min_latency, pa_usec_t
    }
 }
 
-/* Called from IO thread, and from main thread before pa_sink_put() is called */
+/* Called from IO thread, and from main thread before pa_source_put() is called */
 void pa_source_set_latency_range_within_thread(pa_source *s, pa_usec_t min_latency, pa_usec_t max_latency) {
     void *state = NULL;