[vlc-devel] [PATCH 1/2] core: add an option to print the list of audio devices
Thomas Guillem
thomas at gllm.fr
Wed Mar 22 09:50:25 CET 2017
Add config_PrintAdvancedHelp() to deal with such help messages (see function
comment). This function could be used to print other useful lists in the
future.
---
src/config/configuration.h | 1 +
src/config/help.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++
src/libvlc-module.c | 4 ++++
src/libvlc.c | 6 +++++
4 files changed, 71 insertions(+)
diff --git a/src/config/configuration.h b/src/config/configuration.h
index dd02c7f4af..d292588def 100644
--- a/src/config/configuration.h
+++ b/src/config/configuration.h
@@ -37,6 +37,7 @@ int config_LoadConfigFile( vlc_object_t * );
#define config_LoadCmdLine(a,b,c,d) config_LoadCmdLine(VLC_OBJECT(a),b,c,d)
#define config_LoadConfigFile(a) config_LoadConfigFile(VLC_OBJECT(a))
bool config_PrintHelp (vlc_object_t *);
+bool config_PrintAdvancedHelp (vlc_object_t *);
int config_SortConfig (void);
void config_UnsortConfig (void);
diff --git a/src/config/help.c b/src/config/help.c
index 5298f15ec3..663bf0630b 100644
--- a/src/config/help.c
+++ b/src/config/help.c
@@ -34,8 +34,10 @@
#include <vlc_modules.h>
#include <vlc_plugin.h>
#include <vlc_charset.h>
+#include <vlc_aout.h>
#include "modules/modules.h"
#include "config/configuration.h"
+#include "audio_output/aout_internal.h"
#include "libvlc.h"
#if defined( _WIN32 )
@@ -59,6 +61,7 @@ static void Help (vlc_object_t *, const char *);
static void Usage (vlc_object_t *, const char *);
static void Version (void);
static void ListModules (vlc_object_t *, bool);
+static void ListAoutDevices (vlc_object_t *);
/**
* Returns the console width or a best guess.
@@ -153,6 +156,28 @@ bool config_PrintHelp (vlc_object_t *obj)
return false;
}
+/**
+ * Checks for help command line options that need a valid libvlc instance
+ *
+ * Contrary to config_PrintHelp that is called in an early state (used to print
+ * a help message before libvlc initialisation can fail), this function need a
+ * fully initialized libvlc.
+ *
+ * If one help is found, print the corresponding text.
+ * \return true if a command line options caused some help message to be
+ * printed, false otherwise.
+ */
+bool config_PrintAdvancedHelp (vlc_object_t *obj)
+{
+ if (var_InheritBool (obj, "list-audio-devices"))
+ {
+ ListAoutDevices (obj);
+ return true;
+ }
+
+ return false;
+}
+
/*****************************************************************************
* Help: print program help
*****************************************************************************
@@ -682,6 +707,41 @@ static void ListModules (vlc_object_t *p_this, bool b_verbose)
PauseConsole();
}
+static void ListAoutDevices (vlc_object_t *obj)
+{
+ ShowConsole();
+
+ var_Create (obj, "mute", VLC_VAR_BOOL);
+ audio_output_t *aout = aout_New(obj);
+ if (!aout)
+ {
+ printf("couldn't find any audio outputs\n");
+ return;
+ }
+ aout_owner_t *owner = aout_owner (aout);
+
+ char **ids, **names;
+ int count = aout_DevicesList(aout, &ids, &names);
+ if (count > 0)
+ {
+ printf("\nThe '%s' aout module has %d audio device%s:\n\n",
+ module_get_name(owner->module, false),
+ count, count > 1 ? "s" : "");
+ for (int i = 0; i < count; ++i)
+ {
+ printf("device[%d]:\n id: [%s]\n name: \"%s\"\n\n", i, ids[i],
+ names[i]);
+ free(ids[i]);
+ free(names[i]);
+ }
+ free(ids);
+ free(names);
+ }
+ aout_Destroy(aout);
+
+ PauseConsole();
+}
+
/*****************************************************************************
* Version: print complete program version
*****************************************************************************
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 6d60e807af..cd52b77d87 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -2693,6 +2693,8 @@ vlc_module_begin ()
N_("print a list of available modules")
#define LIST_VERBOSE_TEXT \
N_("print a list of available modules with extra detail")
+#define LIST_AOUT_DEVICE_TEXT \
+ N_("print a list of available audio devices")
#define MODULE_TEXT \
N_("print help on a specific module (can be combined with --advanced " \
"and --help-verbose). Prefix the module name with = for strict " \
@@ -2725,6 +2727,8 @@ vlc_module_begin ()
add_bool( "list-verbose", false, LIST_VERBOSE_TEXT, "",
false )
change_volatile ()
+ add_bool( "list-audio-devices", false, LIST_AOUT_DEVICE_TEXT, "", false )
+ change_volatile ()
add_string( "module", NULL, MODULE_TEXT, "", false )
change_short( 'p' )
change_volatile ()
diff --git a/src/libvlc.c b/src/libvlc.c
index 34f24baf7f..879ba257b3 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -492,6 +492,12 @@ dbus_out:
free( psz_val );
}
+ if (config_PrintAdvancedHelp (VLC_OBJECT(p_libvlc)))
+ {
+ libvlc_InternalCleanup (p_libvlc);
+ exit(0);
+ }
+
return VLC_SUCCESS;
error:
--
2.11.0
More information about the vlc-devel
mailing list