[PATCH v2 10/21] sink-input, source-output: Allocate the object early in new()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The sink input/source output node will have to be created already
during the routing phase, because doing it later makes it impossible
to use node-based routing to set the initial routing. When the node is
created, it will need the sink input/source output pointer, and that's
why we need to allocate the object already before the routing phase.

I had to choose which fields to initialize early. I think at least
index, core and state need to be initialized before passing the object
to any external code, but I chose to move up the initialization of all
fields that only require a one-liner.

I also removed explicit initialization of fields that were just set
to zero, because pa_msgobject_new() nowadays zeroes the memory anyway.
---
 src/pulsecore/sink-input.c    | 49 +++++++++++++++++--------------------------
 src/pulsecore/source-output.c | 37 ++++++++++++++------------------
 2 files changed, 35 insertions(+), 51 deletions(-)

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 1f88bfc..6af64ae 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -304,6 +304,24 @@ int pa_sink_input_new(
     pa_assert(data);
     pa_assert_ctl_context();
 
+    i = pa_msgobject_new(pa_sink_input);
+    i->parent.parent.free = sink_input_free;
+    i->parent.process_msg = pa_sink_input_process_msg;
+    pa_assert_se(pa_idxset_put(core->sink_inputs, i, &i->index) >= 0);
+    i->core = core;
+    i->state = PA_SINK_INPUT_INIT;
+    i->flags = data->flags;
+    i->module = data->module;
+    i->client = data->client;
+    i->origin_sink = data->origin_sink;
+    i->direct_outputs = pa_idxset_new(NULL, NULL);
+
+    i->thread_info.state = i->state;
+    pa_atomic_store(&i->thread_info.drained, 1);
+    i->thread_info.underrun_for = (uint64_t) -1;
+    i->thread_info.requested_sink_latency = (pa_usec_t) -1;
+    i->thread_info.direct_outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+
     if (data->client)
         pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->client->proplist);
 
@@ -544,20 +562,9 @@ int pa_sink_input_new(
             }
     }
 
-    i = pa_msgobject_new(pa_sink_input);
-    i->parent.parent.free = sink_input_free;
-    i->parent.process_msg = pa_sink_input_process_msg;
-
-    i->core = core;
-    i->state = PA_SINK_INPUT_INIT;
-    i->flags = data->flags;
     i->proplist = pa_proplist_copy(data->proplist);
     i->driver = pa_xstrdup(pa_path_get_filename(data->driver));
-    i->module = data->module;
     i->sink = data->sink;
-    i->origin_sink = data->origin_sink;
-    i->client = data->client;
-
     i->requested_resample_method = data->resample_method;
     i->actual_resample_method = resampler ? pa_resampler_get_method(resampler) : PA_RESAMPLER_INVALID;
     i->sample_spec = data->sample_spec;
@@ -600,31 +607,13 @@ int pa_sink_input_new(
         if (data->sync_base->sync_next)
             data->sync_base->sync_next->sync_prev = i;
         data->sync_base->sync_next = i;
-    } else
-        i->sync_next = i->sync_prev = NULL;
-
-    i->direct_outputs = pa_idxset_new(NULL, NULL);
-
-    reset_callbacks(i);
-    i->userdata = NULL;
+    }
 
-    i->thread_info.state = i->state;
-    i->thread_info.attached = false;
-    pa_atomic_store(&i->thread_info.drained, 1);
     i->thread_info.sample_spec = i->sample_spec;
     i->thread_info.resampler = resampler;
     i->thread_info.soft_volume = i->soft_volume;
     i->thread_info.muted = i->muted;
-    i->thread_info.requested_sink_latency = (pa_usec_t) -1;
-    i->thread_info.rewrite_nbytes = 0;
-    i->thread_info.rewrite_flush = false;
-    i->thread_info.dont_rewind_render = false;
-    i->thread_info.underrun_for = (uint64_t) -1;
-    i->thread_info.underrun_for_sink = 0;
-    i->thread_info.playing_for = 0;
-    i->thread_info.direct_outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
 
-    pa_assert_se(pa_idxset_put(core->sink_inputs, i, &i->index) == 0);
     pa_assert_se(pa_idxset_put(i->sink->inputs, pa_sink_input_ref(i), NULL) == 0);
 
     if (i->client)
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 3d2cd4a..35d1ea8 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -239,6 +239,22 @@ int pa_source_output_new(
     pa_assert(data);
     pa_assert_ctl_context();
 
+    o = pa_msgobject_new(pa_source_output);
+    o->parent.parent.free = source_output_free;
+    o->parent.process_msg = pa_source_output_process_msg;
+    pa_assert_se(pa_idxset_put(core->source_outputs, o, &o->index) >= 0);
+    o->core = core;
+    o->state = PA_SOURCE_OUTPUT_INIT;
+    o->flags = data->flags;
+    o->module = data->module;
+    o->client = data->client;
+    o->destination_source = data->destination_source;
+    o->direct_on_input = data->direct_on_input;
+
+    o->thread_info.state = o->state;
+    o->thread_info.requested_source_latency = (pa_usec_t) -1;
+    o->thread_info.direct_on_input = o->direct_on_input;
+
     if (data->client)
         pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->client->proplist);
 
@@ -499,19 +515,9 @@ int pa_source_output_new(
             }
     }
 
-    o = pa_msgobject_new(pa_source_output);
-    o->parent.parent.free = source_output_free;
-    o->parent.process_msg = pa_source_output_process_msg;
-
-    o->core = core;
-    o->state = PA_SOURCE_OUTPUT_INIT;
-    o->flags = data->flags;
     o->proplist = pa_proplist_copy(data->proplist);
     o->driver = pa_xstrdup(pa_path_get_filename(data->driver));
-    o->module = data->module;
     o->source = data->source;
-    o->destination_source = data->destination_source;
-    o->client = data->client;
 
     o->requested_resample_method = data->resample_method;
     o->actual_resample_method = resampler ? pa_resampler_get_method(resampler) : PA_RESAMPLER_INVALID;
@@ -539,22 +545,12 @@ int pa_source_output_new(
     o->save_volume = data->save_volume;
     o->save_source = data->save_source;
     o->save_muted = data->save_muted;
-
     o->muted = data->muted;
 
-    o->direct_on_input = data->direct_on_input;
-
-    reset_callbacks(o);
-    o->userdata = NULL;
-
-    o->thread_info.state = o->state;
-    o->thread_info.attached = false;
     o->thread_info.sample_spec = o->sample_spec;
     o->thread_info.resampler = resampler;
     o->thread_info.soft_volume = o->soft_volume;
     o->thread_info.muted = o->muted;
-    o->thread_info.requested_source_latency = (pa_usec_t) -1;
-    o->thread_info.direct_on_input = o->direct_on_input;
 
     o->thread_info.delay_memblockq = pa_memblockq_new(
             "source output delay_memblockq",
@@ -567,7 +563,6 @@ int pa_source_output_new(
             0,
             &o->source->silence);
 
-    pa_assert_se(pa_idxset_put(core->source_outputs, o, &o->index) == 0);
     pa_assert_se(pa_idxset_put(o->source->outputs, pa_source_output_ref(o), NULL) == 0);
 
     if (o->client)
-- 
1.8.3.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux