diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-03 00:05:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-03 00:05:47 +0000 |
commit | f3c7f9aa97c759ff56dc65c887b87be09da877c7 (patch) | |
tree | 917584c5dcf0c78a7c41f32d9a02b558f5f7e91f /src/conversation/gnunet-helper-audio-record.c | |
parent | 17ee77576112312de11efa52eda7fa960fb908e2 (diff) | |
download | gnunet-f3c7f9aa97c759ff56dc65c887b87be09da877c7.tar.gz gnunet-f3c7f9aa97c759ff56dc65c887b87be09da877c7.zip |
-much better latency
Diffstat (limited to 'src/conversation/gnunet-helper-audio-record.c')
-rw-r--r-- | src/conversation/gnunet-helper-audio-record.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/conversation/gnunet-helper-audio-record.c b/src/conversation/gnunet-helper-audio-record.c index c14b35fe6..b3828498f 100644 --- a/src/conversation/gnunet-helper-audio-record.c +++ b/src/conversation/gnunet-helper-audio-record.c | |||
@@ -221,6 +221,11 @@ stream_read_callback (pa_stream * s, | |||
221 | { | 221 | { |
222 | const void *data; | 222 | const void *data; |
223 | 223 | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
225 | "Got %u/%u bytes of PCM data\n", | ||
226 | length, | ||
227 | pcm_length); | ||
228 | |||
224 | GNUNET_assert (NULL != s); | 229 | GNUNET_assert (NULL != s); |
225 | GNUNET_assert (length > 0); | 230 | GNUNET_assert (length > 0); |
226 | if (stdio_event) | 231 | if (stdio_event) |
@@ -288,6 +293,7 @@ stream_state_callback (pa_stream * s, void *userdata) | |||
288 | case PA_STREAM_READY: | 293 | case PA_STREAM_READY: |
289 | { | 294 | { |
290 | const pa_buffer_attr *a; | 295 | const pa_buffer_attr *a; |
296 | |||
291 | char cmt[PA_CHANNEL_MAP_SNPRINT_MAX], | 297 | char cmt[PA_CHANNEL_MAP_SNPRINT_MAX], |
292 | sst[PA_SAMPLE_SPEC_SNPRINT_MAX]; | 298 | sst[PA_SAMPLE_SPEC_SNPRINT_MAX]; |
293 | 299 | ||
@@ -307,7 +313,7 @@ stream_state_callback (pa_stream * s, void *userdata) | |||
307 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
308 | _("Buffer metrics: maxlength=%u, fragsize=%u\n"), | 314 | _("Buffer metrics: maxlength=%u, fragsize=%u\n"), |
309 | a->maxlength, a->fragsize); | 315 | a->maxlength, a->fragsize); |
310 | } | 316 | } |
311 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
312 | _("Using sample spec '%s', channel map '%s'.\n"), | 318 | _("Using sample spec '%s', channel map '%s'.\n"), |
313 | pa_sample_spec_snprint (sst, sizeof (sst), | 319 | pa_sample_spec_snprint (sst, sizeof (sst), |
@@ -321,7 +327,7 @@ stream_state_callback (pa_stream * s, void *userdata) | |||
321 | pa_stream_get_device_index (s), | 327 | pa_stream_get_device_index (s), |
322 | pa_stream_is_suspended (s) ? "" : "not "); | 328 | pa_stream_is_suspended (s) ? "" : "not "); |
323 | } | 329 | } |
324 | break; | 330 | break; |
325 | case PA_STREAM_FAILED: | 331 | case PA_STREAM_FAILED: |
326 | default: | 332 | default: |
327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 333 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -350,6 +356,7 @@ context_state_callback (pa_context * c, | |||
350 | case PA_CONTEXT_READY: | 356 | case PA_CONTEXT_READY: |
351 | { | 357 | { |
352 | int r; | 358 | int r; |
359 | pa_buffer_attr na; | ||
353 | 360 | ||
354 | GNUNET_assert (!stream_in); | 361 | GNUNET_assert (!stream_in); |
355 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -362,9 +369,13 @@ context_state_callback (pa_context * c, | |||
362 | pa_strerror (pa_context_errno (c))); | 369 | pa_strerror (pa_context_errno (c))); |
363 | goto fail; | 370 | goto fail; |
364 | } | 371 | } |
365 | pa_stream_set_state_callback (stream_in, stream_state_callback, NULL); | 372 | pa_stream_set_state_callback (stream_in, &stream_state_callback, NULL); |
366 | pa_stream_set_read_callback (stream_in, stream_read_callback, NULL); | 373 | pa_stream_set_read_callback (stream_in, &stream_read_callback, NULL); |
367 | if ((r = pa_stream_connect_record (stream_in, NULL, NULL, 0)) < 0) | 374 | memset (&na, 0, sizeof (na)); |
375 | na.maxlength = UINT32_MAX; | ||
376 | na.fragsize = pcm_length; | ||
377 | if ((r = pa_stream_connect_record (stream_in, NULL, &na, | ||
378 | PA_STREAM_EARLY_REQUESTS)) < 0) | ||
368 | { | 379 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 380 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
370 | _("pa_stream_connect_record() failed: %s\n"), | 381 | _("pa_stream_connect_record() failed: %s\n"), |
@@ -416,8 +427,8 @@ pa_init () | |||
416 | /* listen to signals */ | 427 | /* listen to signals */ |
417 | r = pa_signal_init (mainloop_api); | 428 | r = pa_signal_init (mainloop_api); |
418 | GNUNET_assert (r == 0); | 429 | GNUNET_assert (r == 0); |
419 | pa_signal_new (SIGINT, exit_signal_callback, NULL); | 430 | pa_signal_new (SIGINT, &exit_signal_callback, NULL); |
420 | pa_signal_new (SIGTERM, exit_signal_callback, NULL); | 431 | pa_signal_new (SIGTERM, &exit_signal_callback, NULL); |
421 | 432 | ||
422 | /* connect to the main pulseaudio context */ | 433 | /* connect to the main pulseaudio context */ |
423 | 434 | ||
@@ -426,7 +437,7 @@ pa_init () | |||
426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 437 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
427 | _("pa_context_new() failed.\n")); | 438 | _("pa_context_new() failed.\n")); |
428 | } | 439 | } |
429 | pa_context_set_state_callback (context, context_state_callback, NULL); | 440 | pa_context_set_state_callback (context, &context_state_callback, NULL); |
430 | if (pa_context_connect (context, NULL, 0, NULL) < 0) | 441 | if (pa_context_connect (context, NULL, 0, NULL) < 0) |
431 | { | 442 | { |
432 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 443 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -475,6 +486,8 @@ main (int argc, char *argv[]) | |||
475 | GNUNET_log_setup ("gnunet-helper-audio-record", | 486 | GNUNET_log_setup ("gnunet-helper-audio-record", |
476 | "DEBUG", | 487 | "DEBUG", |
477 | "/tmp/helper-audio-record")); | 488 | "/tmp/helper-audio-record")); |
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
490 | "Audio source starts\n"); | ||
478 | audio_message = GNUNET_malloc (UINT16_MAX); | 491 | audio_message = GNUNET_malloc (UINT16_MAX); |
479 | audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 492 | audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
480 | opus_init (); | 493 | opus_init (); |