summaryrefslogtreecommitdiff
path: root/src/rharchive.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rharchive.c')
-rw-r--r--src/rharchive.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/rharchive.c b/src/rharchive.c
index 96b6aa9..7014fdd 100644
--- a/src/rharchive.c
+++ b/src/rharchive.c
@@ -33,6 +33,9 @@
#include <errno.h>
#include <string.h>
#include <sys/select.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
#include <gst/gst.h>
@@ -42,16 +45,17 @@
#include "log.h"
#include "sig_handler.h"
#include "daemon.h"
+#include "rhmain.h"
#include "writer.h"
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
{
- GMainLoop *loop = (GMainLoop *)data;
+ RHMainLoop *loop = (RHMainLoop *)data;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS: {
log_printf(NOTICE, "End of stream");
- g_main_loop_quit(loop);
+ rhmain_loop_quit(loop, -3);
break;
}
case GST_MESSAGE_INFO: {
@@ -73,7 +77,7 @@ static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
gst_message_parse_error(msg, &error, NULL);
log_printf(ERROR, "%s", error->message);
g_error_free(error);
- g_main_loop_quit(loop);
+ rhmain_loop_quit(loop, -1);
break;
}
default:
@@ -86,22 +90,26 @@ int main_loop(options_t* opt)
{
log_printf(INFO, "entering main loop");
- GMainLoop *loop;
+ RHMainLoop loop;
GstElement *pipeline, *source;
GstBus *bus;
writer_t writer;
- loop = g_main_loop_new(NULL, FALSE);
+ if(!rhmain_loop_init(&loop)) {
+ log_printf(ERROR, "the loop object could not be created. Exiting.");
+ return -1;
+ }
+
pipeline = gst_pipeline_new("rharchive");
- if(!pipeline || !loop) {
- log_printf(ERROR, "the pipeline/loop object could not be created. Exiting.");
+ if(!pipeline) {
+ log_printf(ERROR, "the pipeline object could not be created. Exiting.");
return -1;
}
- int ret = writer_init(&writer, loop, opt->name_format_, opt->mode_, opt->nocache_, opt->output_dir_, opt->interval_, opt->offset_, opt->post_process_);
+ int ret = writer_init(&writer, &loop, opt->name_format_, opt->mode_, opt->nocache_, opt->output_dir_, opt->interval_, opt->offset_, opt->post_process_);
if(ret) {
gst_object_unref(GST_OBJECT(pipeline));
- gst_object_unref(GST_OBJECT(loop));
+ rhmain_loop_destroy(&loop);
return ret;
}
@@ -112,14 +120,14 @@ int main_loop(options_t* opt)
g_error_free(error);
gst_object_unref(GST_OBJECT(writer.sink_));
gst_object_unref(GST_OBJECT(pipeline));
- gst_object_unref(GST_OBJECT(loop));
+ rhmain_loop_destroy(&loop);
return -1;
}
gst_bin_add_many(GST_BIN(pipeline), source, writer.sink_, NULL);
gst_element_link_many(source, writer.sink_, NULL);
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
- gst_bus_add_watch(bus, bus_call, loop);
+ gst_bus_add_watch(bus, bus_call, &loop);
gst_object_unref(bus);
log_printf(INFO, "Set State: Paused");
@@ -127,10 +135,10 @@ int main_loop(options_t* opt)
log_printf(INFO, "Set State: Playing");
gst_element_set_state(pipeline, GST_STATE_PLAYING);
- signal_start(loop);
+ signal_start(&loop);
ret = writer_start(&writer);
if(!ret) {
- g_main_loop_run(loop);
+ ret = rhmain_loop_run(&loop);
signal_stop();
}
@@ -138,6 +146,7 @@ int main_loop(options_t* opt)
gst_element_set_state (pipeline, GST_STATE_NULL);
writer_stop(&writer);
gst_object_unref(GST_OBJECT(pipeline));
+ //rhmain_loop_destroy(&loop);
return ret;
}
@@ -247,9 +256,18 @@ int main(int argc, char* argv[])
options_clear(&opt);
- log_printf(NOTICE, "rharchive shutdown");
-
gst_deinit();
+
+ if(!ret)
+ log_printf(NOTICE, "normal shutdown");
+ else if(ret < 0)
+ log_printf(NOTICE, "shutdown after error");
+ else {
+ log_printf(NOTICE, "shutdown after signal");
+ log_close();
+ kill(getpid(), ret);
+ }
+
log_close();
return ret;