From 034f1c9a29123761c1d981e057acbdc5ac466cd0 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 20 Feb 2011 00:02:50 +0000 Subject: added new command line options diff --git a/src/options.c b/src/options.c index f4a101b..eddf914 100644 --- a/src/options.c +++ b/src/options.c @@ -197,10 +197,17 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_STRING_LIST("-L","--log", opt->log_targets_) PARSE_BOOL_PARAM("-U", "--debug", opt->debug_) PARSE_STRING_PARAM("-s","--source", opt->src_bin_desc_) - else + PARSE_STRING_PARAM("-d","--output-dir", opt->output_dir_) + PARSE_STRING_PARAM("-f","--name-format", opt->name_format_) + PARSE_INT_PARAM("-l","--length", opt->length_) + PARSE_INT_PARAM("-o","--offset", opt->offset_) + else return i; } + if(opt->length_ <= 0) + return -4; + if(opt->debug_) { string_list_add(&opt->log_targets_, "stdout:5"); opt->daemonize_ = 0; @@ -235,6 +242,10 @@ void options_default(options_t* opt) string_list_init(&opt->log_targets_); opt->debug_ = 0; opt->src_bin_desc_ = NULL; + opt->output_dir_ = strdup("/srv/archiv"); + opt->name_format_ = strdup("%Y-%m-%d-%H00.ogg"); + opt->length_ = 3600; + opt->offset_ = 0; } void options_clear(options_t* opt) @@ -255,6 +266,10 @@ void options_clear(options_t* opt) string_list_clear(&opt->log_targets_); if(opt->src_bin_desc_) free(opt->src_bin_desc_); + if(opt->output_dir_) + free(opt->output_dir_); + if(opt->name_format_) + free(opt->name_format_); } void options_print_usage() @@ -272,6 +287,10 @@ void options_print_usage() printf(" [-U|--debug] don't daemonize and log to stdout with maximum log level\n"); printf(" [-s|--source] a gstreamer pipeline-style description which will be used\n"); printf(" as data source, see gst-launch man-page for syntax\n"); + printf(" [-d|--output-dir] path to the output directory\n"); + printf(" [-f|--name-format] the file name format, see manpage of date for the syntax\n"); + printf(" [-l|--length] length of one file in seconds\n"); + printf(" [-o|--offset] time offset for recordings in 0.1s\n"); } void options_print_version() @@ -295,4 +314,8 @@ void options_print(options_t* opt) string_list_print(&opt->log_targets_, " '", "'\n"); printf("debug: %s\n", !opt->debug_ ? "false" : "true"); printf("src_bin_desc: >>%s<<\n", opt->src_bin_desc_); + printf("output_dir: '%s'\n", opt->output_dir_); + printf("name_format: '%s'\n", opt->name_format_); + printf("length: %d\n", opt->length_); + printf("offset: %d\n", opt->offset_); } diff --git a/src/options.h b/src/options.h index 22013d5..666e513 100644 --- a/src/options.h +++ b/src/options.h @@ -41,6 +41,10 @@ struct options_struct { string_list_t log_targets_; int debug_; char* src_bin_desc_; + char* output_dir_; + char* name_format_; + int length_; + int offset_; }; typedef struct options_struct options_t; diff --git a/src/rharchive.c b/src/rharchive.c index a2ff037..234f47b 100644 --- a/src/rharchive.c +++ b/src/rharchive.c @@ -84,7 +84,6 @@ int main_loop(options_t* opt) log_printf(INFO, "entering main loop"); GMainLoop *loop; - GstElement *pipeline, *source, *writer; GstBus *bus; @@ -109,8 +108,8 @@ int main_loop(options_t* opt) GError *error = NULL; source = gst_parse_bin_from_description(opt->src_bin_desc_, TRUE, &error); - if(error) { - log_printf(ERROR, "Source Bin Description Parser Error: %s", error->message); + if(!source || error) { + log_printf(ERROR, "Source Bin Description Parser Error: %s", error ? error->message : "unknown"); g_error_free(error); return -1; } @@ -141,17 +140,16 @@ int main(int argc, char* argv[]) options_t opt; int ret = options_parse(&opt, argc, argv); if(ret) { - if(ret > 0) { + if(ret > 0) fprintf(stderr, "syntax error near: %s\n\n", argv[ret]); - } - if(ret == -2) { + if(ret == -2) fprintf(stderr, "memory error on options_parse, exitting\n"); - } - if(ret == -3) { + if(ret == -3) options_print_version(); - } + if(ret == -4) + fprintf(stderr, "the length must be bigger than 0\n"); - if(ret != -2 && ret != -3) + if(ret != -2 && ret != -3 && ret != -4) options_print_usage(); if(ret == -1 || ret == -3) @@ -225,7 +223,7 @@ int main(int argc, char* argv[]) signal_init(); gst_init(NULL, NULL); - const gchar *nano_str; + const gchar *nano_str; guint major, minor, micro, nano; gst_version(&major, &minor, µ, &nano); if (nano == 1) -- cgit v0.10.2