2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file conversation/gnunet_gst.c
25 #include "gnunet_gst_def.h"
30 static struct GNUNET_CONFIGURATION_Handle *cfg;
34 dump_buffer (unsigned n, const unsigned char*buf)
36 const unsigned char *p, *end;
44 for (j = 0; j < 16; j++)
46 fprintf (stderr, "%02X ", p[j]);
50 fprintf (stderr, " ");
52 for (j = 0; j < 16; j++)
54 fprintf (stderr, "%c", isprint (p[j]) ? p[j] :
59 fprintf (stderr, "\n");
67 * load gnunet configuration
70 gg_load_configuration (GNUNET_gstData *d)
72 char *audiobackend_string;
74 cfg = GNUNET_CONFIGURATION_create ();
75 GNUNET_CONFIGURATION_load (cfg, "mediahelper.conf");
77 GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "JACK_PP_IN",
79 GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "JACK_PP_OUT",
82 GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "AUDIOBACKEND",
83 &audiobackend_string);
85 // printf("abstring: %s \n", audiobackend_string);
87 if (0 == strcasecmp (audiobackend_string, "AUTO"))
89 d->audiobackend = AUTO;
91 else if (0 == strcasecmp (audiobackend_string, "JACK"))
93 d->audiobackend = JACK;
95 else if (0 == strcasecmp (audiobackend_string, "ALSA"))
97 d->audiobackend = ALSA;
99 else if (0 == strcasecmp (audiobackend_string, "FAKE"))
101 d->audiobackend = FAKE;
103 else if (0 == strcasecmp (audiobackend_string, "TEST"))
105 d->audiobackend = TEST;
109 d->audiobackend = AUTO;
112 if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER",
113 "REMOVESILENCE") == GNUNET_YES)
115 d->dropsilence = TRUE;
119 d->dropsilence = FALSE;
122 if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER",
123 "NO_GN_HEADERS") == GNUNET_YES)
133 if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER", "USERTP") ==
143 // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf");
148 write_data (const char *ptr, size_t msg_size)
154 while (off < msg_size)
156 ret = write (1, &ptr[off], msg_size - off);
160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write");
169 on_appsink_new_sample (GstElement *element, GNUNET_gstData *d)
171 // size of message including gnunet header
179 const GstStructure *si;
183 */if (gst_app_sink_is_eos (GST_APP_SINK (element)))
186 // pull sample from appsink
187 s = gst_app_sink_pull_sample (GST_APP_SINK (element));
192 if (! GST_IS_SAMPLE (s))
195 b = gst_sample_get_buffer (s);
197 GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps (s));
200 gst_buffer_map (b, &map, GST_MAP_READ);
204 if (len > UINT16_MAX - sizeof(struct AudioMessage))
206 // this should never happen?
207 printf ("GSTREAMER sample too big! \n");
209 len = UINT16_MAX - sizeof(struct AudioMessage);
212 msg_size = sizeof(struct AudioMessage) + len;
214 // copy the data into audio_message
215 GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len);
216 (d->audio_message)->header.size = htons ((uint16_t) msg_size);
218 // write the audio_message without the gnunet headers
219 write_data ((const char *) &(d->audio_message)[1], len);
221 write_data ((const char *) d->audio_message, msg_size);
223 gst_sample_unref (s);
229 * Dump a pipeline graph
232 pl_graph (GstElement *pipeline)
235 gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline),
236 GST_DEBUG_GRAPH_SHOW_ALL,
237 "playback_helper.dot");
240 gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline),
241 GST_DEBUG_GRAPH_SHOW_ALL,
242 "record_helper.dot");
246 // load_configuration();
251 gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data)
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 switch (GST_MESSAGE_TYPE (msg))
257 case GST_MESSAGE_EOS:
258 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
263 case GST_MESSAGE_ERROR:
268 gst_message_parse_error (msg, &error, &debug);
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
274 g_error_free (error);
288 /* called when pipeline changes state */
290 state_changed_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *d)
292 GstState old_state, new_state, pending_state;
294 gst_message_parse_state_changed (msg, &old_state, &new_state,
298 case GST_STATE_READY:
299 // printf("ready.... \n");
300 // pl_graph(GST_ELEMENT(d->pipeline));
303 case GST_STATE_PLAYING:
305 // GST_LOG ("caps are %" GST_PTR_FORMAT, caps);
307 // printf("Playing.... \n");
308 pl_graph (GST_ELEMENT (d->pipeline));
311 case GST_STATE_VOID_PENDING:
312 // printf("void_pending.... \n");
313 // pl_graph(GST_ELEMENT(d->pipeline));
317 // printf("null.... \n");
318 // pl_graph(GST_ELEMENT(d->pipeline));
321 case GST_STATE_PAUSED:
322 // printf("paused.... \n");
323 // pl_graph(GST_ELEMENT(d->pipeline));
330 application_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
332 // printf("application cb");
338 error_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
340 // printf("error cb");
346 eos_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
354 gg_setup_gst_bus (GNUNET_gstData *d)
358 bus = gst_element_get_bus (GST_ELEMENT (d->pipeline));
359 gst_bus_add_signal_watch (bus);
360 g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,
362 g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb,
364 g_signal_connect (G_OBJECT (bus), "message::state-changed",
365 (GCallback) state_changed_cb, d);
366 g_signal_connect (G_OBJECT (bus), "message::application",
367 (GCallback) application_cb, d);
368 g_signal_connect (G_OBJECT (bus), "message::about-to-finish",
369 (GCallback) application_cb, d);
370 gst_object_unref (bus);
375 * take buffer from gstreamer and feed it to gnunet
379 feed_buffer_to_gnunet (GNUNET_gstData * d)
384 size_t len, msg_size;
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n");
389 s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink));
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n");
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n");
397 const GstStructure *si;
401 si = gst_sample_get_info (s);
404 si_str = gst_structure_to_string (si);
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str);
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n");
413 s_caps = gst_sample_get_caps (s);
416 caps_str = gst_caps_to_string (s_caps);
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str);
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n");
426 b = gst_sample_get_buffer (s);
427 if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ))
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b);
430 gst_sample_unref (s);
435 if (len > UINT16_MAX - sizeof (struct AudioMessage))
438 len = UINT16_MAX - sizeof (struct AudioMessage);
440 msg_size = sizeof (struct AudioMessage) + len;
441 audio_message.header.size = htons ((uint16_t) msg_size);
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "Sending %u bytes of audio data\n", (unsigned int) msg_size);
446 for (phase = 0; phase < 2; phase++)
451 if (0 == phase && !d->pure_ogg)
453 //#ifdef DEBUG_RECORD_PURE_OGG
459 ptr = (const char *) &audio_message;
460 to_send = sizeof (audio_message);
464 ptr = (const char *) m.data;
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Sending %u bytes on phase %d\n", (unsigned int) to_send, phase);
469 for (offset = 0; offset < to_send; offset += ret)
471 ret = write (1, &ptr[offset], to_send - offset);
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
477 (unsigned int) to_send - offset, (unsigned int) offset,
478 (unsigned int) (to_send + offset), phase, strerror (errno));
488 gst_buffer_unmap (b, &m);
489 gst_sample_unref (s);
495 feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData *d)
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "Feeding %u bytes to GStreamer\n",
503 (unsigned int) b_len);
505 bufspace = g_memdup (audio, b_len);
506 b = gst_buffer_new_wrapped (bufspace, b_len);
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Failed to wrap a buffer\n");
512 return GNUNET_SYSERR;
514 if (GST_APP_SRC (d->appsrc) == NULL)
516 flow = gst_app_src_push_buffer (GST_APP_SRC (d->appsrc), b);
517 /* They all return GNUNET_OK, because currently player stops when
518 * data stops coming. This might need to be changed for the player
519 * to also stop when pipeline breaks.
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525 "Fed %u bytes to the pipeline\n",
526 (unsigned int) b_len);
529 case GST_FLOW_FLUSHING:
530 /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */
531 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
532 "Dropped a buffer\n");
537 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
542 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
543 "Unexpected push result\n");
551 * debug making elements
554 gst_element_factory_make_debug (gchar *factoryname, gchar *name)
558 element = gst_element_factory_make (factoryname, name);
562 printf ("\n Failed to create element - type: %s name: %s \n", factoryname,
576 gst_element_link_many_debug(...)
579 gst_element_link_many(argptr);
582 #define gst_element_link_many(...) \
583 gst_element_link_many_debug(__VA_ARGS__)
588 printf ("linking elements failed: %s", msg);
594 * used to set properties on autoaudiosink's chosen sink
597 autoaudiosink_child_added (GstChildProxy *child_proxy,
602 if (GST_IS_AUDIO_BASE_SRC (object))
603 g_object_set (object,
604 "buffer-time", (gint64) BUFFER_TIME,
605 "latency-time", (gint64) LATENCY_TIME,
611 * used to set properties on autoaudiosource's chosen sink
614 autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object,
615 gchar *name, gpointer user_data)
617 if (GST_IS_AUDIO_BASE_SRC (object))
618 g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time",
619 (gint64) LATENCY_TIME, NULL);
624 get_pipeline (GstElement *element)
628 p = GST_PIPELINE (gst_object_get_parent (GST_OBJECT (element)));
630 return GST_ELEMENT (p);
635 decoder_ogg_pad_added (GstElement *element,
640 GstElement *decoder = (GstElement *) data;
642 printf ("==== ogg pad added callback \n");
643 /* We can now link this pad with the opus-decoder sink pad */
644 // pl_graph(get_pipeline(element));
645 sinkpad = gst_element_get_static_pad (decoder, "sink");
647 gst_pad_link (pad, sinkpad);
648 gst_element_link_many (element, decoder, NULL);
649 gst_object_unref (sinkpad);
654 gnunet_read (GNUNET_gstData *d)
656 char readbuf[MAXLINE];
660 ret = read (0, readbuf, sizeof(readbuf));
663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
664 _ ("Read error from STDIN: %d %s\n"),
665 ret, strerror (errno));
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
670 "Received %d bytes of audio data\n",
674 // #ifdef DEBUG_READ_PURE_OGG
678 feed_buffer_to_gst (readbuf, ret, d);
683 GNUNET_MST_from_buffer (d->stdin_mst,
696 * @param msg message we received.
697 * @return #GNUNET_OK on success,
698 * #GNUNET_NO to stop further processing due to disconnect (no error)
699 * #GNUNET_SYSERR to stop further processing due to error
702 stdin_receiver (void *cls,
703 const struct GNUNET_MessageHeader *msg)
705 struct AudioMessage *audio;
708 printf ("stdin receiver \n ");
709 dump_buffer (sizeof(msg),
710 (const unsigned char *) msg);
712 switch (ntohs (msg->type))
714 case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO:
715 audio = (struct AudioMessage *) msg;
717 b_len = ntohs (audio->header.size) - sizeof(struct AudioMessage);
718 printf ("feeding buffer to gst \n ");
719 feed_buffer_to_gst ((const char *) &audio[1], b_len, cls);
723 printf ("No audio message: %u \n ", ntohs (msg->type));
731 get_app (GNUNET_gstData *d, int type)
734 GstPad *pad, *ghostpad;
738 bin = GST_BIN (gst_bin_new ("Gnunet appsrc"));
741 GNUNET_assert (GNUNET_OK ==
742 GNUNET_log_setup ("gnunet-helper-audio-playback",
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
747 "Audio playback starts\n");
748 printf (" creating appsrc \n ");
749 // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
751 // d->audio_message = GNUNET_malloc (UINT16_MAX);
752 // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage));
753 // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage));
756 // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
759 d->stdin_mst = GNUNET_MST_create (&stdin_receiver, d);
761 if (d->stdin_mst == NULL)
762 printf ("stdin_mst = NULL");
764 d->appsrc = gst_element_factory_make ("appsrc", "appsrc");
766 gst_bin_add_many (bin, d->appsrc, NULL);
767 // gst_element_link_many ( encoder, muxer, NULL);
769 pad = gst_element_get_static_pad (d->appsrc, "src");
770 ghostpad = gst_ghost_pad_new ("src", pad);
774 bin = GST_BIN (gst_bin_new ("Gnunet appsink"));
777 GNUNET_assert (GNUNET_OK ==
778 GNUNET_log_setup ("gnunet-helper-audio-record",
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
783 "Audio source starts\n");
785 d->appsink = gst_element_factory_make ("appsink", "appsink");
787 // Move this out of here!
788 d->audio_message = GNUNET_malloc (UINT16_MAX);
789 (d->audio_message)->header.type = htons (
790 GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
791 g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE,
794 g_signal_connect (d->appsink, "new-sample",
795 G_CALLBACK (on_appsink_new_sample), &d);
797 gst_bin_add_many (bin, d->appsink, NULL);
798 // gst_element_link_many ( encoder, muxer, NULL);
800 pad = gst_element_get_static_pad (d->appsink, "sink");
801 ghostpad = gst_ghost_pad_new ("sink", pad);
804 /* set the bin pads */
805 gst_pad_set_active (ghostpad, TRUE);
806 gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
808 gst_object_unref (pad);
815 get_coder (GNUNET_gstData *d, int type)
818 GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad;
820 GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer,
823 if (d->usertp == TRUE)
826 * application/x-rtp, media=(string)audio, clock-rate=(int)48000, encoding-name=(string)OPUS, sprop-maxcapturerate=(string)48000, sprop-stereo=(string)0, payload=(int)96, encoding-params=(string)2, ssrc=(uint)630297634, timestamp-offset=(uint)678334141, seqnum-offset=(uint)16938 */
828 rtpcaps = gst_caps_new_simple ("application/x-rtp",
829 "media", G_TYPE_STRING, "audio",
830 "clock-rate", G_TYPE_INT, SAMPLING_RATE,
831 "encoding-name", G_TYPE_STRING, "OPUS",
832 "payload", G_TYPE_INT, 96,
833 "sprop-stereo", G_TYPE_STRING, "0",
834 "encoding-params", G_TYPE_STRING, "2",
836 */ rtpcaps = gst_caps_new_simple ("application/x-rtp",
837 "media", G_TYPE_STRING, "audio",
838 "clock-rate", G_TYPE_INT, SAMPLING_RATE,
839 "encoding-name", G_TYPE_STRING, "OPUS",
840 "payload", G_TYPE_INT, 96,
841 "sprop-stereo", G_TYPE_STRING, "0",
842 "encoding-params", G_TYPE_STRING, "2",
846 rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter");
848 g_object_set (G_OBJECT (rtpcapsfilter),
851 gst_caps_unref (rtpcaps);
857 bin = GST_BIN (gst_bin_new ("Gnunet audioencoder"));
859 encoder = gst_element_factory_make ("opusenc", "opus-encoder");
860 if (d->usertp == TRUE)
862 muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader");
866 muxer = gst_element_factory_make ("oggmux", "ogg-muxer");
868 g_object_set (G_OBJECT (encoder),
869 /* "bitrate", 64000, */
870 /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */
871 "inband-fec", INBAND_FEC_MODE,
872 "packet-loss-percentage", PACKET_LOSS_PERCENTAGE,
873 "max-payload-size", MAX_PAYLOAD_SIZE,
874 "audio", TRUE, /* VoIP, not audio */
875 "frame-size", OPUS_FRAME_SIZE,
878 if (d->usertp != TRUE)
880 g_object_set (G_OBJECT (muxer),
881 "max-delay", OGG_MAX_DELAY,
882 "max-page-delay", OGG_MAX_PAGE_DELAY,
886 gst_bin_add_many (bin, encoder, muxer, NULL);
887 gst_element_link_many (encoder, muxer, NULL);
888 sinkpad = gst_element_get_static_pad (encoder, "sink");
889 sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
891 srcpad = gst_element_get_static_pad (muxer, "src");
892 srcghostpad = gst_ghost_pad_new ("src", srcpad);
896 bin = GST_BIN (gst_bin_new ("Gnunet audiodecoder"));
899 if (d->usertp == TRUE)
901 demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer");
902 jitterbuffer = gst_element_factory_make ("rtpjitterbuffer",
907 demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer");
909 decoder = gst_element_factory_make ("opusdec", "opus-decoder");
911 if (d->usertp == TRUE)
913 gst_bin_add_many (bin, rtpcapsfilter, jitterbuffer, demuxer, decoder,
915 gst_element_link_many (rtpcapsfilter, jitterbuffer, demuxer, decoder,
917 sinkpad = gst_element_get_static_pad (rtpcapsfilter, "sink");
921 gst_bin_add_many (bin, demuxer, decoder, NULL);
923 g_signal_connect (demuxer,
925 G_CALLBACK (decoder_ogg_pad_added),
928 sinkpad = gst_element_get_static_pad (demuxer, "sink");
930 sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
932 srcpad = gst_element_get_static_pad (decoder, "src");
933 srcghostpad = gst_ghost_pad_new ("src", srcpad);
936 // add pads to the bin
937 gst_pad_set_active (sinkghostpad, TRUE);
938 gst_element_add_pad (GST_ELEMENT (bin), sinkghostpad);
940 gst_pad_set_active (srcghostpad, TRUE);
941 gst_element_add_pad (GST_ELEMENT (bin), srcghostpad);
949 get_audiobin (GNUNET_gstData *d, int type)
952 GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter;
953 GstPad *pad, *ghostpad;
958 bin = GST_BIN (gst_bin_new ("Gnunet audiosink"));
960 /* Create all the elements */
961 if (d->dropsilence == TRUE)
963 queue = gst_element_factory_make ("queue", "queue");
964 removesilence = gst_element_factory_make ("removesilence",
968 conv = gst_element_factory_make ("audioconvert", "converter");
969 resampler = gst_element_factory_make ("audioresample", "resampler");
971 if (d->audiobackend == AUTO)
973 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
974 g_signal_connect (sink, "child-added", G_CALLBACK (
975 autoaudiosink_child_added), NULL);
978 if (d->audiobackend == ALSA)
980 sink = gst_element_factory_make ("alsaaudiosink", "audiosink");
983 if (d->audiobackend == JACK)
985 sink = gst_element_factory_make ("jackaudiosink", "audiosink");
987 g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL);
989 if (g_object_class_find_property
990 (G_OBJECT_GET_CLASS (sink), "port-pattern"))
992 // char *portpattern = "system";
994 g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out,
999 if (d->audiobackend == FAKE)
1001 sink = gst_element_factory_make ("fakesink", "audiosink");
1005 "buffer-time", (gint64) BUFFER_TIME,
1006 "latency-time", (gint64) LATENCY_TIME,
1009 if (d->dropsilence == TRUE)
1011 // Do not remove silence by default
1012 g_object_set (removesilence, "remove", FALSE, NULL);
1013 g_object_set (queue, "max-size-buffers", 12, NULL);
1015 g_signal_connect (source,
1017 G_CALLBACK(appsrc_need_data),
1020 g_signal_connect (source,
1022 G_CALLBACK(appsrc_enough_data),
1025 g_signal_connect (queue,
1026 "notify::current-level-bytes",
1027 G_CALLBACK(queue_current_level),
1030 g_signal_connect (queue,
1032 G_CALLBACK(queue_underrun),
1035 g_signal_connect (queue,
1037 G_CALLBACK(queue_running),
1040 g_signal_connect (queue,
1042 G_CALLBACK(queue_overrun),
1045 g_signal_connect (queue,
1047 G_CALLBACK(queue_pushing),
1052 gst_bin_add_many (bin, conv, resampler, sink, NULL);
1053 gst_element_link_many (conv, resampler, sink, NULL);
1055 if (d->dropsilence == TRUE)
1057 gst_bin_add_many (bin, queue, removesilence, NULL);
1059 if (! gst_element_link_many (queue, removesilence, conv, NULL))
1060 lf ("queue, removesilence, conv ");
1062 pad = gst_element_get_static_pad (queue, "sink");
1066 pad = gst_element_get_static_pad (conv, "sink");
1069 ghostpad = gst_ghost_pad_new ("sink", pad);
1075 bin = GST_BIN (gst_bin_new ("Gnunet audiosource"));
1077 // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla");
1079 if (d->audiobackend == AUTO)
1081 source = gst_element_factory_make ("autoaudiosrc", "audiosource");
1083 if (d->audiobackend == ALSA)
1085 source = gst_element_factory_make ("alsasrc", "audiosource");
1087 if (d->audiobackend == JACK)
1089 source = gst_element_factory_make ("jackaudiosrc", "audiosource");
1091 if (d->audiobackend == TEST)
1093 source = gst_element_factory_make ("audiotestsrc", "audiosource");
1096 filter = gst_element_factory_make ("capsfilter", "filter");
1097 conv = gst_element_factory_make ("audioconvert", "converter");
1098 resampler = gst_element_factory_make ("audioresample", "resampler");
1100 if (d->audiobackend == AUTO)
1102 g_signal_connect (source, "child-added", G_CALLBACK (
1103 autoaudiosource_child_added), NULL);
1107 if (GST_IS_AUDIO_BASE_SRC (source))
1108 g_object_set (source, "buffer-time", (gint64) BUFFER_TIME,
1109 "latency-time", (gint64) LATENCY_TIME, NULL);
1110 if (d->audiobackend == JACK)
1112 g_object_set (G_OBJECT (source), "client-name", "gnunet", NULL);
1113 if (g_object_class_find_property
1114 (G_OBJECT_GET_CLASS (source), "port-pattern"))
1116 char *portpattern = "moc";
1118 g_object_set (G_OBJECT (source), "port-pattern", portpattern,
1124 caps = gst_caps_new_simple ("audio/x-raw",
1125 /* "format", G_TYPE_STRING, "S16LE", */
1126 /* "rate", G_TYPE_INT, SAMPLING_RATE,*/
1127 "channels", G_TYPE_INT, OPUS_CHANNELS,
1128 /* "layout", G_TYPE_STRING, "interleaved",*/
1131 g_object_set (G_OBJECT (filter),
1134 gst_caps_unref (caps);
1136 gst_bin_add_many (bin, source, filter, conv, resampler, NULL);
1137 gst_element_link_many (source, filter, conv, resampler, NULL);
1139 pad = gst_element_get_static_pad (resampler, "src");
1143 ghostpad = gst_ghost_pad_new ("src", pad);
1146 /* set the bin pads */
1147 gst_pad_set_active (ghostpad, TRUE);
1148 gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
1150 gst_object_unref (pad);