summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-04-20 14:31:37 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-04-20 14:31:37 (GMT)
commitc8bc6703879da5a96dbc1319a07fa307cf1892f1 (patch)
tree0609dcb236987385401664ffc3a3b5082c042f02
parent011afcdbf0614cc61dd4022448122fe40cfa39ff (diff)
added option for post processing
-rw-r--r--src/file_list.c19
-rw-r--r--src/file_list.h1
-rw-r--r--src/options.c6
-rw-r--r--src/options.h1
-rw-r--r--src/rharchive.c2
-rw-r--r--src/writer.c11
-rw-r--r--src/writer.h3
7 files changed, 38 insertions, 5 deletions
diff --git a/src/file_list.c b/src/file_list.c
index c427381..c2027a0 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -120,6 +120,25 @@ int file_list_remove(file_list_t* list, int fd)
return 0;
}
+int file_list_call_post_process(file_list_t* list, int fd)
+{
+ if(!list || !(list->mutex_))
+ return -1;
+
+ g_mutex_lock(list->mutex_);
+ slist_element_t* tmp = list->list_.first_;
+ while(tmp) {
+ if(((file_t*)tmp->data_)->fd_ == fd) {
+ log_printf(INFO, "calling post processing for '%s'", ((file_t*)tmp->data_)->path_);
+ break;
+ }
+ tmp = tmp->next_;
+ }
+ g_mutex_unlock(list->mutex_);
+
+ return 0;
+}
+
int open_file(file_t* file)
{
if(!file || file->fd_ > 0) // file already open!
diff --git a/src/file_list.h b/src/file_list.h
index 322df62..4415f12 100644
--- a/src/file_list.h
+++ b/src/file_list.h
@@ -51,6 +51,7 @@ typedef struct file_list_struct file_list_t;
int file_list_init(file_list_t* list);
void file_list_clear(file_list_t* list);
file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, const char* format, const char* dir, mode_t mode);
+int file_list_call_post_process(file_list_t* list, int fd);
int file_list_remove(file_list_t* list, int fd);
int open_file(file_t* file);
diff --git a/src/options.c b/src/options.c
index 0ad0844..90ea6f3 100644
--- a/src/options.c
+++ b/src/options.c
@@ -202,6 +202,7 @@ int options_parse(options_t* opt, int argc, char* argv[])
PARSE_INT_PARAM("-m","--mode", opt->mode_, 8)
PARSE_INT_PARAM("-i","--interval", opt->interval_, 10)
PARSE_INT_PARAM("-o","--offset", opt->offset_, 10)
+ PARSE_STRING_PARAM("-x","--post-process", opt->post_process_)
else
return i;
}
@@ -248,6 +249,7 @@ void options_default(options_t* opt)
opt->mode_ = 0644;
opt->interval_ = 50;
opt->offset_ = 0;
+ opt->post_process_ = NULL;
}
void options_clear(options_t* opt)
@@ -272,6 +274,8 @@ void options_clear(options_t* opt)
free(opt->output_dir_);
if(opt->name_format_)
free(opt->name_format_);
+ if(opt->post_process_)
+ free(opt->post_process_);
}
void options_print_usage()
@@ -294,6 +298,7 @@ void options_print_usage()
printf(" [-m|--mode] <value> ocatl represantion of the file permission mode\n");
printf(" [-i|--interval] <value> interval for time checks in ms\n");
printf(" [-o|--offset] <value> time offset for recordings in ms\n");
+ printf(" [-x|--post-process] <script> call script when file is finished\n");
}
void options_print_version()
@@ -322,4 +327,5 @@ void options_print(options_t* opt)
printf("mode: %04o\n", (int)opt->mode_);
printf("interval: %d\n", opt->interval_);
printf("offset: %d\n", opt->offset_);
+ printf("post_process: '%s'\n", opt->post_process_);
}
diff --git a/src/options.h b/src/options.h
index e74218e..3cd2abd 100644
--- a/src/options.h
+++ b/src/options.h
@@ -47,6 +47,7 @@ struct options_struct {
mode_t mode_;
int interval_;
int offset_;
+ char* post_process_;
};
typedef struct options_struct options_t;
diff --git a/src/rharchive.c b/src/rharchive.c
index 1744118..82f7dda 100644
--- a/src/rharchive.c
+++ b/src/rharchive.c
@@ -94,7 +94,7 @@ int main_loop(options_t* opt)
return -1;
}
- int ret = writer_init(&writer, loop, opt->name_format_, opt->mode_, opt->output_dir_, opt->interval_, opt->offset_);
+ int ret = writer_init(&writer, loop, opt->name_format_, opt->mode_, opt->output_dir_, opt->interval_, opt->offset_, opt->post_process_);
if(ret) {
gst_object_unref(GST_OBJECT(pipeline));
gst_object_unref(GST_OBJECT(loop));
diff --git a/src/writer.c b/src/writer.c
index 8d08cd9..f5ce2d9 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -89,11 +89,13 @@ static void fdremoved_cb(GstElement* sink, gint fd, gpointer data)
log_printf(INFO, "fdsink: successfully removed fd %d (sink has now %d fds)", fd, num_fds);
writer_t *writer = (writer_t*)data;
- // call post processing script
- file_list_remove(&(writer->files_), fd);
+ if(writer->post_process_)
+ file_list_call_post_process(&(writer->files_), fd);
+ else
+ file_list_remove(&(writer->files_), fd);
}
-int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset)
+int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset, const char* post_process)
{
if(!writer)
return -1;
@@ -118,6 +120,7 @@ int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode
writer->output_dir_ = output_dir;
writer->interval_ = interval * GST_MSECOND;
writer->offset_ = offset * GST_MSECOND;
+ writer->post_process_ = post_process;
writer->clock_id_ = NULL;
writer->thread_ = NULL;
int ret = file_list_init(&(writer->files_));
@@ -166,6 +169,8 @@ static int check_boundaries(writer_t* writer)
writer->next_ = file_list_add(&(writer->files_), &bd_time, "next", writer->name_format_, writer->output_dir_, writer->mode_);
if(writer->next_ == NULL) return -2;
+
+ // TODO: waitpid for post processing scripts and remove file after it has finished
}
return 0;
diff --git a/src/writer.h b/src/writer.h
index e732b28..7e10e82 100644
--- a/src/writer.h
+++ b/src/writer.h
@@ -46,6 +46,7 @@ struct writer_struct {
mode_t mode_;
GstClockTime interval_;
GstClockTime offset_;
+ const char* post_process_;
file_list_t files_;
file_t* current_;
file_t* next_;
@@ -53,7 +54,7 @@ struct writer_struct {
};
typedef struct writer_struct writer_t;
-int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset);
+int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset, const char* post_process);
int writer_start(writer_t* writer);
void writer_stop(writer_t* writer);