gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r29801 - gnunet/src/conversation
Date: Wed, 2 Oct 2013 22:06:07 +0200

Author: grothoff
Date: 2013-10-02 22:06:07 +0200 (Wed, 02 Oct 2013)
New Revision: 29801

Added:
   gnunet/src/conversation/gnunet-conversation-test.c
Modified:
   gnunet/src/conversation/Makefile.am
Log:
-tool to record and replay, to test microphone and speaker logic

Modified: gnunet/src/conversation/Makefile.am
===================================================================
--- gnunet/src/conversation/Makefile.am 2013-10-02 19:48:12 UTC (rev 29800)
+++ gnunet/src/conversation/Makefile.am 2013-10-02 20:06:07 UTC (rev 29801)
@@ -55,7 +55,9 @@
   -version-info 0:0:0
 
 
-bin_PROGRAMS = gnunet-conversation
+bin_PROGRAMS = \
+ gnunet-conversation-test \
+ gnunet-conversation
 
 libexec_PROGRAMS = \
   gnunet-service-conversation 
@@ -83,7 +85,7 @@
   -lpulse  -lopus\
   $(INTLLIBS) 
 gnunet_helper_audio_record_LDFLAGS = \
-  $(GNUNET_LDFLAGS)  $(WINFLAGS) -export-dynamic
+  $(GNUNET_LDFLAGS)  $(WINFLAGS) 
 
 gnunet_helper_audio_playback_SOURCES = \
   gnunet-helper-audio-playback.c
@@ -92,7 +94,7 @@
   -lpulse -lopus\
   $(INTLLIBS) 
 gnunet_helper_audio_playback_LDFLAGS = \
-  $(GNUNET_LDFLAGS)  $(WINFLAGS) -export-dynamic  
+  $(GNUNET_LDFLAGS)  $(WINFLAGS) 
 
 gnunet_service_conversation_SOURCES = \
   gnunet-service-conversation.c
@@ -100,7 +102,7 @@
   -lgnunetutil -lgnunetmesh -lgnunetnamestore -lgnunetgns\
     $(INTLLIBS) 
 gnunet_service_conversation_LDFLAGS = \
-  $(GNUNET_LDFLAGS)  $(WINFLAGS) -export-dynamic 
+  $(GNUNET_LDFLAGS)  $(WINFLAGS) 
 
 gnunet_conversation_SOURCES = \
   gnunet-conversation.c
@@ -108,8 +110,17 @@
   -lgnunetutil -lgnunetconversation \
   $(INTLLIBS) 
 gnunet_conversation_LDFLAGS = \
- $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic 
+ $(GNUNET_LDFLAGS) $(WINFLAGS) 
 
+gnunet_conversation_test_SOURCES = \
+  gnunet-conversation-test.c
+gnunet_conversation_test_LDADD = \
+  libgnunetmicrophone.la \
+  libgnunetspeaker.la \
+  $(top_builddir)/src/util/libgnunetutil.la 
+  $(INTLLIBS) 
+gnunet_conversation_test_LDFLAGS = \
+ $(GNUNET_LDFLAGS) $(WINFLAGS) 
 
 
 test_conversation_api_SOURCES = \

Added: gnunet/src/conversation/gnunet-conversation-test.c
===================================================================
--- gnunet/src/conversation/gnunet-conversation-test.c                          
(rev 0)
+++ gnunet/src/conversation/gnunet-conversation-test.c  2013-10-02 20:06:07 UTC 
(rev 29801)
@@ -0,0 +1,243 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file conversation/gnunet-conversation-test.c
+ * @brief tool to test speaker and microphone (for end users!)
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_speaker_lib.h" 
+#include "gnunet_microphone_lib.h" 
+
+/**
+ * How long do we record before we replay?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+
+
+/**
+ * A recording we made.
+ */
+struct Recording
+{
+  /**
+   * Kept in a DLL.
+   */
+  struct Recording *next;
+
+  /**
+   * Kept in a DLL.
+   */
+  struct Recording *prev;
+
+  /**
+   * Number of bytes that follow.
+   */
+  size_t size;
+};
+
+
+/**
+ * Final status code.
+ */
+static int ret;
+
+/**
+ * Handle to the microphone.
+ */
+static struct GNUNET_MICROPHONE_Handle *microphone;
+
+/**
+ * Handle to the speaker.
+ */
+static struct GNUNET_SPEAKER_Handle *speaker;
+
+/**
+ * Task scheduled to switch from recording to playback.
+ */
+static GNUNET_SCHEDULER_TaskIdentifier switch_task;
+
+/**
+ * The shutdown task.
+ */
+static GNUNET_SCHEDULER_TaskIdentifier st;
+
+/**
+ * Head of DLL with recorded frames.
+ */
+static struct Recording *rec_head;
+
+/**
+ * Tail of DLL with recorded frames.
+ */
+static struct Recording *rec_tail;
+
+
+/**
+ * Terminate test.
+ *
+ * @param cls NULL
+ * @param tc unused
+ */
+static void
+do_shutdown (void *cls,
+            const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct Recording *rec;
+
+  if (GNUNET_SCHEDULER_NO_TASK != switch_task)
+    GNUNET_SCHEDULER_cancel (switch_task);
+  if (NULL != microphone)
+    GNUNET_MICROPHONE_destroy (microphone);
+  if (NULL != speaker)
+    GNUNET_SPEAKER_destroy (speaker);
+  while (NULL != (rec = rec_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (rec_head,
+                                rec_tail,
+                                rec);
+    GNUNET_free (rec);
+  }
+  fprintf (stderr, "\n");
+}
+
+
+/**
+ * Terminate recording process and switch to playback.
+ *
+ * @param cls NULL
+ * @param tc unused
+ */
+static void
+switch_to_speaker (void *cls,
+                  const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct Recording *rec;
+
+  switch_task = GNUNET_SCHEDULER_NO_TASK;
+  microphone->disable_microphone (microphone->cls);
+  if (GNUNET_OK !=
+      speaker->enable_speaker (speaker->cls))
+  {
+    fprintf (stderr,
+            "Failed to enable microphone\n");
+    ret = 1;
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  fprintf (stderr, "\nPlaying...");
+  for (rec=rec_head;NULL != rec; rec = rec->next)
+    speaker->play (speaker->cls,
+                  rec->size,
+                  &rec[1]);
+  GNUNET_SCHEDULER_cancel (st);
+  st = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                    &do_shutdown,
+                                    NULL);
+}
+
+
+/**
+ * Process recorded audio data.
+ *
+ * @param cls clsoure
+ * @param data_size number of bytes in @a data
+ * @param data audio data to play
+ */
+static void 
+record (void *cls,
+       size_t data_size,
+       const void *data)
+{
+  struct Recording *rec;
+
+  fprintf (stderr, ".");
+  rec = GNUNET_malloc (sizeof (struct Recording) + data_size);
+  rec->size = data_size;
+  memcpy (&rec[1], data, data_size);
+  GNUNET_CONTAINER_DLL_insert_tail (rec_head,
+                                   rec_tail,
+                                   rec);
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  microphone = GNUNET_MICROPHONE_create_from_hardware (cfg);
+  GNUNET_assert (NULL != microphone);
+  speaker = GNUNET_SPEAKER_create_from_hardware (cfg);
+  GNUNET_assert (NULL != speaker);
+  switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                             &switch_to_speaker,
+                                             NULL);
+  st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                    &do_shutdown,
+                                    NULL);
+  fprintf (stderr, "Recording...");
+  if (GNUNET_OK !=
+      microphone->enable_microphone (microphone->cls,
+                                    &record, NULL))
+  {
+    fprintf (stderr,
+            "Failed to enable microphone\n");
+    ret = 1;
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+}
+
+
+/**
+ * The main function of our code to test microphone and speaker.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+
+  ret = (GNUNET_OK ==
+        GNUNET_PROGRAM_run (argc, argv, "gnunet-conversation-test",
+                            gettext_noop ("help text"), options, &run,
+                            NULL)) ? ret : 1;
+  GNUNET_free ((void*) argv);
+  return ret;
+}
+
+/* end of gnunet-conversation-test.c */




reply via email to

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