GNUnet  0.11.x
Functions | Variables
gnunet_gst.c File Reference

FIXME. More...

#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 34 of file gnunet_gst.c.

References end, and p.

Referenced by stdin_receiver().

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

◆ gg_load_configuration()

void gg_load_configuration ( GNUNET_gstData d)

Definition at line 70 of file gnunet_gst.c.

References ALSA, GNUNET_gstData::audiobackend, AUTO, 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().

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

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, and ret.

Referenced by on_appsink_new_sample().

149 {
150  ssize_t ret;
151  size_t off;
152 
153  off = 0;
154  while (off < msg_size)
155  {
156  ret = write (1, &ptr[off], msg_size - off);
157  if (0 >= ret)
158  {
159  if (-1 == ret)
161 // quit (2);
162  }
163  off += ret;
164  }
165 }
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 &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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 169 of file gnunet_gst.c.

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

Referenced by get_app().

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

Referenced by main(), and state_changed_cb().

233 {
234 #ifdef IS_SPEAKER
235  gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline),
236  GST_DEBUG_GRAPH_SHOW_ALL,
237  "playback_helper.dot");
238 #endif
239 #ifdef IS_MIC
240  gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline),
241  GST_DEBUG_GRAPH_SHOW_ALL,
242  "record_helper.dot");
243 #endif
244 
245 
246  // load_configuration();
247 }
static GstElement * pipeline
Main pipeline.
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 251 of file gnunet_gst.c.

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

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

◆ state_changed_cb()

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

Definition at line 290 of file gnunet_gst.c.

References GNUNET_gstData::pipeline, and pl_graph().

Referenced by gg_setup_gst_bus().

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

Referenced by gg_setup_gst_bus().

331 {
332  // printf("application cb");
333  return;
334 }
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 338 of file gnunet_gst.c.

Referenced by gg_setup_gst_bus().

339 {
340  // printf("error cb");
341  return;
342 }
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 346 of file gnunet_gst.c.

Referenced by gg_setup_gst_bus().

347 {
348  // printf("eos cb");
349  return;
350 }
Here is the caller graph for this function:

◆ gg_setup_gst_bus()

void gg_setup_gst_bus ( GNUNET_gstData d)

Definition at line 354 of file gnunet_gst.c.

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

Referenced by main().

355 {
356  GstBus *bus;
357 
358  bus = gst_element_get_bus (GST_ELEMENT (d->pipeline));
359  gst_bus_add_signal_watch (bus);
360  g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,
361  d);
362  g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb,
363  d);
364  g_signal_connect (G_OBJECT (bus), "message::state-changed",
365  (GCallback) state_changed_cb, d);
366  g_signal_connect (G_OBJECT (bus), "message::application",
367  (GCallback) application_cb, d);
368  g_signal_connect (G_OBJECT (bus), "message::about-to-finish",
369  (GCallback) application_cb, d);
370  gst_object_unref (bus);
371 }
GstPipeline * pipeline
static void error_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
Definition: gnunet_gst.c:338
void state_changed_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *d)
Definition: gnunet_gst.c:290
static void eos_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
Definition: gnunet_gst.c:346
static void application_cb(GstBus *bus, GstMessage *msg, GNUNET_gstData *data)
Definition: gnunet_gst.c:330
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 495 of file gnunet_gst.c.

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().

496 {
497  GstBuffer *b;
498  gchar *bufspace;
499  GstFlowReturn flow;
500 
502  "Feeding %u bytes to GStreamer\n",
503  (unsigned int) b_len);
504 
505  bufspace = g_memdup (audio, b_len);
506  b = gst_buffer_new_wrapped (bufspace, b_len);
507  if (NULL == b)
508  {
510  "Failed to wrap a buffer\n");
511  g_free (bufspace);
512  return GNUNET_SYSERR;
513  }
514  if (GST_APP_SRC (d->appsrc) == NULL)
515  exit (10);
516  flow = gst_app_src_push_buffer (GST_APP_SRC (d->appsrc), b);
517  /* They all return GNUNET_OK, because currently player stops when
518  * data stops coming. This might need to be changed for the player
519  * to also stop when pipeline breaks.
520  */
521  switch (flow)
522  {
523  case GST_FLOW_OK:
525  "Fed %u bytes to the pipeline\n",
526  (unsigned int) b_len);
527  break;
528 
529  case GST_FLOW_FLUSHING:
530  /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */
532  "Dropped a buffer\n");
533  break;
534 
535  case GST_FLOW_EOS:
536  /* end of stream */
538  "EOS\n");
539  break;
540 
541  default:
543  "Unexpected push result\n");
544  break;
545  }
546  return GNUNET_OK;
547 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
GstElement * appsrc
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
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 554 of file gnunet_gst.c.

References gst_element_factory_make.

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

◆ lf()

void lf ( char *  msg)

Definition at line 586 of file gnunet_gst.c.

Referenced by get_audiobin().

587 {
588  printf ("linking elements failed: %s", msg);
589  exit (10);
590 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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 597 of file gnunet_gst.c.

References BUFFER_TIME, and LATENCY_TIME.

Referenced by get_audiobin().

601 {
602  if (GST_IS_AUDIO_BASE_SRC (object))
603  g_object_set (object,
604  "buffer-time", (gint64) BUFFER_TIME,
605  "latency-time", (gint64) LATENCY_TIME,
606  NULL);
607 }
#define LATENCY_TIME
Min number of microseconds to buffer in audiosink.
#define BUFFER_TIME
Max number of microseconds to buffer in audiosink.
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 614 of file gnunet_gst.c.

References BUFFER_TIME, and LATENCY_TIME.

Referenced by get_audiobin().

616 {
617  if (GST_IS_AUDIO_BASE_SRC (object))
618  g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time",
619  (gint64) LATENCY_TIME, NULL);
620 }
#define LATENCY_TIME
Min number of microseconds to buffer in audiosink.
#define BUFFER_TIME
Max number of microseconds to buffer in audiosink.
Here is the caller graph for this function:

◆ get_pipeline()

GstElement* get_pipeline ( GstElement *  element)

Definition at line 624 of file gnunet_gst.c.

References p.

625 {
626  GstPipeline *p;
627 
628  p = GST_PIPELINE (gst_object_get_parent (GST_OBJECT (element)));
629 
630  return GST_ELEMENT (p);
631 }
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59

◆ decoder_ogg_pad_added()

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

Definition at line 635 of file gnunet_gst.c.

References decoder.

Referenced by get_coder().

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

◆ gnunet_read()

int gnunet_read ( GNUNET_gstData d)

Definition at line 654 of file gnunet_gst.c.

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().

655 {
656  char readbuf[MAXLINE];
657  int ret;
658 
659  printf ("read \n");
660  ret = read (0, readbuf, sizeof(readbuf));
661  if (0 > ret)
662  {
664  _ ("Read error from STDIN: %d %s\n"),
665  ret, strerror (errno));
666  return FAIL;
667  }
668  // toff += ret;
670  "Received %d bytes of audio data\n",
671  (int) ret);
672  if (0 == ret)
673  return FAIL;
674  // #ifdef DEBUG_READ_PURE_OGG
675 
676  if (d->pure_ogg)
677  {
678  feed_buffer_to_gst (readbuf, ret, d);
679  }
680  else
681  {
682  // #endif
684  readbuf,
685  ret,
686  GNUNET_NO,
687  GNUNET_NO);
688  }
689  return 0;
690 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define MAXLINE
How much data to read in one go.
int 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:114
struct GNUNET_MessageStreamTokenizer * stdin_mst
#define GNUNET_log(kind,...)
int feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData *d)
Definition: gnunet_gst.c:495
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 702 of file gnunet_gst.c.

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

Referenced by get_app().

704 {
705  struct AudioMessage *audio;
706  size_t b_len;
707 
708  printf ("stdin receiver \n ");
709  dump_buffer (sizeof(msg),
710  (const unsigned char *) msg);
711 
712  switch (ntohs (msg->type))
713  {
715  audio = (struct AudioMessage *) msg;
716 
717  b_len = ntohs (audio->header.size) - sizeof(struct AudioMessage);
718  printf ("feeding buffer to gst \n ");
719  feed_buffer_to_gst ((const char *) &audio[1], b_len, cls);
720  break;
721 
722  default:
723  printf ("No audio message: %u \n ", ntohs (msg->type));
724  break;
725  }
726  return GNUNET_OK;
727 }
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
Definition: conversation.h:61
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Message to transmit the audio (between client and helpers).
Definition: conversation.h:56
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
int feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData *d)
Definition: gnunet_gst.c:495
void dump_buffer(unsigned n, const unsigned char *buf)
Definition: gnunet_gst.c:34
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 731 of file gnunet_gst.c.

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(), and GNUNET_MessageHeader::type.

Referenced by main().

732 {
733  GstBin *bin;
734  GstPad *pad, *ghostpad;
735 
736  if (type == SOURCE)
737  {
738  bin = GST_BIN (gst_bin_new ("Gnunet appsrc"));
739 
740 
742  GNUNET_log_setup ("gnunet-helper-audio-playback",
743  "WARNING",
744  NULL));
745 
747  "Audio playback starts\n");
748  printf (" creating appsrc \n ");
749  // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
750 
751 // d->audio_message = GNUNET_malloc (UINT16_MAX);
752 // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage));
753 // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage));
754 
755 
756  // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
757 
758 
760 
761  if (d->stdin_mst == NULL)
762  printf ("stdin_mst = NULL");
763 
764  d->appsrc = gst_element_factory_make ("appsrc", "appsrc");
765 
766  gst_bin_add_many (bin, d->appsrc, NULL);
767 // gst_element_link_many ( encoder, muxer, NULL);
768 
769  pad = gst_element_get_static_pad (d->appsrc, "src");
770  ghostpad = gst_ghost_pad_new ("src", pad);
771  }
772  if (type == SINK)
773  {
774  bin = GST_BIN (gst_bin_new ("Gnunet appsink"));
775 
776 
778  GNUNET_log_setup ("gnunet-helper-audio-record",
779  "WARNING",
780  NULL));
781 
783  "Audio source starts\n");
784 
785  d->appsink = gst_element_factory_make ("appsink", "appsink");
786 
787  // Move this out of here!
788  d->audio_message = GNUNET_malloc (UINT16_MAX);
789  (d->audio_message)->header.type = htons (
791  g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE,
792  NULL);
793 
794  g_signal_connect (d->appsink, "new-sample",
795  G_CALLBACK (on_appsink_new_sample), &d);
796 
797  gst_bin_add_many (bin, d->appsink, NULL);
798 // gst_element_link_many ( encoder, muxer, NULL);
799 
800  pad = gst_element_get_static_pad (d->appsink, "sink");
801  ghostpad = gst_ghost_pad_new ("sink", pad);
802  }
803 
804  /* set the bin pads */
805  gst_pad_set_active (ghostpad, TRUE);
806  gst_element_add_pad (GST_ELEMENT (bin), ghostpad);
807 
808  gst_object_unref (pad);
809 
810  return bin;
811 }
struct AudioMessage * audio_message
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
Definition: conversation.h:61
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static int stdin_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
Message callback.
Definition: gnunet_gst.c:702
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
GstFlowReturn on_appsink_new_sample(GstElement *element, GNUNET_gstData *d)
Definition: gnunet_gst.c:169
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
#define gst_element_factory_make(element, name)
Definition: gnunet_gst.h:36
struct GNUNET_MessageStreamTokenizer * stdin_mst
GstElement * appsrc
#define GNUNET_log(kind,...)
GstElement * appsink
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 815 of file gnunet_gst.c.

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, and GNUNET_gstData::usertp.

Referenced by main().

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

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, and TEST.

Referenced by main().

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