2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file conversation/microphone.c
23 * @brief API to access an audio microphone; provides access to hardware microphones;
24 * actually just wraps the gnunet-helper-audio-record
25 * @author Simon Dieterle
26 * @author Andreas Fuchs
27 * @author Christian Grothoff
30 #include "gnunet_microphone_lib.h"
31 #include "conversation.h"
35 * Internal data structures for the microphone.
43 const struct GNUNET_CONFIGURATION_Handle *cfg;
46 * Handle for the record helper
48 struct GNUNET_HELPER_Handle *record_helper;
51 * Function to call with audio data (if we are enabled).
53 GNUNET_MICROPHONE_RecordedDataCallback rdc;
64 * Function to process the audio from the record helper
66 * @param cls clsoure with our `struct Microphone`
68 * @param msg the message from the helper
69 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
72 process_record_messages (void *cls,
74 const struct GNUNET_MessageHeader *msg)
76 struct Microphone *mic = cls;
78 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO)
83 mic->rdc (mic->rdc_cls,
91 * Enable a microphone.
93 * @param cls clsoure with our `struct Microphone`
94 * @param rdc function to call with recorded data
95 * @param rdc_cls closure for @a dc
99 GNUNET_MICROPHONE_RecordedDataCallback rdc,
102 struct Microphone *mic = cls;
103 static char * const record_helper_argv[] =
105 "gnunet-helper-audio-record",
110 mic->rdc_cls = rdc_cls;
111 mic->record_helper = GNUNET_HELPER_start (GNUNET_NO,
112 "gnunet-helper-audio-record",
114 &process_record_messages,
116 if (NULL == mic->record_helper)
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
119 _("Could not start record audio helper\n"));
120 return GNUNET_SYSERR;
127 * Function that disables a microphone.
134 struct Microphone *mic = cls;
136 if (NULL == mic->record_helper)
141 GNUNET_break (GNUNET_OK ==
142 GNUNET_HELPER_kill (mic->record_helper, GNUNET_NO));
143 GNUNET_HELPER_destroy (mic->record_helper);
144 mic->record_helper = NULL;
149 * Function to destroy a microphone.
156 struct Microphone *mic = cls;
158 if (NULL != mic->record_helper)
164 * Create a microphone that corresponds to the microphone hardware
167 * @param cfg configuration to use
168 * @return NULL on error
170 struct GNUNET_MICROPHONE_Handle *
171 GNUNET_MICROPHONE_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg)
173 struct GNUNET_MICROPHONE_Handle *microphone;
174 struct Microphone *mic;
176 mic = GNUNET_new (struct Microphone);
178 microphone = GNUNET_new (struct GNUNET_MICROPHONE_Handle);
179 microphone->cls = mic;
180 microphone->enable_microphone = &enable;
181 microphone->disable_microphone = &disable;
182 microphone->destroy_microphone = &destroy;
188 * Destroy a microphone.
190 * @param microphone microphone to destroy
193 GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone)
195 microphone->destroy_microphone (microphone->cls);
196 GNUNET_free (microphone);
199 /* end of microphone.c */