[pulseaudio-discuss] [PATCH v2 08/22] sink, source: Support creating suspended sinks and sources
Mikel Astiz
mikel.astiz.oss at gmail.com
Fri Aug 31 03:51:00 PDT 2012
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
The initial state of a sink or source might not necessarily be IDLE,
because sometimes it might be suspended from the very beginning.
---
src/modules/bluetooth/module-bluetooth-device.c | 8 ++++++--
src/pulsecore/sink.c | 7 +++++--
src/pulsecore/sink.h | 2 ++
src/pulsecore/source.c | 7 +++++--
src/pulsecore/source.h | 2 ++
5 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 89bbbae..f5f77bc 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -380,7 +380,9 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
case PA_SINK_SUSPENDED:
- pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
+ /* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */
+ if (!PA_SINK_IS_OPENED(u->sink->thread_info.state))
+ break;
/* Stop the device if the source is suspended as well */
if (!u->source || u->source->state == PA_SOURCE_SUSPENDED)
@@ -454,7 +456,9 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
switch ((pa_source_state_t) PA_PTR_TO_UINT(data)) {
case PA_SOURCE_SUSPENDED:
- pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state));
+ /* Ignore if transition is PA_SOURCE_INIT->PA_SOURCE_SUSPENDED */
+ if (!PA_SOURCE_IS_OPENED(u->source->thread_info.state))
+ break;
/* Stop the device if the sink is suspended as well */
if (!u->sink || u->sink->state == PA_SINK_SUSPENDED)
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 3d72f55..237b859 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -248,7 +248,7 @@ pa_sink* pa_sink_new(
s->state = PA_SINK_INIT;
s->flags = flags;
s->priority = 0;
- s->suspend_cause = 0;
+ s->suspend_cause = data->suspend_cause;
pa_sink_set_mixer_dirty(s, FALSE);
s->name = pa_xstrdup(name);
s->proplist = pa_proplist_copy(data->proplist);
@@ -650,7 +650,10 @@ void pa_sink_put(pa_sink* s) {
pa_assert(s->monitor_source->thread_info.min_latency == s->thread_info.min_latency);
pa_assert(s->monitor_source->thread_info.max_latency == s->thread_info.max_latency);
- pa_assert_se(sink_set_state(s, PA_SINK_IDLE) == 0);
+ if (s->suspend_cause)
+ pa_assert_se(sink_set_state(s, PA_SINK_SUSPENDED) == 0);
+ else
+ pa_assert_se(sink_set_state(s, PA_SINK_IDLE) == 0);
pa_source_put(s->monitor_source);
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 2c52348..fcda5ef 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -328,6 +328,8 @@ typedef enum pa_sink_message {
} pa_sink_message_t;
typedef struct pa_sink_new_data {
+ pa_suspend_cause_t suspend_cause;
+
char *name;
pa_proplist *proplist;
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index cefddae..7af86f5 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -235,7 +235,7 @@ pa_source* pa_source_new(
s->state = PA_SOURCE_INIT;
s->flags = flags;
s->priority = 0;
- s->suspend_cause = 0;
+ s->suspend_cause = data->suspend_cause;
pa_source_set_mixer_dirty(s, FALSE);
s->name = pa_xstrdup(name);
s->proplist = pa_proplist_copy(data->proplist);
@@ -595,7 +595,10 @@ void pa_source_put(pa_source *s) {
pa_assert(!(s->flags & PA_SOURCE_DECIBEL_VOLUME) || s->n_volume_steps == PA_VOLUME_NORM+1);
pa_assert(!(s->flags & PA_SOURCE_DYNAMIC_LATENCY) == (s->thread_info.fixed_latency != 0));
- pa_assert_se(source_set_state(s, PA_SOURCE_IDLE) == 0);
+ if (s->suspend_cause)
+ pa_assert_se(source_set_state(s, PA_SOURCE_SUSPENDED) == 0);
+ else
+ pa_assert_se(source_set_state(s, PA_SOURCE_IDLE) == 0);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index);
pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PUT], s);
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index dd1e09b..224155b 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -265,6 +265,8 @@ typedef enum pa_source_message {
} pa_source_message_t;
typedef struct pa_source_new_data {
+ pa_suspend_cause_t suspend_cause;
+
char *name;
pa_proplist *proplist;
--
1.7.7.6
More information about the pulseaudio-discuss
mailing list