summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile1
-rw-r--r--src/rharchive.c34
-rw-r--r--src/writer.c68
-rw-r--r--src/writer.h46
4 files changed, 132 insertions, 17 deletions
diff --git a/src/Makefile b/src/Makefile
index ba2f19a..e104c75 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -36,6 +36,7 @@ C_OBJS := log.o \
options.o \
slist.o \
string_list.o \
+ writer.o \
rharchive.o
C_SRCS := $(C_OBJS:%.o=%.c)
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;
}
diff --git a/src/writer.c b/src/writer.c
new file mode 100644
index 0000000..1697262
--- /dev/null
+++ b/src/writer.c
@@ -0,0 +1,68 @@
+/*
+ * rharchive
+ *
+ * rharchive is a simple tcp connection proxy which combines the
+ * features of rinetd and 6tunnel. rharchive supports IPv4 and
+ * IPv6 and also supports connections from IPv6 to IPv4
+ * endpoints and vice versa.
+ *
+ *
+ * Copyright (C) 2010-2011 Christian Pointner <equinox@helsinki.at>
+ *
+ * This file is part of rharchive.
+ *
+ * rharchive is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * rharchive is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with rharchive. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gst/gst.h>
+
+#include "writer.h"
+
+#include "datatypes.h"
+#include "log.h"
+
+int writer_init(writer_t* writer, const char* name_format, const char* output_dir, int length, int offset)
+{
+ if(!writer)
+ return -1;
+
+ writer->sink_ = gst_element_factory_make("filesink", "writer");
+ if(!writer->sink_) {
+ log_printf(ERROR, "the writer object could not be created. Exiting.");
+ return -1;
+ }
+ g_object_set(G_OBJECT(writer->sink_), "location", "output.ogg", NULL);
+ writer->name_format_ = name_format;
+ writer->output_dir_ = output_dir;
+ writer->length_ = length;
+ writer->offset_ = offset;
+
+ return 0;
+}
+
+void writer_start(writer_t* writer)
+{
+ if(!writer)
+ return;
+
+ // nothing yet
+}
+
+void writer_stop(writer_t* writer)
+{
+ if(!writer)
+ return;
+
+ // nothing yet
+}
diff --git a/src/writer.h b/src/writer.h
new file mode 100644
index 0000000..8081644
--- /dev/null
+++ b/src/writer.h
@@ -0,0 +1,46 @@
+/*
+ * rharchive
+ *
+ * rharchive is a simple tcp connection proxy which combines the
+ * features of rinetd and 6tunnel. rharchive supports IPv4 and
+ * IPv6 and also supports connections from IPv6 to IPv4
+ * endpoints and vice versa.
+ *
+ *
+ * Copyright (C) 2010-2011 Christian Pointner <equinox@helsinki.at>
+ *
+ * This file is part of rharchive.
+ *
+ * rharchive is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * rharchive is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with rharchive. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RHARCHIVE_writer_h_INCLUDED
+#define RHARCHIVE_writer_h_INCLUDED
+
+#include <gst/gst.h>
+
+struct writer_struct {
+ GstElement* sink_;
+ const char* name_format_;
+ const char* output_dir_;
+ int length_;
+ int offset_;
+};
+typedef struct writer_struct writer_t;
+
+int writer_init(writer_t* writer, const char* name_format, const char* output_dir, int length, int offset);
+void writer_start(writer_t* writer);
+void writer_stop(writer_t* writer);
+
+#endif