GNUnet 0.22.2
gnunet-conversation-test.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_speaker_lib.h"
30
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
35
36
41{
45 struct Recording *next;
46
50 struct Recording *prev;
51
55 size_t size;
56};
57
58
62static int ret;
63
68
73
78
83
87static struct Recording *rec_head;
88
92static struct Recording *rec_tail;
93
94
100static void
101do_shutdown (void *cls)
102{
103 struct Recording *rec;
104
105 (void) cls;
106 if (NULL != switch_task)
108 if (NULL != microphone)
110 if (NULL != speaker)
112 while (NULL != (rec = rec_head))
113 {
115 rec_tail,
116 rec);
117 GNUNET_free (rec);
118 }
119 fprintf (stderr,
120 _ ("\nEnd of transmission. Have a GNU day.\n"));
121}
122
123
129static void
131{
132 (void) cls;
133 switch_task = NULL;
135 if (GNUNET_OK !=
137 {
138 fprintf (stderr,
139 "Failed to enable microphone\n");
140 ret = 1;
142 return;
143 }
144 fprintf (stderr,
145 _ (
146 "\new are now playing your recording back. If you can hear it, your audio settings are working..."));
147 for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next)
148 {
150 "Replaying %u bytes\n",
151 (unsigned int) rec->size);
153 rec->size,
154 &rec[1]);
155 }
159 NULL);
160}
161
162
170static void
171record (void *cls,
172 size_t data_size,
173 const void *data)
174{
175 struct Recording *rec;
176
177 (void) cls;
179 "Recorded %u bytes\n",
180 (unsigned int) data_size);
181 rec = GNUNET_malloc (sizeof(struct Recording) + data_size);
182 rec->size = data_size;
183 GNUNET_memcpy (&rec[1], data, data_size);
185 rec_tail,
186 rec);
187}
188
189
198static void
199run (void *cls,
200 char *const *args,
201 const char *cfgfile,
202 const struct GNUNET_CONFIGURATION_Handle *cfg)
203{
204 (void) cls;
205 (void) args;
206 (void) cfgfile;
208 GNUNET_assert (NULL != microphone);
210 GNUNET_assert (NULL != speaker);
213 NULL);
215 NULL);
216 fprintf (stderr,
217 _ (
218 "We will now be recording you for %s. After that time, the recording will be played back to you..."),
220 if (GNUNET_OK !=
222 &record, NULL))
223 {
224 fprintf (stderr,
225 "Failed to enable microphone\n");
226 ret = 1;
228 return;
229 }
230}
231
232
240int
241main (int argc,
242 char *const *argv)
243{
244 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
246 };
247
248 ret = (GNUNET_OK ==
250 argc, argv,
251 "gnunet-conversation-test",
252 gettext_noop ("help text"),
253 options,
254 &run,
255 NULL)) ? ret : 1;
256 return ret;
257}
258
259
260/* end of gnunet-conversation-test.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static struct GNUNET_MICROPHONE_Handle * microphone
Handle to the microphone.
static struct GNUNET_SCHEDULER_Task * switch_task
Task scheduled to switch from recording to playback.
#define TIMEOUT
How long do we record before we replay?
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static int ret
Final status code.
static void do_shutdown(void *cls)
Terminate test.
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
static void switch_to_speaker(void *cls)
Terminate recording process and switch to playback.
static struct Recording * rec_tail
Tail of DLL with recorded frames.
static struct Recording * rec_head
Head of DLL with recorded frames.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
int main(int argc, char *const *argv)
The main function of our code to test microphone and speaker.
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
API to access an audio microphone; provides access to hardware microphones.
API to access an audio speaker; provides access to hardware speakers.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone)
Destroy a microphone.
Definition: microphone.c:195
struct GNUNET_MICROPHONE_Handle * GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a microphone that corresponds to the microphone hardware of our system.
Definition: microphone.c:172
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:407
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
struct GNUNET_SPEAKER_Handle * GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a speaker that corresponds to the speaker hardware of our system.
Definition: speaker.c:160
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:184
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Definition of a command line option.
A microphone is a device that can capture or otherwise produce audio data.
void * cls
Closure for the callbacks.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
GNUNET_MICROPHONE_EnableCallback enable_microphone
Turn on the microphone.
Entry in list of pending tasks.
Definition: scheduler.c:136
A speaker is a device that can play or record audio data.
void * cls
Closure for the callbacks.
GNUNET_SPEAKER_PlayCallback play
Play audio.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.
A recording we made.
struct Recording * next
Kept in a DLL.
size_t size
Number of bytes that follow.
struct Recording * prev
Kept in a DLL.