if (data->sync_base->sync_next)
data->sync_base->sync_next->sync_prev = i;
data->sync_base->sync_next = i;
- } else
+ } else
i->sync_next = i->sync_prev = NULL;
-
+
i->peek = NULL;
i->drop = NULL;
i->kill = NULL;
pa_atomic_store(&i->thread_info.drained, 1);
i->thread_info.sample_spec = i->sample_spec;
i->thread_info.silence_memblock = NULL;
- i->thread_info.move_silence = 0;
+ i->thread_info.move_silence = 0;
pa_memchunk_reset(&i->thread_info.resampled_chunk);
i->thread_info.resampler = resampler;
i->thread_info.volume = i->volume;
i->thread_info.muted = i->muted;
+ i->thread_info.attached = FALSE;
pa_assert_se(pa_idxset_put(core->sink_inputs, pa_sink_input_ref(i), &i->index) == 0);
pa_assert_se(pa_idxset_put(i->sink->inputs, i, NULL) == 0);
update_n_corked(i, state);
i->state = state;
-
+
for (ssync = i->sync_prev; ssync; ssync = ssync->sync_prev) {
update_n_corked(ssync, state);
ssync->state = state;
update_n_corked(ssync, state);
ssync->state = state;
}
-
+
return 0;
}
pa_assert(PA_SINK_INPUT_LINKED(i->state));
pa_hook_fire(&i->sink->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], i);
-
+
if (i->sync_prev)
i->sync_prev->sync_next = i->sync_next;
if (i->sync_next)
i->sync_next->sync_prev = i->sync_prev;
-
+
i->sync_prev = i->sync_next = NULL;
-
+
pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_REMOVE_INPUT, i, 0, NULL);
pa_idxset_remove_by_data(i->sink->core->sink_inputs, i, NULL);
pa_idxset_remove_by_data(i->sink->inputs, i, NULL);
sink_input_set_state(i, PA_SINK_INPUT_UNLINKED);
pa_sink_update_status(i->sink);
-
+
i->peek = NULL;
i->drop = NULL;
i->kill = NULL;
pa_log_info("Freeing output %u \"%s\"", i->index, i->name);
+ pa_assert(!i->thread_info.attached);
+
if (i->thread_info.resampled_chunk.memblock)
pa_memblock_unref(i->thread_info.resampled_chunk.memblock);
block_size_max = pa_mempool_block_size_max(i->sink->core->mempool);
if (length > block_size_max)
length = pa_frame_align(block_size_max, &i->sink->sample_spec);
-
+
if (i->thread_info.move_silence > 0) {
size_t l;
rmbs = pa_resampler_max_block_size(i->thread_info.resampler);
if (l > rmbs)
l = rmbs;
-
+
if ((ret = i->peek(i, l, &tchunk)) < 0)
goto finish;
/* It might be necessary to adjust the volume here */
if (do_volume_adj_here && !volume_is_norm) {
pa_memchunk_make_writable(&tchunk, 0);
-
+
if (i->thread_info.muted)
pa_silence_memchunk(&tchunk, &i->thread_info.sample_spec);
else
i->thread_info.resampled_chunk.index += l;
i->thread_info.resampled_chunk.length -= l;
-
+
if (i->thread_info.resampled_chunk.length <= 0) {
pa_memblock_unref(i->thread_info.resampled_chunk.memblock);
pa_memchunk_reset(&i->thread_info.resampled_chunk);
}
if (length > 0) {
-
+
if (i->thread_info.resampler) {
/* So, we have a resampler. To avoid discontinuities we
* have to actually read all data that could be read and
while (length > 0) {
pa_memchunk chunk;
pa_cvolume volume;
-
+
if (pa_sink_input_peek(i, length, &chunk, &volume) >= 0) {
size_t l;
-
+
pa_memblock_unref(chunk.memblock);
l = chunk.length;
if (l > length)
l = length;
-
+
pa_sink_input_drop(i, l);
length -= l;
-
+
} else {
size_t l;
-
+
l = pa_resampler_request(i->thread_info.resampler, length);
-
+
/* Hmmm, peeking failed, so let's at least drop
* the right amount of data */
if (l > 0)
if (i->drop)
i->drop(i, l);
-
+
break;
}
}
memset(&info, 0, sizeof(info));
info.sink_input = i;
-
+
if (!immediately) {
pa_usec_t old_latency, new_latency;
}
/* Okey, let's move it */
-
+
if (info.buffer_bytes > 0) {
-
+
info.ghost_sink_input = pa_memblockq_sink_input_new(
origin,
"Ghost Stream",
info.ghost_sink_input->thread_info.state = info.ghost_sink_input->state = PA_SINK_INPUT_RUNNING;
info.ghost_sink_input->thread_info.volume = info.ghost_sink_input->volume;
info.ghost_sink_input->thread_info.muted = info.ghost_sink_input->muted;
-
+
info.buffer = pa_memblockq_new(0, MOVE_BUFFER_LENGTH, 0, pa_frame_size(&origin->sample_spec), 0, 0, NULL);
}
}
if (info.ghost_sink_input) {
/* Basically, do what pa_sink_input_put() does ...*/
-
+
pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, info.ghost_sink_input->index);
pa_hook_fire(&i->sink->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], info.ghost_sink_input);
pa_sink_input_unref(info.ghost_sink_input);
}
-
+
pa_idxset_remove_by_data(origin->inputs, i, NULL);
pa_idxset_put(dest->inputs, i, NULL);
i->sink = dest;
&dest->sample_spec);
pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_ADD_INPUT, i, 0, NULL);
-
+
pa_sink_update_status(origin);
pa_sink_update_status(dest);
pa_hook_fire(&i->sink->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_POST], i);
-
+
pa_log_debug("Successfully moved sink input %i from %s to %s.", i->index, origin->name, dest->name);
-
+
/* Notify everyone */
pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
if (i->thread_info.resampled_chunk.memblock)
*r += pa_bytes_to_usec(i->thread_info.resampled_chunk.length, &i->sink->sample_spec);
- if (i->thread_info.move_silence)
- *r += pa_bytes_to_usec(i->thread_info.move_silence, &i->sink->sample_spec);
+ if (i->thread_info.move_silence)
+ *r += pa_bytes_to_usec(i->thread_info.move_silence, &i->sink->sample_spec);
return 0;
}
- case PA_SINK_INPUT_MESSAGE_SET_RATE:
+ case PA_SINK_INPUT_MESSAGE_SET_RATE:
i->thread_info.sample_spec.rate = PA_PTR_TO_UINT(userdata);
pa_resampler_set_input_rate(i->thread_info.resampler, PA_PTR_TO_UINT(userdata));
case PA_SINK_INPUT_MESSAGE_SET_STATE: {
pa_sink_input *ssync;
-
+
if ((PA_PTR_TO_UINT(userdata) == PA_SINK_INPUT_DRAINED || PA_PTR_TO_UINT(userdata) == PA_SINK_INPUT_RUNNING) &&
(i->thread_info.state != PA_SINK_INPUT_DRAINED) && (i->thread_info.state != PA_SINK_INPUT_RUNNING))
pa_atomic_store(&i->thread_info.drained, 1);
-
+
i->thread_info.state = PA_PTR_TO_UINT(userdata);
for (ssync = i->thread_info.sync_prev; ssync; ssync = ssync->thread_info.sync_prev) {
pa_atomic_store(&ssync->thread_info.drained, 1);
ssync->thread_info.state = PA_PTR_TO_UINT(userdata);
}
-
+
for (ssync = i->thread_info.sync_next; ssync; ssync = ssync->thread_info.sync_next) {
if ((PA_PTR_TO_UINT(userdata) == PA_SINK_INPUT_DRAINED || PA_PTR_TO_UINT(userdata) == PA_SINK_INPUT_RUNNING) &&
(ssync->thread_info.state != PA_SINK_INPUT_DRAINED) && (ssync->thread_info.state != PA_SINK_INPUT_RUNNING))
pa_atomic_store(&ssync->thread_info.drained, 1);
ssync->thread_info.state = PA_PTR_TO_UINT(userdata);
}
-
+
return 0;
}
}
return i->state;
}
-
struct {
pa_sink_input_state_t state;
pa_atomic_t drained;
+
+ pa_bool_t attached; /* True only between ->attach() and ->detach() calls */
pa_sample_spec sample_spec;
pa_assert(s->rtpoll);
s->thread_info.state = s->state = PA_SINK_IDLE;
-
+
pa_source_put(s->monitor_source);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_NEW, s->index);
static int sink_set_state(pa_sink *s, pa_sink_state_t state) {
int ret;
-
+
pa_assert(s);
if (s->state == state)
(PA_SINK_OPENED(s->state) && state == PA_SINK_SUSPENDED)) {
pa_sink_input *i;
uint32_t idx;
-
+
/* We're suspending or resuming, tell everyone about it */
-
+
for (i = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx)))
if (i->suspend)
i->suspend(i, state == PA_SINK_SUSPENDED);
}
-
+
if (s->set_state)
if ((ret = s->set_state(s, state)) < 0)
return -1;
pa_assert(PA_SINK_LINKED(s->state));
pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_UNLINK], s);
-
+
pa_namereg_unregister(s->core, s->name);
pa_idxset_remove_by_data(s->core->sinks, s, NULL);
while ((i = pa_hashmap_steal_first(s->thread_info.inputs)))
pa_sink_input_unref(i);
-
+
pa_hashmap_free(s->thread_info.inputs, NULL, NULL);
if (s->silence)
pa_memblock_unref(s->silence);
-
+
pa_xfree(s->name);
pa_xfree(s->description);
pa_xfree(s->driver);
pa_mix_info info[MAX_MIX_CHANNELS];
unsigned n;
size_t block_size_max;
-
+
pa_sink_assert_ref(s);
pa_assert(PA_SINK_OPENED(s->thread_info.state));
pa_assert(pa_frame_aligned(length, &s->sample_spec));
length = pa_frame_align(block_size_max, &s->sample_spec);
pa_assert(length > 0);
-
+
n = s->thread_info.state == PA_SINK_RUNNING ? fill_mix_info(s, length, info, MAX_MIX_CHANNELS) : 0;
if (n == 0) {
pa_assert(PA_SINK_OPENED(s->thread_info.state));
pa_assert(length > 0);
pa_assert(pa_frame_aligned(length, &s->sample_spec));
-
+
if (pa_source_used_by(s->monitor_source)) {
pa_memchunk chunk;
-
+
/* If something is connected to our monitor source, we have to
* pass valid data to it */
pa_assert(chunk.length <= length);
length -= chunk.length;
}
-
+
} else {
/* Ok, noone cares about the rendered data, so let's not even render it */
pa_assert(PA_SINK_LINKED(s->thread_info.state));
switch ((pa_sink_message_t) code) {
-
+
case PA_SINK_MESSAGE_ADD_INPUT: {
pa_sink_input *i = PA_SINK_INPUT(userdata);
pa_hashmap_put(s->thread_info.inputs, PA_UINT32_TO_PTR(i->index), pa_sink_input_ref(i));
i->thread_info.sync_next->thread_info.sync_prev = i;
}
+ pa_assert(!i->thread_info.attached);
+ i->thread_info.attached = TRUE;
+
if (i->attach)
i->attach(i);
if (i->detach)
i->detach(i);
-
+
+ pa_assert(i->thread_info.attached);
+ i->thread_info.attached = FALSE;
+
/* Since the caller sleeps in pa_sink_input_unlink(),
* we can safely access data outside of thread_info even
* though it is mutable */
pa_assert(!i->thread_info.sync_prev);
pa_assert(!i->thread_info.sync_next);
-
+
if (i->thread_info.sync_prev) {
i->thread_info.sync_prev->thread_info.sync_next = i->thread_info.sync_prev->sync_next;
i->thread_info.sync_prev = NULL;
i->thread_info.sync_next->thread_info.sync_prev = i->thread_info.sync_next->sync_prev;
i->thread_info.sync_next = NULL;
}
-
+
if (pa_hashmap_remove(s->thread_info.inputs, PA_UINT32_TO_PTR(i->index)))
pa_sink_input_unref(i);
-
+
return 0;
}
pa_assert(!info->sink_input->sync_next);
pa_assert(!info->sink_input->thread_info.sync_next);
pa_assert(!info->sink_input->thread_info.sync_prev);
-
+
if (info->ghost_sink_input) {
pa_assert(info->buffer_bytes > 0);
pa_assert(info->buffer);
-
+
volume_is_norm = pa_cvolume_is_norm(&info->sink_input->thread_info.volume);
pa_log_debug("Buffering %lu bytes ...", (unsigned long) info->buffer_bytes);
-
+
while (info->buffer_bytes > 0) {
pa_memchunk memchunk;
pa_cvolume volume;
size_t n;
-
+
if (pa_sink_input_peek(info->sink_input, info->buffer_bytes, &memchunk, &volume) < 0)
break;
-
+
n = memchunk.length > info->buffer_bytes ? info->buffer_bytes : memchunk.length;
pa_sink_input_drop(info->sink_input, n);
memchunk.length = n;
-
+
if (!volume_is_norm) {
pa_memchunk_make_writable(&memchunk, 0);
pa_volume_memchunk(&memchunk, &s->sample_spec, &volume);
}
-
+
if (pa_memblockq_push(info->buffer, &memchunk) < 0) {
pa_memblock_unref(memchunk.memblock);
break;
}
-
+
pa_memblock_unref(memchunk.memblock);
info->buffer_bytes -= n;
}
pa_hashmap_put(s->thread_info.inputs, PA_UINT32_TO_PTR(info->ghost_sink_input->index), pa_sink_input_ref(info->ghost_sink_input));
info->ghost_sink_input->thread_info.sync_prev = info->ghost_sink_input->thread_info.sync_next = NULL;
}
-
+
return 0;
}
return 0;
case PA_SINK_MESSAGE_SET_STATE:
-
+
s->thread_info.state = PA_PTR_TO_UINT(userdata);
return 0;
/* Reattach all streams */
pa_sink_attach_within_thread(s);
break;
-
+
case PA_SINK_MESSAGE_GET_LATENCY:
case PA_SINK_MESSAGE_MAX:
;
pa_sink *sink;
uint32_t idx;
int ret = 0;
-
+
pa_core_assert_ref(c);
for (sink = PA_SINK(pa_idxset_first(c->sinks, &idx)); sink; sink = PA_SINK(pa_idxset_next(c->sinks, &idx)))
if (s->monitor_source)
pa_source_attach_within_thread(s->monitor_source);
}
-
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;
pa_assert_se(o->source->n_corked -- >= 1);
else if (o->state != PA_SOURCE_OUTPUT_CORKED && state == PA_SOURCE_OUTPUT_CORKED)
o->source->n_corked++;
-
+
o->state = state;
-
+
return 0;
}
pa_assert(PA_SOURCE_OUTPUT_LINKED(o->state));
pa_hook_fire(&o->source->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], o);
-
+
pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_REMOVE_OUTPUT, o, 0, NULL);
pa_idxset_remove_by_data(o->source->core->source_outputs, o, NULL);
pa_log_info("Freeing output %u \"%s\"", o->index, o->name);
+ pa_assert(!o->thread_info.attached);
+
if (o->thread_info.resampler)
pa_resampler_free(o->thread_info.resampler);
void pa_source_output_kill(pa_source_output*o) {
pa_source_output_assert_ref(o);
pa_assert(PA_SOURCE_OUTPUT_LINKED(o->state));
-
+
if (o->kill)
o->kill(o);
}
pa_source_output_assert_ref(o);
pa_assert(PA_SOURCE_OUTPUT_LINKED(o->state));
pa_source_assert_ref(dest);
-
+
origin = o->source;
if (dest == origin)
/* Okey, let's move it */
pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_REMOVE_OUTPUT, o, 0, NULL);
-
+
pa_idxset_remove_by_data(origin->outputs, o, NULL);
pa_idxset_put(dest->outputs, o, NULL);
o->source = dest;
return 0;
}
-
+
}
return -1;
struct {
pa_source_output_state_t state;
+
+ pa_bool_t attached; /* True only between ->attach() and ->detach() calls */
pa_sample_spec sample_spec;
static int source_set_state(pa_source *s, pa_source_state_t state) {
int ret;
-
+
pa_assert(s);
if (s->state == state)
if (state == PA_SOURCE_SUSPENDED && !(s->flags & PA_SOURCE_CAN_SUSPEND))
return -1;
-
+
if ((s->state == PA_SOURCE_SUSPENDED && PA_SOURCE_OPENED(state)) ||
(PA_SOURCE_OPENED(s->state) && state == PA_SOURCE_SUSPENDED)) {
pa_source_output *o;
uint32_t idx;
-
+
/* We're suspending or resuming, tell everyone about it */
-
+
for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx)))
if (o->suspend)
o->suspend(o, state == PA_SINK_SUSPENDED);
pa_assert(s);
pa_assert(PA_SOURCE_LINKED(s->state));
- pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], s);
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], s);
pa_namereg_unregister(s->core, s->name);
pa_idxset_remove_by_data(s->core->sources, s, NULL);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
- pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], s);
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], s);
}
static void source_free(pa_object *o) {
while ((so = pa_hashmap_steal_first(s->thread_info.outputs)))
pa_source_output_unref(so);
-
+
pa_hashmap_free(s->thread_info.outputs, NULL, NULL);
pa_xfree(s->name);
if (s->thread_info.state != PA_SOURCE_RUNNING)
return;
-
+
if (s->thread_info.soft_muted || !pa_cvolume_is_norm(&s->thread_info.soft_volume)) {
pa_memchunk vchunk = *chunk;
unsigned pa_source_used_by(pa_source *s) {
unsigned ret;
-
+
pa_source_assert_ref(s);
pa_assert(PA_SOURCE_LINKED(s->state));
pa_source_output *o = PA_SOURCE_OUTPUT(userdata);
pa_hashmap_put(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index), pa_source_output_ref(o));
+ pa_assert(!o->thread_info.attached);
+ o->thread_info.attached = TRUE;
+
if (o->attach)
o->attach(o);
-
+
return 0;
}
if (o->detach)
o->detach(o);
+ pa_assert(o->thread_info.attached);
+ o->thread_info.attached = FALSE;
+
if (pa_hashmap_remove(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index)))
pa_source_output_unref(o);
/* Reattach all streams */
pa_source_attach_within_thread(s);
break;
-
+
case PA_SOURCE_MESSAGE_GET_LATENCY:
case PA_SOURCE_MESSAGE_MAX:
;
uint32_t idx;
pa_source *source;
int ret = 0;
-
+
pa_core_assert_ref(c);
-
+
for (source = PA_SOURCE(pa_idxset_first(c->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(c->sources, &idx)))
ret -= pa_source_suspend(source, suspend) < 0;