37 const unsigned char *
p, *
end;
45 for (j = 0; j < 16; j++)
47 fprintf (stderr,
"%02X ",
p[j]);
51 fprintf (stderr,
" ");
53 for (j = 0; j < 16; j++)
55 fprintf (stderr,
"%c", isprint (
p[j]) ?
p[j] :
60 fprintf (stderr,
"\n");
73 char *audiobackend_string;
84 &audiobackend_string);
88 if (0 == strcasecmp (audiobackend_string,
"AUTO"))
90 d->audiobackend =
AUTO;
92 else if (0 == strcasecmp (audiobackend_string,
"JACK"))
94 d->audiobackend =
JACK;
96 else if (0 == strcasecmp (audiobackend_string,
"ALSA"))
98 d->audiobackend =
ALSA;
100 else if (0 == strcasecmp (audiobackend_string,
"FAKE"))
102 d->audiobackend =
FAKE;
104 else if (0 == strcasecmp (audiobackend_string,
"TEST"))
106 d->audiobackend =
TEST;
110 d->audiobackend =
AUTO;
116 d->dropsilence = TRUE;
120 d->dropsilence = FALSE;
155 while (off < msg_size)
157 ret = write (1, &ptr[off], msg_size - off);
184if (gst_app_sink_is_eos (GST_APP_SINK (element)))
188 s = gst_app_sink_pull_sample (GST_APP_SINK (element));
193 if (! GST_IS_SAMPLE (s))
196 b = gst_sample_get_buffer (s);
198 GST_WARNING (
"caps are %" GST_PTR_FORMAT, gst_sample_get_caps (s));
201 gst_buffer_map (b, &
map, GST_MAP_READ);
208 printf (
"GSTREAMER sample too big! \n");
217 (
d->audio_message)->
header.
size = htons ((uint16_t) msg_size);
220 write_data ((
const char *) &(
d->audio_message)[1], len);
222 write_data ((
const char *)
d->audio_message, msg_size);
224 gst_sample_unref (s);
236 gst_debug_bin_to_dot_file_with_ts (GST_BIN (
pipeline),
237 GST_DEBUG_GRAPH_SHOW_ALL,
238 "playback_helper.dot");
241 gst_debug_bin_to_dot_file_with_ts (GST_BIN (
pipeline),
242 GST_DEBUG_GRAPH_SHOW_ALL,
243 "record_helper.dot");
256 switch (GST_MESSAGE_TYPE (
msg))
258 case GST_MESSAGE_EOS:
264 case GST_MESSAGE_ERROR:
269 gst_message_parse_error (
msg, &error, &
debug);
275 g_error_free (error);
293 GstState old_state, new_state, pending_state;
295 gst_message_parse_state_changed (
msg, &old_state, &new_state,
299 case GST_STATE_READY:
304 case GST_STATE_PLAYING:
312 case GST_STATE_VOID_PENDING:
322 case GST_STATE_PAUSED:
359 bus = gst_element_get_bus (GST_ELEMENT (
d->pipeline));
360 gst_bus_add_signal_watch (bus);
361 g_signal_connect (G_OBJECT (bus),
"message::error", (GCallback)
error_cb,
363 g_signal_connect (G_OBJECT (bus),
"message::eos", (GCallback)
eos_cb,
365 g_signal_connect (G_OBJECT (bus),
"message::state-changed",
367 g_signal_connect (G_OBJECT (bus),
"message::application",
369 g_signal_connect (G_OBJECT (bus),
"message::about-to-finish",
371 gst_object_unref (bus);
503 "Feeding %u bytes to GStreamer\n",
504 (
unsigned int) b_len);
506 bufspace = g_memdup (audio, b_len);
507 b = gst_buffer_new_wrapped (bufspace, b_len);
511 "Failed to wrap a buffer\n");
515 if (GST_APP_SRC (
d->appsrc) == NULL)
517 flow = gst_app_src_push_buffer (GST_APP_SRC (
d->appsrc), b);
526 "Fed %u bytes to the pipeline\n",
527 (
unsigned int) b_len);
530 case GST_FLOW_FLUSHING:
533 "Dropped a buffer\n");
544 "Unexpected push result\n");
563 printf (
"\n Failed to create element - type: %s name: %s \n", factoryname,
589 printf (
"linking elements failed: %s",
msg);
603 if (GST_IS_AUDIO_BASE_SRC (
object))
604 g_object_set (
object,
616 gchar *
name, gpointer user_data)
618 if (GST_IS_AUDIO_BASE_SRC (
object))
619 g_object_set (
object,
"buffer-time", (gint64)
BUFFER_TIME,
"latency-time",
629 p = GST_PIPELINE (gst_object_get_parent (GST_OBJECT (element)));
631 return GST_ELEMENT (
p);
643 printf (
"==== ogg pad added callback \n");
646 sinkpad = gst_element_get_static_pad (
decoder,
"sink");
648 gst_pad_link (pad, sinkpad);
649 gst_element_link_many (element,
decoder, NULL);
650 gst_object_unref (sinkpad);
661 ret = read (0, readbuf,
sizeof(readbuf));
665 _ (
"Read error from STDIN: %d %s\n"),
666 ret, strerror (errno));
671 "Received %d bytes of audio data\n",
709 printf (
"stdin receiver \n ");
711 (
const unsigned char *)
msg);
719 printf (
"feeding buffer to gst \n ");
724 printf (
"No audio message: %u \n ", ntohs (
msg->
type));
735 GstPad *pad, *ghostpad;
739 bin = GST_BIN (gst_bin_new (
"Gnunet appsrc"));
748 "Audio playback starts\n");
749 printf (
" creating appsrc \n ");
762 if (
d->stdin_mst == NULL)
763 printf (
"stdin_mst = NULL");
767 gst_bin_add_many (bin,
d->appsrc, NULL);
770 pad = gst_element_get_static_pad (
d->appsrc,
"src");
771 ghostpad = gst_ghost_pad_new (
"src", pad);
775 bin = GST_BIN (gst_bin_new (
"Gnunet appsink"));
784 "Audio source starts\n");
792 g_object_set (G_OBJECT (
d->appsink),
"emit-signals", TRUE,
"sync", TRUE,
795 g_signal_connect (
d->appsink,
"new-sample",
798 gst_bin_add_many (bin,
d->appsink, NULL);
801 pad = gst_element_get_static_pad (
d->appsink,
"sink");
802 ghostpad = gst_ghost_pad_new (
"sink", pad);
806 gst_pad_set_active (ghostpad, TRUE);
807 gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
809 gst_object_unref (pad);
819 GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad;
824 if (
d->usertp == TRUE)
837 rtpcaps = gst_caps_new_simple (
"application/x-rtp",
838 "media", G_TYPE_STRING,
"audio",
840 "encoding-name", G_TYPE_STRING,
"OPUS",
841 "payload", G_TYPE_INT, 96,
842 "sprop-stereo", G_TYPE_STRING,
"0",
843 "encoding-params", G_TYPE_STRING,
"2",
849 g_object_set (G_OBJECT (rtpcapsfilter),
852 gst_caps_unref (rtpcaps);
858 bin = GST_BIN (gst_bin_new (
"Gnunet audioencoder"));
861 if (
d->usertp == TRUE)
869 g_object_set (G_OBJECT (encoder),
879 if (
d->usertp != TRUE)
881 g_object_set (G_OBJECT (muxer),
887 gst_bin_add_many (bin, encoder, muxer, NULL);
888 gst_element_link_many (encoder, muxer, NULL);
889 sinkpad = gst_element_get_static_pad (encoder,
"sink");
890 sinkghostpad = gst_ghost_pad_new (
"sink", sinkpad);
892 srcpad = gst_element_get_static_pad (muxer,
"src");
893 srcghostpad = gst_ghost_pad_new (
"src", srcpad);
897 bin = GST_BIN (gst_bin_new (
"Gnunet audiodecoder"));
900 if (
d->usertp == TRUE)
912 if (
d->usertp == TRUE)
914 gst_bin_add_many (bin, rtpcapsfilter, jitterbuffer,
demuxer,
decoder,
916 gst_element_link_many (rtpcapsfilter, jitterbuffer,
demuxer,
decoder,
918 sinkpad = gst_element_get_static_pad (rtpcapsfilter,
"sink");
929 sinkpad = gst_element_get_static_pad (
demuxer,
"sink");
931 sinkghostpad = gst_ghost_pad_new (
"sink", sinkpad);
933 srcpad = gst_element_get_static_pad (
decoder,
"src");
934 srcghostpad = gst_ghost_pad_new (
"src", srcpad);
938 gst_pad_set_active (sinkghostpad, TRUE);
939 gst_element_add_pad (GST_ELEMENT (bin), sinkghostpad);
941 gst_pad_set_active (srcghostpad, TRUE);
942 gst_element_add_pad (GST_ELEMENT (bin), srcghostpad);
954 GstPad *pad, *ghostpad;
959 bin = GST_BIN (gst_bin_new (
"Gnunet audiosink"));
962 if (
d->dropsilence == TRUE)
972 if (
d->audiobackend ==
AUTO)
975 g_signal_connect (
sink,
"child-added", G_CALLBACK (
979 if (
d->audiobackend ==
ALSA)
984 if (
d->audiobackend ==
JACK)
988 g_object_set (G_OBJECT (
sink),
"client-name",
"gnunet", NULL);
990 if (g_object_class_find_property
991 (G_OBJECT_GET_CLASS (
sink),
"port-pattern"))
995 g_object_set (G_OBJECT (
sink),
"port-pattern",
d->jack_pp_out,
1000 if (
d->audiobackend ==
FAKE)
1010 if (
d->dropsilence == TRUE)
1013 g_object_set (removesilence,
"remove", FALSE, NULL);
1014 g_object_set (
queue,
"max-size-buffers", 12, NULL);
1056 if (
d->dropsilence == TRUE)
1058 gst_bin_add_many (bin,
queue, removesilence, NULL);
1060 if (! gst_element_link_many (
queue, removesilence,
conv, NULL))
1061 lf (
"queue, removesilence, conv ");
1063 pad = gst_element_get_static_pad (
queue,
"sink");
1067 pad = gst_element_get_static_pad (
conv,
"sink");
1070 ghostpad = gst_ghost_pad_new (
"sink", pad);
1076 bin = GST_BIN (gst_bin_new (
"Gnunet audiosource"));
1080 if (
d->audiobackend ==
AUTO)
1084 if (
d->audiobackend ==
ALSA)
1088 if (
d->audiobackend ==
JACK)
1092 if (
d->audiobackend ==
TEST)
1101 if (
d->audiobackend ==
AUTO)
1103 g_signal_connect (
source,
"child-added", G_CALLBACK (
1108 if (GST_IS_AUDIO_BASE_SRC (
source))
1111 if (
d->audiobackend ==
JACK)
1113 g_object_set (G_OBJECT (
source),
"client-name",
"gnunet", NULL);
1114 if (g_object_class_find_property
1115 (G_OBJECT_GET_CLASS (
source),
"port-pattern"))
1117 char *portpattern =
"moc";
1119 g_object_set (G_OBJECT (
source),
"port-pattern", portpattern,
1125 caps = gst_caps_new_simple (
"audio/x-raw",
1132 g_object_set (G_OBJECT (
filter),
1135 gst_caps_unref (caps);
1140 pad = gst_element_get_static_pad (
resampler,
"src");
1144 ghostpad = gst_ghost_pad_new (
"src", pad);
1148 gst_pad_set_active (ghostpad, TRUE);
1149 gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
1151 gst_object_unref (pad);
struct GNUNET_MessageHeader * msg
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static int ret
Final status code.
static int end
Set if we are to shutdown all services (including ARM).
static char * data
The data to insert into the dht.
static GstElement * source
Appsrc instance into which we write data for the pipeline.
#define LATENCY_TIME
Min number of microseconds to buffer in audiosink.
static GstElement * pipeline
Main pipeline.
#define MAXLINE
How much data to read in one go.
static GstElement * decoder
static GstElement * resampler
static GstElement * demuxer
#define BUFFER_TIME
Max number of microseconds to buffer in audiosink.
#define MAX_PAYLOAD_SIZE
Maximal size of a single opus packet.
#define OGG_MAX_DELAY
Maximum delay in multiplexing streams, in ns.
#define INBAND_FEC_MODE
Set to 1 to enable forward error correction.
#define OPUS_FRAME_SIZE
Size of a single frame fed to the encoder, in ms.
#define OGG_MAX_PAGE_DELAY
Maximum delay for sending out a page, in ns.
#define OPUS_CHANNELS
Number of channels.
#define PACKET_LOSS_PERCENTAGE
Expected packet loss to prepare for, in percents.
static char * name
Name (label) of the records to list.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
static struct GNUNET_OS_Process * p
Helper process we started.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void autoaudiosource_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
static void eos_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
void gg_load_configuration(GNUNET_gstData *d)
GstBin * get_app(GNUNET_gstData *d, int type)
void state_changed_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *d)
static void application_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
void pl_graph(GstElement *pipeline)
void gg_setup_gst_bus(GNUNET_gstData *d)
int gnunet_read(GNUNET_gstData *d)
static int stdin_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
Message callback.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
GstBin * get_coder(GNUNET_gstData *d, int type)
GstElement * gst_element_factory_make_debug(gchar *factoryname, gchar *name)
debug making elements
void dump_buffer(unsigned n, const unsigned char *buf)
gboolean gnunet_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data)
GstFlowReturn on_appsink_new_sample(GstElement *element, GNUNET_gstData *d)
GstBin * get_audiobin(GNUNET_gstData *d, int type)
static void write_data(const char *ptr, size_t msg_size)
int feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData *d)
GstElement * get_pipeline(GstElement *element)
static void decoder_ogg_pad_added(GstElement *element, GstPad *pad, gpointer data)
static void error_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
static void autoaudiosink_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
#define gst_element_factory_make(element, name)
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
enum GNUNET_GenericReturnValue GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Message to transmit the audio (between client and helpers).
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
unsigned int size
Number of entries in the map.