diff options
author | Christian Pointner <equinox@spreadspace.org> | 2014-09-24 23:34:21 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2014-09-24 23:34:21 +0200 |
commit | be982f880df6388bd00386b2cae8c318f902f1b2 (patch) | |
tree | 4452fa85d9b32bd1f98dca9fa25c97b9d2b76e1a /src | |
parent | added simple UDP protocol (diff) |
moved pipeline creation subs to own file
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 1 | ||||
-rw-r--r-- | src/datatypes.h | 24 | ||||
-rw-r--r-- | src/pipelines.c | 272 | ||||
-rw-r--r-- | src/pipelines.h | 45 | ||||
-rw-r--r-- | src/sydra.c | 257 | ||||
-rw-r--r-- | src/utils.c | 13 | ||||
-rw-r--r-- | src/utils.h | 1 |
7 files changed, 357 insertions, 256 deletions
diff --git a/src/Makefile b/src/Makefile index 6b23ff3..ac91c33 100644 --- a/src/Makefile +++ b/src/Makefile @@ -44,6 +44,7 @@ C_OBJS := log.o \ slist.o \ string_list.o \ utils.o \ + pipelines.o \ sydra.o C_SRCS := $(C_OBJS:%.o=%.c) diff --git a/src/datatypes.h b/src/datatypes.h index 6481eb8..b6c6003 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -38,4 +38,28 @@ #include <stdint.h> +#include <glib.h> +#include <gst/gst.h> + +#include <netdb.h> + +struct addr_port{ + enum { IPv4, IPv6 } type_; + gchar addr_[INET6_ADDRSTRLEN + 1]; + guint16 port_; +}; + +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_; +}; + + #endif diff --git a/src/pipelines.c b/src/pipelines.c new file mode 100644 index 0000000..f2f787c --- /dev/null +++ b/src/pipelines.c @@ -0,0 +1,272 @@ +/* + * sydra + * + * sydra is a toolbox which allows you to set up multiple bidirectional + * Video/Audio streams from external locations. + * sydra has been written to be used for the Elevate Festival in Graz + * Austria in order to involve external locations to present themselves + * at the festival. + * Sydra is based on GStreamer and is written in C. + * + * + * Copyright (C) 2014 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of sydra. + * + * sydra 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. + * + * sydra 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 sydra. If not, see <http://www.gnu.org/licenses/>. + * + * In addition, as a special exception, the copyright holders hereby + * grant permission for non-GPL-compatible GStreamer plugins to be used + * and distributed together with GStreamer and sydra. + * This permission goes above and beyond the permissions granted by the + * GPL license sydra is covered by. + */ + +#include "datatypes.h" + +#include <gst/gst.h> +#include <stdio.h> + +#include "options.h" +#include "utils.h" +#include "log.h" + + +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; +} + +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; +} + +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; +} diff --git a/src/pipelines.h b/src/pipelines.h new file mode 100644 index 0000000..3c68365 --- /dev/null +++ b/src/pipelines.h @@ -0,0 +1,45 @@ +/* + * sydra + * + * sydra is a toolbox which allows you to set up multiple bidirectional + * Video/Audio streams from external locations. + * sydra has been written to be used for the Elevate Festival in Graz + * Austria in order to involve external locations to present themselves + * at the festival. + * Sydra is based on GStreamer and is written in C. + * + * + * Copyright (C) 2014 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of sydra. + * + * sydra 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. + * + * sydra 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 sydra. If not, see <http://www.gnu.org/licenses/>. + * + * In addition, as a special exception, the copyright holders hereby + * grant permission for non-GPL-compatible GStreamer plugins to be used + * and distributed together with GStreamer and sydra. + * This permission goes above and beyond the permissions granted by the + * GPL license sydra is covered by. + */ + +#ifndef SYDRA_pipelines_h_INCLUDED +#define SYDRA_pipelines_h_INCLUDED + +#include "datatypes.h" +#include <gst/gst.h> +#include "options.h" + +GstElement* create_pipeline(options_t* opt, struct udp_sinks *udp); + +#endif 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) { diff --git a/src/utils.c b/src/utils.c index e9466fa..1180b0a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -36,8 +36,21 @@ #include "datatypes.h" #include "utils.h" #include "log.h" + +#include <string.h> + #include <gst/gst.h> +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_)); +} + GstElement* sydra_create_bin_from_desc(const char* type, const char* desc) { GError *error = NULL; diff --git a/src/utils.h b/src/utils.h index 17c48c3..9916ea3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -38,6 +38,7 @@ #include <gst/gst.h> +gint cmp_addr_port(gconstpointer A, gconstpointer B); GstElement* sydra_create_bin_from_desc(const char* type, const char* desc); GstElement* sydra_create_element(const char* type, const char* name); gboolean sydra_link_request_static(GstElement* src, const char* src_pad_name, GstElement* sink, const char* sink_pad_name); |