3871b59
From 196a14977a6c783cf4df531f8a71949763a63527 Mon Sep 17 00:00:00 2001
3871b59
From: Hans de Goede <hdegoede@redhat.com>
3871b59
Date: Tue, 2 Feb 2016 12:46:46 +0100
3871b59
Subject: [PATCH xawtv3 4/9] xawtv: Allow setting alsa_latency from ~/.xawtv
3871b59
3871b59
This avoids the need to always have to specify this on the cmdline on
3871b59
systems which need a value different from the default.
3871b59
3871b59
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3871b59
---
3871b59
 man/xawtvrc.5 |  5 +++++
3871b59
 x11/xt.c      | 16 +++++++++++++---
3871b59
 2 files changed, 18 insertions(+), 3 deletions(-)
3871b59
3871b59
diff --git a/man/xawtvrc.5 b/man/xawtvrc.5
3871b59
index 136ceba..f1c3333 100644
3871b59
--- a/man/xawtvrc.5
3871b59
+++ b/man/xawtvrc.5
3871b59
@@ -209,6 +209,11 @@ details.
3871b59
 .TP
3871b59
 .B filter = name
3871b59
 Enable the specified filter.
3871b59
+.TP
3871b59
+.B alsa_latency = time_in_ms
3871b59
+This can be used to specify the latency for the ALSA digital sound loopback
3871b59
+which xawtv does. The default is 30ms if you're getting sound dropouts on your
3871b59
+system try increasing this setting.
3871b59
 .SS The [launch] section
3871b59
 You can start other programs from within xawtv.  This is configured
3871b59
 with entries in the "[launch]" section:
3871b59
diff --git a/x11/xt.c b/x11/xt.c
3871b59
index 2065ff4..9affb4a 100644
3871b59
--- a/x11/xt.c
3871b59
+++ b/x11/xt.c
3871b59
@@ -65,6 +65,10 @@
3871b59
 
3871b59
 /*----------------------------------------------------------------------*/
3871b59
 
3871b59
+#define ALSA_LATENCY_DEFAULT 30
3871b59
+#define STR(X) __STR(X)
3871b59
+#define __STR(X) #X
3871b59
+
3871b59
 XtAppContext      app_context;
3871b59
 Widget            app_shell, tv;
3871b59
 Widget            on_shell;
3871b59
@@ -167,7 +171,7 @@ XtResource args_desc[] = {
3871b59
 	"alsa_latency",
3871b59
 	XtCValue, XtRInt, sizeof(int),
3871b59
 	XtOffset(struct ARGS*,alsa_latency),
3871b59
-	XtRString, "30"
3871b59
+	XtRString, STR(ALSA_LATENCY_DEFAULT)
3871b59
     },{
3871b59
 	/* Integer */
3871b59
 	"debug",
3871b59
@@ -1414,9 +1418,15 @@ static void x11_mute_notify(int val)
3871b59
 {
3871b59
     if (val)
3871b59
 	alsa_thread_stop();
3871b59
-    else if (!alsa_thread_is_running())
3871b59
+    else if (!alsa_thread_is_running()) {
3871b59
+        if (args.readconfig && args.alsa_latency == ALSA_LATENCY_DEFAULT) {
3871b59
+            int val = cfg_get_int("global", "alsa_latency");
3871b59
+            if (val > 0)
3871b59
+                args.alsa_latency = val;
3871b59
+        }
3871b59
 	alsa_thread_startup(alsa_out, alsa_cap, args.alsa_latency,
3871b59
 			    stderr, debug);
3871b59
+    }
3871b59
 }
3871b59
 #endif
3871b59
 
3871b59
@@ -1698,7 +1708,7 @@ usage(void)
3871b59
 	    "      -(no)alsa       enable/disable alsa streaming. Default: enabled\n"
3871b59
 	    "      -(no)alsa-cap   manually specify an alsa capture interface\n"
3871b59
 	    "      -(no)alsa-pb    manually specify an alsa playback interface\n"
3871b59
-	    "      -alsa-latency   manually specify an alsa latency in ms. Default: 30\n"
3871b59
+	    "      -alsa-latency   manually specify an alsa latency in ms. Default: " STR(ALSA_LATENCY_DEFAULT) "\n"
3871b59
 #endif
3871b59
 	    "  -b  -bpp n          color depth of the display is n (n=24,32)\n"
3871b59
 	    "  -o  -outfile file   filename base for snapshots\n"
3871b59
-- 
3871b59
2.7.1
3871b59