gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29806 - gnunet/src/conversation


From: gnunet
Subject: [GNUnet-SVN] r29806 - gnunet/src/conversation
Date: Wed, 2 Oct 2013 23:05:48 +0200

Author: grothoff
Date: 2013-10-02 23:05:48 +0200 (Wed, 02 Oct 2013)
New Revision: 29806

Modified:
   gnunet/src/conversation/conversation.h
   gnunet/src/conversation/gnunet-helper-audio-playback.c
   gnunet/src/conversation/gnunet-helper-audio-record.c
   gnunet/src/conversation/gnunet-service-conversation.c
   gnunet/src/conversation/microphone.c
   gnunet/src/conversation/speaker.c
Log:
-fix logging

Modified: gnunet/src/conversation/conversation.h
===================================================================
--- gnunet/src/conversation/conversation.h      2013-10-02 20:56:46 UTC (rev 
29805)
+++ gnunet/src/conversation/conversation.h      2013-10-02 21:05:48 UTC (rev 
29806)
@@ -396,12 +396,9 @@
    * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
    */
   struct GNUNET_MessageHeader header;
-  int32_t SequenceNumber;
-  struct GNUNET_TIME_Absolute time;
-  int32_t length;
-  int32_t encrypted;
-  uint8_t audio[200];
 
+  /* followed by audio data */
+
 };
 
 

Modified: gnunet/src/conversation/gnunet-helper-audio-playback.c
===================================================================
--- gnunet/src/conversation/gnunet-helper-audio-playback.c      2013-10-02 
20:56:46 UTC (rev 29805)
+++ gnunet/src/conversation/gnunet-helper-audio-playback.c      2013-10-02 
21:05:48 UTC (rev 29806)
@@ -55,77 +55,77 @@
 };
 
 /**
-* Pulseaudio mainloop api
-*/
+ * Pulseaudio mainloop api
+ */
 static pa_mainloop_api *mainloop_api;
 
 /**
-* Pulseaudio threaded mainloop
-*/
+ * Pulseaudio threaded mainloop
+ */
 static pa_threaded_mainloop *m;
 
 /**
-* Pulseaudio context
-*/
+ * Pulseaudio context
+ */
 static pa_context *context;
 
 /**
-* Pulseaudio output stream
-*/
+ * Pulseaudio output stream
+ */
 static pa_stream *stream_out;
 
 /**
-* Pulseaudio io events
-*/
+ * Pulseaudio io events
+ */
 static pa_io_event *stdio_event;
 
 /**
-* OPUS decoder
-*/
+ * OPUS decoder
+ */
 static OpusDecoder *dec;
 
 /**
-* PCM data buffer
-*/
+ * PCM data buffer
+ */
 static float *pcm_buffer;
 
 /**
-* Length of PCM buffer
-*/
+ * Length of PCM buffer
+ */
 static int pcm_length;
 
 /**
-* Number of samples for one frame
-*/
+ * Number of samples for one frame
+ */
 static int frame_size;
 
 /**
-* The sampling rate used in Pulseaudio specification
-*/
+ * The sampling rate used in Pulseaudio specification
+ */
 static opus_int32 sampling_rate;
 
 /**
-* Audio buffer
-*/
+ * Audio buffer
+ */
 static void *buffer;
 
 /**
-* Length of audio buffer
-*/
+ * Length of audio buffer
+ */
 static size_t buffer_length;
 
 /**
-* Read index for transmit buffer
-*/
+ * Read index for transmit buffer
+ */
 static size_t buffer_index;
 
 
-
 /**
-* Message callback
-*/
+ * Message callback
+ */
 static void
-stdin_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
+stdin_receiver (void *cls, 
+               const struct GNUNET_MessageHeader *msg)
 {
   struct AudioMessage *audio;
 
@@ -135,9 +135,12 @@
       audio = (struct AudioMessage *) msg;
 
       int len =
-       opus_decode_float (dec, audio->audio, audio->length, pcm_buffer,
+       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???
       if (pa_stream_write
          (stream_out, (uint8_t *) pcm_buffer, pcm_length, NULL, 0,
           PA_SEEK_RELATIVE) < 0)
@@ -156,9 +159,10 @@
     }
 }
 
+
 /**
-* Pulseaudio shutdown task
-*/
+ * Pulseaudio shutdown task
+ */
 static void
 quit (int ret)
 {
@@ -166,9 +170,10 @@
   exit (ret);
 }
 
+
 /**
-* Write some data to the stream 
-*/
+ * Write some data to the stream 
+ */
 static void
 do_stream_write (size_t length)
 {
@@ -210,9 +215,10 @@
     }
 }
 
+
 /**
-* Callback when data is there for playback
-*/
+ * Callback when data is there for playback
+ */
 static void
 stream_write_callback (pa_stream * s, size_t length, void *userdata)
 {
@@ -232,9 +238,10 @@
   do_stream_write (length);
 }
 
+
 /**
-* Exit callback for SIGTERM and SIGINT
-*/
+ * Exit callback for SIGTERM and SIGINT
+ */
 static void
 exit_signal_callback (pa_mainloop_api * m, pa_signal_event * e, int sig,
                      void *userdata)
@@ -244,9 +251,10 @@
   quit (1);
 }
 
+
 /**
-* Pulseaudio stream state callback
-*/
+ * Pulseaudio stream state callback
+ */
 static void
 context_state_callback (pa_context * c, void *userdata)
 {
@@ -309,13 +317,13 @@
 
 fail:
   quit (1);
-
 }
 
+
 /**
-* Pulseaudio initialization
-*/
-void
+ * Pulseaudio initialization
+ */
+static void
 pa_init ()
 {
   int r;
@@ -365,10 +373,11 @@
     }
 }
 
+
 /**
-* OPUS initialization
-*/
-void
+ * OPUS initialization
+ */
+static void
 opus_init ()
 {
   int err;
@@ -381,6 +390,7 @@
   pcm_buffer = (float *) pa_xmalloc (frame_size * channels * sizeof (float));
 }
 
+
 /**
  * The main function for the playback helper.
  *
@@ -394,25 +404,25 @@
   char readbuf[MAXLINE];
   struct MessageStreamTokenizer *stdin_mst;
 
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_log_setup ("gnunet-helper-audio-playback",
+                                  "WARNING",
+                                  NULL));
   stdin_mst = mst_create (&stdin_receiver, NULL);
-
   opus_init ();
   pa_init ();
-
   while (1)
+  {
+    ssize_t ret = read (0, readbuf, sizeof (readbuf));   
+    if (0 > ret)
     {
-      ssize_t ret = read (0, readbuf, sizeof (readbuf));
-
-      if (0 > ret)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     _("Read error from STDIN: %s\n"), strerror (errno));
-         break;
-       }
-
-      mst_receive (stdin_mst, readbuf, ret);
-    }
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Read error from STDIN: %s\n"), 
+                 strerror (errno));
+      break;
+    }    
+    mst_receive (stdin_mst, readbuf, ret);
+  }
   mst_destroy (stdin_mst);
-
   return 0;
 }

Modified: gnunet/src/conversation/gnunet-helper-audio-record.c
===================================================================
--- gnunet/src/conversation/gnunet-helper-audio-record.c        2013-10-02 
20:56:46 UTC (rev 29805)
+++ gnunet/src/conversation/gnunet-helper-audio-record.c        2013-10-02 
21:05:48 UTC (rev 29806)
@@ -74,11 +74,6 @@
 static pa_io_event *stdio_event;
 
 /**
- * Message tokenizer
- */
-static struct MessageStreamTokenizer *stdin_mst;
-
-/**
  * OPUS encoder
  */
 static OpusEncoder *enc;
@@ -148,55 +143,57 @@
 {
   while (transmit_buffer_length >= transmit_buffer_index + pcm_length)
   {
-      int ret;
-      int len;
+    ssize_t ret;
+    int len; // FIXME: int?
+    size_t msg_size;
 
-      size_t msg_size = sizeof (struct AudioMessage);
+    memcpy (pcm_buffer,
+           (float *) transmit_buffer +
+           (transmit_buffer_index / sizeof (float)), pcm_length);
+    len =
+      opus_encode_float (enc, pcm_buffer, frame_size, opus_data,
+                        max_payload_bytes);
+    if (len > UINT16_MAX - sizeof (struct AudioMessage))
+    {
+      GNUNET_break (0);
+      len = UINT16_MAX - sizeof (struct AudioMessage);
+    }
+    msg_size = sizeof (struct AudioMessage) + len;
+    audio_message->header.size = htons ((uint16_t) msg_size);
+    memcpy (&audio_message[1], opus_data, len);
 
-      memcpy (pcm_buffer,
-             (float *) transmit_buffer +
-             (transmit_buffer_index / sizeof (float)), pcm_length);
-      len =
-       opus_encode_float (enc, pcm_buffer, frame_size, opus_data,
-                          max_payload_bytes);
+    // FIXME: handle partial writes better...
+    if ((ret = write (1, audio_message, msg_size)) != msg_size)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("write"));
+      return;
+    }    
+    transmit_buffer_index += pcm_length;
+  }
 
-      audio_message->length = len;
-      memcpy (audio_message->audio, opus_data, len);
-
-      if ((ret = write (1, audio_message, msg_size)) != msg_size)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("write"));
-         return;
-       }
-
-      transmit_buffer_index += pcm_length;
-    }
-
   int 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;
+  }
+}
 
-      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;
-    }
-
-}
-
 /**
-* Pulseaudio callback when new data is available.
-*/
+ * Pulseaudio callback when new data is available.
+ */
 static void
 stream_read_callback (pa_stream * s, size_t length, void *userdata)
 {
   const void *data;
+
   GNUNET_assert (s);
   GNUNET_assert (length > 0);
-
   if (stdio_event)
     mainloop_api->io_enable (stdio_event, PA_IO_EVENT_OUTPUT);
 
@@ -212,39 +209,43 @@
   GNUNET_assert (length > 0);
 
   if (transmit_buffer)
-    {
-      transmit_buffer =
-       pa_xrealloc (transmit_buffer, transmit_buffer_length + length);
-      memcpy ((uint8_t *) transmit_buffer + transmit_buffer_length, data,
-             length);
-      transmit_buffer_length += length;
-    }
+  {
+    transmit_buffer =
+      pa_xrealloc (transmit_buffer, transmit_buffer_length + length);
+    memcpy ((uint8_t *) transmit_buffer + transmit_buffer_length, data,
+           length);
+    transmit_buffer_length += length;
+  }
   else
-    {
-      transmit_buffer = pa_xmalloc (length);
-      memcpy (transmit_buffer, data, length);
-      transmit_buffer_length = length;
-      transmit_buffer_index = 0;
-    }
-
+  {
+    transmit_buffer = pa_xmalloc (length);
+    memcpy (transmit_buffer, data, length);
+    transmit_buffer_length = length;
+    transmit_buffer_index = 0;
+  }
   pa_stream_drop (s);
   packetizer ();
 }
 
+
 /**
-* Exit callback for SIGTERM and SIGINT
-*/
+ * Exit callback for SIGTERM and SIGINT
+ */
 static void
-exit_signal_callback (pa_mainloop_api * m, pa_signal_event * e, int sig,
+exit_signal_callback (pa_mainloop_api * m, 
+                     pa_signal_event * e, 
+                     int sig,
                      void *userdata)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got signal, exiting.\n"));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+             _("Got signal, exiting.\n"));
   quit (1);
 }
 
+
 /**
-* Pulseaudio stream state callback
-*/
+ * Pulseaudio stream state callback
+ */
 static void
 stream_state_callback (pa_stream * s, void *userdata)
 {
@@ -305,11 +306,13 @@
     }
 }
 
+
 /**
-* Pulseaudio context state callback
-*/
+ * Pulseaudio context state callback
+ */
 static void
-context_state_callback (pa_context * c, void *userdata)
+context_state_callback (pa_context * c,
+                       void *userdata)
 {
   GNUNET_assert (c);
 
@@ -370,13 +373,13 @@
 
 fail:
   quit (1);
-
 }
 
+
 /**
  * Pulsaudio init
  */
-void
+static void
 pa_init ()
 {
   int r;
@@ -425,28 +428,26 @@
     }
 }
 
+
 /**
  * OPUS init
  */
-void
+static void
 opus_init ()
 {
   opus_int32 sampling_rate = 48000;
-  frame_size = sampling_rate / 50;
   int channels = 1;
+  int err;
 
+  frame_size = sampling_rate / 50;
   pcm_length = frame_size * channels * sizeof (float);
-
-  int err;
-
   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 (sizeof (struct AudioMessage));
-  audio_message->header.size = htons (sizeof (struct AudioMessage));
+  audio_message = pa_xmalloc (UINT16_MAX);
   audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
 }
 
@@ -461,6 +462,10 @@
 int
 main (int argc, char *argv[])
 {
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_log_setup ("gnunet-helper-audio-record",
+                                  "WARNING",
+                                  NULL));
   opus_init ();
   pa_init ();
 

Modified: gnunet/src/conversation/gnunet-service-conversation.c
===================================================================
--- gnunet/src/conversation/gnunet-service-conversation.c       2013-10-02 
20:56:46 UTC (rev 29805)
+++ gnunet/src/conversation/gnunet-service-conversation.c       2013-10-02 
21:05:48 UTC (rev 29806)
@@ -128,36 +128,31 @@
 /**
 * List for missed calls
 */
-struct GNUNET_CONTAINER_SList *missed_calls;
+static struct GNUNET_CONTAINER_SList *missed_calls;
 
 /**
 * List for peers to notify that we are available again
 */
-struct GNUNET_CONTAINER_SList *peers_to_notify;
+static struct GNUNET_CONTAINER_SList *peers_to_notify;
 
 /**
 * Audio buffer (outgoing)
 */
-struct GNUNET_CONTAINER_SList *audio_buffer;
+static struct GNUNET_CONTAINER_SList *audio_buffer;
 
 /**
 * The pointer to the task for sending audio
 */
-GNUNET_SCHEDULER_TaskIdentifier audio_task;
+static GNUNET_SCHEDULER_TaskIdentifier audio_task;
 
 /**
 * The pointer to the task for checking timeouts an calling a peer
 */
-GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
 
 /**
-* Sequencenumber for the pakets (for evaltuation purposes)
-*/
-int SequenceNumber = 0;
-
-/**
-* Timestamp for call statistics
-*/
+ * Timestamp for call statistics
+ */
 static struct GNUNET_TIME_Absolute start_time;
 
 /**
@@ -891,8 +886,6 @@
 {
   struct VoIPMeshMessageHeader *msg_header =
     (struct VoIPMeshMessageHeader *) cls;
-  msg_header->SequenceNumber = SequenceNumber += 1;
-  msg_header->time = GNUNET_TIME_absolute_get ();
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting message over mesh\n"));
 
@@ -984,9 +977,6 @@
       iterator = GNUNET_CONTAINER_slist_begin (audio_buffer);
       msg =
        (struct AudioMessage *) GNUNET_CONTAINER_slist_get (&iterator, NULL);
-      msg->SequenceNumber = SequenceNumber += 1;
-      msg->time = GNUNET_TIME_absolute_get ();
-
       GNUNET_CONTAINER_slist_erase (&iterator);
       GNUNET_CONTAINER_slist_iter_destroy (&iterator);
     }
@@ -1344,30 +1334,19 @@
                           void **tunnel_ctx,
                           const struct GNUNET_MessageHeader *message)
 {
+  const struct AudioMessage *audio;
+  audio = (const struct AudioMessage *) message;
 
   GNUNET_MESH_receive_done (tunnel);
-
   if (CONNECTED != connection.status)
     return GNUNET_OK;
-
-
-  struct AudioMessage *audio;
-  size_t msg_size;
-  msg_size = sizeof (struct AudioMessage);
-
-  audio = (struct AudioMessage *) message;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "[RECV] %dbytes\n", audio->length);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+             "[RECV] %dbytes\n", 
+             ntohs (audio->header.size));
   if (NULL == playback_helper)
     return GNUNET_OK;
-
   (void) GNUNET_HELPER_send (playback_helper,
                             message, GNUNET_YES, NULL, NULL);
-
-  data_received++;
-  data_received_size += msg_size;
-
   return GNUNET_OK;
 }
 
@@ -1387,14 +1366,14 @@
 process_record_messages (void *cls GNUNET_UNUSED, void *client,
                         const struct GNUNET_MessageHeader *msg)
 {
-  size_t msg_size;
-  struct AudioMessage *message = (struct AudioMessage *) msg;
-  msg_size = sizeof (struct AudioMessage);
+  const struct AudioMessage *message = (const struct AudioMessage *) msg;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, " [REC] %dbyte\n", message->length);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+             " [REC] %dbyte\n", 
+             ntohs (message->header.size));
   GNUNET_CONTAINER_slist_add_end (audio_buffer,
                                  GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
-                                 message, msg_size);
+                                 message, ntohs (message->header.size));
 
   return GNUNET_OK;
 }

Modified: gnunet/src/conversation/microphone.c
===================================================================
--- gnunet/src/conversation/microphone.c        2013-10-02 20:56:46 UTC (rev 
29805)
+++ gnunet/src/conversation/microphone.c        2013-10-02 21:05:48 UTC (rev 
29806)
@@ -75,14 +75,13 @@
 {
   struct Microphone *mic = cls;
 
-  if ( (ntohs (msg->size) != sizeof (struct AudioMessage)) ||
-       (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO) )
+  if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO)
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
   mic->rdc (mic->rdc_cls,
-           sizeof (struct AudioMessage),
+           ntohs (msg->size),
            (const char *) msg);
   return GNUNET_OK;
 }

Modified: gnunet/src/conversation/speaker.c
===================================================================
--- gnunet/src/conversation/speaker.c   2013-10-02 20:56:46 UTC (rev 29805)
+++ gnunet/src/conversation/speaker.c   2013-10-02 21:05:48 UTC (rev 29806)
@@ -137,7 +137,7 @@
     GNUNET_break (0);
     return;
   }
-  if (sizeof (struct AudioMessage) != data_size)
+  if (sizeof (struct AudioMessage) > data_size)
   {
     GNUNET_break (0);
     return;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]