summaryrefslogtreecommitdiff
path: root/src/sydra.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-09-24 23:34:21 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-09-24 23:34:21 +0200
commitbe982f880df6388bd00386b2cae8c318f902f1b2 (patch)
tree4452fa85d9b32bd1f98dca9fa25c97b9d2b76e1a /src/sydra.c
parentadded simple UDP protocol (diff)
moved pipeline creation subs to own file
Diffstat (limited to 'src/sydra.c')
-rw-r--r--src/sydra.c257
1 files changed, 1 insertions, 256 deletions
diff --git a/src/sydra.c b/src/sydra.c
index 624ce2e..680836d 100644
--- a/src/sydra.c
+++ b/src/sydra.c
@@ -40,7 +40,6 @@
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
-#include <netdb.h>
#include <glib.h>
#include <glib-unix.h>
@@ -53,6 +52,7 @@
#include "log.h"
#include "daemon.h"
#include "utils.h"
+#include "pipelines.h"
static gboolean sig_handler_terminate(gpointer user_data)
{
@@ -165,262 +165,7 @@ static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
-struct media_elements {
- const char* name_;
- const char* src_str_;
- GstElement* src_;
-
- GstElement* tee_raw_;
-
- const char* enc_str_;
- GstElement* enc_;
-
- GstElement* tee_enc_;
-
- const char* payloader_str_;
- GstElement* payloader_;
-};
-
-static gboolean create_media_elements(struct media_elements *me, GstElement* pipeline, GstElement *rtp, uint32_t idx)
-{
- char bin_name[32];
-
- snprintf(bin_name, sizeof(bin_name), "%s source", me->name_);
- me->src_ = sydra_create_bin_from_desc(bin_name, me->src_str_);
- me->tee_raw_ = sydra_create_element("tee", NULL);
- GstElement *qr = sydra_create_element("queue", NULL);
-
- snprintf(bin_name, sizeof(bin_name), "%s encoder", me->name_);
- me->enc_ = sydra_create_bin_from_desc(bin_name, me->enc_str_);
- me->tee_enc_ = sydra_create_element("tee", NULL);
- GstElement *qe = sydra_create_element("queue", NULL);
-
- me->payloader_ = sydra_create_element(me->payloader_str_, NULL);
-
- if(!me->src_ || !me->tee_raw_ || !qr || !me->enc_ || !me->tee_enc_ || !qe || !me->payloader_) {
- return FALSE;
- }
-
- log_printf(DEBUG, "%s path created successfully!", me->name_);
-
- gst_bin_add_many (GST_BIN(pipeline), me->src_, me->tee_raw_, qr, me->enc_, me->tee_enc_, qe, me->payloader_, NULL);
- gst_element_link(me->src_, me->tee_raw_);
- gst_element_link_many(qr, me->enc_, me->tee_enc_, NULL);
- gst_element_link(qe, me->payloader_);
-
- char pad_name[32];
- snprintf(pad_name, sizeof(bin_name), "send_rtp_sink_%u", idx);
- if(!sydra_link_request_static(me->tee_raw_, "src_%u", qr, "sink") ||
- !sydra_link_request_static(me->tee_enc_, "src_%u", qe, "sink") ||
- !sydra_link_static_request(me->payloader_, "src", rtp, pad_name)) {
- return FALSE;
- }
-
- log_printf(DEBUG, "%s path linked successfully!", me->name_);
- return TRUE;
-}
-
-struct udp_sink {
- GstElement *udp_;
- GList* clients_;
-};
-
-struct udp_sinks {
- struct udp_sink rtp_video_;
- struct udp_sink rtcp_video_;
- struct udp_sink rtp_audio_;
- struct udp_sink rtcp_audio_;
-};
-
-static gboolean create_udp_sinks(options_t* opt, GstElement* pipeline, GstElement* rtp, struct udp_sinks *sinks)
-{
- sinks->rtp_video_.udp_ = sydra_create_element("multiudpsink", "udprtpv");
- sinks->rtcp_video_.udp_ = sydra_create_element("multiudpsink", "udprtcpv");
- sinks->rtp_audio_.udp_ = sydra_create_element("multiudpsink", "udprtpa");
- sinks->rtcp_audio_.udp_ = sydra_create_element("multiudpsink", "udprtcpa");
-
- if(!(sinks->rtp_video_.udp_) || !(sinks->rtcp_video_.udp_) || !(sinks->rtp_audio_.udp_) || !(sinks->rtcp_audio_.udp_))
- return FALSE;
-
- log_printf(DEBUG, "udp elements created successfully!");
-
- int rtp_port_local = opt->rtp_port_base_local_;
- g_object_set(G_OBJECT(sinks->rtp_video_.udp_), "bind-port", rtp_port_local++, NULL);
- g_object_set(G_OBJECT(sinks->rtcp_video_.udp_), "bind-port", rtp_port_local++, "sync", FALSE, "async", FALSE, NULL);
- g_object_set(G_OBJECT(sinks->rtp_audio_.udp_), "bind-port", rtp_port_local++, NULL);
- g_object_set(G_OBJECT(sinks->rtcp_audio_.udp_), "bind-port", rtp_port_local++, "sync", FALSE, "async", FALSE, NULL);
-
- if(opt->rtp_host_) {
- int rtp_port = opt->rtp_port_base_;
- g_signal_emit_by_name(G_OBJECT(sinks->rtp_video_.udp_), "add", opt->rtp_host_, rtp_port++, NULL);
- g_signal_emit_by_name(G_OBJECT(sinks->rtcp_video_.udp_), "add", opt->rtp_host_, rtp_port++, NULL);
- g_signal_emit_by_name(G_OBJECT(sinks->rtp_audio_.udp_), "add", opt->rtp_host_, rtp_port++, NULL);
- g_signal_emit_by_name(G_OBJECT(sinks->rtcp_audio_.udp_), "add", opt->rtp_host_, rtp_port++, NULL);
- // TODO: add this to the clients_ list
- }
- if(opt->rtp_addr_local_) {
- g_object_set(G_OBJECT(sinks->rtp_video_.udp_), "bind-address", opt->rtp_addr_local_, NULL);
- g_object_set(G_OBJECT(sinks->rtcp_video_.udp_), "bind-address", opt->rtp_addr_local_, NULL);
- g_object_set(G_OBJECT(sinks->rtp_audio_.udp_), "bind-address", opt->rtp_addr_local_, NULL);
- g_object_set(G_OBJECT(sinks->rtcp_audio_.udp_), "bind-address", opt->rtp_addr_local_, NULL);
- }
-
- gst_bin_add_many(GST_BIN (pipeline), sinks->rtp_video_.udp_, sinks->rtcp_video_.udp_, sinks->rtp_audio_.udp_, sinks->rtcp_audio_.udp_, NULL);
-
- if(!sydra_link_static_static(rtp, "send_rtp_src_0", sinks->rtp_video_.udp_, "sink") ||
- !sydra_link_request_static(rtp, "send_rtcp_src_0", sinks->rtcp_video_.udp_, "sink") ||
- !sydra_link_static_static(rtp, "send_rtp_src_1", sinks->rtp_audio_.udp_, "sink") ||
- !sydra_link_request_static(rtp, "send_rtcp_src_1", sinks->rtcp_audio_.udp_, "sink"))
- return FALSE;
-
- log_printf(DEBUG, "udp elements linked successfully!");
-
- return TRUE;
-}
-
-static gboolean create_preview_elements(const char* preview_bin_desc, GstElement* pipeline, GstElement* tee)
-{
- GstElement *qr = sydra_create_element("queue", NULL);
- GstElement *to = sydra_create_element("textoverlay", NULL);
- GstElement *preview_bin = sydra_create_bin_from_desc("preview sink", preview_bin_desc);
-
- if(!qr || !to || !preview_bin) {
- return FALSE;
- }
-
- log_printf(DEBUG, "preview path created successfully!");
-
- g_object_set(G_OBJECT(to), "text", " local ", "halignment", 1 , "valignment", 0,
- "shaded-background", TRUE, "font-desc", "Sans 18", NULL);
-
- gst_bin_add_many (GST_BIN(pipeline), qr, to, preview_bin, NULL);
- gst_element_link_many(qr, to, preview_bin, NULL);
-
- if(!sydra_link_request_static(tee, "src_%u", qr, "sink")) {
- return FALSE;
- }
-
- log_printf(DEBUG, "preview path linked successfully!");
- return TRUE;
-}
-
-static gboolean create_recorder_elements(options_t* opt, GstElement* pipeline, struct media_elements *mv, struct media_elements *ma)
-{
- GstElement *qv = sydra_create_element("queue", NULL);
- GstElement *qa = sydra_create_element("queue", NULL);
- GstElement *mux = sydra_create_element(opt->rec_mux_, NULL);
- GstElement *sink = sydra_create_element("filesink", NULL);
-
- if(!qv || !qa || !mux || !sink) {
- return FALSE;
- }
-
- GstElement *ev = NULL, *tv = mv->tee_enc_;
- if(opt->video_enc_rec_) {
- ev = sydra_create_bin_from_desc("record video encoder", opt->video_enc_rec_);
- if(!ev) return FALSE;
- tv = mv->tee_raw_;
- }
- GstElement *ea = NULL, *ta = ma->tee_enc_;
- if(opt->audio_enc_rec_) {
- ea = sydra_create_bin_from_desc("record audio encoder", opt->audio_enc_rec_);
- if(!ea) return FALSE;
- ta = ma->tee_raw_;
- }
-
- log_printf(DEBUG, "recorder path created successfully!");
-
- struct timespec now;
- clock_gettime(CLOCK_REALTIME, &now);
- struct tm bd_time;
- localtime_r(&(now.tv_sec), &bd_time);
- char recfile[1024]; //TODO: fix this hardcoded length
- recfile[0] = 0;
- strftime(recfile, sizeof(recfile), opt->rec_name_format_, &bd_time);
- g_object_set(G_OBJECT(sink), "location", recfile, NULL);
-
- gst_bin_add_many(GST_BIN(pipeline), qv, qa, mux, sink, NULL);
- gst_element_link(mux, sink);
- GstElement* sv = qv;
- if(ev) {
- gst_bin_add(GST_BIN(pipeline), ev);
- gst_element_link(qv, ev);
- sv = ev;
- }
- GstElement* sa = qa;
- if(ev) {
- gst_bin_add(GST_BIN(pipeline), ea);
- gst_element_link(qa, ea);
- sa = ea;
- }
-
- if(!sydra_link_request_static(tv, "src_%u", qv, "sink") ||
- !sydra_link_static_compatible(sv, "src", mux) ||
- !sydra_link_request_static(ta, "src_%u", qa, "sink") ||
- !sydra_link_static_compatible(sa, "src", mux)) {
- return FALSE;
- }
-
- log_printf(DEBUG, "recorder path linked successfully!");
- return TRUE;
-}
-
-static GstElement* create_pipeline(options_t* opt, struct udp_sinks *udp)
-{
- GstElement *pipeline = gst_pipeline_new ("sydra");
- if(!pipeline) {
- log_printf(ERROR, "Creating pipeline failed!");
- return NULL;
- }
- GstElement *rtp = sydra_create_element("rtpbin", "rtpbin");
- if(!rtp || !gst_bin_add(GST_BIN(pipeline), rtp)) {
- return NULL;
- }
- log_printf(DEBUG, "rtpbin created successfully!");
-
- struct media_elements video = { "video", opt->video_src_, NULL, NULL,
- opt->video_enc_, NULL, NULL,
- opt->video_payloader_, NULL };
- struct media_elements audio = { "audio", opt->audio_src_, NULL, NULL,
- opt->audio_enc_, NULL, NULL,
- opt->audio_payloader_, NULL };
- if(!create_media_elements(&video, pipeline, rtp, 0) ||
- !create_media_elements(&audio, pipeline, rtp, 1) ||
- !create_udp_sinks(opt, pipeline, rtp, udp)) {
- return NULL;
- }
-
- if(opt->preview_videosink_) {
- if(!create_preview_elements(opt->preview_videosink_, pipeline, video.tee_raw_))
- return NULL;
- }
-
- if(opt->rec_mux_) {
- if(!create_recorder_elements(opt, pipeline, &video, &audio))
- return NULL;
- }
-
- log_printf(DEBUG, "pipeline created successfully!");
- return pipeline;
-}
-
-
-struct addr_port{
- enum { IPv4, IPv6 } type_;
- gchar addr_[INET6_ADDRSTRLEN + 1];
- guint16 port_;
-};
-
-gint cmp_addr_port(gconstpointer A, gconstpointer B)
-{
- const struct addr_port *a = (const struct addr_port *)A;
- const struct addr_port *b = (const struct addr_port *)B;
-
- if(a->type_ != b->type_ || a->port_ != b->port_)
- return -1;
- return strncmp(a->addr_, b->addr_, sizeof(a->addr_));
-}
static void udp_add_client(struct sockaddr_storage *addr, socklen_t addrlen, struct udp_sink* sink)
{