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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file conversation/gnunet_gst.c
25 #include "gnunet_gst_def.h"
30 static struct GNUNET_CONFIGURATION_Handle *cfg;
33 dump_buffer(unsigned n, const unsigned char* buf)
35 const unsigned char *p, *end;
40 for (i = 0; ; i += 16) {
42 for (j = 0; j < 16; j++) {
43 fprintf(stderr, "%02X ", p[j]);
49 for (j = 0; j < 16; j++) {
50 fprintf(stderr, "%c", isprint(p[j]) ? p[j] :
55 fprintf(stderr, "\n");
62 * load gnunet configuration
65 gg_load_configuration(GNUNET_gstData * d)
67 char *audiobackend_string;
68 cfg = GNUNET_CONFIGURATION_create();
69 GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf");
71 char *section = "MEDIAHELPER";
73 GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in);
74 GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_OUT", &d->jack_pp_out);
76 GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string);
78 // printf("abstring: %s \n", audiobackend_string);
80 if ( audiobackend_string == "AUTO" )
82 d->audiobackend = AUTO;
83 } else if ( audiobackend_string = "JACK" )
85 d->audiobackend = JACK;
86 } else if ( audiobackend_string = "ALSA" )
88 d->audiobackend = ALSA;
89 } else if ( audiobackend_string = "FAKE" )
91 d->audiobackend = FAKE;
92 } else if ( audiobackend_string = "TEST" )
94 d->audiobackend = TEST;
97 d->audiobackend = AUTO;
100 if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES)
102 d->dropsilence = TRUE;
104 d->dropsilence = FALSE;
107 if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES)
115 if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES)
122 // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf");
127 write_data (const char *ptr, size_t msg_size)
132 while (off < msg_size)
134 ret = write (1, &ptr[off], msg_size - off);
138 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write");
148 on_appsink_new_sample (GstElement * element, GNUNET_gstData * d)
150 static unsigned long long toff;
152 //size of message including gnunet header
159 const GstStructure *si;
164 (d->audio_message)->header.size = htons ((uint16_t) msg_size);
166 if (gst_app_sink_is_eos(GST_APP_SINK(element)))
169 //pull sample from appsink
170 s = gst_app_sink_pull_sample (GST_APP_SINK(element));
175 if (!GST_IS_SAMPLE (s))
178 b = gst_sample_get_buffer(s);
180 GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s));
184 gst_buffer_map (b, &map, GST_MAP_READ);
188 if (len > UINT16_MAX - sizeof (struct AudioMessage))
190 // this should never happen?
191 printf("GSTREAMER sample too big! \n");
193 len = UINT16_MAX - sizeof (struct AudioMessage);
196 msg_size = sizeof (struct AudioMessage) + len;
198 // copy the data into audio_message
199 GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len);
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Sending %u bytes of audio data (total: %llu)\n",
204 (unsigned int) msg_size,
208 // write the audio_message without the gnunet headers
209 write_data ((const char *) &(d->audio_message)[1], len);
211 write_data ((const char *) d->audio_message, msg_size);
218 * Dump a pipeline graph
221 pl_graph(GstElement * pipeline)
225 gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot");
229 gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot");
234 // load_configuration();
240 gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data)
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 switch (GST_MESSAGE_TYPE (msg))
246 case GST_MESSAGE_EOS:
247 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
252 case GST_MESSAGE_ERROR:
257 gst_message_parse_error (msg, &error, &debug);
260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
263 g_error_free (error);
275 /* called when pipeline changes state */
277 state_changed_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * d)
279 GstState old_state, new_state, pending_state;
281 gst_message_parse_state_changed (msg, &old_state, &new_state,
286 case GST_STATE_READY:
287 // printf("ready.... \n");
288 //pl_graph(GST_ELEMENT(d->pipeline));
290 case GST_STATE_PLAYING:
292 //GST_LOG ("caps are %" GST_PTR_FORMAT, caps);
294 // printf("Playing.... \n");
295 pl_graph(GST_ELEMENT(d->pipeline));
297 case GST_STATE_VOID_PENDING:
298 // printf("void_pending.... \n");
299 //pl_graph(GST_ELEMENT(d->pipeline));
302 // printf("null.... \n");
303 //pl_graph(GST_ELEMENT(d->pipeline));
306 case GST_STATE_PAUSED:
307 // printf("paused.... \n");
308 //pl_graph(GST_ELEMENT(d->pipeline));
314 application_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data)
316 // printf("application cb");
321 error_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data)
323 // printf("error cb");
328 eos_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data)
335 gg_setup_gst_bus (GNUNET_gstData * d)
338 bus = gst_element_get_bus (GST_ELEMENT(d->pipeline));
339 gst_bus_add_signal_watch (bus);
340 g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,
342 g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb,
344 g_signal_connect (G_OBJECT (bus), "message::state-changed",
345 (GCallback) state_changed_cb, d);
346 g_signal_connect (G_OBJECT (bus), "message::application",
347 (GCallback) application_cb, d);
348 g_signal_connect (G_OBJECT (bus), "message::about-to-finish",
349 (GCallback) application_cb, d);
350 gst_object_unref (bus);
355 * take buffer from gstreamer and feed it to gnunet
359 feed_buffer_to_gnunet (GNUNET_gstData * d)
364 size_t len, msg_size;
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n");
369 s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink));
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n");
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n");
377 const GstStructure *si;
381 si = gst_sample_get_info (s);
384 si_str = gst_structure_to_string (si);
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str);
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n");
393 s_caps = gst_sample_get_caps (s);
396 caps_str = gst_caps_to_string (s_caps);
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str);
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n");
406 b = gst_sample_get_buffer (s);
407 if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ))
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b);
410 gst_sample_unref (s);
415 if (len > UINT16_MAX - sizeof (struct AudioMessage))
418 len = UINT16_MAX - sizeof (struct AudioMessage);
420 msg_size = sizeof (struct AudioMessage) + len;
421 audio_message.header.size = htons ((uint16_t) msg_size);
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Sending %u bytes of audio data\n", (unsigned int) msg_size);
426 for (phase = 0; phase < 2; phase++)
431 if (0 == phase && !d->pure_ogg)
433 //#ifdef DEBUG_RECORD_PURE_OGG
439 ptr = (const char *) &audio_message;
440 to_send = sizeof (audio_message);
444 ptr = (const char *) m.data;
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Sending %u bytes on phase %d\n", (unsigned int) to_send, phase);
449 for (offset = 0; offset < to_send; offset += ret)
451 ret = write (1, &ptr[offset], to_send - offset);
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
457 (unsigned int) to_send - offset, (unsigned int) offset,
458 (unsigned int) (to_send + offset), phase, strerror (errno));
468 gst_buffer_unmap (b, &m);
469 gst_sample_unref (s);
475 feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData * d)
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 "Feeding %u bytes to GStreamer\n",
483 (unsigned int) b_len);
485 bufspace = g_memdup (audio, b_len);
486 b = gst_buffer_new_wrapped (bufspace, b_len);
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Failed to wrap a buffer\n");
492 return GNUNET_SYSERR;
494 if (GST_APP_SRC(d->appsrc) == NULL)
496 flow = gst_app_src_push_buffer (GST_APP_SRC(d->appsrc), b);
497 /* They all return GNUNET_OK, because currently player stops when
498 * data stops coming. This might need to be changed for the player
499 * to also stop when pipeline breaks.
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "Fed %u bytes to the pipeline\n",
506 (unsigned int) b_len);
508 case GST_FLOW_FLUSHING:
509 /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */
510 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
511 "Dropped a buffer\n");
515 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
519 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
520 "Unexpected push result\n");
529 * debug making elements
532 gst_element_factory_make_debug( gchar *factoryname, gchar *name)
536 element = gst_element_factory_make(factoryname,name);
538 if (element == NULL) {
540 printf ("\n Failed to create element - type: %s name: %s \n", factoryname, name);
550 gst_element_link_many_debug(...)
553 gst_element_link_many(argptr);
556 #define gst_element_link_many(...) \
557 gst_element_link_many_debug(__VA_ARGS__)
562 printf("linking elements failed: %s", msg);
567 * used to set properties on autoaudiosink's chosen sink
570 autoaudiosink_child_added (GstChildProxy *child_proxy,
575 if (GST_IS_AUDIO_BASE_SRC (object))
576 g_object_set (object,
577 "buffer-time", (gint64) BUFFER_TIME,
578 "latency-time", (gint64) LATENCY_TIME,
583 * used to set properties on autoaudiosource's chosen sink
586 autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
588 if (GST_IS_AUDIO_BASE_SRC (object))
589 g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL);
593 get_pipeline(GstElement *element)
597 p = gst_object_get_parent(element);
603 decoder_ogg_pad_added (GstElement *element,
608 GstElement *decoder = (GstElement *) data;
610 printf("==== ogg pad added callback \n");
611 /* We can now link this pad with the opus-decoder sink pad */
612 // pl_graph(get_pipeline(element));
613 sinkpad = gst_element_get_static_pad (decoder, "sink");
615 gst_pad_link (pad, sinkpad);
616 gst_element_link_many(element, decoder, NULL);
617 gst_object_unref (sinkpad);
621 gnunet_read (GNUNET_gstData * d)
623 char readbuf[MAXLINE];
626 ret = read (0, readbuf, sizeof (readbuf));
629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
630 _("Read error from STDIN: %d %s\n"),
631 ret, strerror (errno));
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Received %d bytes of audio data\n",
640 //#ifdef DEBUG_READ_PURE_OGG
644 feed_buffer_to_gst (readbuf, ret, d);
649 GNUNET_SERVER_mst_receive (d->stdin_mst, NULL,
651 GNUNET_NO, GNUNET_NO);
659 stdin_receiver (void *cls,
661 const struct GNUNET_MessageHeader *msg)
663 struct AudioMessage *audio;
665 printf("stdin receiver \n ");
666 dump_buffer(sizeof(msg), msg);
668 switch (ntohs (msg->type))
670 case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO:
671 audio = (struct AudioMessage *) msg;
673 b_len = ntohs (audio->header.size) - sizeof (struct AudioMessage);
674 printf("feeding buffer to gst \n ");
675 feed_buffer_to_gst ((const char *) &audio[1], b_len, cls);
678 printf("No audio message: %u \n ", ntohs(msg->type));
686 get_app(GNUNET_gstData *d, int type)
689 GstPad *pad, *ghostpad;
691 if ( type == SOURCE )
693 bin = GST_BIN(gst_bin_new("Gnunet appsrc"));
696 GNUNET_assert (GNUNET_OK ==
697 GNUNET_log_setup ("gnunet-helper-audio-playback",
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 "Audio playback starts\n");
703 printf(" creating appsrc \n ");
704 //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
706 // d->audio_message = GNUNET_malloc (UINT16_MAX);
707 // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage));
708 // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage));
711 //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
714 d->stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, d);
716 if ( d->stdin_mst == NULL)
717 printf("stdin_mst = NULL");
719 d->appsrc = gst_element_factory_make ("appsrc", "appsrc");
721 gst_bin_add_many( bin, d->appsrc, NULL);
722 // gst_element_link_many ( encoder, muxer, NULL);
724 pad = gst_element_get_static_pad (d->appsrc, "src");
725 ghostpad = gst_ghost_pad_new ("src", pad);
729 bin = GST_BIN(gst_bin_new("Gnunet appsink"));
732 GNUNET_assert (GNUNET_OK ==
733 GNUNET_log_setup ("gnunet-helper-audio-record",
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Audio source starts\n");
740 d->appsink = gst_element_factory_make ("appsink", "appsink");
742 // Move this out of here!
743 d->audio_message = GNUNET_malloc (UINT16_MAX);
744 (d->audio_message)->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
745 g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL);
747 g_signal_connect (d->appsink, "new-sample",
748 G_CALLBACK (on_appsink_new_sample), &d);
750 gst_bin_add_many( bin, d->appsink, NULL);
751 // gst_element_link_many ( encoder, muxer, NULL);
753 pad = gst_element_get_static_pad (d->appsink, "sink");
754 ghostpad = gst_ghost_pad_new ("sink", pad);
757 /* set the bin pads */
758 gst_pad_set_active (ghostpad, TRUE);
759 gst_element_add_pad (GST_ELEMENT(bin), ghostpad);
761 gst_object_unref (pad);
767 get_coder(GNUNET_gstData *d , int type)
770 GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad;
771 GstCaps *caps, *rtpcaps;
772 GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter;
774 if ( d->usertp == TRUE )
777 * 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 */
779 rtpcaps = gst_caps_new_simple ("application/x-rtp",
780 "media", G_TYPE_STRING, "audio",
781 "clock-rate", G_TYPE_INT, SAMPLING_RATE,
782 "encoding-name", G_TYPE_STRING, "OPUS",
783 "payload", G_TYPE_INT, 96,
784 "sprop-stereo", G_TYPE_STRING, "0",
785 "encoding-params", G_TYPE_STRING, "2",
788 rtpcaps = gst_caps_new_simple ("application/x-rtp",
789 "media", G_TYPE_STRING, "audio",
790 "clock-rate", G_TYPE_INT, SAMPLING_RATE,
791 "encoding-name", G_TYPE_STRING, "OPUS",
792 "payload", G_TYPE_INT, 96,
793 "sprop-stereo", G_TYPE_STRING, "0",
794 "encoding-params", G_TYPE_STRING, "2",
798 rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter");
800 g_object_set (G_OBJECT (rtpcapsfilter),
803 gst_caps_unref (rtpcaps);
808 if ( type == ENCODER )
810 bin = GST_BIN(gst_bin_new("Gnunet audioencoder"));
812 encoder = gst_element_factory_make ("opusenc", "opus-encoder");
813 if ( d->usertp == TRUE )
815 muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader");
817 muxer = gst_element_factory_make ("oggmux", "ogg-muxer");
819 g_object_set (G_OBJECT (encoder),
820 /* "bitrate", 64000, */
821 /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */
822 "inband-fec", INBAND_FEC_MODE,
823 "packet-loss-percentage", PACKET_LOSS_PERCENTAGE,
824 "max-payload-size", MAX_PAYLOAD_SIZE,
825 "audio", TRUE, /* VoIP, not audio */
826 "frame-size", OPUS_FRAME_SIZE,
829 if ( d->usertp != TRUE)
831 g_object_set (G_OBJECT (muxer),
832 "max-delay", OGG_MAX_DELAY,
833 "max-page-delay", OGG_MAX_PAGE_DELAY,
837 gst_bin_add_many( bin, encoder, muxer, NULL);
838 gst_element_link_many ( encoder, muxer, NULL);
839 sinkpad = gst_element_get_static_pad(encoder, "sink");
840 sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
842 srcpad = gst_element_get_static_pad(muxer, "src");
843 srcghostpad = gst_ghost_pad_new ("src", srcpad);
846 if ( type == DECODER )
848 bin = GST_BIN(gst_bin_new("Gnunet audiodecoder"));
851 if ( d->usertp == TRUE )
854 demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer");
855 jitterbuffer = gst_element_factory_make ("rtpjitterbuffer", "rtpjitterbuffer");
857 demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer");
859 decoder = gst_element_factory_make ("opusdec", "opus-decoder");
861 if ( d->usertp == TRUE )
863 gst_bin_add_many( bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL);
864 gst_element_link_many ( rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL);
865 sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink");
869 gst_bin_add_many( bin, demuxer, decoder, NULL);
871 g_signal_connect (demuxer,
873 G_CALLBACK (decoder_ogg_pad_added),
876 sinkpad = gst_element_get_static_pad(demuxer, "sink");
878 sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
880 srcpad = gst_element_get_static_pad(decoder, "src");
881 srcghostpad = gst_ghost_pad_new ("src", srcpad);
885 // add pads to the bin
886 gst_pad_set_active (sinkghostpad, TRUE);
887 gst_element_add_pad (GST_ELEMENT(bin), sinkghostpad);
889 gst_pad_set_active (srcghostpad, TRUE);
890 gst_element_add_pad (GST_ELEMENT(bin), srcghostpad);
896 get_audiobin(GNUNET_gstData *d , int type)
899 GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter;
900 GstPad *pad, *ghostpad;
902 if ( type == SINK ) {
904 bin = GST_BIN(gst_bin_new("Gnunet audiosink"));
906 /* Create all the elements */
907 if ( d->dropsilence == TRUE )
909 queue = gst_element_factory_make ("queue", "queue");
910 removesilence = gst_element_factory_make ("removesilence", "removesilence");
913 conv = gst_element_factory_make ("audioconvert", "converter");
914 resampler= gst_element_factory_make ("audioresample", "resampler");
916 if ( d->audiobackend == AUTO )
918 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
919 g_signal_connect (sink, "child-added", G_CALLBACK (autoaudiosink_child_added), NULL);
923 if ( d->audiobackend == ALSA )
925 sink = gst_element_factory_make ("alsaaudiosink", "audiosink");
928 if ( d->audiobackend == JACK )
930 sink = gst_element_factory_make ("jackaudiosink", "audiosink");
932 g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL);
934 if (g_object_class_find_property
935 (G_OBJECT_GET_CLASS (sink), "port-pattern"))
938 // char *portpattern = "system";
940 g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out,
946 if ( d->audiobackend == FAKE )
948 sink = gst_element_factory_make ("fakesink", "audiosink");
952 "buffer-time", (gint64) BUFFER_TIME,
953 "latency-time", (gint64) LATENCY_TIME,
956 if ( d->dropsilence == TRUE )
958 // Do not remove silence by default
959 g_object_set( removesilence, "remove", FALSE, NULL);
960 g_object_set( queue, "max-size-buffers", 12, NULL);
962 g_signal_connect (source,
964 G_CALLBACK(appsrc_need_data),
967 g_signal_connect (source,
969 G_CALLBACK(appsrc_enough_data),
973 g_signal_connect (queue,
974 "notify::current-level-bytes",
975 G_CALLBACK(queue_current_level),
978 g_signal_connect (queue,
980 G_CALLBACK(queue_underrun),
983 g_signal_connect (queue,
985 G_CALLBACK(queue_running),
988 g_signal_connect (queue,
990 G_CALLBACK(queue_overrun),
993 g_signal_connect (queue,
995 G_CALLBACK(queue_pushing),
1005 gst_bin_add_many (bin , conv, resampler, sink, NULL);
1006 gst_element_link_many ( conv, resampler, sink, NULL);
1008 if ( d->dropsilence == TRUE )
1010 gst_bin_add_many (bin , queue ,removesilence , NULL);
1012 if ( !gst_element_link_many ( queue, removesilence, conv, NULL) )
1013 lf ("queue, removesilence, conv ");
1015 pad = gst_element_get_static_pad (queue, "sink");
1019 pad = gst_element_get_static_pad(conv, "sink");
1023 ghostpad = gst_ghost_pad_new ("sink", pad);
1028 bin = GST_BIN(gst_bin_new("Gnunet audiosource"));
1030 // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla");
1032 if (d->audiobackend == AUTO )
1034 source = gst_element_factory_make ("autoaudiosrc", "audiosource");
1036 if (d->audiobackend == ALSA )
1038 source = gst_element_factory_make ("alsasrc", "audiosource");
1040 if (d->audiobackend == JACK )
1042 source = gst_element_factory_make ("jackaudiosrc", "audiosource");
1044 if (d->audiobackend == TEST )
1046 source = gst_element_factory_make ("audiotestsrc", "audiosource");
1049 filter = gst_element_factory_make ("capsfilter", "filter");
1050 conv = gst_element_factory_make ("audioconvert", "converter");
1051 resampler= gst_element_factory_make ("audioresample", "resampler");
1053 if (d->audiobackend == AUTO ) {
1054 g_signal_connect (source, "child-added", G_CALLBACK (autoaudiosource_child_added), NULL);
1057 if (GST_IS_AUDIO_BASE_SRC (source))
1058 g_object_set (source, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL);
1059 if ( d->audiobackend == JACK ) {
1060 g_object_set (G_OBJECT (source), "client-name", "gnunet", NULL);
1061 if (g_object_class_find_property
1062 (G_OBJECT_GET_CLASS (source), "port-pattern"))
1065 char *portpattern = "moc";
1067 g_object_set (G_OBJECT (source), "port-pattern", portpattern,
1073 caps = gst_caps_new_simple ("audio/x-raw",
1074 /* "format", G_TYPE_STRING, "S16LE", */
1075 /* "rate", G_TYPE_INT, SAMPLING_RATE,*/
1076 "channels", G_TYPE_INT, OPUS_CHANNELS,
1077 /* "layout", G_TYPE_STRING, "interleaved",*/
1080 g_object_set (G_OBJECT (filter),
1083 gst_caps_unref (caps);
1085 gst_bin_add_many (bin , source, filter, conv, resampler, NULL);
1086 gst_element_link_many ( source, filter, conv, resampler, NULL);
1088 pad = gst_element_get_static_pad (resampler, "src");
1092 ghostpad = gst_ghost_pad_new ("src", pad);
1096 /* set the bin pads */
1097 gst_pad_set_active (ghostpad, TRUE);
1098 gst_element_add_pad (GST_ELEMENT(bin), ghostpad);
1100 gst_object_unref (pad);