Pinos modules: Parse options with getopt

Make it possible to add options for modules in pinos.conf.in.
Only a few options for videotestsrc is supported at the moment.
This commit is contained in:
Jonathan Karlsson 2016-11-17 10:51:38 +01:00 committed by Wim Taymans
parent ae93f15965
commit 7c127f91a5
5 changed files with 57 additions and 12 deletions

View file

@ -18,6 +18,10 @@
* Boston, MA 02110-1301, USA.
*/
#include <getopt.h>
#include <limits.h>
#include <client/utils.h>
#include <server/core.h>
#include <server/module.h>
@ -27,18 +31,63 @@
bool
pinos__module_init (PinosModule * module, const char * args)
{
pinos_spa_monitor_load (module->core, "build/spa/plugins/alsa/libspa-alsa.so", "alsa-monitor", args);
pinos_spa_monitor_load (module->core, "build/spa/plugins/v4l2/libspa-v4l2.so", "v4l2-monitor", args);
PinosProperties *video_props = NULL;
if (args != NULL) {
char **tmp_argv;
char **argv;
int n_tokens;
int opt = 0;
tmp_argv = pinos_split_strv (args, " \t", INT_MAX, &n_tokens);
argv = malloc ((n_tokens+1) * sizeof (char *));
/* getopt expects name of executable on the first place of argv */
argv[0] = "videotestsrc";
for (int i = 1; i <= n_tokens; i++) {
argv[i] = tmp_argv[i-1];
}
video_props = pinos_properties_new (NULL, NULL);
static struct option long_options[] = {
{"filter", required_argument, 0, 'f' },
{"pattern", required_argument, 0, 'p' },
{"resolution", required_argument, 0, 'r' },
{0, 0, 0, 0 }
};
while ((opt = getopt_long (n_tokens+1, argv, "p:r:f:", long_options, NULL)) != -1) {
switch (opt) {
case 'f':
pinos_properties_set (video_props, "filter", optarg);
break;
case 'p':
pinos_properties_set (video_props, "pattern", optarg);
break;
case 'r':
pinos_properties_set (video_props, "resolution", optarg);
break;
default:
break;
}
}
free (argv);
}
pinos_spa_monitor_load (module->core, "build/spa/plugins/alsa/libspa-alsa.so", "alsa-monitor");
pinos_spa_monitor_load (module->core, "build/spa/plugins/v4l2/libspa-v4l2.so", "v4l2-monitor");
pinos_spa_node_load (module->core,
"build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so",
"audiotestsrc",
"audiotestsrc",
NULL, args);
NULL);
pinos_spa_node_load (module->core,
"build/spa/plugins/videotestsrc/libspa-videotestsrc.so",
"videotestsrc",
"videotestsrc",
NULL, args);
video_props);
return TRUE;
}

View file

@ -171,8 +171,7 @@ on_monitor_event (SpaMonitor *monitor,
PinosSpaMonitor *
pinos_spa_monitor_load (PinosCore *core,
const char *lib,
const char *factory_name,
const char *args)
const char *factory_name)
{
PinosSpaMonitorImpl *impl;
PinosSpaMonitor *this;

View file

@ -41,8 +41,7 @@ struct _PinosSpaMonitor {
PinosSpaMonitor * pinos_spa_monitor_load (PinosCore *core,
const char *lib,
const char *factory_name,
const char *args);
const char *factory_name);
void pinos_spa_monitor_destroy (PinosSpaMonitor *monitor);
#ifdef __cplusplus

View file

@ -37,8 +37,7 @@ pinos_spa_node_load (PinosCore *core,
const char *lib,
const char *factory_name,
const char *name,
PinosProperties *properties,
const char *args)
PinosProperties *properties)
{
PinosSpaNode *this;
PinosSpaNodeImpl *impl;

View file

@ -42,8 +42,7 @@ PinosSpaNode * pinos_spa_node_load (PinosCore *core,
const char *lib,
const char *factory_name,
const char *name,
PinosProperties *properties,
const char *args);
PinosProperties *properties);
#ifdef __cplusplus
}