[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29798 - in gnunet/src: conversation include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29798 - in gnunet/src: conversation include util |
Date: |
Wed, 2 Oct 2013 21:29:22 +0200 |
Author: grothoff
Date: 2013-10-02 21:29:22 +0200 (Wed, 02 Oct 2013)
New Revision: 29798
Added:
gnunet/src/conversation/microphone.c
Modified:
gnunet/src/conversation/Makefile.am
gnunet/src/conversation/conversation.h
gnunet/src/conversation/gnunet-helper-audio-record.c
gnunet/src/include/gnunet_helper_lib.h
gnunet/src/include/gnunet_microphone_lib.h
gnunet/src/include/gnunet_speaker_lib.h
gnunet/src/util/server_mst.c
Log:
-implement microphone library
Modified: gnunet/src/conversation/Makefile.am
===================================================================
--- gnunet/src/conversation/Makefile.am 2013-10-02 19:06:07 UTC (rev 29797)
+++ gnunet/src/conversation/Makefile.am 2013-10-02 19:29:22 UTC (rev 29798)
@@ -14,17 +14,32 @@
# $(WINFLAGS) \
# -export-dynamic
-lib_LTLIBRARIES = libgnunetconversation.la
+lib_LTLIBRARIES = \
+ libgnunetmicrophone.la \
+ libgnunetconversation.la
pkgcfgdir= $(prefix)/share/gnunet/config.d/
libexecdir= $(prefix)/lib/gnunet/libexec/
+libgnunetmicrophone_la_SOURCES = \
+ microphone.c
+libgnunetmicrophone_la_LIBADD = \
+ -lgnunetutil
+libgnunetmicrophone_la_LDFLAGS = \
+ $(GNUNET_LDFLAGS) $(WINFLAGS) \
+ -version-info 0:0:0
+
+
libgnunetconversation_la_SOURCES = \
conversation_api.c \
conversation_api2.c
libgnunetconversation_la_LIBADD = \
- -lgnunetutil -lgnunetnamestore -lgnunetgns
+ libgnunetmicrophone.la \
+ $(top_builddir)/src/gns/libgnunetgns.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
libgnunetconversation_la_LDFLAGS = \
$(GNUNET_LDFLAGS) $(WINFLAGS) \
-version-info 0:0:0
Modified: gnunet/src/conversation/conversation.h
===================================================================
--- gnunet/src/conversation/conversation.h 2013-10-02 19:06:07 UTC (rev
29797)
+++ gnunet/src/conversation/conversation.h 2013-10-02 19:29:22 UTC (rev
29798)
@@ -396,10 +396,10 @@
* Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
*/
struct GNUNET_MessageHeader header;
- int SequenceNumber;
+ int32_t SequenceNumber;
struct GNUNET_TIME_Absolute time;
- int length;
- int encrypted;
+ int32_t length;
+ int32_t encrypted;
uint8_t audio[200];
};
Modified: gnunet/src/conversation/gnunet-helper-audio-record.c
===================================================================
--- gnunet/src/conversation/gnunet-helper-audio-record.c 2013-10-02
19:06:07 UTC (rev 29797)
+++ gnunet/src/conversation/gnunet-helper-audio-record.c 2013-10-02
19:29:22 UTC (rev 29798)
@@ -38,9 +38,10 @@
#include <opus/opus.h>
#include <opus/opus_types.h>
+
/**
-* Specification for recording. May change in the future to spec negotiation.
-*/
+ * Specification for recording. May change in the future to spec negotiation.
+ */
static pa_sample_spec sample_spec = {
.format = PA_SAMPLE_FLOAT32LE,
.rate = 48000,
@@ -48,90 +49,89 @@
};
/**
-* Pulseaudio mainloop api
-*/
-static pa_mainloop_api *mainloop_api = NULL;
+ * Pulseaudio mainloop api
+ */
+static pa_mainloop_api *mainloop_api;
/**
-* Pulseaudio mainloop
-*/
-static pa_mainloop *m = NULL;
+ * Pulseaudio mainloop
+ */
+static pa_mainloop *m;
/**
-* Pulseaudio context
-*/
-static pa_context *context = NULL;
+ * Pulseaudio context
+ */
+static pa_context *context;
/**
-* Pulseaudio recording stream
-*/
-static pa_stream *stream_in = NULL;
+ * Pulseaudio recording stream
+ */
+static pa_stream *stream_in;
/**
-* Pulseaudio io events
-*/
-static pa_io_event *stdio_event = NULL;
+ * Pulseaudio io events
+ */
+static pa_io_event *stdio_event;
/**
-* Message tokenizer
-*/
-struct MessageStreamTokenizer *stdin_mst;
+ * Message tokenizer
+ */
+static struct MessageStreamTokenizer *stdin_mst;
/**
-* OPUS encoder
-*/
-OpusEncoder *enc = NULL;
+ * OPUS encoder
+ */
+static OpusEncoder *enc;
/**
-*
-*/
-unsigned char *opus_data;
+ *
+ */
+static unsigned char *opus_data;
/**
-* PCM data buffer for one OPUS frame
-*/
-float *pcm_buffer;
+ * PCM data buffer for one OPUS frame
+ */
+static float *pcm_buffer;
/**
* Length of the pcm data needed for one OPUS frame
*/
-int pcm_length;
+static int pcm_length;
/**
-* Number of samples for one frame
-*/
-int frame_size;
+ * Number of samples for one frame
+ */
+static int frame_size;
/**
* Maximum length of opus payload
*/
-int max_payload_bytes = 1500;
+static int max_payload_bytes = 1500;
/**
-* Audio buffer
-*/
-static void *transmit_buffer = NULL;
+ * Audio buffer
+ */
+static void *transmit_buffer;
/**
-* Length of audio buffer
-*/
-static size_t transmit_buffer_length = 0;
+ * Length of audio buffer
+ */
+static size_t transmit_buffer_length;
/**
-* Read index for transmit buffer
-*/
-static size_t transmit_buffer_index = 0;
+ * Read index for transmit buffer
+ */
+static size_t transmit_buffer_index;
/**
-* Audio message skeleton
-*/
-struct AudioMessage *audio_message;
+ * Audio message skeleton
+ */
+static struct AudioMessage *audio_message;
-
/**
-* Pulseaudio shutdown task
-*/
+ * Pulseaudio shutdown task
+ */
static void
quit (int ret)
{
@@ -140,18 +140,14 @@
}
-
/**
-* Creates OPUS packets from PCM data
-*/
+ * Creates OPUS packets from PCM data
+ */
static void
packetizer ()
{
-
-
while (transmit_buffer_length >= transmit_buffer_index + pcm_length)
- {
-
+ {
int ret;
int len;
@@ -450,11 +446,11 @@
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->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
}
+
/**
* The main function for the record helper.
*
Added: gnunet/src/conversation/microphone.c
===================================================================
--- gnunet/src/conversation/microphone.c (rev 0)
+++ gnunet/src/conversation/microphone.c 2013-10-02 19:29:22 UTC (rev
29798)
@@ -0,0 +1,199 @@
+/*
+ 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/microphone.c
+ * @brief API to access an audio microphone; provides access to hardware
microphones;
+ * actually just wraps the gnunet-helper-audio-record
+ * @author Simon Dieterle
+ * @author Andreas Fuchs
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_microphone_lib.h"
+#include "conversation.h"
+
+
+/**
+ * Internal data structures for the microphone.
+ */
+struct Microphone
+{
+
+ /**
+ * Our configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Handle for the record helper
+ */
+ struct GNUNET_HELPER_Handle *record_helper;
+
+ /**
+ * Function to call with audio data (if we are enabled).
+ */
+ GNUNET_MICROPHONE_RecordedDataCallback rdc;
+
+ /**
+ * Closure for @e rdc.
+ */
+ void *rdc_cls;
+
+};
+
+
+/**
+ * Function to process the audio from the record helper
+ *
+ * @param cls clsoure with our `struct Microphone`
+ * @param client NULL
+ * @param msg the message from the helper
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static int
+process_record_messages (void *cls,
+ void *client,
+ const struct GNUNET_MessageHeader *msg)
+{
+ struct Microphone *mic = cls;
+
+ if ( (ntohs (msg->size) != sizeof (struct AudioMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO) )
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ mic->rdc (mic->rdc_cls,
+ sizeof (struct AudioMessage),
+ (const char *) msg);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Enable a microphone.
+ *
+ * @param cls clsoure with our `struct Microphone`
+ * @param rdc function to call with recorded data
+ * @param rdc_cls closure for @a dc
+ */
+static int
+enable (void *cls,
+ GNUNET_MICROPHONE_RecordedDataCallback rdc,
+ void *rdc_cls)
+{
+ struct Microphone *mic = cls;
+ char * const record_helper_argv[] =
+ {
+ "gnunet-helper-audio-record",
+ NULL
+ };
+ mic->rdc = rdc;
+ mic->rdc_cls = rdc_cls;
+ mic->record_helper = GNUNET_HELPER_start (GNUNET_NO,
+ "gnunet-helper-audio-record",
+ record_helper_argv,
+ &process_record_messages,
+ NULL, mic);
+ if (NULL == mic->record_helper)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not start record audio helper\n"));
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function that disables a microphone.
+ *
+ * @param cls clsoure
+ */
+static void
+disable (void *cls)
+{
+ struct Microphone *mic = cls;
+
+ if (NULL == mic->record_helper)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_HELPER_kill (mic->record_helper, GNUNET_NO));
+ GNUNET_HELPER_destroy (mic->record_helper);
+ mic->record_helper = NULL;
+}
+
+
+/**
+ * Function to destroy a microphone.
+ *
+ * @param cls clsoure
+ */
+static void
+destroy (void *cls)
+{
+ struct Microphone *mic = cls;
+
+ if (NULL != mic->record_helper)
+ disable (mic);
+}
+
+
+/**
+ * Create a microphone that corresponds to the microphone hardware
+ * of our system.
+ *
+ * @param cfg configuration to use
+ * @return NULL on error
+ */
+struct GNUNET_MICROPHONE_Handle *
+GNUNET_MICROPHONE_create_from_hardware (const struct
GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_MICROPHONE_Handle *microphone;
+ struct Microphone *mic;
+
+ mic = GNUNET_new (struct Microphone);
+ mic->cfg = cfg;
+ microphone = GNUNET_new (struct GNUNET_MICROPHONE_Handle);
+ microphone->cls = mic;
+ microphone->enable_microphone = &enable;
+ microphone->disable_microphone = &disable;
+ microphone->destroy_microphone = &destroy;
+ return microphone;
+}
+
+
+/**
+ * Destroy a microphone.
+ *
+ * @param microphone microphone to destroy
+ */
+void
+GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone)
+{
+ microphone->destroy_microphone (microphone->cls);
+ GNUNET_free (microphone);
+}
+
+/* end of microphone.c */
Modified: gnunet/src/include/gnunet_helper_lib.h
===================================================================
--- gnunet/src/include/gnunet_helper_lib.h 2013-10-02 19:06:07 UTC (rev
29797)
+++ gnunet/src/include/gnunet_helper_lib.h 2013-10-02 19:29:22 UTC (rev
29798)
@@ -77,21 +77,21 @@
* reaped; call GNUNET_HELPER_wait() for reaping the dead helper process.
*
* @param h the helper handle
- * @param soft_kill if GNUNET_YES, signals termination by closing the helper's
- * stdin; GNUNET_NO to signal termination by sending SIGTERM to helper
- * @return GNUNET_OK on success; GNUNET_SYSERR on error
+ * @param soft_kill if #GNUNET_YES, signals termination by closing the helper's
+ * stdin; #GNUNET_NO to signal termination by sending SIGTERM to
helper
+ * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
*/
int
GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill);
/**
- * Reap the helper process. This call is blocking(!). The helper process
+ * Reap the helper process. This call is blocking (!). The helper process
* should either be sent a termination signal before or should be dead before
* calling this function
*
* @param h the helper handle
- * @return GNUNET_OK on success; GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
*/
int
GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h);
@@ -111,8 +111,8 @@
* helper process
*
* @param h handle to helper to stop
- * @param soft_kill if GNUNET_YES, signals termination by closing the helper's
- * stdin; GNUNET_NO to signal termination by sending SIGTERM to helper
+ * @param soft_kill if #GNUNET_YES, signals termination by closing the helper's
+ * stdin; #GNUNET_NO to signal termination by sending SIGTERM to
helper
*/
void
GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill);
@@ -122,9 +122,9 @@
* Continuation function.
*
* @param cls closure
- * @param result GNUNET_OK on success,
- * GNUNET_NO if helper process died
- * GNUNET_SYSERR during GNUNET_HELPER_stop
+ * @param result #GNUNET_OK on success,
+ * #GNUNET_NO if helper process died
+ * #GNUNET_SYSERR during GNUNET_HELPER_stop
*/
typedef void (*GNUNET_HELPER_Continuation)(void *cls,
int result);
@@ -143,7 +143,7 @@
* @param msg message to send
* @param can_drop can the message be dropped if there is already one in the
queue?
* @param cont continuation to run once the message is out
- * @param cont_cls closure for 'cont'
+ * @param cont_cls closure for @a cont
* @return NULL if the message was dropped,
* otherwise handle to cancel *cont* (actual transmission may
* not be abortable)
@@ -157,13 +157,13 @@
/**
- * Cancel a 'send' operation. If possible, transmitting the
- * message is also aborted, but at least 'cont' won't be
- * called.
+ * Cancel a #GNUNET_HELPER_send operation. If possible, transmitting
+ * the message is also aborted, but at least 'cont' won't be called.
*
* @param sh operation to cancel
*/
void
GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
-#endif /* end of include guard: GNUNET_HELPER_LIB_H */
+#endif
+/* end of include guard: GNUNET_HELPER_LIB_H */
Modified: gnunet/src/include/gnunet_microphone_lib.h
===================================================================
--- gnunet/src/include/gnunet_microphone_lib.h 2013-10-02 19:06:07 UTC (rev
29797)
+++ gnunet/src/include/gnunet_microphone_lib.h 2013-10-02 19:29:22 UTC (rev
29798)
@@ -36,6 +36,8 @@
#endif
#endif
+#include "gnunet_util_lib.h"
+
/**
* Process recorded audio data.
*
@@ -53,10 +55,11 @@
* @param cls clsoure
* @param rdc function to call with recorded data
* @param rdc_cls closure for @a dc
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
-typedef void (*GNUNET_MICROPHONE_EnableCallback)(void *cls,
-
GNUNET_MICROPHONE_RecordedDataCallback rdc,
- void *rdc_cls);
+typedef int (*GNUNET_MICROPHONE_EnableCallback)(void *cls,
+
GNUNET_MICROPHONE_RecordedDataCallback rdc,
+ void *rdc_cls);
/**
* Function that disables a microphone.
Modified: gnunet/src/include/gnunet_speaker_lib.h
===================================================================
--- gnunet/src/include/gnunet_speaker_lib.h 2013-10-02 19:06:07 UTC (rev
29797)
+++ gnunet/src/include/gnunet_speaker_lib.h 2013-10-02 19:29:22 UTC (rev
29798)
@@ -40,8 +40,9 @@
* Function that enables a speaker.
*
* @param cls clsoure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
-typedef void (*GNUNET_SPEAKER_EnableCallback)(void *cls);
+typedef int (*GNUNET_SPEAKER_EnableCallback)(void *cls);
/**
* Function that disables a speaker.
Modified: gnunet/src/util/server_mst.c
===================================================================
--- gnunet/src/util/server_mst.c 2013-10-02 19:06:07 UTC (rev 29797)
+++ gnunet/src/util/server_mst.c 2013-10-02 19:29:22 UTC (rev 29798)
@@ -90,7 +90,7 @@
{
struct GNUNET_SERVER_MessageStreamTokenizer *ret;
- ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_MessageStreamTokenizer));
+ ret = GNUNET_new (struct GNUNET_SERVER_MessageStreamTokenizer);
ret->hdr = GNUNET_malloc (GNUNET_SERVER_MIN_BUFFER_SIZE);
ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE;
ret->cb = cb;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29798 - in gnunet/src: conversation include util,
gnunet <=