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/>.
19 * @file conversation/gnunet_gst.c
23 #include "gnunet_gst_def.h"
28 static struct GNUNET_CONFIGURATION_Handle *cfg;
32 dump_buffer(unsigned n, const unsigned char* buf)
34 const unsigned char *p, *end;
39 for (i = 0; ; i += 16) {
41 for (j = 0; j < 16; j++) {
42 fprintf(stderr, "%02X ", p[j]);
48 for (j = 0; j < 16; j++) {
49 fprintf(stderr, "%c", isprint(p[j]) ? p[j] :
54 fprintf(stderr, "\n");
61 * load gnunet configuration
64 gg_load_configuration(GNUNET_gstData * d)
66 char *audiobackend_string;
67 cfg = GNUNET_CONFIGURATION_create();
68 GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf");
70 GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in);
71 GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_OUT", &d->jack_pp_out);
73 GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string);
75 // printf("abstring: %s \n", audiobackend_string);
77 if (0 == strcasecmp (audiobackend_string, "AUTO"))
79 d->audiobackend = AUTO;
80 } else if (0 == strcasecmp (audiobackend_string, "JACK"))
82 d->audiobackend = JACK;
83 } else if (0 == strcasecmp (audiobackend_string, "ALSA"))
85 d->audiobackend = ALSA;
86 } else if (0 == strcasecmp (audiobackend_string, "FAKE"))
88 d->audiobackend = FAKE;
89 } else if (0 == strcasecmp (audiobackend_string, "TEST"))
91 d->audiobackend = TEST;
94 d->audiobackend = AUTO;
97 if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES)
99 d->dropsilence = TRUE;
101 d->dropsilence = FALSE;
104 if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES)
112 if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES)
119 // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf");
124 write_data (const char *ptr, size_t msg_size)
129 while (off < msg_size)
131 ret = write (1, &ptr[off], msg_size - off);
135 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write");
145 on_appsink_new_sample (GstElement * element, GNUNET_gstData * d)
147 //size of message including gnunet header
154 const GstStructure *si;
160 if (gst_app_sink_is_eos(GST_APP_SINK(element)))
163 //pull sample from appsink
164 s = gst_app_sink_pull_sample (GST_APP_SINK(element));
169 if (!GST_IS_SAMPLE (s))
172 b = gst_sample_get_buffer(s);
174 GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s));
178 gst_buffer_map (b, &map, GST_MAP_READ);
182 if (len > UINT16_MAX - sizeof (struct AudioMessage))
184 // this should never happen?
185 printf("GSTREAMER sample too big! \n");
187 len = UINT16_MAX - sizeof (struct AudioMessage);
190 msg_size = sizeof (struct AudioMessage) + len;
192 // copy the data into audio_message
193 GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len);
194 (d->audio_message)->header.size = htons ((uint16_t) msg_size);
196 // write the audio_message without the gnunet headers
197 write_data ((const char *) &(d->audio_message)[1], len);
199 write_data ((const char *) d->audio_message, msg_size);
206 * Dump a pipeline graph
209 pl_graph(GstElement * pipeline)
213 gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot");
217 gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot");
222 // load_configuration();
228 gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data)
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
232 switch (GST_MESSAGE_TYPE (msg))
234 case GST_MESSAGE_EOS:
235 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
240 case GST_MESSAGE_ERROR:
245 gst_message_parse_error (msg, &error, &debug);
248 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
251 g_error_free (error);
263 /* called when pipeline changes state */
265 state_changed_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * d)
267 GstState old_state, new_state, pending_state;
269 gst_message_parse_state_changed (msg, &old_state, &new_state,
274 case GST_STATE_READY:
275 // printf("ready.... \n");
276 //pl_graph(GST_ELEMENT(d->pipeline));
278 case GST_STATE_PLAYING:
280 //GST_LOG ("caps are %" GST_PTR_FORMAT, caps);
282 // printf("Playing.... \n");
283 pl_graph(GST_ELEMENT(d->pipeline));
285 case GST_STATE_VOID_PENDING:
286 // printf("void_pending.... \n");
287 //pl_graph(GST_ELEMENT(d->pipeline));
290 // printf("null.... \n");
291 //pl_graph(GST_ELEMENT(d->pipeline));
294 case GST_STATE_PAUSED:
295 // printf("paused.... \n");
296 //pl_graph(GST_ELEMENT(d->pipeline));
302 application_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data)
304 // printf("application cb");
309 error_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data)
311 // printf("error cb");
316 eos_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data)
323 gg_setup_gst_bus (GNUNET_gstData * d)
326 bus = gst_element_get_bus (GST_ELEMENT(d->pipeline));
327 gst_bus_add_signal_watch (bus);
328 g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,
330 g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb,
332 g_signal_connect (G_OBJECT (bus), "message::state-changed",
333 (GCallback) state_changed_cb, d);
334 g_signal_connect (G_OBJECT (bus), "message::application",
335 (GCallback) application_cb, d);
336 g_signal_connect (G_OBJECT (bus), "message::about-to-finish",
337 (GCallback) application_cb, d);
338 gst_object_unref (bus);
343 * take buffer from gstreamer and feed it to gnunet
347 feed_buffer_to_gnunet (GNUNET_gstData * d)
352 size_t len, msg_size;
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n");
357 s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink));
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n");
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n");
365 const GstStructure *si;
369 si = gst_sample_get_info (s);
372 si_str = gst_structure_to_string (si);
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str);
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n");
381 s_caps = gst_sample_get_caps (s);
384 caps_str = gst_caps_to_string (s_caps);
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str);
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n");
394 b = gst_sample_get_buffer (s);
395 if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ))
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b);
398 gst_sample_unref (s);
403 if (len > UINT16_MAX - sizeof (struct AudioMessage))
406 len = UINT16_MAX - sizeof (struct AudioMessage);
408 msg_size = sizeof (struct AudioMessage) + len;
409 audio_message.header.size = htons ((uint16_t) msg_size);
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Sending %u bytes of audio data\n", (unsigned int) msg_size);
414 for (phase = 0; phase < 2; phase++)
419 if (0 == phase && !d->pure_ogg)
421 //#ifdef DEBUG_RECORD_PURE_OGG
427 ptr = (const char *) &audio_message;
428 to_send = sizeof (audio_message);
432 ptr = (const char *) m.data;
435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
436 "Sending %u bytes on phase %d\n", (unsigned int) to_send, phase);
437 for (offset = 0; offset < to_send; offset += ret)
439 ret = write (1, &ptr[offset], to_send - offset);
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
445 (unsigned int) to_send - offset, (unsigned int) offset,
446 (unsigned int) (to_send + offset), phase, strerror (errno));
456 gst_buffer_unmap (b, &m);
457 gst_sample_unref (s);
463 feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData * d)
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
470 "Feeding %u bytes to GStreamer\n",
471 (unsigned int) b_len);
473 bufspace = g_memdup (audio, b_len);
474 b = gst_buffer_new_wrapped (bufspace, b_len);
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
478 "Failed to wrap a buffer\n");
480 return GNUNET_SYSERR;
482 if (GST_APP_SRC(d->appsrc) == NULL)
484 flow = gst_app_src_push_buffer (GST_APP_SRC(d->appsrc), b);
485 /* They all return GNUNET_OK, because currently player stops when
486 * data stops coming. This might need to be changed for the player
487 * to also stop when pipeline breaks.
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "Fed %u bytes to the pipeline\n",
494 (unsigned int) b_len);
496 case GST_FLOW_FLUSHING:
497 /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */
498 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
499 "Dropped a buffer\n");
503 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
507 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
508 "Unexpected push result\n");
517 * debug making elements
520 gst_element_factory_make_debug( gchar *factoryname, gchar *name)
524 element = gst_element_factory_make(factoryname,name);
526 if (element == NULL) {
528 printf ("\n Failed to create element - type: %s name: %s \n", factoryname, name);
538 gst_element_link_many_debug(...)
541 gst_element_link_many(argptr);
544 #define gst_element_link_many(...) \
545 gst_element_link_many_debug(__VA_ARGS__)
550 printf("linking elements failed: %s", msg);
555 * used to set properties on autoaudiosink's chosen sink
558 autoaudiosink_child_added (GstChildProxy *child_proxy,
563 if (GST_IS_AUDIO_BASE_SRC (object))
564 g_object_set (object,
565 "buffer-time", (gint64) BUFFER_TIME,
566 "latency-time", (gint64) LATENCY_TIME,
571 * used to set properties on autoaudiosource's chosen sink
574 autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
576 if (GST_IS_AUDIO_BASE_SRC (object))
577 g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL);
582 get_pipeline(GstElement *element)
586 p = GST_PIPELINE (gst_object_get_parent(GST_OBJECT (element)));
588 return GST_ELEMENT (p);
592 decoder_ogg_pad_added (GstElement *element,
597 GstElement *decoder = (GstElement *) data;
599 printf("==== ogg pad added callback \n");
600 /* We can now link this pad with the opus-decoder sink pad */
601 // pl_graph(get_pipeline(element));
602 sinkpad = gst_element_get_static_pad (decoder, "sink");
604 gst_pad_link (pad, sinkpad);
605 gst_element_link_many(element, decoder, NULL);
606 gst_object_unref (sinkpad);
611 gnunet_read (GNUNET_gstData * d)
613 char readbuf[MAXLINE];
616 ret = read (0, readbuf, sizeof (readbuf));
619 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
620 _("Read error from STDIN: %d %s\n"),
621 ret, strerror (errno));
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
626 "Received %d bytes of audio data\n",
630 //#ifdef DEBUG_READ_PURE_OGG
634 feed_buffer_to_gst (readbuf, ret, d);
639 GNUNET_MST_from_buffer (d->stdin_mst,
651 * @param msg message we received.
652 * @return #GNUNET_OK on success,
653 * #GNUNET_NO to stop further processing due to disconnect (no error)
654 * #GNUNET_SYSERR to stop further processing due to error
657 stdin_receiver (void *cls,
658 const struct GNUNET_MessageHeader *msg)
660 struct AudioMessage *audio;
663 printf("stdin receiver \n ");
664 dump_buffer (sizeof(msg),
665 (const unsigned char *) msg);
667 switch (ntohs (msg->type))
669 case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO:
670 audio = (struct AudioMessage *) msg;
672 b_len = ntohs (audio->header.size) - sizeof (struct AudioMessage);
673 printf("feeding buffer to gst \n ");
674 feed_buffer_to_gst ((const char *) &audio[1], b_len, cls);
677 printf("No audio message: %u \n ", ntohs(msg->type));
685 get_app(GNUNET_gstData *d, int type)
688 GstPad *pad, *ghostpad;
690 if ( type == SOURCE )
692 bin = GST_BIN(gst_bin_new("Gnunet appsrc"));
695 GNUNET_assert (GNUNET_OK ==
696 GNUNET_log_setup ("gnunet-helper-audio-playback",
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
701 "Audio playback starts\n");
702 printf(" creating appsrc \n ");
703 //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
705 // d->audio_message = GNUNET_malloc (UINT16_MAX);
706 // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage));
707 // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage));
710 //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
713 d->stdin_mst = GNUNET_MST_create (&stdin_receiver, d);
715 if ( d->stdin_mst == NULL)
716 printf("stdin_mst = NULL");
718 d->appsrc = gst_element_factory_make ("appsrc", "appsrc");
720 gst_bin_add_many( bin, d->appsrc, NULL);
721 // gst_element_link_many ( encoder, muxer, NULL);
723 pad = gst_element_get_static_pad (d->appsrc, "src");
724 ghostpad = gst_ghost_pad_new ("src", pad);
728 bin = GST_BIN(gst_bin_new("Gnunet appsink"));
731 GNUNET_assert (GNUNET_OK ==
732 GNUNET_log_setup ("gnunet-helper-audio-record",
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Audio source starts\n");
739 d->appsink = gst_element_factory_make ("appsink", "appsink");
741 // Move this out of here!
742 d->audio_message = GNUNET_malloc (UINT16_MAX);
743 (d->audio_message)->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
744 g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL);
746 g_signal_connect (d->appsink, "new-sample",
747 G_CALLBACK (on_appsink_new_sample), &d);
749 gst_bin_add_many( bin, d->appsink, NULL);
750 // gst_element_link_many ( encoder, muxer, NULL);
752 pad = gst_element_get_static_pad (d->appsink, "sink");
753 ghostpad = gst_ghost_pad_new ("sink", pad);
756 /* set the bin pads */
757 gst_pad_set_active (ghostpad, TRUE);
758 gst_element_add_pad (GST_ELEMENT(bin), ghostpad);
760 gst_object_unref (pad);
766 get_coder(GNUNET_gstData *d , int type)
769 GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad;
771 GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter;
773 if ( d->usertp == TRUE )
776 * 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 */
778 rtpcaps = gst_caps_new_simple ("application/x-rtp",
779 "media", G_TYPE_STRING, "audio",
780 "clock-rate", G_TYPE_INT, SAMPLING_RATE,
781 "encoding-name", G_TYPE_STRING, "OPUS",
782 "payload", G_TYPE_INT, 96,
783 "sprop-stereo", G_TYPE_STRING, "0",
784 "encoding-params", G_TYPE_STRING, "2",
787 rtpcaps = gst_caps_new_simple ("application/x-rtp",
788 "media", G_TYPE_STRING, "audio",
789 "clock-rate", G_TYPE_INT, SAMPLING_RATE,
790 "encoding-name", G_TYPE_STRING, "OPUS",
791 "payload", G_TYPE_INT, 96,
792 "sprop-stereo", G_TYPE_STRING, "0",
793 "encoding-params", G_TYPE_STRING, "2",
797 rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter");
799 g_object_set (G_OBJECT (rtpcapsfilter),
802 gst_caps_unref (rtpcaps);
807 if ( type == ENCODER )
809 bin = GST_BIN(gst_bin_new("Gnunet audioencoder"));
811 encoder = gst_element_factory_make ("opusenc", "opus-encoder");
812 if ( d->usertp == TRUE )
814 muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader");
816 muxer = gst_element_factory_make ("oggmux", "ogg-muxer");
818 g_object_set (G_OBJECT (encoder),
819 /* "bitrate", 64000, */
820 /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */
821 "inband-fec", INBAND_FEC_MODE,
822 "packet-loss-percentage", PACKET_LOSS_PERCENTAGE,
823 "max-payload-size", MAX_PAYLOAD_SIZE,
824 "audio", TRUE, /* VoIP, not audio */
825 "frame-size", OPUS_FRAME_SIZE,
828 if ( d->usertp != TRUE)
830 g_object_set (G_OBJECT (muxer),
831 "max-delay", OGG_MAX_DELAY,
832 "max-page-delay", OGG_MAX_PAGE_DELAY,
836 gst_bin_add_many( bin, encoder, muxer, NULL);
837 gst_element_link_many ( encoder, muxer, NULL);
838 sinkpad = gst_element_get_static_pad(encoder, "sink");
839 sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
841 srcpad = gst_element_get_static_pad(muxer, "src");
842 srcghostpad = gst_ghost_pad_new ("src", srcpad);
845 if ( type == DECODER )
847 bin = GST_BIN(gst_bin_new("Gnunet audiodecoder"));
850 if ( d->usertp == TRUE )
853 demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer");
854 jitterbuffer = gst_element_factory_make ("rtpjitterbuffer", "rtpjitterbuffer");
856 demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer");
858 decoder = gst_element_factory_make ("opusdec", "opus-decoder");
860 if ( d->usertp == TRUE )
862 gst_bin_add_many( bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL);
863 gst_element_link_many ( rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL);
864 sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink");
868 gst_bin_add_many( bin, demuxer, decoder, NULL);
870 g_signal_connect (demuxer,
872 G_CALLBACK (decoder_ogg_pad_added),
875 sinkpad = gst_element_get_static_pad(demuxer, "sink");
877 sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
879 srcpad = gst_element_get_static_pad(decoder, "src");
880 srcghostpad = gst_ghost_pad_new ("src", srcpad);
884 // add pads to the bin
885 gst_pad_set_active (sinkghostpad, TRUE);
886 gst_element_add_pad (GST_ELEMENT(bin), sinkghostpad);
888 gst_pad_set_active (srcghostpad, TRUE);
889 gst_element_add_pad (GST_ELEMENT(bin), srcghostpad);
897 get_audiobin(GNUNET_gstData *d , int type)
900 GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter;
901 GstPad *pad, *ghostpad;
903 if ( type == SINK ) {
905 bin = GST_BIN(gst_bin_new("Gnunet audiosink"));
907 /* Create all the elements */
908 if ( d->dropsilence == TRUE )
910 queue = gst_element_factory_make ("queue", "queue");
911 removesilence = gst_element_factory_make ("removesilence", "removesilence");
914 conv = gst_element_factory_make ("audioconvert", "converter");
915 resampler= gst_element_factory_make ("audioresample", "resampler");
917 if ( d->audiobackend == AUTO )
919 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
920 g_signal_connect (sink, "child-added", G_CALLBACK (autoaudiosink_child_added), NULL);
924 if ( d->audiobackend == ALSA )
926 sink = gst_element_factory_make ("alsaaudiosink", "audiosink");
929 if ( d->audiobackend == JACK )
931 sink = gst_element_factory_make ("jackaudiosink", "audiosink");
933 g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL);
935 if (g_object_class_find_property
936 (G_OBJECT_GET_CLASS (sink), "port-pattern"))
939 // char *portpattern = "system";
941 g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out,
947 if ( d->audiobackend == FAKE )
949 sink = gst_element_factory_make ("fakesink", "audiosink");
953 "buffer-time", (gint64) BUFFER_TIME,
954 "latency-time", (gint64) LATENCY_TIME,
957 if ( d->dropsilence == TRUE )
959 // Do not remove silence by default
960 g_object_set( removesilence, "remove", FALSE, NULL);
961 g_object_set( queue, "max-size-buffers", 12, NULL);
963 g_signal_connect (source,
965 G_CALLBACK(appsrc_need_data),
968 g_signal_connect (source,
970 G_CALLBACK(appsrc_enough_data),
974 g_signal_connect (queue,
975 "notify::current-level-bytes",
976 G_CALLBACK(queue_current_level),
979 g_signal_connect (queue,
981 G_CALLBACK(queue_underrun),
984 g_signal_connect (queue,
986 G_CALLBACK(queue_running),
989 g_signal_connect (queue,
991 G_CALLBACK(queue_overrun),
994 g_signal_connect (queue,
996 G_CALLBACK(queue_pushing),
1006 gst_bin_add_many (bin , conv, resampler, sink, NULL);
1007 gst_element_link_many ( conv, resampler, sink, NULL);
1009 if ( d->dropsilence == TRUE )
1011 gst_bin_add_many (bin , queue ,removesilence , NULL);
1013 if ( !gst_element_link_many ( queue, removesilence, conv, NULL) )
1014 lf ("queue, removesilence, conv ");
1016 pad = gst_element_get_static_pad (queue, "sink");
1020 pad = gst_element_get_static_pad(conv, "sink");
1024 ghostpad = gst_ghost_pad_new ("sink", pad);
1029 bin = GST_BIN(gst_bin_new("Gnunet audiosource"));
1031 // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla");
1033 if (d->audiobackend == AUTO )
1035 source = gst_element_factory_make ("autoaudiosrc", "audiosource");
1037 if (d->audiobackend == ALSA )
1039 source = gst_element_factory_make ("alsasrc", "audiosource");
1041 if (d->audiobackend == JACK )
1043 source = gst_element_factory_make ("jackaudiosrc", "audiosource");
1045 if (d->audiobackend == TEST )
1047 source = gst_element_factory_make ("audiotestsrc", "audiosource");
1050 filter = gst_element_factory_make ("capsfilter", "filter");
1051 conv = gst_element_factory_make ("audioconvert", "converter");
1052 resampler= gst_element_factory_make ("audioresample", "resampler");
1054 if (d->audiobackend == AUTO ) {
1055 g_signal_connect (source, "child-added", G_CALLBACK (autoaudiosource_child_added), NULL);
1058 if (GST_IS_AUDIO_BASE_SRC (source))
1059 g_object_set (source, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL);
1060 if ( d->audiobackend == JACK ) {
1061 g_object_set (G_OBJECT (source), "client-name", "gnunet", NULL);
1062 if (g_object_class_find_property
1063 (G_OBJECT_GET_CLASS (source), "port-pattern"))
1066 char *portpattern = "moc";
1068 g_object_set (G_OBJECT (source), "port-pattern", portpattern,
1074 caps = gst_caps_new_simple ("audio/x-raw",
1075 /* "format", G_TYPE_STRING, "S16LE", */
1076 /* "rate", G_TYPE_INT, SAMPLING_RATE,*/
1077 "channels", G_TYPE_INT, OPUS_CHANNELS,
1078 /* "layout", G_TYPE_STRING, "interleaved",*/
1081 g_object_set (G_OBJECT (filter),
1084 gst_caps_unref (caps);
1086 gst_bin_add_many (bin , source, filter, conv, resampler, NULL);
1087 gst_element_link_many ( source, filter, conv, resampler, NULL);
1089 pad = gst_element_get_static_pad (resampler, "src");
1093 ghostpad = gst_ghost_pad_new ("src", pad);
1097 /* set the bin pads */
1098 gst_pad_set_active (ghostpad, TRUE);
1099 gst_element_add_pad (GST_ELEMENT(bin), ghostpad);
1101 gst_object_unref (pad);