GNUnet  0.11.x
Data Structures | Functions
microphone.c File Reference

API to access an audio microphone; provides access to hardware microphones; actually just wraps the gnunet-helper-audio-record. More...

#include "platform.h"
#include "gnunet_microphone_lib.h"
#include "conversation.h"
Include dependency graph for microphone.c:

Go to the source code of this file.

Data Structures

struct  Microphone
 Internal data structures for the microphone. More...
 

Functions

static int process_record_messages (void *cls, const struct GNUNET_MessageHeader *msg)
 Function to process the audio from the record helper. More...
 
static int enable (void *cls, GNUNET_MICROPHONE_RecordedDataCallback rdc, void *rdc_cls)
 Enable a microphone. More...
 
static void disable (void *cls)
 Function that disables a microphone. More...
 
static void destroy (void *cls)
 Function to destroy a microphone. More...
 
struct GNUNET_MICROPHONE_HandleGNUNET_MICROPHONE_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Create a microphone that corresponds to the microphone hardware of our system. More...
 
void GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone)
 Destroy a microphone. More...
 

Detailed Description

API to access an audio microphone; provides access to hardware microphones; actually just wraps the gnunet-helper-audio-record.

Author
Simon Dieterle
Andreas Fuchs
Christian Grothoff

Definition in file microphone.c.

Function Documentation

◆ process_record_messages()

static int process_record_messages ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Function to process the audio from the record helper.

Parameters
clsclsoure with our struct Microphone
msgthe message from the helper
Returns
GNUNET_OK on success, GNUNET_NO to stop further processing (no error) GNUNET_SYSERR to stop further processing with error

Definition at line 71 of file microphone.c.

References GNUNET_break, GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO, GNUNET_OK, GNUNET_SYSERR, mic, Microphone::rdc, Microphone::rdc_cls, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by enable().

73 {
74  struct Microphone *mic = cls;
75  const struct AudioMessage *am;
76 
77  if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO)
78  {
79  GNUNET_break (0);
80  return GNUNET_SYSERR;
81  }
82  am = (const struct AudioMessage *) msg;
83  mic->rdc (mic->rdc_cls,
84  ntohs (msg->size) - sizeof(struct AudioMessage),
85  &am[1]);
86  return GNUNET_OK;
87 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Message to transmit the audio (between client and helpers).
Definition: conversation.h:56
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Internal data structures for the microphone.
Definition: microphone.c:37
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
void * rdc_cls
Closure for rdc.
Definition: microphone.c:57
GNUNET_MICROPHONE_RecordedDataCallback rdc
Function to call with audio data (if we are enabled).
Definition: microphone.c:52
Here is the caller graph for this function:

◆ enable()

static int enable ( void *  cls,
GNUNET_MICROPHONE_RecordedDataCallback  rdc,
void *  rdc_cls 
)
static

Enable a microphone.

Parameters
clsclsoure with our struct Microphone
rdcfunction to call with recorded data
rdc_clsclosure for dc

Definition at line 98 of file microphone.c.

References _, GNUNET_ERROR_TYPE_ERROR, GNUNET_HELPER_start(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, mic, process_record_messages(), Microphone::rdc, Microphone::rdc_cls, and Microphone::record_helper.

Referenced by GNUNET_MICROPHONE_create_from_hardware().

101 {
102  struct Microphone *mic = cls;
103  static char *const record_helper_argv[] = {
104  "gnunet-helper-audio-record",
105  NULL
106  };
107 
108  mic->rdc = rdc;
109  mic->rdc_cls = rdc_cls;
111  "gnunet-helper-audio-record",
112  record_helper_argv,
114  NULL, mic);
115  if (NULL == mic->record_helper)
116  {
118  _ ("Could not start record audio helper\n"));
119  return GNUNET_SYSERR;
120  }
121  return GNUNET_OK;
122 }
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
Starts a helper and begins reading from it.
Definition: helper.c:489
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static int process_record_messages(void *cls, const struct GNUNET_MessageHeader *msg)
Function to process the audio from the record helper.
Definition: microphone.c:71
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_HELPER_Handle * record_helper
Handle for the record helper.
Definition: microphone.c:47
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Internal data structures for the microphone.
Definition: microphone.c:37
#define GNUNET_log(kind,...)
void * rdc_cls
Closure for rdc.
Definition: microphone.c:57
GNUNET_MICROPHONE_RecordedDataCallback rdc
Function to call with audio data (if we are enabled).
Definition: microphone.c:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable()

static void disable ( void *  cls)
static

Function that disables a microphone.

Parameters
clsclsoure

Definition at line 131 of file microphone.c.

References GNUNET_break, GNUNET_HELPER_destroy(), GNUNET_HELPER_kill(), GNUNET_NO, GNUNET_OK, mic, and Microphone::record_helper.

Referenced by destroy(), and GNUNET_MICROPHONE_create_from_hardware().

132 {
133  struct Microphone *mic = cls;
134 
135  if (NULL == mic->record_helper)
136  {
137  GNUNET_break (0);
138  return;
139  }
143  mic->record_helper = NULL;
144 }
int GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
Definition: helper.c:177
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
struct GNUNET_HELPER_Handle * record_helper
Handle for the record helper.
Definition: microphone.c:47
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:528
Internal data structures for the microphone.
Definition: microphone.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy()

static void destroy ( void *  cls)
static

Function to destroy a microphone.

Parameters
clsclsoure

Definition at line 153 of file microphone.c.

References disable(), mic, and Microphone::record_helper.

Referenced by GNUNET_MICROPHONE_create_from_hardware().

154 {
155  struct Microphone *mic = cls;
156 
157  if (NULL != mic->record_helper)
158  disable (mic);
159 }
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
struct GNUNET_HELPER_Handle * record_helper
Handle for the record helper.
Definition: microphone.c:47
static void disable(void *cls)
Function that disables a microphone.
Definition: microphone.c:131
Internal data structures for the microphone.
Definition: microphone.c:37
Here is the call graph for this function:
Here is the caller graph for this function: