GNUnet  last
speaker.c File Reference

API to access an audio speaker; provides access to hardware speakers. More...

#include "platform.h"
#include "gnunet_speaker_lib.h"
#include "conversation.h"
Include dependency graph for speaker.c:

Go to the source code of this file.

Data Structures

struct  Speaker
 Internal data structures for the speaker. More...
 

Functions

static int enable (void *cls)
 Function that enables a speaker. More...
 
static void disable (void *cls)
 Function that disables a speaker. More...
 
static void destroy (void *cls)
 Function to destroy a speaker. More...
 
static void play (void *cls, size_t data_size, const void *data)
 Function to cause a speaker to play audio data. More...
 
struct GNUNET_SPEAKER_HandleGNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Create a speaker that corresponds to the speaker hardware of our system. More...
 
void GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker)
 Destroy a speaker. More...
 

Detailed Description

API to access an audio speaker; provides access to hardware speakers.

Author
Simon Dieterle
Andreas Fuchs
Christian Grothoff

Definition in file speaker.c.

Function Documentation

◆ enable()

static int enable ( void *  cls)
static

Function that enables a speaker.

Parameters
clsclosure with the struct Speaker
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 57 of file speaker.c.

58 {
59  struct Speaker *spe = cls;
60  static char *playback_helper_argv[] = {
61  "gnunet-helper-audio-playback",
62  NULL
63  };
64 
66  "gnunet-helper-audio-playback",
67  playback_helper_argv,
68  NULL,
69  NULL, spe);
70  if (NULL == spe->playback_helper)
71  {
73  _ ("Could not start playback audio helper.\n"));
74  return GNUNET_SYSERR;
75  }
76  return GNUNET_OK;
77 }
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:460
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Internal data structures for the speaker.
Definition: speaker.c:37
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:46

References _, GNUNET_ERROR_TYPE_ERROR, GNUNET_HELPER_start(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, and Speaker::playback_helper.

Referenced by GNUNET_SPEAKER_create_from_hardware().

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 speaker.

Parameters
clsclosure with the struct Speaker

Definition at line 86 of file speaker.c.

87 {
88  struct Speaker *spe = cls;
89 
90  if (NULL == spe->playback_helper)
91  {
92  GNUNET_break (0);
93  return;
94  }
98  spe->playback_helper = NULL;
99 }
enum GNUNET_GenericReturnValue GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
Definition: helper.c:166
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:499
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_HELPER_destroy(), GNUNET_HELPER_kill(), GNUNET_NO, GNUNET_OK, and Speaker::playback_helper.

Referenced by destroy(), and GNUNET_SPEAKER_create_from_hardware().

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 speaker.

Parameters
clsclosure with the struct Speaker

Definition at line 108 of file speaker.c.

109 {
110  struct Speaker *spe = cls;
111 
112  if (NULL != spe->playback_helper)
113  disable (spe);
114 }
static void disable(void *cls)
Function that disables a speaker.
Definition: speaker.c:86

References disable(), and Speaker::playback_helper.

Referenced by GNUNET_SPEAKER_create_from_hardware().

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

◆ play()

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

Function to cause a speaker to play audio data.

Parameters
clsclsoure with the struct Speaker
data_sizenumber of bytes in data
dataaudio data to play, format is opaque to the API but should be OPUS.

Definition at line 126 of file speaker.c.

129 {
130  struct Speaker *spe = cls;
131  char buf[sizeof(struct AudioMessage) + data_size];
132  struct AudioMessage *am;
133 
134  if (NULL == spe->playback_helper)
135  {
136  GNUNET_break (0);
137  return;
138  }
139  am = (struct AudioMessage *) buf;
140  am->header.size = htons (sizeof(struct AudioMessage) + data_size);
142  GNUNET_memcpy (&am[1], data, data_size);
143  (void) GNUNET_HELPER_send (spe->playback_helper,
144  &am->header,
145  GNUNET_NO,
146  NULL, NULL);
147 }
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:613
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
Message to transmit the audio (between client and helpers).
Definition: conversation.h:59
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
Definition: conversation.h:63
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References data, data_size, GNUNET_break, GNUNET_HELPER_send(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO, GNUNET_NO, AudioMessage::header, Speaker::playback_helper, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GNUNET_SPEAKER_create_from_hardware().

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