diff options
author | Jonathan Karlsson <jonakn@axis.com> | 2016-11-17 10:51:38 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2016-11-21 08:58:54 +0100 |
commit | 7c127f91a5e264e0be7e2b5f13bcf9d817746fa1 (patch) | |
tree | 51f1a380eed3c92d73369059944ba311845e08a8 | |
parent | ae93f1596590ca26809ba3f60c02bb71fad1fd2b (diff) |
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.
-rw-r--r-- | pinos/modules/spa/module.c | 57 | ||||
-rw-r--r-- | pinos/modules/spa/spa-monitor.c | 3 | ||||
-rw-r--r-- | pinos/modules/spa/spa-monitor.h | 3 | ||||
-rw-r--r-- | pinos/modules/spa/spa-node.c | 3 | ||||
-rw-r--r-- | pinos/modules/spa/spa-node.h | 3 |
5 files changed, 57 insertions, 12 deletions
diff --git a/pinos/modules/spa/module.c b/pinos/modules/spa/module.c index 740d1114..e8c60dc3 100644 --- a/pinos/modules/spa/module.c +++ b/pinos/modules/spa/module.c @@ -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; } diff --git a/pinos/modules/spa/spa-monitor.c b/pinos/modules/spa/spa-monitor.c index 9dd60107..5351a4be 100644 --- a/pinos/modules/spa/spa-monitor.c +++ b/pinos/modules/spa/spa-monitor.c @@ -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; diff --git a/pinos/modules/spa/spa-monitor.h b/pinos/modules/spa/spa-monitor.h index 480d4c84..5b3e81aa 100644 --- a/pinos/modules/spa/spa-monitor.h +++ b/pinos/modules/spa/spa-monitor.h @@ -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 diff --git a/pinos/modules/spa/spa-node.c b/pinos/modules/spa/spa-node.c index d9240ba8..5e16e5aa 100644 --- a/pinos/modules/spa/spa-node.c +++ b/pinos/modules/spa/spa-node.c @@ -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; diff --git a/pinos/modules/spa/spa-node.h b/pinos/modules/spa/spa-node.h index 0cc6e787..374b6b9c 100644 --- a/pinos/modules/spa/spa-node.h +++ b/pinos/modules/spa/spa-node.h @@ -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 } |