diff options
author | Christian Pointner <equinox@spreadspace.org> | 2014-09-27 17:51:18 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2014-09-27 17:51:18 +0200 |
commit | 957983c5052aadb45d655f49fc22e0bb091ad381 (patch) | |
tree | 8c71d74454b40fce5556af709056737c6f3b6945 /src | |
parent | no more debugging for GOptions (diff) |
added option for mode
Diffstat (limited to 'src')
-rw-r--r-- | src/datatypes.h | 2 | ||||
-rw-r--r-- | src/options.c | 58 | ||||
-rw-r--r-- | src/options.h | 1 |
3 files changed, 50 insertions, 11 deletions
diff --git a/src/datatypes.h b/src/datatypes.h index c5b5168..44912f8 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -43,6 +43,8 @@ #include <netdb.h> +typedef enum { SENDER, RECEIVER } sydra_mode_t; + struct addr_port { enum { IPv4, IPv6 } type_; gchar addr_[INET6_ADDRSTRLEN + 1]; diff --git a/src/options.c b/src/options.c index 2ed8aed..18fe1e1 100644 --- a/src/options.c +++ b/src/options.c @@ -40,6 +40,7 @@ #include "log.h" #include <stdio.h> +#include <string.h> #include <glib.h> #include <gst/gst.h> @@ -56,7 +57,9 @@ static void options_defaults(options_t* opt) opt->pid_file_ = NULL; opt->log_targets_ = NULL; opt->debug_ = 0; + opt->appname_ = NULL; + opt->mode_ = SENDER; opt->video_src_ = g_strdup("v4l2src ! videoconvert ! videoscale ! video/x-raw,format=I420,width=864,height=480,framerate=25/1,pixel-aspect-ratio=1/1 ! identity"); opt->video_enc_ = g_strdup("vp8enc keyframe-max-dist=25 error-resilient=2 end-usage=1 target-bitrate=1200000 cpu-used=4 deadline=1000000 threads=2"); @@ -80,6 +83,15 @@ static void options_defaults(options_t* opt) opt->rec_name_format_ = g_strdup("./recordings/%Y-%m-%d_%H-%M-%S"); } +static GQuark options_error_quark() +{ + static GQuark quark = 0; + if (!quark) + quark = g_quark_from_static_string("sydra_options_error"); + + return quark; +} + static GOptionGroup* options_get_av_group(options_t* opt) { GOptionEntry av_entries[] = { @@ -98,7 +110,7 @@ static GOptionGroup* options_get_av_group(options_t* opt) { NULL } }; GOptionGroup* av_group = g_option_group_new ("av", "Audio/Video Options", - "Show Audio/Video Options", NULL, NULL); + "Show Audio/Video Options", opt, NULL); if(!av_group) return NULL; g_option_group_add_entries(av_group, av_entries); @@ -121,7 +133,7 @@ static GOptionGroup* options_get_rtp_group(options_t* opt) { NULL } }; GOptionGroup* rtp_group = g_option_group_new ("rtp", "RTP Options", - "Show RTP Options", NULL, NULL); + "Show RTP Options", opt, NULL); if(!rtp_group) return NULL; g_option_group_add_entries(rtp_group, rtp_entries); @@ -142,13 +154,29 @@ static GOptionGroup* options_get_rec_group(options_t* opt) { NULL } }; GOptionGroup* rec_group = g_option_group_new ("rec", "Recording Options", - "Show Recording Options", NULL, NULL); + "Show Recording Options", opt, NULL); if(!rec_group) return NULL; g_option_group_add_entries(rec_group, rec_entries); return rec_group; } +static gboolean options_parse_mode(const gchar *option_name, const gchar *value, gpointer data, GError **error) +{ + options_t* opt = (options_t*)data; + + if(!strcmp(value, "sender")) + opt->mode_ = SENDER; + else if(!strcmp(value, "receiver")) + opt->mode_ = RECEIVER; + else { + g_set_error(error, options_error_quark(), G_OPTION_ERROR_FAILED, + "Invalid value for mode parameter '%s' - allowed values are: sender, receiver", value); + return FALSE; + } + return TRUE; +} + static int options_parse_post(options_t* opt); int options_parse(options_t* opt, int argc, char* argv[]) @@ -161,7 +189,7 @@ int options_parse(options_t* opt, int argc, char* argv[]) g_free(opt->progname_); opt->progname_ = g_strdup(argv[0]); if(!opt->progname_) - return -255; + return -127; gboolean show_version = FALSE; GOptionEntry main_entries[] = { @@ -183,25 +211,32 @@ int options_parse(options_t* opt, int argc, char* argv[]) "don't daemonize and log to stdout with maximum log level", NULL }, { "appname", 'n', 0, G_OPTION_ARG_STRING, &opt->appname_, "set the application name (will be used by xvimagesink for window title)", "NAME" }, + { "mode", 'm', 0, G_OPTION_ARG_CALLBACK, options_parse_mode, + "the main operation mode", "(sender|receiver)" }, { "videosink", 'V', 0, G_OPTION_ARG_STRING, &opt->preview_videosink_, "video sink element for local preview (i.e. textoverlay text=\" preview \" ! xvimagesink) - leave empty to disable preview", "BIN DESCRIPTION" }, { NULL } }; GOptionContext *ctx = g_option_context_new("- spreadspace streaming hydra "); - g_option_context_add_main_entries(ctx, main_entries, NULL); + GOptionGroup* main_group = g_option_group_new ("main", "Application Options", + "Show Application Options", opt, NULL); + if(main_group) + g_option_group_add_entries(main_group, main_entries); GOptionGroup* av_group = options_get_av_group(opt); GOptionGroup* rtp_group = options_get_rtp_group(opt); GOptionGroup* rec_group = options_get_rec_group(opt); GOptionGroup* gst_group = gst_init_get_option_group(); - if(!av_group || !rtp_group || !rec_group || !gst_group) { + if(!main_group || !av_group || !rtp_group || !rec_group || !gst_group) { printf("Failed to initialize: memory error\n"); - return -255; + return -127; } + g_option_context_set_main_group(ctx, main_group); g_option_context_add_group(ctx, av_group); g_option_context_add_group(ctx, rtp_group); g_option_context_add_group(ctx, rec_group); g_option_context_add_group(ctx, gst_group); + GError *err = NULL; if(!g_option_context_parse(ctx, &argc, &argv, &err)) { printf("Failed to initialize: %s\n", err->message); @@ -232,17 +267,17 @@ static int options_parse_post(options_t* opt) opt->daemonize_ = 0; g_strfreev(opt->log_targets_); opt->log_targets_ = g_new(gchar*, 2); - if(!opt->log_targets_) return -255; + if(!opt->log_targets_) return -127; opt->log_targets_[0] = g_strdup("stdout:5"); - if(!(opt->log_targets_[0])) return -255; + if(!(opt->log_targets_[0])) return -127; opt->log_targets_[1] = NULL; } if(!g_strv_length(opt->log_targets_)) { opt->log_targets_ = g_new(gchar*, 2); - if(!opt->log_targets_) return -255; + if(!opt->log_targets_) return -127; opt->log_targets_[0] = g_strdup("syslog:3,sydra,daemon"); - if(!(opt->log_targets_[0])) return -255; + if(!(opt->log_targets_[0])) return -127; opt->log_targets_[1] = NULL; } @@ -317,6 +352,7 @@ void options_print(options_t* opt) } printf(" debug: %s\n", opt->debug_ ? "true" : "false"); printf(" appname: >>%s<<\n", opt->appname_); + printf(" mode: >>%s<<\n", opt->mode_ == SENDER ? "sender" : "receiver"); printf(" video_src: >>%s<<\n", opt->video_src_); printf(" video_enc: >>%s<<\n", opt->video_enc_); printf(" video_payloader: >>%s<<\n", opt->video_payloader_); diff --git a/src/options.h b/src/options.h index f639ad4..a4e0bc7 100644 --- a/src/options.h +++ b/src/options.h @@ -49,6 +49,7 @@ struct options_struct { gboolean debug_; gchar* appname_; + sydra_mode_t mode_; gchar* video_src_; gchar* video_enc_; |