tor_multipath_voip/src/dcall.c

101 lines
3.7 KiB
C

#include <gst/gst.h>
int create_rx_chain(GstElement *pipeline) {
GstElement *rx_tap, *rx_jitterbuffer, *rx_depay, *rx_opusdec, *rx_resample, *rx_sink;
rx_tap = gst_element_factory_make("udpsrc", "rx-tap");
rx_jitterbuffer = gst_element_factory_make("rtpjitterbuffer", "rx-jitterbuffer");
rx_depay = gst_element_factory_make("rtpopusdepay", "rx-depay");
rx_opusdec = gst_element_factory_make("opusdec", "rx-opusdec");
rx_resample = gst_element_factory_make("audioresample", "rx-audioresample");
rx_sink = gst_element_factory_make("autoaudiosink", "rx-sink");
if (!rx_tap || !rx_jitterbuffer || !rx_depay || !rx_opusdec || !rx_resample || !rx_sink) {
g_printerr ("One element of the rx chain could not be created. Exiting.\n");
return -1;
}
g_object_set(G_OBJECT (rx_tap), "port", 5000, NULL);
g_object_set(G_OBJECT (rx_tap), "caps", gst_caps_new_simple("application/x-rtp", "media", G_TYPE_STRING, "audio", NULL), NULL);
g_object_set(G_OBJECT (rx_jitterbuffer), "do-lost", TRUE, NULL);
g_object_set(G_OBJECT (rx_jitterbuffer), "do-retransmission", FALSE, NULL);
g_object_set(G_OBJECT (rx_jitterbuffer), "latency", 50, NULL);
g_object_set(G_OBJECT (rx_opusdec), "plc", TRUE, NULL);
g_object_set(G_OBJECT (rx_opusdec), "use-inband-fec", FALSE, NULL);
gst_bin_add_many (GST_BIN (pipeline), rx_tap, rx_jitterbuffer, rx_depay, rx_opusdec, rx_resample, rx_sink, NULL);
gst_element_link_many (rx_tap, rx_jitterbuffer, rx_depay, rx_opusdec, rx_resample, rx_sink, NULL);
return 0;
}
int create_tx_chain(GstElement *pipeline, char* remote_host) {
GstElement *tx_tap, *tx_resample, *tx_opusenc, *tx_pay, *tx_sink;
tx_tap = gst_element_factory_make("autoaudiosrc", "tx-tap");
tx_resample = gst_element_factory_make("audioresample", "tx-resample");
tx_opusenc = gst_element_factory_make("opusenc", "tx-opusenc");
tx_pay = gst_element_factory_make("rtpopuspay", "tx-rtpopuspay");
tx_sink = gst_element_factory_make("udpsink", "tx-sink");
if (!tx_tap || !tx_resample || !tx_opusenc || !tx_pay || !tx_sink) {
g_printerr("One element of the tx chain could not be created. Exiting.\n");
return -1;
}
gst_util_set_object_arg(G_OBJECT(tx_opusenc), "audio-type", "voice");
g_object_set(G_OBJECT(tx_opusenc), "inband-fec", FALSE, NULL);
g_object_set(G_OBJECT(tx_opusenc), "frame-size", 40, NULL);
g_object_set(G_OBJECT(tx_opusenc), "bitrate", 32000, NULL);
g_object_set(G_OBJECT(tx_opusenc), "dtx", FALSE, NULL); // gstreamer dtx opus implem. is broken
g_object_set(G_OBJECT(tx_sink), "host", remote_host, NULL);
g_object_set(G_OBJECT(tx_sink), "port", 5000, NULL);
g_object_set(G_OBJECT(tx_sink), "async", FALSE, NULL);
gst_bin_add_many(GST_BIN(pipeline), tx_tap, tx_resample, tx_opusenc, tx_pay, tx_sink, NULL);
gst_element_link_many(tx_tap, tx_resample, tx_opusenc, tx_pay, tx_sink, NULL);
return 0;
}
int main(int argc, char *argv[]) {
GMainLoop *loop;
GstElement *pipeline;
char *remote_host;
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s <Remote host>\n", argv[0]);
return -1;
}
remote_host = argv[1];
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
pipeline = gst_pipeline_new ("pipeline");
if (!pipeline) {
g_printerr ("Pipeline could not be created. Exiting.\n");
return -1;
}
if (create_rx_chain (pipeline) != 0) return -1;
if (create_tx_chain (pipeline, remote_host) != 0) return -1;
gst_element_set_state (pipeline, GST_STATE_PLAYING);
g_print ("Running...\n");
g_main_loop_run (loop);
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
g_main_loop_unref (loop);
return 0;
}