+/**
+ * \file pulse.c
+ * \brief PulseAudio input plugin for vlc
+ */
/*****************************************************************************
- * pulse.c : PulseAudio input plugin for vlc
- *****************************************************************************
- * Copyright (C) 2008 the VideoLAN team
- * Copyright (C) 2009-2011 Rémi Denis-Courmont
+ * Copyright (C) 2011 Rémi Denis-Courmont
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
}
}
+static void stream_success_cb (pa_stream *s, int success, void *userdata)
+{
+ pa_threaded_mainloop *mainloop = userdata;
+
+ pa_threaded_mainloop_signal(mainloop, 0);
+ (void) s;
+ (void) success;
+}
+
+static void stream_buffer_attr_cb(pa_stream *s, void *userdata)
+{
+ demux_t *demux = userdata;
+ const struct pa_buffer_attr *pba = pa_stream_get_buffer_attr(s);
+
+ msg_Dbg(demux, "using buffer metrics: maxlength=%"PRIu32", "
+ "fragsize=%"PRIu32, pba->maxlength, pba->fragsize);
+}
+
static void stream_moved_cb(pa_stream *s, void *userdata)
{
demux_t *demux = userdata;
msg_Dbg(demux, "connected to source %"PRIu32": %s", idx,
pa_stream_get_device_name(s));
+ stream_buffer_attr_cb(s, userdata);
}
static void stream_overflow_cb(pa_stream *s, void *userdata)
if (demux->psz_location != NULL && demux->psz_location[0] != '\0')
dev = demux->psz_location;
- const struct pa_buffer_attr attr = {
+ struct pa_buffer_attr attr = {
.maxlength = -1,
.fragsize = pa_usec_to_bytes(sys->caching, &ss) / 2,
};
/* Create record stream */
pa_stream *s;
+ pa_operation *op;
pa_threaded_mainloop_lock(sys->mainloop);
s = pa_stream_new(sys->context, "audio stream", &ss, &map);
sys->stream = s;
pa_stream_set_state_callback(s, stream_state_cb, sys->mainloop);
pa_stream_set_read_callback(s, stream_read_cb, demux);
+ pa_stream_set_buffer_attr_callback(s, stream_buffer_attr_cb, demux);
pa_stream_set_moved_callback(s, stream_moved_cb, demux);
pa_stream_set_overflow_callback(s, stream_overflow_cb, demux);
pa_stream_set_started_callback(s, stream_started_cb, demux);
sys->framesize = fmt.audio.i_blockalign;
sys->es = es_out_Add (demux->out, &fmt);
- const struct pa_buffer_attr *pba = pa_stream_get_buffer_attr(s);
- msg_Dbg(obj, "using buffer metrics: maxlength=%"PRIu32", fragsize=%"PRIu32,
- pba->maxlength, pba->fragsize);
+ /* Update the buffer attributes according to actual format */
+ attr.fragsize = pa_usec_to_bytes(sys->caching, pss) / 2;
+ op = pa_stream_set_buffer_attr(s, &attr, stream_success_cb, sys->mainloop);
+ if (likely(op != NULL)) {
+ while (pa_operation_get_state(op) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(sys->mainloop);
+ pa_operation_unref(op);
+ }
+ stream_buffer_attr_cb(s, demux);
pa_threaded_mainloop_unlock(sys->mainloop);
demux->pf_demux = NULL;
pa_stream_disconnect(s);
pa_stream_set_state_callback(s, NULL, NULL);
pa_stream_set_read_callback(s, NULL, NULL);
+ pa_stream_set_buffer_attr_callback(s, NULL, NULL);
pa_stream_set_moved_callback(s, NULL, NULL);
pa_stream_set_overflow_callback(s, NULL, NULL);
pa_stream_set_started_callback(s, NULL, NULL);