+/*
+ This file is part of GNUnet.
+ Copyright (C) 2016 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file conversation/gnunet_gst.c
+ * @brief FIXME
+ * @author Hark
+ */
#include "gnunet_gst_def.h"
/**
*/
static struct GNUNET_CONFIGURATION_Handle *cfg;
- void
+void
dump_buffer(unsigned n, const unsigned char* buf)
{
const unsigned char *p, *end;
} else if ( audiobackend_string = "TEST" )
{
d->audiobackend = TEST;
- } else
+ } else
{
d->audiobackend = AUTO;
}
{
ret = write (1, &ptr[off], msg_size - off);
if (0 >= ret)
- {
+ {
if (-1 == ret)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write");
// quit (2);
on_appsink_new_sample (GstElement * element, GNUNET_gstData * d)
{
static unsigned long long toff;
-
+
//size of message including gnunet header
size_t msg_size;
-
+
GstSample *s;
GstBuffer *b;
GstMapInfo map;
//pull sample from appsink
s = gst_app_sink_pull_sample (GST_APP_SINK(element));
-
+
if (s == NULL)
return GST_FLOW_OK;
- gst_buffer_map (b, &map, GST_MAP_READ);
+ gst_buffer_map (b, &map, GST_MAP_READ);
size_t len;
len = map.size;
if (len > UINT16_MAX - sizeof (struct AudioMessage))
- {
+ {
// this should never happen?
printf("GSTREAMER sample too big! \n");
exit(20);
len = UINT16_MAX - sizeof (struct AudioMessage);
}
-
+
msg_size = sizeof (struct AudioMessage) + len;
-
+
// copy the data into audio_message
memcpy (((char *) &(d->audio_message)[1]), map.data, len);
/*
gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot");
#endif
-
+
// load_configuration();
}
extern gboolean
gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Bus message\n");
switch (GST_MESSAGE_TYPE (msg))
{
{
gchar *debug;
GError *error;
-
+
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error: %s\n",
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error: %s\n",
error->message);
g_error_free (error);
-
+
exit (10);
break;
}
state_changed_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * d)
{
GstState old_state, new_state, pending_state;
-
+
gst_message_parse_state_changed (msg, &old_state, &new_state,
&pending_state);
switch (new_state)
return OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n");
-
+
const GstStructure *si;
char *si_str;
GstCaps *s_caps;
}
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n");
-
+
b = gst_sample_get_buffer (s);
if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ))
{
msg_size = sizeof (struct AudioMessage) + len;
audio_message.header.size = htons ((uint16_t) msg_size);
-
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending %u bytes of audio data\n", (unsigned int) msg_size);
for (phase = 0; phase < 2; phase++)
return FAIL;
}
}
-
+
// if (abort_send)
// break;
-
+
}
gst_buffer_unmap (b, &m);
gst_sample_unref (s);
switch (flow)
{
case GST_FLOW_OK:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Fed %u bytes to the pipeline\n",
(unsigned int) b_len);
break;
break;
case GST_FLOW_EOS:
/* end of stream */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"EOS\n");
break;
default:
/*
static gboolean
-gst_element_link_many_debug(...)
+gst_element_link_many_debug(...)
{
va_list arguments;
gst_element_link_many(argptr);
*/
static void
autoaudiosink_child_added (GstChildProxy *child_proxy,
- GObject *object,
+ GObject *object,
gchar *name,
gpointer user_data)
{
if (GST_IS_AUDIO_BASE_SRC (object))
g_object_set (object,
- "buffer-time", (gint64) BUFFER_TIME,
+ "buffer-time", (gint64) BUFFER_TIME,
"latency-time", (gint64) LATENCY_TIME,
NULL);
}
get_pipeline(GstElement *element)
{
GstPipeline *p;
-
+
p = gst_object_get_parent(element);
return p;
}
static void
-decoder_ogg_pad_added (GstElement *element,
+decoder_ogg_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
}
int
-gnunet_read (GNUNET_gstData * d)
+gnunet_read (GNUNET_gstData * d)
{
char readbuf[MAXLINE];
int ret;
if (0 == ret)
return FAIL;
//#ifdef DEBUG_READ_PURE_OGG
-
+
if (d->pure_ogg)
{
feed_buffer_to_gst (readbuf, ret, d);
}
else
- {
+ {
//#endif
GNUNET_SERVER_mst_receive (d->stdin_mst, NULL,
readbuf, ret,
feed_buffer_to_gst ((const char *) &audio[1], b_len, cls);
break;
default:
- printf("No audio message: %u \n ", ntohs(msg->type));
+ printf("No audio message: %u \n ", ntohs(msg->type));
break;
}
return GNUNET_OK;
"Audio playback starts\n");
printf(" creating appsrc \n ");
//d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
-
+
// d->audio_message = GNUNET_malloc (UINT16_MAX);
// d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage));
// d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage));
//d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
-
+
d->stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, d);
-
+
if ( d->stdin_mst == NULL)
- printf("stdin_mst = NULL");
+ printf("stdin_mst = NULL");
d->appsrc = gst_element_factory_make ("appsrc", "appsrc");
"Audio source starts\n");
d->appsink = gst_element_factory_make ("appsink", "appsink");
-
+
// Move this out of here!
d->audio_message = GNUNET_malloc (UINT16_MAX);
(d->audio_message)->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
- g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL);
+ g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL);
g_signal_connect (d->appsink, "new-sample",
G_CALLBACK (on_appsink_new_sample), &d);
"payload", G_TYPE_INT, 96,
"sprop-stereo", G_TYPE_STRING, "0",
"encoding-params", G_TYPE_STRING, "2",
- NULL);
+ NULL);
*/
rtpcaps = gst_caps_new_simple ("application/x-rtp",
"media", G_TYPE_STRING, "audio",
"payload", G_TYPE_INT, 96,
"sprop-stereo", G_TYPE_STRING, "0",
"encoding-params", G_TYPE_STRING, "2",
- NULL);
+ NULL);
rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter");
if ( type == ENCODER )
- {
+ {
bin = GST_BIN(gst_bin_new("Gnunet audioencoder"));
encoder = gst_element_factory_make ("opusenc", "opus-encoder");
srcghostpad = gst_ghost_pad_new ("src", srcpad);
}
- if ( type == DECODER )
+ if ( type == DECODER )
{
bin = GST_BIN(gst_bin_new("Gnunet audiodecoder"));
demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer");
jitterbuffer = gst_element_factory_make ("rtpjitterbuffer", "rtpjitterbuffer");
- } else {
+ } else {
demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer");
}
decoder = gst_element_factory_make ("opusdec", "opus-decoder");
} else {
gst_bin_add_many( bin, demuxer, decoder, NULL);
- g_signal_connect (demuxer,
+ g_signal_connect (demuxer,
"pad-added",
- G_CALLBACK (decoder_ogg_pad_added),
+ G_CALLBACK (decoder_ogg_pad_added),
decoder);
sinkpad = gst_element_get_static_pad(demuxer, "sink");
gst_element_add_pad (GST_ELEMENT(bin), srcghostpad);
- return bin;
+ return bin;
}
extern GstBin *
get_audiobin(GNUNET_gstData *d , int type)
{
sink = gst_element_factory_make ("autoaudiosink", "audiosink");
g_signal_connect (sink, "child-added", G_CALLBACK (autoaudiosink_child_added), NULL);
-
+
}
if ( d->audiobackend == ALSA )
if ( d->audiobackend == JACK )
{
sink = gst_element_factory_make ("jackaudiosink", "audiosink");
-
+
g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL);
if (g_object_class_find_property
}
g_object_set (sink,
- "buffer-time", (gint64) BUFFER_TIME,
+ "buffer-time", (gint64) BUFFER_TIME,
"latency-time", (gint64) LATENCY_TIME,
NULL);
if ( d->dropsilence == TRUE )
{
- gst_bin_add_many (bin , queue ,removesilence , NULL);
+ gst_bin_add_many (bin , queue ,removesilence , NULL);
if ( !gst_element_link_many ( queue, removesilence, conv, NULL) )
lf ("queue, removesilence, conv ");
pad = gst_element_get_static_pad(conv, "sink");
}
-
+
ghostpad = gst_ghost_pad_new ("sink", pad);
- } else {
+ } else {
// SOURCE
bin = GST_BIN(gst_bin_new("Gnunet audiosource"));
if (d->audiobackend == AUTO ) {
g_signal_connect (source, "child-added", G_CALLBACK (autoaudiosource_child_added), NULL);
-
+
} else {
if (GST_IS_AUDIO_BASE_SRC (source))
g_object_set (source, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL);
{
char *portpattern = "moc";
-
+
g_object_set (G_OBJECT (source), "port-pattern", portpattern,
NULL);
}