diff options
Diffstat (limited to 'src/conversation/gnunet-helper-audio-record.c')
-rw-r--r-- | src/conversation/gnunet-helper-audio-record.c | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/src/conversation/gnunet-helper-audio-record.c b/src/conversation/gnunet-helper-audio-record.c index 82bb6d5b3..89800faa2 100644 --- a/src/conversation/gnunet-helper-audio-record.c +++ b/src/conversation/gnunet-helper-audio-record.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file conversation/gnunet-helper-audio-record.c | 19 | * @file conversation/gnunet-helper-audio-record.c |
@@ -269,30 +267,36 @@ static int dump_pure_ogg; | |||
269 | static void | 267 | static void |
270 | quit (int ret) | 268 | quit (int ret) |
271 | { | 269 | { |
272 | mainloop_api->quit (mainloop_api, ret); | 270 | mainloop_api->quit (mainloop_api, |
271 | ret); | ||
273 | exit (ret); | 272 | exit (ret); |
274 | } | 273 | } |
275 | 274 | ||
276 | 275 | ||
277 | static void | 276 | static void |
278 | write_data (const char *ptr, size_t msg_size) | 277 | write_data (const char *ptr, |
278 | size_t msg_size) | ||
279 | { | 279 | { |
280 | ssize_t ret; | 280 | ssize_t ret; |
281 | size_t off; | 281 | size_t off; |
282 | off = 0; | 282 | off = 0; |
283 | while (off < msg_size) | 283 | while (off < msg_size) |
284 | { | 284 | { |
285 | ret = write (1, &ptr[off], msg_size - off); | 285 | ret = write (STDOUT_FILENO, |
286 | &ptr[off], | ||
287 | msg_size - off); | ||
286 | if (0 >= ret) | 288 | if (0 >= ret) |
287 | { | 289 | { |
288 | if (-1 == ret) | 290 | if (-1 == ret) |
289 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write"); | 291 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
292 | "write"); | ||
290 | quit (2); | 293 | quit (2); |
291 | } | 294 | } |
292 | off += ret; | 295 | off += ret; |
293 | } | 296 | } |
294 | } | 297 | } |
295 | 298 | ||
299 | |||
296 | static void | 300 | static void |
297 | write_page (ogg_page *og) | 301 | write_page (ogg_page *og) |
298 | { | 302 | { |
@@ -310,12 +314,15 @@ write_page (ogg_page *og) | |||
310 | toff); | 314 | toff); |
311 | #ifdef DEBUG_RECORD_PURE_OGG | 315 | #ifdef DEBUG_RECORD_PURE_OGG |
312 | if (dump_pure_ogg) | 316 | if (dump_pure_ogg) |
313 | write_data ((const char *) &audio_message[1], og->header_len + og->body_len); | 317 | write_data ((const char *) &audio_message[1], |
318 | og->header_len + og->body_len); | ||
314 | else | 319 | else |
315 | #endif | 320 | #endif |
316 | write_data ((const char *) audio_message, msg_size); | 321 | write_data ((const char *) audio_message, |
322 | msg_size); | ||
317 | } | 323 | } |
318 | 324 | ||
325 | |||
319 | /** | 326 | /** |
320 | * Creates OPUS packets from PCM data | 327 | * Creates OPUS packets from PCM data |
321 | */ | 328 | */ |
@@ -345,7 +352,7 @@ packetizer () | |||
345 | opus_strerror (len)); | 352 | opus_strerror (len)); |
346 | quit (5); | 353 | quit (5); |
347 | } | 354 | } |
348 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) | 355 | if (((uint32_t)len) > UINT16_MAX - sizeof (struct AudioMessage)) |
349 | { | 356 | { |
350 | GNUNET_break (0); | 357 | GNUNET_break (0); |
351 | continue; | 358 | continue; |
@@ -365,7 +372,9 @@ packetizer () | |||
365 | 372 | ||
366 | while (ogg_stream_flush_fill (&os, &og, PAGE_WATERLINE)) | 373 | while (ogg_stream_flush_fill (&os, &og, PAGE_WATERLINE)) |
367 | { | 374 | { |
368 | if (og.header_len + og.body_len > UINT16_MAX - sizeof (struct AudioMessage)) | 375 | if ( ((unsigned long long) og.header_len) + |
376 | ((unsigned long long) og.body_len) > | ||
377 | UINT16_MAX - sizeof (struct AudioMessage)) | ||
369 | { | 378 | { |
370 | GNUNET_assert (0); | 379 | GNUNET_assert (0); |
371 | continue; | 380 | continue; |
@@ -404,6 +413,7 @@ stream_read_callback (pa_stream * s, | |||
404 | { | 413 | { |
405 | const void *data; | 414 | const void *data; |
406 | 415 | ||
416 | (void) userdata; | ||
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
408 | "Got %u/%d bytes of PCM data\n", | 418 | "Got %u/%d bytes of PCM data\n", |
409 | (unsigned int) length, | 419 | (unsigned int) length, |
@@ -454,6 +464,10 @@ exit_signal_callback (pa_mainloop_api * m, | |||
454 | int sig, | 464 | int sig, |
455 | void *userdata) | 465 | void *userdata) |
456 | { | 466 | { |
467 | (void) m; | ||
468 | (void) e; | ||
469 | (void) sig; | ||
470 | (void) userdata; | ||
457 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
458 | _("Got signal, exiting.\n")); | 472 | _("Got signal, exiting.\n")); |
459 | quit (1); | 473 | quit (1); |
@@ -464,10 +478,11 @@ exit_signal_callback (pa_mainloop_api * m, | |||
464 | * Pulseaudio stream state callback | 478 | * Pulseaudio stream state callback |
465 | */ | 479 | */ |
466 | static void | 480 | static void |
467 | stream_state_callback (pa_stream * s, void *userdata) | 481 | stream_state_callback (pa_stream * s, |
482 | void *userdata) | ||
468 | { | 483 | { |
484 | (void) userdata; | ||
469 | GNUNET_assert (NULL != s); | 485 | GNUNET_assert (NULL != s); |
470 | |||
471 | switch (pa_stream_get_state (s)) | 486 | switch (pa_stream_get_state (s)) |
472 | { | 487 | { |
473 | case PA_STREAM_CREATING: | 488 | case PA_STREAM_CREATING: |
@@ -527,6 +542,7 @@ static void | |||
527 | context_state_callback (pa_context * c, | 542 | context_state_callback (pa_context * c, |
528 | void *userdata) | 543 | void *userdata) |
529 | { | 544 | { |
545 | (void) userdata; | ||
530 | GNUNET_assert (c); | 546 | GNUNET_assert (c); |
531 | 547 | ||
532 | switch (pa_context_get_state (c)) | 548 | switch (pa_context_get_state (c)) |
@@ -659,6 +675,7 @@ opus_init () | |||
659 | OPUS_SET_SIGNAL (CONV_OPUS_SIGNAL)); | 675 | OPUS_SET_SIGNAL (CONV_OPUS_SIGNAL)); |
660 | } | 676 | } |
661 | 677 | ||
678 | |||
662 | static void | 679 | static void |
663 | ogg_init () | 680 | ogg_init () |
664 | { | 681 | { |
@@ -667,8 +684,8 @@ ogg_init () | |||
667 | struct OpusCommentsPacket *commentspacket; | 684 | struct OpusCommentsPacket *commentspacket; |
668 | size_t commentspacket_len; | 685 | size_t commentspacket_len; |
669 | 686 | ||
670 | serialno = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 0x7FFFFFFF); | 687 | serialno = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, |
671 | 688 | 0x7FFFFFFF); | |
672 | /*Initialize Ogg stream struct*/ | 689 | /*Initialize Ogg stream struct*/ |
673 | if (-1 == ogg_stream_init (&os, serialno)) | 690 | if (-1 == ogg_stream_init (&os, serialno)) |
674 | { | 691 | { |
@@ -755,8 +772,11 @@ ogg_init () | |||
755 | * @return 0 ok, 1 on error | 772 | * @return 0 ok, 1 on error |
756 | */ | 773 | */ |
757 | int | 774 | int |
758 | main (int argc, char *argv[]) | 775 | main (int argc, |
776 | char *argv[]) | ||
759 | { | 777 | { |
778 | (void) argc; | ||
779 | (void) argv; | ||
760 | GNUNET_assert (GNUNET_OK == | 780 | GNUNET_assert (GNUNET_OK == |
761 | GNUNET_log_setup ("gnunet-helper-audio-record", | 781 | GNUNET_log_setup ("gnunet-helper-audio-record", |
762 | "WARNING", | 782 | "WARNING", |