[pulseaudio-discuss] [PATCH] pacat: paplay stream format extention

Wang Xingchao xingchao.wang at intel.com
Thu May 10 23:43:03 PDT 2012


paplay with "--passthrough" only indicate the stream with PASSTHROUGH flag,
but there's no exact format infomation. the patch makes stream easy to notify
pacore its type in passthrough mode.

Signed-off-by: Wang Xingchao <xingchao.wang at intel.com>
---
 src/map-file       |    2 ++
 src/pulse/stream.c |    2 +-
 src/pulse/stream.h |    9 +++++++++
 src/utils/pacat.c  |   35 ++++++++++++++++++++++++++++++-----
 4 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/src/map-file b/src/map-file
index 69cf25b..867a8c5 100644
--- a/src/map-file
+++ b/src/map-file
@@ -295,6 +295,8 @@ pa_stream_is_suspended;
 pa_stream_new;
 pa_stream_new_extended;
 pa_stream_new_with_proplist;
+pa_stream_new_with_proplist_internal;
+pa_encoding_from_string;
 pa_stream_peek;
 pa_stream_prebuf;
 pa_stream_proplist_remove;
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 39338c1..77e5ec4 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -80,7 +80,7 @@ static void reset_callbacks(pa_stream *s) {
     s->buffer_attr_userdata = NULL;
 }
 
-static pa_stream *pa_stream_new_with_proplist_internal(
+pa_stream *pa_stream_new_with_proplist_internal(
         pa_context *c,
         const char *name,
         const pa_sample_spec *ss,
diff --git a/src/pulse/stream.h b/src/pulse/stream.h
index b4464fa..ba7b1ff 100644
--- a/src/pulse/stream.h
+++ b/src/pulse/stream.h
@@ -357,6 +357,15 @@ pa_stream* pa_stream_new_with_proplist(
         const pa_channel_map *map         /**< The desired channel map, or NULL for default */,
         pa_proplist *p                    /**< The initial property list */);
 
+pa_stream *pa_stream_new_with_proplist_internal(
+        pa_context *c,
+        const char *name,
+        const pa_sample_spec *ss,
+        const pa_channel_map *map,
+        pa_format_info * const *formats,
+        unsigned int n_formats,
+        pa_proplist *p);
+
 /** Create a new, unconnected stream with the specified name, the set of formats
  * this client can provide, and an initial list of properties. While
  * connecting, the server will select the most appropriate format which the
diff --git a/src/utils/pacat.c b/src/utils/pacat.c
index ec360f7..bd984af 100644
--- a/src/utils/pacat.c
+++ b/src/utils/pacat.c
@@ -39,6 +39,8 @@
 
 #include <pulse/pulseaudio.h>
 #include <pulse/rtclock.h>
+#include <pulse/format.h>
+#include <pulse/stream.h>
 
 #include <pulsecore/core-util.h>
 #include <pulsecore/i18n.h>
@@ -76,6 +78,8 @@ static pa_sample_spec sample_spec = {
     .channels = 2
 };
 static pa_bool_t sample_spec_set = FALSE;
+static pa_bool_t passthrough_set = FALSE;
+static pa_encoding_t passthrough_format;
 
 static pa_channel_map channel_map;
 static pa_bool_t channel_map_set = FALSE;
@@ -443,17 +447,30 @@ static void context_state_callback(pa_context *c, void *userdata) {
 
         case PA_CONTEXT_READY: {
             pa_buffer_attr buffer_attr;
+            pa_format_info *formats[1];
 
-            pa_assert(c);
+	    if (passthrough_set == TRUE) {
+                formats[0] = pa_format_info_new();
+                formats[0]->encoding = passthrough_format;
+	    }
+
+	    pa_assert(c);
             pa_assert(!stream);
 
             if (verbose)
                 pa_log(_("Connection established.%s"), CLEAR_LINE);
 
-            if (!(stream = pa_stream_new_with_proplist(c, NULL, &sample_spec, &channel_map, proplist))) {
+	    if (passthrough_set == TRUE) {
+		    if (!(stream = pa_stream_new_with_proplist_internal(c, NULL, NULL, NULL, formats, 1, proplist))) {
+	                pa_log(_("pa_stream_new_new_with_proplist_internal() failed: %s"), pa_strerror(pa_context_errno(c)));
+		        goto fail;
+		    }
+	    }else {
+		    if (!(stream = pa_stream_new_with_proplist(c, NULL, &sample_spec, &channel_map, proplist))) {
                 pa_log(_("pa_stream_new() failed: %s"), pa_strerror(pa_context_errno(c)));
                 goto fail;
-            }
+		    }
+	    }
 
             pa_stream_set_state_callback(stream, stream_state_callback, NULL);
             pa_stream_set_write_callback(stream, stream_write_callback, NULL);
@@ -682,7 +699,7 @@ static void help(const char *argv0) {
              "      --process-time-msec=MSEC          Request the specified process time per request in msec.\n"
              "      --property=PROPERTY=VALUE         Set the specified property to the specified value.\n"
              "      --raw                             Record/play raw PCM data.\n"
-             "      --passthrough                     passthrough data \n"
+             "      --passthrough[=DATAFORMAT]        passthrough data \n"
              "      --file-format[=FFORMAT]           Record/play formatted PCM data.\n"
              "      --list-file-formats               List available file formats.\n")
            , argv0);
@@ -743,7 +760,7 @@ int main(int argc, char *argv[]) {
         {"process-time", 1, NULL, ARG_PROCESS_TIME},
         {"property",     1, NULL, ARG_PROPERTY},
         {"raw",          0, NULL, ARG_RAW},
-        {"passthrough",  0, NULL, ARG_PASSTHROUGH},
+        {"passthrough",  1, NULL, ARG_PASSTHROUGH},
         {"file-format",  2, NULL, ARG_FILE_FORMAT},
         {"list-file-formats", 0, NULL, ARG_LIST_FILE_FORMATS},
         {"latency-msec", 1, NULL, ARG_LATENCY_MSEC},
@@ -944,6 +961,14 @@ int main(int argc, char *argv[]) {
 
             case ARG_PASSTHROUGH:
                 flags |= PA_STREAM_PASSTHROUGH;
+		if (optarg) {
+	            if ((passthrough_format =
+				pa_encoding_from_string(pa_strip(optarg))) <0) {
+                        pa_log(_("Unknown passthrough format %s."), optarg);
+			goto quit;
+		    }
+		    passthrough_set = TRUE;
+		}
                 break;
 
             case ARG_FILE_FORMAT:
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list