4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <pulse/utf8.h>
34 #include <pulse/xmalloc.h>
36 #include <pulsecore/sample-util.h>
37 #include <pulsecore/core-subscribe.h>
38 #include <pulsecore/log.h>
39 #include <pulsecore/play-memblockq.h>
40 #include <pulsecore/namereg.h>
42 #include "sink-input.h"
44 #define CONVERT_BUFFER_LENGTH 4096
45 #define MOVE_BUFFER_LENGTH (1024*1024)
46 #define SILENCE_BUFFER_LENGTH (64*1024)
48 static PA_DEFINE_CHECK_TYPE(pa_sink_input
, sink_input_check_type
, pa_msgobject_check_type
);
50 static void sink_input_free(pa_object
*o
);
52 pa_sink_input_new_data
* pa_sink_input_new_data_init(pa_sink_input_new_data
*data
) {
55 memset(data
, 0, sizeof(*data
));
56 data
->resample_method
= PA_RESAMPLER_INVALID
;
61 void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data
*data
, const pa_channel_map
*map
) {
64 if ((data
->channel_map_is_set
= !!map
))
65 data
->channel_map
= *map
;
68 void pa_sink_input_new_data_set_volume(pa_sink_input_new_data
*data
, const pa_cvolume
*volume
) {
71 if ((data
->volume_is_set
= !!volume
))
72 data
->volume
= *volume
;
75 void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data
*data
, const pa_sample_spec
*spec
) {
78 if ((data
->sample_spec_is_set
= !!spec
))
79 data
->sample_spec
= *spec
;
82 void pa_sink_input_new_data_set_muted(pa_sink_input_new_data
*data
, int mute
) {
85 data
->muted_is_set
= 1;
89 pa_sink_input
* pa_sink_input_new(
91 pa_sink_input_new_data
*data
,
92 pa_sink_input_flags_t flags
) {
95 pa_resampler
*resampler
= NULL
;
96 char st
[PA_SAMPLE_SPEC_SNPRINT_MAX
];
101 if (!(flags
& PA_SINK_INPUT_NO_HOOKS
))
102 if (pa_hook_fire(&core
->hook_sink_input_new
, data
) < 0)
105 pa_return_null_if_fail(!data
->driver
|| pa_utf8_valid(data
->driver
));
106 pa_return_null_if_fail(!data
->name
|| pa_utf8_valid(data
->name
));
109 data
->sink
= pa_namereg_get(core
, NULL
, PA_NAMEREG_SINK
, 1);
111 pa_return_null_if_fail(data
->sink
);
112 pa_return_null_if_fail(pa_sink_get_state(data
->sink
) != PA_SINK_DISCONNECTED
);
114 if (!data
->sample_spec_is_set
)
115 data
->sample_spec
= data
->sink
->sample_spec
;
117 pa_return_null_if_fail(pa_sample_spec_valid(&data
->sample_spec
));
119 if (!data
->channel_map_is_set
) {
120 if (data
->sink
->channel_map
.channels
== data
->sample_spec
.channels
)
121 data
->channel_map
= data
->sink
->channel_map
;
123 pa_channel_map_init_auto(&data
->channel_map
, data
->sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
);
126 pa_return_null_if_fail(pa_channel_map_valid(&data
->channel_map
));
127 pa_return_null_if_fail(data
->channel_map
.channels
== data
->sample_spec
.channels
);
129 if (!data
->volume_is_set
)
130 pa_cvolume_reset(&data
->volume
, data
->sample_spec
.channels
);
132 pa_return_null_if_fail(pa_cvolume_valid(&data
->volume
));
133 pa_return_null_if_fail(data
->volume
.channels
== data
->sample_spec
.channels
);
135 if (!data
->muted_is_set
)
138 if (data
->resample_method
== PA_RESAMPLER_INVALID
)
139 data
->resample_method
= core
->resample_method
;
141 pa_return_null_if_fail(data
->resample_method
< PA_RESAMPLER_MAX
);
143 if (pa_idxset_size(data
->sink
->inputs
) >= PA_MAX_INPUTS_PER_SINK
) {
144 pa_log_warn("Failed to create sink input: too many inputs per sink.");
148 if ((flags
& PA_SINK_INPUT_VARIABLE_RATE
) ||
149 !pa_sample_spec_equal(&data
->sample_spec
, &data
->sink
->sample_spec
) ||
150 !pa_channel_map_equal(&data
->channel_map
, &data
->sink
->channel_map
)) {
152 if (!(resampler
= pa_resampler_new(
154 &data
->sample_spec
, &data
->channel_map
,
155 &data
->sink
->sample_spec
, &data
->sink
->channel_map
,
156 data
->resample_method
))) {
157 pa_log_warn("Unsupported resampling operation.");
161 data
->resample_method
= pa_resampler_get_method(resampler
);
164 i
= pa_msgobject_new(pa_sink_input
, sink_input_check_type
);
165 i
->parent
.parent
.free
= sink_input_free
;
166 i
->parent
.process_msg
= pa_sink_input_process_msg
;
169 i
->state
= PA_SINK_INPUT_RUNNING
;
171 i
->name
= pa_xstrdup(data
->name
);
172 i
->driver
= pa_xstrdup(data
->driver
);
173 i
->module
= data
->module
;
174 i
->sink
= data
->sink
;
175 i
->client
= data
->client
;
177 i
->resample_method
= data
->resample_method
;
178 i
->sample_spec
= data
->sample_spec
;
179 i
->channel_map
= data
->channel_map
;
181 i
->volume
= data
->volume
;
182 i
->muted
= data
->muted
;
187 i
->get_latency
= NULL
;
191 i
->thread_info
.state
= i
->state
;
192 pa_atomic_store(&i
->thread_info
.drained
, 1);
193 i
->thread_info
.sample_spec
= i
->sample_spec
;
194 i
->thread_info
.silence_memblock
= NULL
;
195 /* i->thread_info.move_silence = 0; */
196 pa_memchunk_reset(&i
->thread_info
.resampled_chunk
);
197 i
->thread_info
.resampler
= resampler
;
198 i
->thread_info
.volume
= i
->volume
;
199 i
->thread_info
.muted
= i
->muted
;
201 pa_assert_se(pa_idxset_put(core
->sink_inputs
, i
, &i
->index
) == 0);
202 pa_assert_se(pa_idxset_put(i
->sink
->inputs
, i
, NULL
) == 0);
204 pa_log_info("Created input %u \"%s\" on %s with sample spec %s",
208 pa_sample_spec_snprint(st
, sizeof(st
), &i
->sample_spec
));
210 /* Don't forget to call pa_sink_input_put! */
215 static int sink_input_set_state(pa_sink_input
*i
, pa_sink_input_state_t state
) {
218 if (state
== PA_SINK_INPUT_DRAINED
)
219 state
= PA_SINK_INPUT_RUNNING
;
221 if (i
->state
== state
)
224 if (pa_asyncmsgq_send(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
), PA_SINK_INPUT_MESSAGE_SET_STATE
, PA_UINT_TO_PTR(state
), NULL
) < 0)
231 void pa_sink_input_disconnect(pa_sink_input
*i
) {
233 pa_return_if_fail(i
->state
!= PA_SINK_INPUT_DISCONNECTED
);
235 pa_asyncmsgq_send(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
->sink
), PA_SINK_MESSAGE_REMOVE_INPUT
, i
, NULL
);
236 pa_idxset_remove_by_data(i
->sink
->core
->sink_inputs
, i
, NULL
);
237 pa_idxset_remove_by_data(i
->sink
->inputs
, i
, NULL
);
239 pa_subscription_post(i
->sink
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_REMOVE
, i
->index
);
241 sink_input_set_state(i
, PA_SINK_INPUT_DISCONNECTED
);
242 pa_sink_update_status(i
->sink
);
248 i
->get_latency
= NULL
;
252 static void sink_input_free(pa_object
*o
) {
253 pa_sink_input
* i
= PA_SINK_INPUT(o
);
256 pa_assert(pa_sink_input_refcnt(i
) == 0);
258 if (i
->state
!= PA_SINK_INPUT_DISCONNECTED
)
259 pa_sink_input_disconnect(i
);
261 pa_log_info("Freeing output %u \"%s\"", i
->index
, i
->name
);
263 if (i
->thread_info
.resampled_chunk
.memblock
)
264 pa_memblock_unref(i
->thread_info
.resampled_chunk
.memblock
);
266 if (i
->thread_info
.resampler
)
267 pa_resampler_free(i
->thread_info
.resampler
);
269 if (i
->thread_info
.silence_memblock
)
270 pa_memblock_unref(i
->thread_info
.silence_memblock
);
277 void pa_sink_input_put(pa_sink_input
*i
) {
278 pa_sink_input_assert_ref(i
);
280 i
->thread_info
.volume
= i
->volume
;
281 i
->thread_info
.muted
= i
->muted
;
283 pa_asyncmsgq_post(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
->sink
), PA_SINK_MESSAGE_ADD_INPUT
, pa_sink_input_ref(i
), NULL
, (pa_free_cb_t
) pa_sink_input_unref
);
284 pa_sink_update_status(i
->sink
);
286 pa_subscription_post(i
->sink
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_NEW
, i
->index
);
289 void pa_sink_input_kill(pa_sink_input
*i
) {
290 pa_sink_input_assert_ref(i
);
296 pa_usec_t
pa_sink_input_get_latency(pa_sink_input
*i
) {
299 pa_sink_input_assert_ref(i
);
301 if (pa_asyncmsgq_send(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
), PA_SINK_INPUT_MESSAGE_GET_LATENCY
, &r
, NULL
) < 0)
305 r
+= i
->get_latency(i
);
310 int pa_sink_input_peek(pa_sink_input
*i
, pa_memchunk
*chunk
, pa_cvolume
*volume
) {
312 int do_volume_adj_here
;
315 pa_sink_input_assert_ref(i
);
319 if (!i
->peek
|| !i
->drop
|| i
->thread_info
.state
== PA_SINK_INPUT_DISCONNECTED
|| i
->thread_info
.state
== PA_SINK_INPUT_CORKED
)
322 pa_assert(i
->thread_info
.state
== PA_SINK_INPUT_RUNNING
|| i
->thread_info
.state
== PA_SINK_INPUT_DRAINED
);
324 /* if (i->thread_info.move_silence > 0) { */
327 /* /\* We have just been moved and shall play some silence for a */
328 /* * while until the old sink has drained its playback buffer *\/ */
330 /* if (!i->thread_info.silence_memblock) */
331 /* i->thread_info.silence_memblock = pa_silence_memblock_new(i->sink->core->mempool, &i->sink->sample_spec, SILENCE_BUFFER_LENGTH); */
333 /* chunk->memblock = pa_memblock_ref(i->thread_info.silence_memblock); */
334 /* chunk->index = 0; */
335 /* l = pa_memblock_get_length(chunk->memblock); */
336 /* chunk->length = i->move_silence < l ? i->move_silence : l; */
339 /* do_volume_adj_here = 1; */
343 if (!i
->thread_info
.resampler
) {
344 do_volume_adj_here
= 0;
345 ret
= i
->peek(i
, chunk
);
349 do_volume_adj_here
= !pa_channel_map_equal(&i
->channel_map
, &i
->sink
->channel_map
);
350 volume_is_norm
= pa_cvolume_is_norm(&i
->thread_info
.volume
) && !i
->thread_info
.muted
;
352 while (!i
->thread_info
.resampled_chunk
.memblock
) {
356 if ((ret
= i
->peek(i
, &tchunk
)) < 0)
359 pa_assert(tchunk
.length
);
361 l
= pa_resampler_request(i
->thread_info
.resampler
, CONVERT_BUFFER_LENGTH
);
363 if (l
> tchunk
.length
)
366 i
->drop(i
, &tchunk
, l
);
369 /* It might be necessary to adjust the volume here */
370 if (do_volume_adj_here
&& !volume_is_norm
) {
371 pa_memchunk_make_writable(&tchunk
, 0);
372 pa_volume_memchunk(&tchunk
, &i
->thread_info
.sample_spec
, &i
->thread_info
.volume
);
375 pa_resampler_run(i
->thread_info
.resampler
, &tchunk
, &i
->thread_info
.resampled_chunk
);
376 pa_memblock_unref(tchunk
.memblock
);
379 pa_assert(i
->thread_info
.resampled_chunk
.memblock
);
380 pa_assert(i
->thread_info
.resampled_chunk
.length
);
382 *chunk
= i
->thread_info
.resampled_chunk
;
383 pa_memblock_ref(i
->thread_info
.resampled_chunk
.memblock
);
389 if (ret
< 0 && !pa_atomic_load(&i
->thread_info
.drained
) && i
->underrun
)
393 pa_atomic_store(&i
->thread_info
.drained
, 0);
395 pa_atomic_store(&i
->thread_info
.drained
, 1);
398 /* Let's see if we had to apply the volume adjustment
399 * ourselves, or if this can be done by the sink for us */
401 if (do_volume_adj_here
)
402 /* We had different channel maps, so we already did the adjustment */
403 pa_cvolume_reset(volume
, i
->sink
->sample_spec
.channels
);
405 /* We've both the same channel map, so let's have the sink do the adjustment for us*/
406 *volume
= i
->thread_info
.volume
;
412 void pa_sink_input_drop(pa_sink_input
*i
, const pa_memchunk
*chunk
, size_t length
) {
413 pa_sink_input_assert_ref(i
);
414 pa_assert(length
> 0);
416 /* if (i->move_silence > 0) { */
421 /* l = pa_memblock_get_length(i->silence_memblock); */
423 /* if (chunk->memblock != i->silence_memblock || */
424 /* chunk->index != 0 || */
425 /* (chunk->memblock && (chunk->length != (l < i->move_silence ? l : i->move_silence)))) */
430 /* pa_assert(i->move_silence >= length); */
432 /* i->move_silence -= length; */
434 /* if (i->move_silence <= 0) { */
435 /* pa_assert(i->silence_memblock); */
436 /* pa_memblock_unref(i->silence_memblock); */
437 /* i->silence_memblock = NULL; */
443 if (!i
->thread_info
.resampler
) {
445 i
->drop(i
, chunk
, length
);
449 pa_assert(i
->thread_info
.resampled_chunk
.memblock
);
450 pa_assert(i
->thread_info
.resampled_chunk
.length
>= length
);
452 i
->thread_info
.resampled_chunk
.index
+= length
;
453 i
->thread_info
.resampled_chunk
.length
-= length
;
455 if (i
->thread_info
.resampled_chunk
.length
<= 0) {
456 pa_memblock_unref(i
->thread_info
.resampled_chunk
.memblock
);
457 i
->thread_info
.resampled_chunk
.memblock
= NULL
;
458 i
->thread_info
.resampled_chunk
.index
= i
->thread_info
.resampled_chunk
.length
= 0;
462 void pa_sink_input_set_volume(pa_sink_input
*i
, const pa_cvolume
*volume
) {
463 pa_sink_input_assert_ref(i
);
465 if (pa_cvolume_equal(&i
->volume
, volume
))
470 pa_asyncmsgq_post(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
), PA_SINK_INPUT_MESSAGE_SET_VOLUME
, pa_xnewdup(struct pa_cvolume
, volume
, 1), NULL
, pa_xfree
);
471 pa_subscription_post(i
->sink
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, i
->index
);
474 const pa_cvolume
*pa_sink_input_get_volume(pa_sink_input
*i
) {
475 pa_sink_input_assert_ref(i
);
480 void pa_sink_input_set_mute(pa_sink_input
*i
, int mute
) {
482 pa_sink_input_assert_ref(i
);
484 if (!i
->muted
== !mute
)
489 pa_asyncmsgq_post(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
), PA_SINK_INPUT_MESSAGE_SET_MUTE
, PA_UINT_TO_PTR(mute
), NULL
, NULL
);
490 pa_subscription_post(i
->sink
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, i
->index
);
493 int pa_sink_input_get_mute(pa_sink_input
*i
) {
494 pa_sink_input_assert_ref(i
);
499 void pa_sink_input_cork(pa_sink_input
*i
, int b
) {
500 pa_sink_input_assert_ref(i
);
502 sink_input_set_state(i
, b
? PA_SINK_INPUT_CORKED
: PA_SINK_INPUT_RUNNING
);
505 int pa_sink_input_set_rate(pa_sink_input
*i
, uint32_t rate
) {
506 pa_sink_input_assert_ref(i
);
507 pa_return_val_if_fail(i
->thread_info
.resampler
, -1);
509 if (i
->sample_spec
.rate
== rate
)
512 i
->sample_spec
.rate
= rate
;
514 pa_asyncmsgq_post(i
->sink
->asyncmsgq
, PA_MSGOBJECT(i
), PA_SINK_INPUT_MESSAGE_SET_RATE
, PA_UINT_TO_PTR(rate
), NULL
, NULL
);
516 pa_subscription_post(i
->sink
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, i
->index
);
520 void pa_sink_input_set_name(pa_sink_input
*i
, const char *name
) {
521 pa_sink_input_assert_ref(i
);
523 if (!i
->name
&& !name
)
526 if (i
->name
&& name
&& !strcmp(i
->name
, name
))
530 i
->name
= pa_xstrdup(name
);
532 pa_subscription_post(i
->sink
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, i
->index
);
535 pa_resample_method_t
pa_sink_input_get_resample_method(pa_sink_input
*i
) {
536 pa_sink_input_assert_ref(i
);
538 return i
->resample_method
;
541 int pa_sink_input_move_to(pa_sink_input
*i
, pa_sink
*dest
, int immediately
) {
542 /* pa_resampler *new_resampler = NULL; */
543 /* pa_memblockq *buffer = NULL; */
544 /* pa_sink *origin; */
546 pa_sink_input_assert_ref(i
);
547 pa_sink_assert_ref(dest
);
551 /* origin = i->sink; */
553 /* if (dest == origin) */
556 /* if (pa_idxset_size(dest->inputs) >= PA_MAX_INPUTS_PER_SINK) { */
557 /* pa_log_warn("Failed to move sink input: too many inputs per sink."); */
561 /* if (i->resampler && */
562 /* pa_sample_spec_equal(&origin->sample_spec, &dest->sample_spec) && */
563 /* pa_channel_map_equal(&origin->channel_map, &dest->channel_map)) */
565 /* /\* Try to reuse the old resampler if possible *\/ */
566 /* new_resampler = i->resampler; */
568 /* else if ((i->flags & PA_SINK_INPUT_VARIABLE_RATE) || */
569 /* !pa_sample_spec_equal(&i->sample_spec, &dest->sample_spec) || */
570 /* !pa_channel_map_equal(&i->channel_map, &dest->channel_map)) { */
572 /* /\* Okey, we need a new resampler for the new sink *\/ */
574 /* if (!(new_resampler = pa_resampler_new( */
575 /* dest->core->mempool, */
576 /* &i->sample_spec, &i->channel_map, */
577 /* &dest->sample_spec, &dest->channel_map, */
578 /* i->resample_method))) { */
579 /* pa_log_warn("Unsupported resampling operation."); */
584 /* if (!immediately) { */
585 /* pa_usec_t old_latency, new_latency; */
586 /* pa_usec_t silence_usec = 0; */
588 /* buffer = pa_memblockq_new(0, MOVE_BUFFER_LENGTH, 0, pa_frame_size(&origin->sample_spec), 0, 0, NULL); */
590 /* /\* Let's do a little bit of Voodoo for compensating latency */
591 /* * differences *\/ */
593 /* old_latency = pa_sink_get_latency(origin); */
594 /* new_latency = pa_sink_get_latency(dest); */
596 /* /\* The already resampled data should go to the old sink *\/ */
598 /* if (old_latency >= new_latency) { */
600 /* /\* The latency of the old sink is larger than the latency */
601 /* * of the new sink. Therefore to compensate for the */
602 /* * difference we to play silence on the new one for a */
605 /* silence_usec = old_latency - new_latency; */
609 /* int volume_is_norm; */
611 /* /\* The latency of new sink is larger than the latency of */
612 /* * the old sink. Therefore we have to precompute a little */
613 /* * and make sure that this is still played on the old */
614 /* * sink, until we can play the first sample on the new */
617 /* l = pa_usec_to_bytes(new_latency - old_latency, &origin->sample_spec); */
619 /* volume_is_norm = pa_cvolume_is_norm(&i->volume); */
621 /* while (l > 0) { */
622 /* pa_memchunk chunk; */
623 /* pa_cvolume volume; */
626 /* if (pa_sink_input_peek(i, &chunk, &volume) < 0) */
629 /* n = chunk.length > l ? l : chunk.length; */
630 /* pa_sink_input_drop(i, &chunk, n); */
631 /* chunk.length = n; */
633 /* if (!volume_is_norm) { */
634 /* pa_memchunk_make_writable(&chunk, 0); */
635 /* pa_volume_memchunk(&chunk, &origin->sample_spec, &volume); */
638 /* if (pa_memblockq_push(buffer, &chunk) < 0) { */
639 /* pa_memblock_unref(chunk.memblock); */
643 /* pa_memblock_unref(chunk.memblock); */
648 /* if (i->resampled_chunk.memblock) { */
650 /* /\* There is still some data left in the already resampled */
651 /* * memory block. Hence, let's output it on the old sink */
652 /* * and sleep so long on the new sink *\/ */
654 /* pa_memblockq_push(buffer, &i->resampled_chunk); */
655 /* silence_usec += pa_bytes_to_usec(i->resampled_chunk.length, &origin->sample_spec); */
658 /* /\* Calculate the new sleeping time *\/ */
659 /* i->move_silence = pa_usec_to_bytes( */
660 /* pa_bytes_to_usec(i->move_silence, &i->sample_spec) + */
662 /* &i->sample_spec); */
665 /* /\* Okey, let's move it *\/ */
666 /* pa_idxset_remove_by_data(origin->inputs, i, NULL); */
667 /* pa_idxset_put(dest->inputs, i, NULL); */
668 /* i->sink = dest; */
670 /* /\* Replace resampler *\/ */
671 /* if (new_resampler != i->resampler) { */
672 /* if (i->resampler) */
673 /* pa_resampler_free(i->resampler); */
674 /* i->resampler = new_resampler; */
676 /* /\* if the resampler changed, the silence memblock is */
677 /* * probably invalid now, too *\/ */
678 /* if (i->silence_memblock) { */
679 /* pa_memblock_unref(i->silence_memblock); */
680 /* i->silence_memblock = NULL; */
684 /* /\* Dump already resampled data *\/ */
685 /* if (i->resampled_chunk.memblock) { */
686 /* pa_memblock_unref(i->resampled_chunk.memblock); */
687 /* i->resampled_chunk.memblock = NULL; */
688 /* i->resampled_chunk.index = i->resampled_chunk.length = 0; */
691 /* /\* Notify everyone *\/ */
692 /* pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index); */
693 /* pa_sink_notify(i->sink); */
695 /* /\* Ok, now let's feed the precomputed buffer to the old sink *\/ */
697 /* pa_play_memblockq(origin, "Ghost Stream", &origin->sample_spec, &origin->channel_map, buffer, NULL); */
702 int pa_sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, pa_memchunk
*chunk
) {
703 pa_sink_input
*i
= PA_SINK_INPUT(o
);
705 pa_sink_input_assert_ref(i
);
708 case PA_SINK_INPUT_MESSAGE_SET_VOLUME
:
709 i
->thread_info
.volume
= *((pa_cvolume
*) userdata
);
712 case PA_SINK_INPUT_MESSAGE_SET_MUTE
:
713 i
->thread_info
.muted
= PA_PTR_TO_UINT(userdata
);
716 case PA_SINK_INPUT_MESSAGE_GET_LATENCY
: {
717 pa_usec_t
*r
= userdata
;
719 if (i
->thread_info
.resampled_chunk
.memblock
)
720 *r
+= pa_bytes_to_usec(i
->thread_info
.resampled_chunk
.length
, &i
->sink
->sample_spec
);
722 /* if (i->move_silence) */
723 /* r += pa_bytes_to_usec(i->move_silence, &i->sink->sample_spec); */
728 case PA_SINK_INPUT_MESSAGE_SET_RATE
: {
730 i
->thread_info
.sample_spec
.rate
= PA_PTR_TO_UINT(userdata
);
731 pa_resampler_set_input_rate(i
->thread_info
.resampler
, PA_PTR_TO_UINT(userdata
));
736 case PA_SINK_INPUT_MESSAGE_SET_STATE
: {
737 if ((PA_PTR_TO_UINT(userdata
) == PA_SINK_INPUT_DRAINED
|| PA_PTR_TO_UINT(userdata
) == PA_SINK_INPUT_RUNNING
) &&
738 (i
->thread_info
.state
!= PA_SINK_INPUT_DRAINED
) && (i
->thread_info
.state
!= PA_SINK_INPUT_RUNNING
))
739 pa_atomic_store(&i
->thread_info
.drained
, 1);
741 i
->thread_info
.state
= PA_PTR_TO_UINT(userdata
);
750 pa_sink_input_state_t
pa_sink_input_get_state(pa_sink_input
*i
) {
751 pa_sink_input_assert_ref(i
);
753 if (i
->state
== PA_SINK_INPUT_RUNNING
|| i
->state
== PA_SINK_INPUT_DRAINED
)
754 return pa_atomic_load(&i
->thread_info
.drained
) ? PA_SINK_INPUT_DRAINED
: PA_SINK_INPUT_RUNNING
;