GNUnet  0.19.2
gnunet_gst.c File Reference

FIXME. More...

#include "platform.h"
#include "gnunet_gst_def.h"
Include dependency graph for gnunet_gst.c:

Go to the source code of this file.

Functions

void dump_buffer (unsigned n, const unsigned char *buf)
 
void gg_load_configuration (GNUNET_gstData *d)
 
static void write_data (const char *ptr, size_t msg_size)
 
GstFlowReturn on_appsink_new_sample (GstElement *element, GNUNET_gstData *d)
 
void pl_graph (GstElement *pipeline)
 
gboolean gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data)
 
void state_changed_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *d)
 
static void application_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
 
static void error_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
 
static void eos_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
 
void gg_setup_gst_bus (GNUNET_gstData *d)
 
int feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData *d)
 
GstElement * gst_element_factory_make_debug (gchar *factoryname, gchar *name)
 debug making elements More...
 
void lf (char *msg)
 
static void autoaudiosink_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
 
static void autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
 
GstElement * get_pipeline (GstElement *element)
 
static void decoder_ogg_pad_added (GstElement *element, GstPad *pad, gpointer data)
 
int gnunet_read (GNUNET_gstData *d)
 
static int stdin_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
 Message callback. More...
 
GstBin * get_app (GNUNET_gstData *d, int type)
 
GstBin * get_coder (GNUNET_gstData *d, int type)
 
GstBin * get_audiobin (GNUNET_gstData *d, int type)
 

Variables

static struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 

Detailed Description

FIXME.

Author
Hark

Definition in file gnunet_gst.c.

Function Documentation

◆ dump_buffer()

void dump_buffer ( unsigned  n,
const unsigned char *  buf 
)

Definition at line 35 of file gnunet_gst.c.

36 {
37  const unsigned char *p, *end;
38  unsigned i, j;
39 
40  end = buf + n;
41 
42  for (i = 0;; i += 16)
43  {
44  p = buf + i;
45  for (j = 0; j < 16; j++)
46  {
47  fprintf (stderr, "%02X ", p[j]);
48  if (p + j >= end)
49  goto BREAKOUT;
50  }
51  fprintf (stderr, " ");
52  p = buf + i;
53  for (j = 0; j < 16; j++)
54  {
55  fprintf (stderr, "%c", isprint (p[j]) ? p[j] :
56  '.');
57  if (p + j >= end)
58  goto BREAKOUT;
59  }
60  fprintf (stderr, "\n");
61  }
62 BREAKOUT:
63  return;
64 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static char buf[2048]
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38

References buf, end, and p.

Referenced by stdin_receiver().

Here is the caller graph for this function:

◆ gg_load_configuration()

void gg_load_configuration ( GNUNET_gstData d)

Definition at line 71 of file gnunet_gst.c.

72 {
73  char *audiobackend_string;
74 
76  GNUNET_CONFIGURATION_load (cfg, "mediahelper.conf");
77 
78  GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "JACK_PP_IN",
79  &d->jack_pp_in);
80  GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "JACK_PP_OUT",
81  &d->jack_pp_out);
82 
83  GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "AUDIOBACKEND",
84  &audiobackend_string);
85 
86  // printf("abstring: %s \n", audiobackend_string);
87 
88  if (0 == strcasecmp (audiobackend_string, "AUTO"))
89  {
90  d->audiobackend = AUTO;
91  }
92  else if (0 == strcasecmp (audiobackend_string, "JACK"))
93  {
94  d->audiobackend = JACK;
95  }
96  else if (0 == strcasecmp (audiobackend_string, "ALSA"))
97  {
98  d->audiobackend = ALSA;
99  }
100  else if (0 == strcasecmp (audiobackend_string, "FAKE"))
101  {
102  d->audiobackend = FAKE;
103  }
104  else if (0 == strcasecmp (audiobackend_string, "TEST"))
105  {
106  d->audiobackend = TEST;
107  }
108  else
109  {
110  d->audiobackend = AUTO;
111  }
112 
113  if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER",
114  "REMOVESILENCE") == GNUNET_YES)
115  {
116  d->dropsilence = TRUE;
117  }
118  else
119  {
120  d->dropsilence = FALSE;
121  }
122 
123  if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER",
124  "NO_GN_HEADERS") == GNUNET_YES)
125  {
126  d->pure_ogg = TRUE;
127  }
128  else
129  {
130  d->pure_ogg = FALSE;
131  }
132 
133 
134  if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER", "USERTP") ==
135  GNUNET_YES)
136  {
137  d->usertp = TRUE;
138  }
139  else
140  {
141  d->usertp = FALSE;
142  }
143 
144 // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf");
145 }
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet_gst.c:31
@ ALSA
@ JACK
@ TEST
@ FAKE
@ AUTO
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
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.
@ GNUNET_YES

References ALSA, GNUNET_gstData::audiobackend, AUTO, cfg, GNUNET_gstData::dropsilence, FAKE, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_load(), GNUNET_YES, JACK, GNUNET_gstData::jack_pp_in, GNUNET_gstData::jack_pp_out, GNUNET_gstData::pure_ogg, TEST, and GNUNET_gstData::usertp.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_data()

static void write_data ( const char *  ptr,
size_t  msg_size 
)
static

Definition at line 149 of file gnunet_gst.c.

150 {
151  ssize_t ret;
152  size_t off;
153 
154  off = 0;
155  while (off < msg_size)
156  {
157  ret = write (1, &ptr[off], msg_size - off);
158  if (0 >= ret)
159  {
160  if (-1 == ret)
162 // quit (2);
163  }
164  off += ret;
165  }
166 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#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_ERROR

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, and ret.

Referenced by on_appsink_new_sample().

Here is the caller graph for this function:

◆ on_appsink_new_sample()

GstFlowReturn on_appsink_new_sample ( GstElement *  element,
GNUNET_gstData d 
)

Definition at line 170 of file gnunet_gst.c.

171 {
172  // size of message including gnunet header
173  size_t msg_size;
174 
175  GstSample *s;
176  GstBuffer *b;
177  GstMapInfo map;
178 
179 /*
180  const GstStructure *si;
181  char *si_str;
182  GstCaps *s_caps;
183  char *caps_str;
184  */if (gst_app_sink_is_eos (GST_APP_SINK (element)))
185  return GST_FLOW_OK;
186 
187  // pull sample from appsink
188  s = gst_app_sink_pull_sample (GST_APP_SINK (element));
189 
190  if (s == NULL)
191  return GST_FLOW_OK;
192 
193  if (! GST_IS_SAMPLE (s))
194  return GST_FLOW_OK;
195 
196  b = gst_sample_get_buffer (s);
197 
198  GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps (s));
199 
200 
201  gst_buffer_map (b, &map, GST_MAP_READ);
202 
203  size_t len;
204  len = map.size;
205  if (len > UINT16_MAX - sizeof(struct AudioMessage))
206  {
207  // this should never happen?
208  printf ("GSTREAMER sample too big! \n");
209  exit (20);
210  len = UINT16_MAX - sizeof(struct AudioMessage);
211  }
212 
213  msg_size = sizeof(struct AudioMessage) + len;
214 
215  // copy the data into audio_message
216  GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len);
217  (d->audio_message)->header.size = htons ((uint16_t) msg_size);
218  if (d->pure_ogg)
219  // write the audio_message without the gnunet headers
220  write_data ((const char *) &(d->audio_message)[1], len);
221  else
222  write_data ((const char *) d->audio_message, msg_size);
223 
224  gst_sample_unref (s);
225  return GST_FLOW_OK;
226 }
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static void write_data(const char *ptr, size_t msg_size)
Definition: gnunet_gst.c:149
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Message to transmit the audio (between client and helpers).
Definition: conversation.h:59
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
Definition: conversation.h:63
unsigned int size
Number of entries in the map.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct AudioMessage * audio_message

References GNUNET_gstData::audio_message, GNUNET_memcpy, AudioMessage::header, len, map, GNUNET_gstData::pure_ogg, GNUNET_MessageHeader::size, GNUNET_CONTAINER_MultiPeerMap::size, and write_data().

Referenced by get_app().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pl_graph()

void pl_graph ( GstElement *  pipeline)

Definition at line 233 of file gnunet_gst.c.

234 {
235 #ifdef IS_SPEAKER
236  gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline),
237  GST_DEBUG_GRAPH_SHOW_ALL,
238  "playback_helper.dot");
239 #endif
240 #ifdef IS_MIC
241  gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline),
242  GST_DEBUG_GRAPH_SHOW_ALL,
243  "record_helper.dot");
244 #endif
245 
246 
247  // load_configuration();
248 }
static GstElement * pipeline
Main pipeline.

References pipeline.

Referenced by main(), and state_changed_cb().

Here is the caller graph for this function:

◆ gnunet_gst_bus_call()

gboolean gnunet_gst_bus_call ( GstBus *  bus,
GstMessage *  msg,
gpointer  data 
)

Definition at line 252 of file gnunet_gst.c.

253 {
255  "Bus message\n");
256  switch (GST_MESSAGE_TYPE (msg))
257  {
258  case GST_MESSAGE_EOS:
260  "End of stream\n");
261  exit (10);
262  break;
263 
264  case GST_MESSAGE_ERROR:
265  {
266  gchar *debug;
267  GError *error;
268 
269  gst_message_parse_error (msg, &error, &debug);
270  g_free (debug);
271 
273  "Error: %s\n",
274  error->message);
275  g_error_free (error);
276 
277  exit (10);
278  break;
279  }
280 
281  default:
282  break;
283  }
284 
285  return TRUE;
286 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO

References find_typedefs::debug, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, and msg.

◆ state_changed_cb()

void state_changed_cb ( GstBus *  bus,
GstMessage *  msg,
GNUNET_gstData d 
)

Definition at line 291 of file gnunet_gst.c.

292 {
293  GstState old_state, new_state, pending_state;
294 
295  gst_message_parse_state_changed (msg, &old_state, &new_state,
296  &pending_state);
297  switch (new_state)
298  {
299  case GST_STATE_READY:
300 // printf("ready.... \n");
301  // pl_graph(GST_ELEMENT(d->pipeline));
302  break;
303 
304  case GST_STATE_PLAYING:
305 
306  // GST_LOG ("caps are %" GST_PTR_FORMAT, caps);
307 
308  // printf("Playing.... \n");
309  pl_graph (GST_ELEMENT (d->pipeline));
310  break;
311 
312  case GST_STATE_VOID_PENDING:
313  // printf("void_pending.... \n");
314  // pl_graph(GST_ELEMENT(d->pipeline));
315  break;
316 
317  case GST_STATE_NULL:
318  // printf("null.... \n");
319  // pl_graph(GST_ELEMENT(d->pipeline));
320  break;
321 
322  case GST_STATE_PAUSED:
323  // printf("paused.... \n");
324  // pl_graph(GST_ELEMENT(d->pipeline));
325  break;
326  }
327 }
void pl_graph(GstElement *pipeline)
Definition: gnunet_gst.c:233
GstPipeline * pipeline

References msg, GNUNET_gstData::pipeline, and pl_graph().

Referenced by gg_setup_gst_bus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ application_cb()

static void application_cb ( GstBus *  bus,
GstMessage *  msg,
GNUNET_gstData data 
)
static

Definition at line 331 of file gnunet_gst.c.

332 {
333  // printf("application cb");
334  return;
335 }

Referenced by gg_setup_gst_bus().

Here is the caller graph for this function:

◆ error_cb()

static void error_cb ( GstBus *  bus,
GstMessage *  msg,
GNUNET_gstData data 
)
static

Definition at line 339 of file gnunet_gst.c.

340 {
341  // printf("error cb");
342  return;
343 }

Referenced by gg_setup_gst_bus().

Here is the caller graph for this function:

◆ eos_cb()

static void eos_cb ( GstBus *  bus,
GstMessage *  msg,
GNUNET_gstData data 
)
static

Definition at line 347 of file gnunet_gst.c.

348 {
349  // printf("eos cb");
350  return;
351 }

Referenced by gg_setup_gst_bus().

Here is the caller graph for this function:

◆ gg_setup_gst_bus()

void gg_setup_gst_bus ( GNUNET_gstData d)

Definition at line 355 of file gnunet_gst.c.

356 {
357  GstBus *bus;
358 
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,
362  d);
363  g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb,
364  d);
365  g_signal_connect (G_OBJECT (bus), "message::state-changed",
366  (GCallback) state_changed_cb, d);
367  g_signal_connect (G_OBJECT (bus), "message::application",
368  (GCallback) application_cb, d);
369  g_signal_connect (G_OBJECT (bus), "message::about-to-finish",
370  (GCallback) application_cb, d);
371  gst_object_unref (bus);
372 }
static void eos_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
Definition: gnunet_gst.c:347
void state_changed_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *d)
Definition: gnunet_gst.c:291
static void application_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
Definition: gnunet_gst.c:331
static void error_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
Definition: gnunet_gst.c:339

References application_cb(), eos_cb(), error_cb(), GNUNET_gstData::pipeline, and state_changed_cb().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ feed_buffer_to_gst()

int feed_buffer_to_gst ( const char *  audio,
size_t  b_len,
GNUNET_gstData d 
)

Definition at line 496 of file gnunet_gst.c.

497 {
498  GstBuffer *b;
499  gchar *bufspace;
500  GstFlowReturn flow;
501 
503  "Feeding %u bytes to GStreamer\n",
504  (unsigned int) b_len);
505 
506  bufspace = g_memdup (audio, b_len);
507  b = gst_buffer_new_wrapped (bufspace, b_len);
508  if (NULL == b)
509  {
511  "Failed to wrap a buffer\n");
512  g_free (bufspace);
513  return GNUNET_SYSERR;
514  }
515  if (GST_APP_SRC (d->appsrc) == NULL)
516  exit (10);
517  flow = gst_app_src_push_buffer (GST_APP_SRC (d->appsrc), b);
518  /* They all return GNUNET_OK, because currently player stops when
519  * data stops coming. This might need to be changed for the player
520  * to also stop when pipeline breaks.
521  */
522  switch (flow)
523  {
524  case GST_FLOW_OK:
526  "Fed %u bytes to the pipeline\n",
527  (unsigned int) b_len);
528  break;
529 
530  case GST_FLOW_FLUSHING:
531  /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */
533  "Dropped a buffer\n");
534  break;
535 
536  case GST_FLOW_EOS:
537  /* end of stream */
539  "EOS\n");
540  break;
541 
542  default:
544  "Unexpected push result\n");
545  break;
546  }
547  return GNUNET_OK;
548 }
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_WARNING
GstElement * appsrc

References GNUNET_gstData::appsrc, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, and GNUNET_SYSERR.

Referenced by gnunet_read(), and stdin_receiver().

Here is the caller graph for this function:

◆ gst_element_factory_make_debug()

GstElement* gst_element_factory_make_debug ( gchar *  factoryname,
gchar *  name 
)

debug making elements

Definition at line 555 of file gnunet_gst.c.

556 {
557  GstElement *element;
558 
559  element = gst_element_factory_make (factoryname, name);
560 
561  if (element == NULL)
562  {
563  printf ("\n Failed to create element - type: %s name: %s \n", factoryname,
564  name);
565  exit (10);
566  return element;
567  }
568  else
569  {
570  return element;
571  }
572 }
#define gst_element_factory_make(element, name)
Definition: gnunet_gst.h:36
const char * name

References gst_element_factory_make, and name.

◆ lf()

void lf ( char *  msg)

Definition at line 587 of file gnunet_gst.c.

588 {
589  printf ("linking elements failed: %s", msg);
590  exit (10);
591 }

References msg.

Referenced by get_audiobin(), and helper_mst().

Here is the caller graph for this function:

◆ autoaudiosink_child_added()

static void autoaudiosink_child_added ( GstChildProxy *  child_proxy,
GObject *  object,
gchar *  name,
gpointer  user_data 
)
static

Definition at line 598 of file gnunet_gst.c.

602 {
603  if (GST_IS_AUDIO_BASE_SRC (object))
604  g_object_set (object,
605  "buffer-time", (gint64) BUFFER_TIME,
606  "latency-time", (gint64) LATENCY_TIME,
607  NULL);
608 }
#define LATENCY_TIME
Min number of microseconds to buffer in audiosink.
#define BUFFER_TIME
Max number of microseconds to buffer in audiosink.

References BUFFER_TIME, and LATENCY_TIME.

Referenced by get_audiobin().

Here is the caller graph for this function:

◆ autoaudiosource_child_added()

static void autoaudiosource_child_added ( GstChildProxy *  child_proxy,
GObject *  object,
gchar *  name,
gpointer  user_data 
)
static

Definition at line 615 of file gnunet_gst.c.

617 {
618  if (GST_IS_AUDIO_BASE_SRC (object))
619  g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time",
620  (gint64) LATENCY_TIME, NULL);
621 }

References BUFFER_TIME, and LATENCY_TIME.

Referenced by get_audiobin().

Here is the caller graph for this function:

◆ get_pipeline()

GstElement* get_pipeline ( GstElement *  element)

Definition at line 625 of file gnunet_gst.c.

626 {
627  GstPipeline *p;
628 
629  p = GST_PIPELINE (gst_object_get_parent (GST_OBJECT (element)));
630 
631  return GST_ELEMENT (p);
632 }

References p.

◆ decoder_ogg_pad_added()

static void decoder_ogg_pad_added ( GstElement *  element,
GstPad *  pad,
gpointer  data 
)
static

Definition at line 636 of file gnunet_gst.c.

639 {
640  GstPad *sinkpad;
641  GstElement *decoder = (GstElement *) data;
642 
643  printf ("==== ogg pad added callback \n");
644  /* We can now link this pad with the opus-decoder sink pad */
645 // pl_graph(get_pipeline(element));
646  sinkpad = gst_element_get_static_pad (decoder, "sink");
647 
648  gst_pad_link (pad, sinkpad);
649  gst_element_link_many (element, decoder, NULL);
650  gst_object_unref (sinkpad);
651 }
static GstElement * decoder
uint32_t data
The data value.

References data, and decoder.

Referenced by get_coder().

Here is the caller graph for this function:

◆ gnunet_read()

int gnunet_read ( GNUNET_gstData d)

Definition at line 655 of file gnunet_gst.c.

656 {
657  char readbuf[MAXLINE];
658  int ret;
659 
660  printf ("read \n");
661  ret = read (0, readbuf, sizeof(readbuf));
662  if (0 > ret)
663  {
665  _ ("Read error from STDIN: %d %s\n"),
666  ret, strerror (errno));
667  return FAIL;
668  }
669  // toff += ret;
671  "Received %d bytes of audio data\n",
672  (int) ret);
673  if (0 == ret)
674  return FAIL;
675  // #ifdef DEBUG_READ_PURE_OGG
676 
677  if (d->pure_ogg)
678  {
679  feed_buffer_to_gst (readbuf, ret, d);
680  }
681  else
682  {
683  // #endif
685  readbuf,
686  ret,
687  GNUNET_NO,
688  GNUNET_NO);
689  }
690  return 0;
691 }
#define MAXLINE
How much data to read in one go.
int feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData *d)
Definition: gnunet_gst.c:496
@ FAIL
@ GNUNET_NO
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.
Definition: mst.c:101
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
struct GNUNET_MessageStreamTokenizer * stdin_mst

References _, FAIL, feed_buffer_to_gst(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MST_from_buffer(), GNUNET_NO, MAXLINE, GNUNET_gstData::pure_ogg, ret, and GNUNET_gstData::stdin_mst.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stdin_receiver()

static int stdin_receiver ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Message callback.

Parameters
msgmessage we received.
Returns
GNUNET_OK on success, GNUNET_NO to stop further processing due to disconnect (no error) GNUNET_SYSERR to stop further processing due to error

Definition at line 703 of file gnunet_gst.c.

705 {
706  struct AudioMessage *audio;
707  size_t b_len;
708 
709  printf ("stdin receiver \n ");
710  dump_buffer (sizeof(msg),
711  (const unsigned char *) msg);
712 
713  switch (ntohs (msg->type))
714  {
716  audio = (struct AudioMessage *) msg;
717 
718  b_len = ntohs (audio->header.size) - sizeof(struct AudioMessage);
719  printf ("feeding buffer to gst \n ");
720  feed_buffer_to_gst ((const char *) &audio[1], b_len, cls);
721  break;
722 
723  default:
724  printf ("No audio message: %u \n ", ntohs (msg->type));
725  break;
726  }
727  return GNUNET_OK;
728 }
void dump_buffer(unsigned n, const unsigned char *buf)
Definition: gnunet_gst.c:35
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.

References dump_buffer(), feed_buffer_to_gst(), GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO, GNUNET_OK, AudioMessage::header, msg, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by get_app().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_app()

GstBin* get_app ( GNUNET_gstData d,
int  type 
)

Definition at line 732 of file gnunet_gst.c.

733 {
734  GstBin *bin;
735  GstPad *pad, *ghostpad;
736 
737  if (type == SOURCE)
738  {
739  bin = GST_BIN (gst_bin_new ("Gnunet appsrc"));
740 
741 
743  GNUNET_log_setup ("gnunet-helper-audio-playback",
744  "WARNING",
745  NULL));
746 
748  "Audio playback starts\n");
749  printf (" creating appsrc \n ");
750  // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
751 
752 // d->audio_message = GNUNET_malloc (UINT16_MAX);
753 // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage));
754 // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage));
755 
756 
757  // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
758 
759 
761 
762  if (d->stdin_mst == NULL)
763  printf ("stdin_mst = NULL");
764 
765  d->appsrc = gst_element_factory_make ("appsrc", "appsrc");
766 
767  gst_bin_add_many (bin, d->appsrc, NULL);
768 // gst_element_link_many ( encoder, muxer, NULL);
769 
770  pad = gst_element_get_static_pad (d->appsrc, "src");
771  ghostpad = gst_ghost_pad_new ("src", pad);
772  }
773  if (type == SINK)
774  {
775  bin = GST_BIN (gst_bin_new ("Gnunet appsink"));
776 
777 
779  GNUNET_log_setup ("gnunet-helper-audio-record",
780  "WARNING",
781  NULL));
782 
784  "Audio source starts\n");
785 
786  d->appsink = gst_element_factory_make ("appsink", "appsink");
787 
788  // Move this out of here!
789  d->audio_message = GNUNET_malloc (UINT16_MAX);
790  (d->audio_message)->header.type = htons (
792  g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE,
793  NULL);
794 
795  g_signal_connect (d->appsink, "new-sample",
796  G_CALLBACK (on_appsink_new_sample), &d);
797 
798  gst_bin_add_many (bin, d->appsink, NULL);
799 // gst_element_link_many ( encoder, muxer, NULL);
800 
801  pad = gst_element_get_static_pad (d->appsink, "sink");
802  ghostpad = gst_ghost_pad_new ("sink", pad);
803  }
804 
805  /* set the bin pads */
806  gst_pad_set_active (ghostpad, TRUE);
807  gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
808 
809  gst_object_unref (pad);
810 
811  return bin;
812 }
static int stdin_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
Message callback.
Definition: gnunet_gst.c:703
GstFlowReturn on_appsink_new_sample(GstElement *element, GNUNET_gstData *d)
Definition: gnunet_gst.c:170
@ SOURCE
@ SINK
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:86
GstElement * appsink
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References GNUNET_gstData::appsink, GNUNET_gstData::appsrc, GNUNET_gstData::audio_message, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_log_setup(), GNUNET_malloc, GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO, GNUNET_MST_create(), GNUNET_OK, gst_element_factory_make, AudioMessage::header, on_appsink_new_sample(), SINK, SOURCE, GNUNET_gstData::stdin_mst, stdin_receiver(), GNUNET_MessageHeader::type, and type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_coder()

GstBin* get_coder ( GNUNET_gstData d,
int  type 
)

Definition at line 816 of file gnunet_gst.c.

817 {
818  GstBin *bin;
819  GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad;
820  GstCaps *rtpcaps;
821  GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer,
822  *rtpcapsfilter;
823 
824  if (d->usertp == TRUE)
825  {
826  /*
827  * 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 /*
829  rtpcaps = gst_caps_new_simple ("application/x-rtp",
830  "media", G_TYPE_STRING, "audio",
831  "clock-rate", G_TYPE_INT, SAMPLING_RATE,
832  "encoding-name", G_TYPE_STRING, "OPUS",
833  "payload", G_TYPE_INT, 96,
834  "sprop-stereo", G_TYPE_STRING, "0",
835  "encoding-params", G_TYPE_STRING, "2",
836  NULL);
837  */ rtpcaps = gst_caps_new_simple ("application/x-rtp",
838  "media", G_TYPE_STRING, "audio",
839  "clock-rate", G_TYPE_INT, SAMPLING_RATE,
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",
844  NULL);
845 
846 
847  rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter");
848 
849  g_object_set (G_OBJECT (rtpcapsfilter),
850  "caps", rtpcaps,
851  NULL);
852  gst_caps_unref (rtpcaps);
853  }
854 
855 
856  if (type == ENCODER)
857  {
858  bin = GST_BIN (gst_bin_new ("Gnunet audioencoder"));
859 
860  encoder = gst_element_factory_make ("opusenc", "opus-encoder");
861  if (d->usertp == TRUE)
862  {
863  muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader");
864  }
865  else
866  {
867  muxer = gst_element_factory_make ("oggmux", "ogg-muxer");
868  }
869  g_object_set (G_OBJECT (encoder),
870  /* "bitrate", 64000, */
871  /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */
872  "inband-fec", INBAND_FEC_MODE,
873  "packet-loss-percentage", PACKET_LOSS_PERCENTAGE,
874  "max-payload-size", MAX_PAYLOAD_SIZE,
875  "audio", TRUE, /* VoIP, not audio */
876  "frame-size", OPUS_FRAME_SIZE,
877  NULL);
878 
879  if (d->usertp != TRUE)
880  {
881  g_object_set (G_OBJECT (muxer),
882  "max-delay", OGG_MAX_DELAY,
883  "max-page-delay", OGG_MAX_PAGE_DELAY,
884  NULL);
885  }
886 
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);
891 
892  srcpad = gst_element_get_static_pad (muxer, "src");
893  srcghostpad = gst_ghost_pad_new ("src", srcpad);
894  }
895  if (type == DECODER)
896  {
897  bin = GST_BIN (gst_bin_new ("Gnunet audiodecoder"));
898 
899  // decoder
900  if (d->usertp == TRUE)
901  {
902  demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer");
903  jitterbuffer = gst_element_factory_make ("rtpjitterbuffer",
904  "rtpjitterbuffer");
905  }
906  else
907  {
908  demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer");
909  }
910  decoder = gst_element_factory_make ("opusdec", "opus-decoder");
911 
912  if (d->usertp == TRUE)
913  {
914  gst_bin_add_many (bin, rtpcapsfilter, jitterbuffer, demuxer, decoder,
915  NULL);
916  gst_element_link_many (rtpcapsfilter, jitterbuffer, demuxer, decoder,
917  NULL);
918  sinkpad = gst_element_get_static_pad (rtpcapsfilter, "sink");
919  }
920  else
921  {
922  gst_bin_add_many (bin, demuxer, decoder, NULL);
923 
924  g_signal_connect (demuxer,
925  "pad-added",
926  G_CALLBACK (decoder_ogg_pad_added),
927  decoder);
928 
929  sinkpad = gst_element_get_static_pad (demuxer, "sink");
930  }
931  sinkghostpad = gst_ghost_pad_new ("sink", sinkpad);
932 
933  srcpad = gst_element_get_static_pad (decoder, "src");
934  srcghostpad = gst_ghost_pad_new ("src", srcpad);
935  }
936 
937  // add pads to the bin
938  gst_pad_set_active (sinkghostpad, TRUE);
939  gst_element_add_pad (GST_ELEMENT (bin), sinkghostpad);
940 
941  gst_pad_set_active (srcghostpad, TRUE);
942  gst_element_add_pad (GST_ELEMENT (bin), srcghostpad);
943 
944 
945  return bin;
946 }
static GstElement * demuxer
#define SAMPLING_RATE
#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 PACKET_LOSS_PERCENTAGE
Expected packet loss to prepare for, in percents.
static void decoder_ogg_pad_added(GstElement *element, GstPad *pad, gpointer data)
Definition: gnunet_gst.c:636
@ ENCODER
@ DECODER

References decoder, DECODER, decoder_ogg_pad_added(), demuxer, ENCODER, gst_element_factory_make, INBAND_FEC_MODE, MAX_PAYLOAD_SIZE, OGG_MAX_DELAY, OGG_MAX_PAGE_DELAY, OPUS_FRAME_SIZE, PACKET_LOSS_PERCENTAGE, SAMPLING_RATE, type, and GNUNET_gstData::usertp.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_audiobin()

GstBin* get_audiobin ( GNUNET_gstData d,
int  type 
)

Definition at line 950 of file gnunet_gst.c.

951 {
952  GstBin *bin;
953  GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter;
954  GstPad *pad, *ghostpad;
955  GstCaps *caps;
956 
957  if (type == SINK)
958  {
959  bin = GST_BIN (gst_bin_new ("Gnunet audiosink"));
960 
961  /* Create all the elements */
962  if (d->dropsilence == TRUE)
963  {
964  queue = gst_element_factory_make ("queue", "queue");
965  removesilence = gst_element_factory_make ("removesilence",
966  "removesilence");
967  }
968 
969  conv = gst_element_factory_make ("audioconvert", "converter");
970  resampler = gst_element_factory_make ("audioresample", "resampler");
971 
972  if (d->audiobackend == AUTO)
973  {
974  sink = gst_element_factory_make ("autoaudiosink", "audiosink");
975  g_signal_connect (sink, "child-added", G_CALLBACK (
977  }
978 
979  if (d->audiobackend == ALSA)
980  {
981  sink = gst_element_factory_make ("alsaaudiosink", "audiosink");
982  }
983 
984  if (d->audiobackend == JACK)
985  {
986  sink = gst_element_factory_make ("jackaudiosink", "audiosink");
987 
988  g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL);
989 
990  if (g_object_class_find_property
991  (G_OBJECT_GET_CLASS (sink), "port-pattern"))
992  {
993 // char *portpattern = "system";
994 
995  g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out,
996  NULL);
997  }
998  }
999 
1000  if (d->audiobackend == FAKE)
1001  {
1002  sink = gst_element_factory_make ("fakesink", "audiosink");
1003  }
1004 
1005  g_object_set (sink,
1006  "buffer-time", (gint64) BUFFER_TIME,
1007  "latency-time", (gint64) LATENCY_TIME,
1008  NULL);
1009 
1010  if (d->dropsilence == TRUE)
1011  {
1012  // Do not remove silence by default
1013  g_object_set (removesilence, "remove", FALSE, NULL);
1014  g_object_set (queue, "max-size-buffers", 12, NULL);
1015  /*
1016  g_signal_connect (source,
1017  "need-data",
1018  G_CALLBACK(appsrc_need_data),
1019  NULL);
1020 
1021  g_signal_connect (source,
1022  "enough-data",
1023  G_CALLBACK(appsrc_enough_data),
1024  NULL);
1025  *//*
1026  g_signal_connect (queue,
1027  "notify::current-level-bytes",
1028  G_CALLBACK(queue_current_level),
1029  NULL);
1030 
1031  g_signal_connect (queue,
1032  "underrun",
1033  G_CALLBACK(queue_underrun),
1034  NULL);
1035 
1036  g_signal_connect (queue,
1037  "running",
1038  G_CALLBACK(queue_running),
1039  NULL);
1040 
1041  g_signal_connect (queue,
1042  "overrun",
1043  G_CALLBACK(queue_overrun),
1044  NULL);
1045 
1046  g_signal_connect (queue,
1047  "pushing",
1048  G_CALLBACK(queue_pushing),
1049  NULL);
1050  */ }
1051 
1052 
1053  gst_bin_add_many (bin, conv, resampler, sink, NULL);
1054  gst_element_link_many (conv, resampler, sink, NULL);
1055 
1056  if (d->dropsilence == TRUE)
1057  {
1058  gst_bin_add_many (bin, queue, removesilence, NULL);
1059 
1060  if (! gst_element_link_many (queue, removesilence, conv, NULL))
1061  lf ("queue, removesilence, conv ");
1062 
1063  pad = gst_element_get_static_pad (queue, "sink");
1064  }
1065  else
1066  {
1067  pad = gst_element_get_static_pad (conv, "sink");
1068  }
1069 
1070  ghostpad = gst_ghost_pad_new ("sink", pad);
1071  }
1072  else
1073  {
1074  // SOURCE
1075 
1076  bin = GST_BIN (gst_bin_new ("Gnunet audiosource"));
1077 
1078  // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla");
1079 
1080  if (d->audiobackend == AUTO)
1081  {
1082  source = gst_element_factory_make ("autoaudiosrc", "audiosource");
1083  }
1084  if (d->audiobackend == ALSA)
1085  {
1086  source = gst_element_factory_make ("alsasrc", "audiosource");
1087  }
1088  if (d->audiobackend == JACK)
1089  {
1090  source = gst_element_factory_make ("jackaudiosrc", "audiosource");
1091  }
1092  if (d->audiobackend == TEST)
1093  {
1094  source = gst_element_factory_make ("audiotestsrc", "audiosource");
1095  }
1096 
1097  filter = gst_element_factory_make ("capsfilter", "filter");
1098  conv = gst_element_factory_make ("audioconvert", "converter");
1099  resampler = gst_element_factory_make ("audioresample", "resampler");
1100 
1101  if (d->audiobackend == AUTO)
1102  {
1103  g_signal_connect (source, "child-added", G_CALLBACK (
1105  }
1106  else
1107  {
1108  if (GST_IS_AUDIO_BASE_SRC (source))
1109  g_object_set (source, "buffer-time", (gint64) BUFFER_TIME,
1110  "latency-time", (gint64) LATENCY_TIME, NULL);
1111  if (d->audiobackend == JACK)
1112  {
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"))
1116  {
1117  char *portpattern = "moc";
1118 
1119  g_object_set (G_OBJECT (source), "port-pattern", portpattern,
1120  NULL);
1121  }
1122  }
1123  }
1124 
1125  caps = gst_caps_new_simple ("audio/x-raw",
1126  /* "format", G_TYPE_STRING, "S16LE", */
1127  /* "rate", G_TYPE_INT, SAMPLING_RATE,*/
1128  "channels", G_TYPE_INT, OPUS_CHANNELS,
1129  /* "layout", G_TYPE_STRING, "interleaved",*/
1130  NULL);
1131 
1132  g_object_set (G_OBJECT (filter),
1133  "caps", caps,
1134  NULL);
1135  gst_caps_unref (caps);
1136 
1137  gst_bin_add_many (bin, source, filter, conv, resampler, NULL);
1138  gst_element_link_many (source, filter, conv, resampler, NULL);
1139 
1140  pad = gst_element_get_static_pad (resampler, "src");
1141 
1142 
1143  /* pads */
1144  ghostpad = gst_ghost_pad_new ("src", pad);
1145  }
1146 
1147  /* set the bin pads */
1148  gst_pad_set_active (ghostpad, TRUE);
1149  gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
1150 
1151  gst_object_unref (pad);
1152 
1153  return bin;
1154 }
static GstElement * source
Appsrc instance into which we write data for the pipeline.
static GstElement * resampler
static GstElement * sink
static GstElement * conv
#define OPUS_CHANNELS
Number of channels.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
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)
Definition: gnunet_gst.c:615
void lf(char *msg)
Definition: gnunet_gst.c:587
static void autoaudiosink_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
Definition: gnunet_gst.c:598

References ALSA, GNUNET_gstData::audiobackend, AUTO, autoaudiosink_child_added(), autoaudiosource_child_added(), BUFFER_TIME, conv, GNUNET_gstData::dropsilence, FAKE, filter, gst_element_factory_make, JACK, GNUNET_gstData::jack_pp_out, LATENCY_TIME, lf(), OPUS_CHANNELS, queue(), resampler, sink, SINK, source, TEST, and type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cfg

struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 31 of file gnunet_gst.c.

Referenced by gg_load_configuration().