[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29808 - gnunet/src/conversation
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29808 - gnunet/src/conversation |
Date: |
Thu, 3 Oct 2013 00:13:13 +0200 |
Author: grothoff
Date: 2013-10-03 00:13:12 +0200 (Thu, 03 Oct 2013)
New Revision: 29808
Modified:
gnunet/src/conversation/gnunet-helper-audio-playback.c
gnunet/src/conversation/gnunet-helper-audio-record.c
Log:
-debugging logic
Modified: gnunet/src/conversation/gnunet-helper-audio-playback.c
===================================================================
--- gnunet/src/conversation/gnunet-helper-audio-playback.c 2013-10-02
21:19:33 UTC (rev 29807)
+++ gnunet/src/conversation/gnunet-helper-audio-playback.c 2013-10-02
22:13:12 UTC (rev 29808)
@@ -22,6 +22,7 @@
* @brief constants for network protocols
* @author Siomon Dieterle
* @author Andreas Fuchs
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -40,12 +41,14 @@
#define MAXLINE 4096
+#define SAMPLING_RATE 48000
+
/**
* Pulseaudio specification. May change in the future.
*/
static pa_sample_spec sample_spec = {
.format = PA_SAMPLE_FLOAT32LE,
- .rate = 48000,
+ .rate = SAMPLING_RATE,
.channels = 1
};
@@ -96,11 +99,6 @@
static int frame_size;
/**
- * The sampling rate used in Pulseaudio specification
- */
-static opus_int32 sampling_rate;
-
-/**
* Audio buffer
*/
static void *buffer;
@@ -125,19 +123,27 @@
const struct GNUNET_MessageHeader *msg)
{
struct AudioMessage *audio;
+ int ret;
switch (ntohs (msg->type))
{
case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO:
audio = (struct AudioMessage *) msg;
- int len =
- opus_decode_float (dec,
- (const unsigned char *) &audio[1],
- ntohs (audio->header.size) - sizeof (struct
AudioMessage),
- pcm_buffer,
- frame_size, 0);
- // FIXME: pcm_length != len???
+ ret = opus_decode_float (dec,
+ (const unsigned char *) &audio[1],
+ ntohs (audio->header.size) - sizeof (struct
AudioMessage),
+ pcm_buffer,
+ frame_size, 0);
+ if (ret < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Opus decoding failed: %d\n",
+ ret);
+ return GNUNET_OK;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Decoded frame\n");
if (pa_stream_write
(stream_out, (uint8_t *) pcm_buffer, pcm_length, NULL, 0,
PA_SEEK_RELATIVE) < 0)
@@ -173,41 +179,34 @@
do_stream_write (size_t length)
{
size_t l;
- GNUNET_assert (length);
- if (!buffer || !buffer_length)
- {
- return;
- }
+ GNUNET_assert (0 != length);
+ if ( (! buffer) || (! buffer_length) )
+ return;
-
l = length;
if (l > buffer_length)
- {
- l = buffer_length;
-
- }
-
- if (pa_stream_write
- (stream_out, (uint8_t *) buffer + buffer_index, l, NULL, 0,
- PA_SEEK_RELATIVE) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_stream_write() failed: %s\n"),
- pa_strerror (pa_context_errno (context)));
- quit (1);
- return;
- }
-
+ l = buffer_length;
+ if (0 > pa_stream_write (stream_out,
+ (uint8_t *) buffer + buffer_index,
+ l,
+ NULL, 0,
+ PA_SEEK_RELATIVE))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_write() failed: %s\n"),
+ pa_strerror (pa_context_errno (context)));
+ quit (1);
+ return;
+ }
buffer_length -= l;
buffer_index += l;
-
- if (!buffer_length)
- {
- pa_xfree (buffer);
- buffer = NULL;
- buffer_index = buffer_length = 0;
- }
+ if (! buffer_length)
+ {
+ pa_xfree (buffer);
+ buffer = NULL;
+ buffer_index = buffer_length = 0;
+ }
}
@@ -215,21 +214,14 @@
* Callback when data is there for playback
*/
static void
-stream_write_callback (pa_stream * s, size_t length, void *userdata)
+stream_write_callback (pa_stream * s,
+ size_t length,
+ void *userdata)
{
-
if (stdio_event)
- {
- mainloop_api->io_enable (stdio_event, PA_IO_EVENT_INPUT);
- }
-
-
+ mainloop_api->io_enable (stdio_event, PA_IO_EVENT_INPUT);
if (!buffer)
- {
- return;
- }
-
-
+ return;
do_stream_write (length);
}
@@ -251,66 +243,58 @@
* Pulseaudio stream state callback
*/
static void
-context_state_callback (pa_context * c, void *userdata)
+context_state_callback (pa_context * c,
+ void *userdata)
{
int p;
- GNUNET_assert (c);
+ GNUNET_assert (NULL != c);
switch (pa_context_get_state (c))
+ {
+ case PA_CONTEXT_CONNECTING:
+ case PA_CONTEXT_AUTHORIZING:
+ case PA_CONTEXT_SETTING_NAME:
+ break;
+ case PA_CONTEXT_READY:
+ {
+ GNUNET_assert (!stream_out);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Connection established.\n"));
+ if (!(stream_out =
+ pa_stream_new (c, "GNUNET VoIP playback", &sample_spec, NULL)))
{
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- break;
-
- case PA_CONTEXT_READY:
- {
- GNUNET_assert (c);
- GNUNET_assert (!stream_out);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connection established.\n"));
-
-
- if (!
- (stream_out =
- pa_stream_new (c, "GNUNET VoIP playback", &sample_spec, NULL)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_stream_new() failed: %s\n"),
- pa_strerror (pa_context_errno (c)));
- goto fail;
- }
-
- pa_stream_set_write_callback (stream_out, stream_write_callback,
- NULL);
-
- if ((p =
- pa_stream_connect_playback (stream_out, NULL, NULL, 0, NULL,
- NULL)) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_stream_connect_playback() failed: %s\n"),
- pa_strerror (pa_context_errno (c)));
- goto fail;
- }
-
- break;
- }
-
- case PA_CONTEXT_TERMINATED:
- quit (0);
- break;
-
- case PA_CONTEXT_FAILED:
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connection failure: %s\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_new() failed: %s\n"),
pa_strerror (pa_context_errno (c)));
goto fail;
- }
-
- return;
-
-fail:
+ }
+ pa_stream_set_write_callback (stream_out,
+ stream_write_callback,
+ NULL);
+ if ((p =
+ pa_stream_connect_playback (stream_out, NULL, NULL, 0, NULL,
+ NULL)) < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_connect_playback() failed: %s\n"),
+ pa_strerror (pa_context_errno (c)));
+ goto fail;
+ }
+ break;
+ }
+ case PA_CONTEXT_TERMINATED:
+ quit (0);
+ break;
+
+ case PA_CONTEXT_FAILED:
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Connection failure: %s\n"),
+ pa_strerror (pa_context_errno (c)));
+ goto fail;
+ }
+ return;
+ fail:
quit (1);
}
@@ -324,22 +308,18 @@
int r;
if (!pa_sample_spec_valid (&sample_spec))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Wrong Spec\n"));
- }
-
- /* set up threaded playback mainloop */
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Wrong Spec\n"));
+ }
+ /* set up threaded playback mainloop */
if (!(m = pa_threaded_mainloop_new ()))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_mainloop_new() failed.\n"));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_mainloop_new() failed.\n"));
+ }
mainloop_api = pa_threaded_mainloop_get_api (m);
-
-
/* listen to signals */
-
r = pa_signal_init (mainloop_api);
GNUNET_assert (r == 0);
pa_signal_new (SIGINT, exit_signal_callback, NULL);
@@ -347,25 +327,24 @@
/* connect to the main pulseaudio context */
-
if (!(context = pa_context_new (mainloop_api, "GNUnet VoIP")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_context_new() failed.\n"));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_context_new() failed.\n"));
+ }
pa_context_set_state_callback (context, context_state_callback, NULL);
if (pa_context_connect (context, NULL, 0, NULL) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_context_connect() failed: %s\n"),
- pa_strerror (pa_context_errno (context)));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_context_connect() failed: %s\n"),
+ pa_strerror (pa_context_errno (context)));
+ }
if (pa_threaded_mainloop_start (m) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_mainloop_run() failed.\n"));
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_mainloop_run() failed.\n"));
+ }
}
@@ -377,11 +356,11 @@
{
int err;
int channels = 1;
- sampling_rate = 48000;
- frame_size = sampling_rate / 50;
+
+ frame_size = SAMPLING_RATE / 50;
pcm_length = frame_size * channels * sizeof (float);
- dec = opus_decoder_create (sampling_rate, channels, &err);
+ dec = opus_decoder_create (SAMPLING_RATE, channels, &err);
pcm_buffer = (float *) pa_xmalloc (frame_size * channels * sizeof (float));
}
@@ -396,20 +375,26 @@
int
main (int argc, char *argv[])
{
+ static unsigned long long toff;
+
char readbuf[MAXLINE];
struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
- fprintf (stderr, "HERE!\n");
GNUNET_assert (GNUNET_OK ==
GNUNET_log_setup ("gnunet-helper-audio-playback",
- "WARNING",
- NULL));
+ "DEBUG",
+ "/tmp/helper-audio-playback"));
stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, NULL);
opus_init ();
pa_init ();
while (1)
{
ssize_t ret = read (0, readbuf, sizeof (readbuf));
+ toff += ret;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %d bytes of audio data (total: %llu)\n",
+ (int) ret,
+ toff);
if (0 > ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -417,6 +402,8 @@
strerror (errno));
break;
}
+ if (0 == ret)
+ break;
GNUNET_SERVER_mst_receive (stdin_mst, NULL,
readbuf, ret,
GNUNET_NO, GNUNET_NO);
Modified: gnunet/src/conversation/gnunet-helper-audio-record.c
===================================================================
--- gnunet/src/conversation/gnunet-helper-audio-record.c 2013-10-02
21:19:33 UTC (rev 29807)
+++ gnunet/src/conversation/gnunet-helper-audio-record.c 2013-10-02
22:13:12 UTC (rev 29808)
@@ -22,6 +22,7 @@
* @brief constants for network protocols
* @author Siomon Dieterle
* @author Andreas Fuchs
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -38,13 +39,15 @@
#include <opus/opus.h>
#include <opus/opus_types.h>
+#define SAMPLING_RATE 48000
+
/**
* Specification for recording. May change in the future to spec negotiation.
*/
static pa_sample_spec sample_spec = {
.format = PA_SAMPLE_FLOAT32LE,
- .rate = 48000,
+ .rate = SAMPLING_RATE,
.channels = 1
};
@@ -106,7 +109,7 @@
/**
* Audio buffer
*/
-static void *transmit_buffer;
+static char *transmit_buffer;
/**
* Length of audio buffer
@@ -141,15 +144,21 @@
static void
packetizer ()
{
+ static unsigned long long toff;
+ char *nbuf;
+ size_t new_size;
+ const char *ptr;
+ size_t off;
+ ssize_t ret;
+ int len; // FIXME: int?
+ size_t msg_size;
+
while (transmit_buffer_length >= transmit_buffer_index + pcm_length)
{
- ssize_t ret;
- int len; // FIXME: int?
- size_t msg_size;
-
memcpy (pcm_buffer,
- (float *) transmit_buffer +
- (transmit_buffer_index / sizeof (float)), pcm_length);
+ &transmit_buffer[transmit_buffer_index],
+ pcm_length);
+ transmit_buffer_index += pcm_length;
len =
opus_encode_float (enc, pcm_buffer, frame_size, opus_data,
max_payload_bytes);
@@ -162,25 +171,43 @@
audio_message->header.size = htons ((uint16_t) msg_size);
memcpy (&audio_message[1], opus_data, len);
- // FIXME: handle partial writes better...
- if ((ret = write (1, audio_message, msg_size)) != msg_size)
+ toff += msg_size;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %u bytes of audio data (total: %llu)\n",
+ (unsigned int) msg_size,
+ toff);
+ ptr = (const char *) audio_message;
+ off = 0;
+ while (off < msg_size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("write"));
- return;
- }
- transmit_buffer_index += pcm_length;
+ ret = write (1, &ptr[off], msg_size - off);
+ if (0 >= ret)
+ {
+ if (-1 == ret)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write");
+ quit (2);
+ }
+ off += ret;
+ }
}
- int new_size = transmit_buffer_length - transmit_buffer_index;
+ new_size = transmit_buffer_length - transmit_buffer_index;
if (0 != new_size)
{
- transmit_buffer = pa_xrealloc (transmit_buffer, new_size);
- memcpy (transmit_buffer, transmit_buffer + transmit_buffer_index,
- new_size);
-
- transmit_buffer_index = 0;
- transmit_buffer_length = new_size;
+ nbuf = pa_xmalloc (new_size);
+ memmove (nbuf,
+ &transmit_buffer[transmit_buffer_index],
+ new_size);
+ pa_xfree (transmit_buffer);
+ transmit_buffer = nbuf;
}
+ else
+ {
+ pa_xfree (transmit_buffer);
+ transmit_buffer = NULL;
+ }
+ transmit_buffer_index = 0;
+ transmit_buffer_length = new_size;
}
@@ -188,31 +215,33 @@
* Pulseaudio callback when new data is available.
*/
static void
-stream_read_callback (pa_stream * s, size_t length, void *userdata)
+stream_read_callback (pa_stream * s,
+ size_t length,
+ void *userdata)
{
const void *data;
- GNUNET_assert (s);
+ GNUNET_assert (NULL != s);
GNUNET_assert (length > 0);
if (stdio_event)
mainloop_api->io_enable (stdio_event, PA_IO_EVENT_OUTPUT);
if (pa_stream_peek (s, (const void **) &data, &length) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_stream_peek() failed: %s\n"),
- pa_strerror (pa_context_errno (context)));
- quit (1);
- return;
- }
-
- GNUNET_assert (data);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_peek() failed: %s\n"),
+ pa_strerror (pa_context_errno (context)));
+ quit (1);
+ return;
+ }
+ GNUNET_assert (NULL != data);
GNUNET_assert (length > 0);
-
- if (transmit_buffer)
+ if (NULL != transmit_buffer)
{
- transmit_buffer =
- pa_xrealloc (transmit_buffer, transmit_buffer_length + length);
- memcpy ((uint8_t *) transmit_buffer + transmit_buffer_length, data,
+ transmit_buffer = pa_xrealloc (transmit_buffer,
+ transmit_buffer_length + length);
+ memcpy (&transmit_buffer[transmit_buffer_length],
+ data,
length);
transmit_buffer_length += length;
}
@@ -249,61 +278,57 @@
static void
stream_state_callback (pa_stream * s, void *userdata)
{
- GNUNET_assert (s);
+ GNUNET_assert (NULL != s);
switch (pa_stream_get_state (s))
+ {
+ case PA_STREAM_CREATING:
+ case PA_STREAM_TERMINATED:
+ break;
+ case PA_STREAM_READY:
{
- case PA_STREAM_CREATING:
- case PA_STREAM_TERMINATED:
- break;
-
- case PA_STREAM_READY:
- if (1)
- {
- const pa_buffer_attr *a;
- char cmt[PA_CHANNEL_MAP_SNPRINT_MAX],
- sst[PA_SAMPLE_SPEC_SNPRINT_MAX];
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Stream successfully created.\n"));
-
- if (!(a = pa_stream_get_buffer_attr (s)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_stream_get_buffer_attr() failed: %s\n"),
- pa_strerror (pa_context_errno
- (pa_stream_get_context (s))));
-
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Buffer metrics: maxlength=%u, fragsize=%u\n"),
- a->maxlength, a->fragsize);
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Using sample spec '%s', channel map '%s'.\n"),
- pa_sample_spec_snprint (sst, sizeof (sst),
- pa_stream_get_sample_spec (s)),
- pa_channel_map_snprint (cmt, sizeof (cmt),
- pa_stream_get_channel_map (s)));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Connected to device %s (%u, %ssuspended).\n"),
- pa_stream_get_device_name (s),
- pa_stream_get_device_index (s),
- pa_stream_is_suspended (s) ? "" : "not ");
- }
-
- break;
-
- case PA_STREAM_FAILED:
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Stream error: %s\n"),
- pa_strerror (pa_context_errno (pa_stream_get_context (s))));
- quit (1);
- }
+ const pa_buffer_attr *a;
+ char cmt[PA_CHANNEL_MAP_SNPRINT_MAX],
+ sst[PA_SAMPLE_SPEC_SNPRINT_MAX];
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Stream successfully created.\n"));
+
+ if (!(a = pa_stream_get_buffer_attr (s)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_get_buffer_attr() failed: %s\n"),
+ pa_strerror (pa_context_errno
+ (pa_stream_get_context (s))));
+
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Buffer metrics: maxlength=%u, fragsize=%u\n"),
+ a->maxlength, a->fragsize);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Using sample spec '%s', channel map '%s'.\n"),
+ pa_sample_spec_snprint (sst, sizeof (sst),
+ pa_stream_get_sample_spec (s)),
+ pa_channel_map_snprint (cmt, sizeof (cmt),
+ pa_stream_get_channel_map (s)));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Connected to device %s (%u, %ssuspended).\n"),
+ pa_stream_get_device_name (s),
+ pa_stream_get_device_index (s),
+ pa_stream_is_suspended (s) ? "" : "not ");
+ }
+ break;
+ case PA_STREAM_FAILED:
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Stream error: %s\n"),
+ pa_strerror (pa_context_errno (pa_stream_get_context (s))));
+ quit (1);
+ }
}
@@ -317,58 +342,48 @@
GNUNET_assert (c);
switch (pa_context_get_state (c))
+ {
+ case PA_CONTEXT_CONNECTING:
+ case PA_CONTEXT_AUTHORIZING:
+ case PA_CONTEXT_SETTING_NAME:
+ break;
+ case PA_CONTEXT_READY:
+ {
+ int r;
+
+ GNUNET_assert (!stream_in);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Connection established.\n"));
+ if (! (stream_in =
+ pa_stream_new (c, "GNUNET_VoIP recorder", &sample_spec, NULL)))
{
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- break;
-
- case PA_CONTEXT_READY:
- {
- int r;
-
- GNUNET_assert (c);
- GNUNET_assert (!stream_in);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connection established.\n"));
-
- if (!
- (stream_in =
- pa_stream_new (c, "GNUNET_VoIP recorder", &sample_spec, NULL)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_stream_new() failed: %s\n"),
- pa_strerror (pa_context_errno (c)));
- goto fail;
- }
-
-
- pa_stream_set_state_callback (stream_in, stream_state_callback, NULL);
- pa_stream_set_read_callback (stream_in, stream_read_callback, NULL);
-
-
- if ((r = pa_stream_connect_record (stream_in, NULL, NULL, 0)) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_stream_connect_record() failed: %s\n"),
- pa_strerror (pa_context_errno (c)));
- goto fail;
- }
-
- break;
- }
-
- case PA_CONTEXT_TERMINATED:
- quit (0);
- break;
-
- case PA_CONTEXT_FAILED:
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connection failure: %s\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_new() failed: %s\n"),
pa_strerror (pa_context_errno (c)));
goto fail;
}
-
+ pa_stream_set_state_callback (stream_in, stream_state_callback, NULL);
+ pa_stream_set_read_callback (stream_in, stream_read_callback, NULL);
+ if ((r = pa_stream_connect_record (stream_in, NULL, NULL, 0)) < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_stream_connect_record() failed: %s\n"),
+ pa_strerror (pa_context_errno (c)));
+ goto fail;
+ }
+
+ break;
+ }
+ case PA_CONTEXT_TERMINATED:
+ quit (0);
+ break;
+ case PA_CONTEXT_FAILED:
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Connection failure: %s\n"),
+ pa_strerror (pa_context_errno (c)));
+ goto fail;
+ }
return;
fail:
@@ -386,21 +401,19 @@
int i;
if (!pa_sample_spec_valid (&sample_spec))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong Spec\n"));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Wrong Spec\n"));
+ }
/* set up main record loop */
-
if (!(m = pa_mainloop_new ()))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_mainloop_new() failed.\n"));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_mainloop_new() failed.\n"));
+ }
mainloop_api = pa_mainloop_get_api (m);
/* listen to signals */
-
r = pa_signal_init (mainloop_api);
GNUNET_assert (r == 0);
pa_signal_new (SIGINT, exit_signal_callback, NULL);
@@ -409,23 +422,22 @@
/* connect to the main pulseaudio context */
if (!(context = pa_context_new (mainloop_api, "GNUNET VoIP")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_context_new() failed.\n"));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_context_new() failed.\n"));
+ }
pa_context_set_state_callback (context, context_state_callback, NULL);
-
if (pa_context_connect (context, NULL, 0, NULL) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("pa_context_connect() failed: %s\n"),
- pa_strerror (pa_context_errno (context)));
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_context_connect() failed: %s\n"),
+ pa_strerror (pa_context_errno (context)));
+ }
if (pa_mainloop_run (m, &i) < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("pa_mainloop_run() failed.\n"));
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("pa_mainloop_run() failed.\n"));
+ }
}
@@ -435,20 +447,17 @@
static void
opus_init ()
{
- opus_int32 sampling_rate = 48000;
int channels = 1;
int err;
- frame_size = sampling_rate / 50;
+ frame_size = SAMPLING_RATE / 50;
pcm_length = frame_size * channels * sizeof (float);
- enc =
- opus_encoder_create (sampling_rate, channels, OPUS_APPLICATION_VOIP,
- &err);
- pcm_buffer = (float *) pa_xmalloc (pcm_length);
- opus_data = (unsigned char *) calloc (max_payload_bytes, sizeof (char));
-
- audio_message = pa_xmalloc (UINT16_MAX);
- audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
+ pcm_buffer = pa_xmalloc (pcm_length);
+ opus_data = GNUNET_malloc (max_payload_bytes);
+ enc = opus_encoder_create (SAMPLING_RATE,
+ channels,
+ OPUS_APPLICATION_VOIP,
+ &err);
}
@@ -462,14 +471,13 @@
int
main (int argc, char *argv[])
{
- fprintf (stderr, "HERE2!\n");
-
GNUNET_assert (GNUNET_OK ==
GNUNET_log_setup ("gnunet-helper-audio-record",
- "WARNING",
- NULL));
+ "DEBUG",
+ "/tmp/helper-audio-record"));
+ audio_message = GNUNET_malloc (UINT16_MAX);
+ audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
opus_init ();
pa_init ();
-
return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29808 - gnunet/src/conversation,
gnunet <=