Lines Matching refs:sink
35 #include <pulsecore/sink.h>
36 #include <pulsecore/sink-input.h>
60 "sink_name=<name for the sink> "
61 "sink_properties=<properties for the sink> "
96 pa_sink *sink;
101 * carry audio data from the sink thread to the output thread. The POST
104 * sink input pop() callback. Processing other messages (such as
111 /* This message queue is for all other messages than POST from the sink
116 /* Message queue from the output thread to the sink thread. */
136 /* For communication of the stream parameters to the sink thread */
147 pa_sink *sink;
262 pa_sink_assert_ref(u->sink);
267 if (u->sink->state != PA_SINK_RUNNING)
270 /* Get sink snapshot */
271 pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_GET_SNAPSHOT, &rdata, 0, NULL);
273 /* The sink snapshot time is the time when the last data was rendered.
285 if (!o->sink_input || !PA_SINK_IS_OPENED(o->sink->state))
289 * render time was before the sink input snapshot. In this case, the sink
294 /* Latency at sink snapshot time is sink input snapshot latency minus time
300 /* Add the data that was sent between taking the sink input snapshot
301 * and the sink snapshot. */
304 /* This is the current combined latency of the slave sink and the related
305 * memblockq at the time of the sink snapshot. */
319 pa_log_debug("[%s] Snapshot sink latency = %0.2fms, total snapshot latency = %0.2fms", o->sink->name, (double) o->latency_snapshot.sink_latency / PA_USEC_PER_MSEC, (double) snapshot_latency / PA_USEC_PER_MSEC);
322 pa_log_warn("[%s] Total latency of output is very high (%0.2fms), most likely the audio timing in one of your drivers is broken.", o->sink->name, (double) o->total_latency / PA_USEC_PER_MSEC);
341 pa_log_info("[%s] avg total latency is %0.2f msec.", u->sink->name, (double) avg_total_latency / PA_USEC_PER_MSEC);
342 pa_log_info("[%s] target latency for all slaves is %0.2f msec.", u->sink->name, (double) target_latency / PA_USEC_PER_MSEC);
344 base_rate = u->sink->sample_spec.rate;
346 /* Calculate and set rates for the sink inputs. */
351 if (!o->sink_input || !PA_SINK_IS_OPENED(o->sink->state))
357 pa_log_info("[%s] new rate is %u Hz; ratio is %0.3f.", o->sink_input->sink->name, new_rate, (double) new_rate / base_rate);
361 pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, NULL, (int64_t) avg_total_latency, NULL);
371 if (u->sink->state == PA_SINK_SUSPENDED) {
393 pa_assert(u->sink->thread_info.state == PA_SINK_RUNNING);
401 pa_sink_render(u->sink, u->sink->thread_info.max_request, &chunk);
407 u->thread_info.timestamp += pa_bytes_to_usec(chunk.length, &u->sink->sample_spec);
411 if (ate >= u->sink->thread_info.max_request)
419 u->thread_info.counter - pa_usec_to_bytes(u->thread_info.timestamp - now, &u->sink->sample_spec));
422 pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec) - (u->thread_info.timestamp - now));
444 if (PA_UNLIKELY(u->sink->thread_info.rewind_requested))
445 pa_sink_process_rewind(u->sink, 0);
448 if (u->sink->thread_info.state == PA_SINK_RUNNING && !u->thread_info.active_outputs) {
483 /* Called from combine sink I/O thread context */
488 /* We are run by the sink thread, on behalf of an output (o). The
510 pa_sink_render(u->sink, length, &chunk);
533 pa_sink_assert_ref(o->userdata->sink);
545 /* OK, we need to prepare new data, but only if the sink is actually running */
547 pa_asyncmsgq_send(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_NEED, o, (int64_t) length, NULL);
561 /* i->sink->name, */
607 pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_MAX_REQUEST, NULL, 0, NULL, NULL);
620 fix = i->sink->thread_info.fixed_latency;
625 min = i->sink->thread_info.min_latency;
626 max = i->sink->thread_info.max_latency;
636 pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_LATENCY_RANGE, NULL, 0, NULL, NULL);
648 /* Set up the queue from the sink thread to us */
654 i->sink->thread_info.rtpoll,
659 i->sink->thread_info.rtpoll,
664 i->sink->thread_info.rtpoll,
674 fix = i->sink->thread_info.fixed_latency;
678 min = i->sink->thread_info.min_latency;
679 max = i->sink->thread_info.max_latency;
685 /* We register the output. That means that the sink will start to pass data to
687 pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_ADD_OUTPUT, o, 0, NULL);
697 /* We unregister the output. That means that the sink doesn't
699 pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_REMOVE_OUTPUT, o, 0, NULL);
748 if (o->sink_input->sink->thread_info.state == PA_SINK_RUNNING) {
771 /* Add content of memblockq's to sink latency */
772 o->latency_snapshot.sink_latency = pa_sink_get_latency_within_thread(o->sink, true) +
773 pa_bytes_to_usec(length, &o->sink->sample_spec);
817 static int sink_set_state_in_main_thread_cb(pa_sink *sink, pa_sink_state_t state, pa_suspend_cause_t suspend_cause) {
820 pa_sink_assert_ref(sink);
821 pa_assert_se(u = sink->userdata);
825 if (state == u->sink->state)
833 pa_assert(PA_SINK_IS_OPENED(u->sink->state));
841 if (u->sink->state == PA_SINK_SUSPENDED)
845 * not be aware of the slave sink latencies and report far too small values.
846 * This is especially important if after an unsuspend the sink runs on a different
849 u->time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + pa_sink_get_requested_latency(u->sink), time_callback, u);
899 pa_sink_assert_io_context(u->sink);
912 max_request = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec);
915 pa_sink_set_max_request_within_thread(u->sink, max_request);
924 pa_sink_assert_io_context(u->sink);
954 pa_sink_set_latency_range_within_thread(u->sink, min_latency, max_latency);
960 pa_sink_assert_io_context(o->sink);
986 pa_sink_assert_io_context(o->sink);
1006 /* Called from sink I/O thread context */
1046 c = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
1074 latency = pa_usec_to_bytes((pa_usec_t)offset, &u->sink->sample_spec);
1083 y = pa_bytes_to_usec(u->thread_info.snapshot_counter, &u->sink->sample_spec);
1131 pa_sink_set_description(u->sink, "Simultaneous output");
1141 e = pa_sprintf_malloc("%s %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
1144 e = pa_sprintf_malloc("%s, %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
1150 pa_sink_set_description(u->sink, t);
1166 pa_sink_input_new_data_set_sink(&data, o->sink, false, true);
1168 pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "Simultaneous output on %s", pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
1170 pa_sink_input_new_data_set_sample_spec(&data, &u->sink->sample_spec);
1171 pa_sink_input_new_data_set_channel_map(&data, &u->sink->channel_map);
1175 data.origin_sink = u->sink;
1198 pa_sink_input_set_requested_latency(o->sink_input, pa_sink_get_requested_latency(u->sink));
1204 static struct output *output_new(struct userdata *u, pa_sink *sink) {
1208 pa_assert(sink);
1209 pa_assert(u->sink);
1232 o->sink = sink;
1234 "module-combine-sink output memblockq",
1238 &u->sink->sample_spec,
1242 &u->sink->silence);
1299 /* This might cause the sink to be resumed. The state change hook
1300 * of the sink might hence be called from here, which might then
1307 if (o->sink->state != PA_SINK_INIT) {
1308 /* Enable the sink input. That means that the sink
1324 /* We disable the sink input. That means that the sink is
1343 if (PA_SINK_IS_OPENED(o->userdata->sink->state))
1355 if (s == u->sink)
1383 /* Check if the sink is a previously unlinked slave (non-automatic mode) */
1395 pa_log_info("Configuring new sink: %s", s->name);
1397 pa_log("Failed to create sink input on sink '%s'.", s->name);
1414 if (u->sink == s)
1418 if (o->sink == s)
1435 pa_log_info("Unconfiguring sink: %s", s->name);
1538 /* Check the specified slave sinks for sample_spec and channel_map to use for the combined sink */
1552 pa_log("Invalid slave sink '%s'", n);
1618 u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY);
1621 if (!u->sink) {
1622 pa_log("Failed to create sink");
1628 u->thread_info.smoother = pa_smoother_2_new(u->adjust_time + 5*PA_USEC_PER_SEC, pa_rtclock_now(), pa_frame_size(&u->sink->sample_spec), u->sink->sample_spec.rate);
1631 u->sink->parent.process_msg = sink_process_msg;
1632 u->sink->set_state_in_main_thread = sink_set_state_in_main_thread_cb;
1633 u->sink->set_state_in_io_thread = sink_set_state_in_io_thread_cb;
1634 u->sink->update_requested_latency = sink_update_requested_latency;
1635 u->sink->userdata = u;
1637 pa_sink_set_rtpoll(u->sink, u->rtpoll);
1638 pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
1640 nbytes = pa_usec_to_bytes(BLOCK_USEC, &u->sink->sample_spec);
1641 pa_sink_set_max_request(u->sink, nbytes);
1642 pa_sink_set_latency_range(u->sink, 0, BLOCK_USEC);
1644 u->default_min_latency = u->sink->thread_info.min_latency;
1645 u->default_max_latency = u->sink->thread_info.max_latency;
1646 u->block_usec = u->sink->thread_info.max_latency;
1660 if (!(slave_sink = pa_namereg_get(m->core, n, PA_NAMEREG_SINK)) || slave_sink == u->sink) {
1661 pa_log("Invalid slave sink '%s'", n);
1669 pa_log("Failed to create slave sink input on sink '%s'.", slave_sink->name);
1682 /* We're in automatic mode, we add every sink that matches our needs */
1690 pa_log("Failed to create sink input on sink '%s'.", s->name);
1707 /* Activate the sink and the sink inputs */
1708 pa_sink_put(u->sink);
1752 if (u->sink)
1753 pa_sink_unlink(u->sink);
1762 if (u->sink)
1763 pa_sink_unref(u->sink);