GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
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.

Referenced by run(), and switch_to_speaker().

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Terminate test.

Parameters
clsNULL

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

References _, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MICROPHONE_destroy(), GNUNET_SCHEDULER_cancel(), and GNUNET_SPEAKER_destroy().

Referenced by run(), and switch_to_speaker().

101 {
102  struct Recording *rec;
103 
104  (void)cls;
105  if (NULL != switch_task)
107  if (NULL != microphone)
109  if (NULL != speaker)
111  while (NULL != (rec = rec_head))
112  {
114  rec_tail,
115  rec);
116  GNUNET_free(rec);
117  }
118  fprintf(stderr,
119  _("\nEnd of transmission. Have a GNU day.\n"));
120 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
A recording we made.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct Recording * rec_tail
Tail of DLL with recorded frames.
static struct Recording * rec_head
Head of DLL with recorded frames.
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:181
void GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone)
Destroy a microphone.
Definition: microphone.c:192
static struct GNUNET_SCHEDULER_Task * switch_task
Task scheduled to switch from recording to playback.
static struct GNUNET_MICROPHONE_Handle * microphone
Handle to the microphone.
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 129 of file gnunet-conversation-test.c.

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(), Recording::next, GNUNET_SPEAKER_Handle::play, ret, and TIMEOUT.

Referenced by run().

130 {
131  (void)cls;
132  switch_task = NULL;
134  if (GNUNET_OK !=
136  {
137  fprintf(stderr,
138  "Failed to enable microphone\n");
139  ret = 1;
141  return;
142  }
143  fprintf(stderr,
144  _("\nWe are now playing your recording back. If you can hear it, your audio settings are working..."));
145  for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next)
146  {
148  "Replaying %u bytes\n",
149  (unsigned int)rec->size);
151  rec->size,
152  &rec[1]);
153  }
156  &do_shutdown,
157  NULL);
158 }
#define TIMEOUT
How long do we record before we replay?
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
GNUNET_SPEAKER_PlayCallback play
Play audio.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
A recording we made.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static int ret
Final status code.
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:1237
void * cls
Closure for the callbacks.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.
void * cls
Closure for the callbacks.
static struct Recording * rec_head
Head of DLL with recorded frames.
static void do_shutdown(void *cls)
Terminate test.
static struct GNUNET_SCHEDULER_Task * switch_task
Task scheduled to switch from recording to playback.
#define GNUNET_log(kind,...)
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static struct GNUNET_MICROPHONE_Handle * microphone
Handle to the microphone.
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
struct Recording * next
Kept in a DLL.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 169 of file gnunet-conversation-test.c.

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

Referenced by check_iterate(), check_store(), forward_reply(), get_channel(), GNUNET_JSON_from_gnsrecord(), handle_iterate(), handle_iterate_result(), handle_store(), handle_watch_record(), PEERSTORE_parse_record_message(), register_service(), run(), store_record_continuation(), and watch_notifier_it().

172 {
173  struct Recording *rec;
174 
175  (void)cls;
177  "Recorded %u bytes\n",
178  (unsigned int)data_size);
179  rec = GNUNET_malloc(sizeof(struct Recording) + data_size);
180  rec->size = data_size;
181  GNUNET_memcpy(&rec[1], data, data_size);
183  rec_tail,
184  rec);
185 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
A recording we made.
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_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
size_t size
Number of bytes that follow.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 197 of file gnunet-conversation-test.c.

References _, 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, record(), ret, switch_to_speaker(), and TIMEOUT.

Referenced by main().

201 {
202  (void)cls;
203  (void)args;
204  (void)cfgfile;
206  GNUNET_assert(NULL != microphone);
208  GNUNET_assert(NULL != speaker);
211  NULL);
213  NULL);
214  fprintf(stderr,
215  _("We will now be recording you for %s. After that time, the recording will be played back to you..."),
217  if (GNUNET_OK !=
219  &record, NULL))
220  {
221  fprintf(stderr,
222  "Failed to enable microphone\n");
223  ret = 1;
225  return;
226  }
227 }
#define TIMEOUT
How long do we record before we replay?
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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
GNUNET_MICROPHONE_EnableCallback enable_microphone
Turn on the microphone.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static int ret
Final status code.
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:1237
void * cls
Closure for the callbacks.
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:686
static void do_shutdown(void *cls)
Terminate test.
static void switch_to_speaker(void *cls)
Terminate recording process and switch to playback.
static struct GNUNET_SCHEDULER_Task * switch_task
Task scheduled to switch from recording to playback.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
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
static struct GNUNET_MICROPHONE_Handle * microphone
Handle to the microphone.
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
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 238 of file gnunet-conversation-test.c.

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

240 {
241  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
243  };
244 
245  if (GNUNET_OK !=
246  GNUNET_STRINGS_get_utf8_args(argc, argv,
247  &argc, &argv))
248  return 2;
249 
250  ret = (GNUNET_OK ==
251  GNUNET_PROGRAM_run(argc, argv,
252  "gnunet-conversation-test",
253  gettext_noop("help text"),
254  options,
255  &run,
256  NULL)) ? ret : 1;
257  GNUNET_free((void*)argv);
258  return ret;
259 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static int ret
Final status code.
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 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, parse options).
Definition: program.c:367
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Final status code.

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

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

◆ microphone

struct GNUNET_MICROPHONE_Handle* microphone
static

Handle to the microphone.

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

Referenced by GNUNET_MICROPHONE_create_from_hardware().

◆ speaker

struct GNUNET_SPEAKER_Handle* speaker
static

Handle to the speaker.

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

Referenced by GNUNET_SPEAKER_create_from_hardware().

◆ switch_task

struct GNUNET_SCHEDULER_Task* switch_task
static

Task scheduled to switch from recording to playback.

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

◆ st

struct GNUNET_SCHEDULER_Task* st
static

◆ rec_head

struct Recording* rec_head
static

Head of DLL with recorded frames.

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

◆ rec_tail

struct Recording* rec_tail
static

Tail of DLL with recorded frames.

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