diff options
Diffstat (limited to 'src/rharchive.c')
-rw-r--r-- | src/rharchive.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/rharchive.c b/src/rharchive.c index 234f47b..da64ad4 100644 --- a/src/rharchive.c +++ b/src/rharchive.c @@ -38,8 +38,7 @@ #include "string_list.h" #include "log.h" #include "daemon.h" - - +#include "writer.h" static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) { @@ -84,38 +83,37 @@ int main_loop(options_t* opt) log_printf(INFO, "entering main loop"); GMainLoop *loop; - GstElement *pipeline, *source, *writer; + GstElement *pipeline, *source; GstBus *bus; + writer_t writer; - loop = g_main_loop_new(NULL, FALSE); + int ret = writer_init(&writer, opt->name_format_, opt->output_dir_, opt->length_, opt->offset_); + if(ret) return ret; + loop = g_main_loop_new(NULL, FALSE); pipeline = gst_pipeline_new("rharchive"); - if(!pipeline) { - log_printf(ERROR, "the pipeline object could not be created. Exiting."); + if(!pipeline || !loop) { + log_printf(ERROR, "the pipeline/loop object could not be created. Exiting."); + gst_object_unref(GST_OBJECT(writer.sink_)); return -1; } bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); gst_bus_add_watch(bus, bus_call, loop); gst_object_unref(bus); - - writer = gst_element_factory_make("filesink", "writer"); - if(!writer) { - log_printf(ERROR, "the writer object could not be created. Exiting."); - return -1; - } - g_object_set(G_OBJECT(writer), "location", "output.ogg", NULL); - GError *error = NULL; source = gst_parse_bin_from_description(opt->src_bin_desc_, TRUE, &error); if(!source || error) { log_printf(ERROR, "Source Bin Description Parser Error: %s", error ? error->message : "unknown"); g_error_free(error); + gst_object_unref(GST_OBJECT(writer.sink_)); + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(loop)); return -1; } - gst_bin_add_many(GST_BIN(pipeline), source, writer, NULL); - gst_element_link_many(source, writer, NULL); + gst_bin_add_many(GST_BIN(pipeline), source, writer.sink_, NULL); + gst_element_link_many(source, writer.sink_, NULL); log_printf(INFO, "Set State: Paused"); gst_element_set_state(pipeline, GST_STATE_PAUSED); @@ -123,12 +121,14 @@ int main_loop(options_t* opt) gst_element_set_state(pipeline, GST_STATE_PLAYING); signal_start(loop); + writer_start(&writer); g_main_loop_run(loop); + writer_stop(&writer); signal_stop(); log_printf(INFO, "Stopping pipeline"); gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (GST_OBJECT (pipeline)); + gst_object_unref(GST_OBJECT(pipeline)); return 0; } |