aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/conversation/gnunet-helper-audio-playback-gst.c94
1 files changed, 64 insertions, 30 deletions
diff --git a/src/conversation/gnunet-helper-audio-playback-gst.c b/src/conversation/gnunet-helper-audio-playback-gst.c
index ab206b082..3f84b8127 100644
--- a/src/conversation/gnunet-helper-audio-playback-gst.c
+++ b/src/conversation/gnunet-helper-audio-playback-gst.c
@@ -43,13 +43,13 @@
43 43
44/** 44/**
45 * Max number of microseconds to buffer in audiosink. 45 * Max number of microseconds to buffer in audiosink.
46 * Default is 200000 46 * Default is 1000
47 */ 47 */
48#define BUFFER_TIME 1000 48#define BUFFER_TIME 1000
49 49
50/** 50/**
51 * Min number of microseconds to buffer in audiosink. 51 * Min number of microseconds to buffer in audiosink.
52 * Default is 10000 52 * Default is 1000
53 */ 53 */
54#define LATENCY_TIME 1000 54#define LATENCY_TIME 1000
55 55
@@ -79,15 +79,25 @@ static GstElement *sink;
79 */ 79 */
80static int abort_read; 80static int abort_read;
81 81
82
82static void 83static void
83sink_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) 84sink_child_added (GstChildProxy *child_proxy,
85 GObject *object,
86 gchar *name,
87 gpointer user_data)
84{ 88{
85 if (GST_IS_AUDIO_BASE_SRC (object)) 89 if (GST_IS_AUDIO_BASE_SRC (object))
86 g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL); 90 g_object_set (object,
91 "buffer-time", (gint64) BUFFER_TIME,
92 "latency-time", (gint64) LATENCY_TIME,
93 NULL);
87} 94}
88 95
96
89static void 97static void
90ogg_pad_added (GstElement *element, GstPad *pad, gpointer data) 98ogg_pad_added (GstElement *element,
99 GstPad *pad,
100 gpointer data)
91{ 101{
92 GstPad *sinkpad; 102 GstPad *sinkpad;
93 GstElement *decoder = (GstElement *) data; 103 GstElement *decoder = (GstElement *) data;
@@ -102,6 +112,7 @@ ogg_pad_added (GstElement *element, GstPad *pad, gpointer data)
102 gst_object_unref (sinkpad); 112 gst_object_unref (sinkpad);
103} 113}
104 114
115
105static void 116static void
106quit () 117quit ()
107{ 118{
@@ -112,14 +123,17 @@ quit ()
112 abort_read = 1; 123 abort_read = 1;
113} 124}
114 125
126
115static gboolean 127static gboolean
116bus_call (GstBus *bus, GstMessage *msg, gpointer data) 128bus_call (GstBus *bus, GstMessage *msg, gpointer data)
117{ 129{
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bus message\n"); 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
131 "Bus message\n");
119 switch (GST_MESSAGE_TYPE (msg)) 132 switch (GST_MESSAGE_TYPE (msg))
120 { 133 {
121 case GST_MESSAGE_EOS: 134 case GST_MESSAGE_EOS:
122 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "End of stream\n"); 135 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
136 "End of stream\n");
123 quit (); 137 quit ();
124 break; 138 break;
125 139
@@ -131,7 +145,9 @@ bus_call (GstBus *bus, GstMessage *msg, gpointer data)
131 gst_message_parse_error (msg, &error, &debug); 145 gst_message_parse_error (msg, &error, &debug);
132 g_free (debug); 146 g_free (debug);
133 147
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error: %s\n", error->message); 148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
149 "Error: %s\n",
150 error->message);
135 g_error_free (error); 151 g_error_free (error);
136 152
137 quit (); 153 quit ();
@@ -151,6 +167,7 @@ signalhandler (int s)
151 quit (); 167 quit ();
152} 168}
153 169
170
154static int 171static int
155feed_buffer_to_gst (const char *audio, size_t b_len) 172feed_buffer_to_gst (const char *audio, size_t b_len)
156{ 173{
@@ -159,14 +176,15 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
159 GstFlowReturn flow; 176 GstFlowReturn flow;
160 177
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
162 "Feeding %u bytes to GStreamer\n", 179 "Feeding %u bytes to GStreamer\n",
163 (unsigned int) b_len); 180 (unsigned int) b_len);
164 181
165 bufspace = g_memdup (audio, b_len); 182 bufspace = g_memdup (audio, b_len);
166 b = gst_buffer_new_wrapped (bufspace, b_len); 183 b = gst_buffer_new_wrapped (bufspace, b_len);
167 if (NULL == b) 184 if (NULL == b)
168 { 185 {
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to wrap a buffer\n"); 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Failed to wrap a buffer\n");
170 g_free (bufspace); 188 g_free (bufspace);
171 return GNUNET_SYSERR; 189 return GNUNET_SYSERR;
172 } 190 }
@@ -178,24 +196,29 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
178 switch (flow) 196 switch (flow)
179 { 197 {
180 case GST_FLOW_OK: 198 case GST_FLOW_OK:
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fed %u bytes to the pipeline\n", 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
182 (unsigned int) b_len); 200 "Fed %u bytes to the pipeline\n",
201 (unsigned int) b_len);
183 break; 202 break;
184 case GST_FLOW_FLUSHING: 203 case GST_FLOW_FLUSHING:
185 /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ 204 /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */
186 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Dropped a buffer\n"); 205 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
206 "Dropped a buffer\n");
187 break; 207 break;
188 case GST_FLOW_EOS: 208 case GST_FLOW_EOS:
189 /* end of stream */ 209 /* end of stream */
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "EOS\n"); 210 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
211 "EOS\n");
191 break; 212 break;
192 default: 213 default:
193 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unexpected push result\n"); 214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
215 "Unexpected push result\n");
194 break; 216 break;
195 } 217 }
196 return GNUNET_OK; 218 return GNUNET_OK;
197} 219}
198 220
221
199/** 222/**
200 * Message callback 223 * Message callback
201 */ 224 */
@@ -236,26 +259,29 @@ main (int argc, char **argv)
236 int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0; 259 int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0;
237#endif 260#endif
238 261
239 inthandler = signal (SIGINT, signalhandler); 262 inthandler = signal (SIGINT,
240 termhandler = signal (SIGTERM, signalhandler); 263 &signalhandler);
241 264 termhandler = signal (SIGTERM,
265 &signalhandler);
266
242#ifdef WINDOWS 267#ifdef WINDOWS
243 setmode (0, _O_BINARY); 268 setmode (0, _O_BINARY);
244#endif 269#endif
245 270
246 /* Initialisation */ 271 /* Initialisation */
247 gst_init (&argc, &argv); 272 gst_init (&argc, &argv);
248 273
249 GNUNET_assert (GNUNET_OK == 274 GNUNET_assert (GNUNET_OK ==
250 GNUNET_log_setup ("gnunet-helper-audio-playback", 275 GNUNET_log_setup ("gnunet-helper-audio-playback-gst",
251 "WARNING", 276 "WARNING",
252 NULL)); 277 NULL));
253 278
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Audio sink starts\n"); 280 "Audio sink starts\n");
256 281
257 stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, NULL); 282 stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver,
258 283 NULL);
284
259 /* Create gstreamer elements */ 285 /* Create gstreamer elements */
260 pipeline = gst_pipeline_new ("audio-player"); 286 pipeline = gst_pipeline_new ("audio-player");
261 source = gst_element_factory_make ("appsrc", "audio-input"); 287 source = gst_element_factory_make ("appsrc", "audio-input");
@@ -268,12 +294,18 @@ main (int argc, char **argv)
268 if (!pipeline || !source || !conv || !resampler || !decoder || !demuxer || !sink) 294 if (!pipeline || !source || !conv || !resampler || !decoder || !demuxer || !sink)
269 { 295 {
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 296 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 "One element could not be created. Exiting.\n"); 297 "One element could not be created. Exiting.\n");
272 return -1; 298 return -1;
273 } 299 }
274 300
275 g_signal_connect (sink, "child-added", G_CALLBACK (sink_child_added), NULL); 301 g_signal_connect (sink,
276 g_signal_connect (demuxer, "pad-added", G_CALLBACK (ogg_pad_added), decoder); 302 "child-added",
303 G_CALLBACK (sink_child_added),
304 NULL);
305 g_signal_connect (demuxer,
306 "pad-added",
307 G_CALLBACK (ogg_pad_added),
308 decoder);
277 309
278 /* Keep a reference to it, we operate on it */ 310 /* Keep a reference to it, we operate on it */
279 gst_object_ref (GST_OBJECT (source)); 311 gst_object_ref (GST_OBJECT (source));
@@ -349,10 +381,12 @@ main (int argc, char **argv)
349 signal (SIGINT, inthandler); 381 signal (SIGINT, inthandler);
350 signal (SIGINT, termhandler); 382 signal (SIGINT, termhandler);
351 383
352 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); 384 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
385 "Returned, stopping playback\n");
353 quit (); 386 quit ();
354 387
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); 388 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
389 "Deleting pipeline\n");
356 gst_object_unref (GST_OBJECT (source)); 390 gst_object_unref (GST_OBJECT (source));
357 source = NULL; 391 source = NULL;
358 gst_object_unref (GST_OBJECT (pipeline)); 392 gst_object_unref (GST_OBJECT (pipeline));