]> git.sesse.net Git - vlc/blobdiff - modules/access/pulse.c
posix: drop support for non-UTF-8 operating systems
[vlc] / modules / access / pulse.c
index 9618e08fc5ef7e41a7571fa373902892e8f4e6f8..8a5818faca08e8b45924dc86c4c986348a04a11f 100644 (file)
@@ -1,22 +1,23 @@
+/**
+ * \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
@@ -77,6 +78,24 @@ static void stream_state_cb(pa_stream *s, void *userdata)
     }
 }
 
+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;
@@ -84,6 +103,7 @@ static void stream_moved_cb(pa_stream *s, void *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)
@@ -275,7 +295,7 @@ static int Open(vlc_object_t *obj)
     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,
     };
@@ -284,6 +304,7 @@ static int Open(vlc_object_t *obj)
 
     /* 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);
@@ -293,6 +314,7 @@ static int Open(vlc_object_t *obj)
     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);
@@ -331,9 +353,15 @@ static int Open(vlc_object_t *obj)
     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;
@@ -357,6 +385,7 @@ static void Close (vlc_object_t *obj)
         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);