GNUnet  0.19.4
gnunet-conversation-test.c File Reference

tool to test speaker and microphone (for end users!) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_speaker_lib.h"
#include "gnunet_microphone_lib.h"
Include dependency graph for gnunet-conversation-test.c:

Go to the source code of this file.

Data Structures

struct  Recording
 A recording we made. More...
 

Macros

#define TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 How long do we record before we replay? More...
 

Functions

static void do_shutdown (void *cls)
 Terminate test. More...
 
static void switch_to_speaker (void *cls)
 Terminate recording process and switch to playback. More...
 
static void record (void *cls, size_t data_size, const void *data)
 Process recorded audio data. More...
 
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. More...
 
int main (int argc, char *const *argv)
 The main function of our code to test microphone and speaker. More...
 

Variables

static int ret
 Final status code. More...
 
static struct GNUNET_MICROPHONE_Handlemicrophone
 Handle to the microphone. More...
 
static struct GNUNET_SPEAKER_Handlespeaker
 Handle to the speaker. More...
 
static struct GNUNET_SCHEDULER_Taskswitch_task
 Task scheduled to switch from recording to playback. More...
 
static struct GNUNET_SCHEDULER_Taskst
 The shutdown task. More...
 
static struct Recordingrec_head
 Head of DLL with recorded frames. More...
 
static struct Recordingrec_tail
 Tail of DLL with recorded frames. More...
 

Detailed Description

tool to test speaker and microphone (for end users!)

Author
Christian Grothoff

Definition in file gnunet-conversation-test.c.

Macro Definition Documentation

◆ TIMEOUT

How long do we record before we replay?

Definition at line 34 of file gnunet-conversation-test.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Terminate test.

Parameters
clsNULL

Definition at line 101 of file gnunet-conversation-test.c.

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 }
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.
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
static struct Recording * rec_tail
Tail of DLL with recorded frames.
static struct Recording * rec_head
Head of DLL with recorded frames.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone)
Destroy a microphone.
Definition: microphone.c:193
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:182
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
A recording we made.

References _, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MICROPHONE_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_SPEAKER_destroy(), microphone, rec_head, rec_tail, speaker, and switch_task.

Referenced by run(), and switch_to_speaker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switch_to_speaker()

static void switch_to_speaker ( void *  cls)
static

Terminate recording process and switch to playback.

Parameters
clsNULL

Definition at line 130 of file gnunet-conversation-test.c.

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);
152  speaker->play (speaker->cls,
153  rec->size,
154  &rec[1]);
155  }
158  &do_shutdown,
159  NULL);
160 }
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
#define TIMEOUT
How long do we record before we replay?
static int ret
Final status code.
static void do_shutdown(void *cls)
Terminate test.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
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:1272
void * cls
Closure for the callbacks.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
void * cls
Closure for the callbacks.
GNUNET_SPEAKER_PlayCallback play
Play audio.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.
struct Recording * next
Kept in a DLL.

References _, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, GNUNET_MICROPHONE_Handle::disable_microphone, do_shutdown(), GNUNET_SPEAKER_Handle::enable_speaker, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), microphone, Recording::next, GNUNET_SPEAKER_Handle::play, rec_head, ret, speaker, st, switch_task, and TIMEOUT.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ record()

static void record ( void *  cls,
size_t  data_size,
const void *  data 
)
static

Process recorded audio data.

Parameters
clsclsoure
data_sizenumber of bytes in data
dataaudio data to play

Definition at line 171 of file gnunet-conversation-test.c.

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 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.
size_t size
Number of bytes that follow.

References data, data_size, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, rec_head, rec_tail, and Recording::size.

Referenced by add_record(), backtalker_monotime_cb(), cache_answers(), check_iterate(), check_store(), display_record(), get_channel(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), handle_hello_for_client(), handle_hello_for_incoming(), handle_iterate(), handle_iterate_result(), handle_store(), handle_watch_record(), handshake_ack_monotime_cb(), handshake_monotime_cb(), hello_iter_cb(), messenger_string_to_value(), messenger_value_to_string(), modify_record(), neighbour_dv_monotime_cb(), parse_recordline(), peer_respect_cb(), PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), record_iterator(), register_service(), rekey_monotime_cb(), remove_client_query_record(), run(), send_reply(), store_record_continuation(), try_cache(), watch_notifier(), and watch_notifier_it().

Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 199 of file gnunet-conversation-test.c.

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 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static void switch_to_speaker(void *cls)
Terminate recording process and switch to playback.
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:170
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:1334
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:158
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:569
GNUNET_MICROPHONE_EnableCallback enable_microphone
Turn on the microphone.

References _, consensus-simulation::args, cfg, GNUNET_MICROPHONE_Handle::cls, do_shutdown(), GNUNET_MICROPHONE_Handle::enable_microphone, GNUNET_assert, GNUNET_MICROPHONE_create_from_hardware(), GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SPEAKER_create_from_hardware(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, microphone, record(), ret, speaker, st, switch_task, switch_to_speaker(), and TIMEOUT.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function of our code to test microphone and speaker.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 241 of file gnunet-conversation-test.c.

243 {
244  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
246  };
247 
248  if (GNUNET_OK !=
249  GNUNET_STRINGS_get_utf8_args (argc, argv,
250  &argc, &argv))
251  return 2;
252 
253  ret = (GNUNET_OK ==
254  GNUNET_PROGRAM_run (argc, argv,
255  "gnunet-conversation-test",
256  gettext_noop ("help text"),
257  options,
258  &run,
259  NULL)) ? ret : 1;
260  GNUNET_free_nz ((void *) argv);
261  return ret;
262 }
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:70
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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(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:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
Definition of a command line option.

References gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Final status code.

Definition at line 62 of file gnunet-conversation-test.c.

Referenced by main(), run(), and switch_to_speaker().

◆ microphone

struct GNUNET_MICROPHONE_Handle* microphone
static

◆ speaker

◆ switch_task

struct GNUNET_SCHEDULER_Task* switch_task
static

Task scheduled to switch from recording to playback.

Definition at line 77 of file gnunet-conversation-test.c.

Referenced by do_shutdown(), run(), and switch_to_speaker().

◆ st

◆ rec_head

struct Recording* rec_head
static

Head of DLL with recorded frames.

Definition at line 87 of file gnunet-conversation-test.c.

Referenced by do_shutdown(), record(), and switch_to_speaker().

◆ rec_tail

struct Recording* rec_tail
static

Tail of DLL with recorded frames.

Definition at line 92 of file gnunet-conversation-test.c.

Referenced by do_shutdown(), and record().