GNUnet  0.10.x
Data Structures | Functions
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 58 of file speaker.c.

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().

59 {
60  struct Speaker *spe = cls;
61  static char *playback_helper_argv[] =
62  {
63  "gnunet-helper-audio-playback",
64  NULL
65  };
66 
68  "gnunet-helper-audio-playback",
69  playback_helper_argv,
70  NULL,
71  NULL, spe);
72  if (NULL == spe->playback_helper)
73  {
75  _("Could not start playback audio helper.\n"));
76  return GNUNET_SYSERR;
77  }
78  return GNUNET_OK;
79 }
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:491
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Internal data structures for the speaker.
Definition: speaker.c:36
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:46
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_log(kind,...)
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 88 of file speaker.c.

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().

89 {
90  struct Speaker *spe = cls;
91 
92  if (NULL == spe->playback_helper)
93  {
94  GNUNET_break (0);
95  return;
96  }
100  spe->playback_helper = NULL;
101 }
int GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
Definition: helper.c:180
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Internal data structures for the speaker.
Definition: speaker.c:36
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:46
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:530
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 110 of file speaker.c.

References disable(), and Speaker::playback_helper.

Referenced by GNUNET_SPEAKER_create_from_hardware().

111 {
112  struct Speaker *spe = cls;
113 
114  if (NULL != spe->playback_helper)
115  disable (spe);
116 }
Internal data structures for the speaker.
Definition: speaker.c:36
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:46
static void disable(void *cls)
Function that disables a speaker.
Definition: speaker.c:88
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 128 of file speaker.c.

References buf, 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().

131 {
132  struct Speaker *spe = cls;
133  char buf[sizeof (struct AudioMessage) + data_size];
134  struct AudioMessage *am;
135 
136  if (NULL == spe->playback_helper)
137  {
138  GNUNET_break (0);
139  return;
140  }
141  am = (struct AudioMessage *) buf;
142  am->header.size = htons (sizeof (struct AudioMessage) + data_size);
144  GNUNET_memcpy (&am[1], data, data_size);
145  (void) GNUNET_HELPER_send (spe->playback_helper,
146  &am->header,
147  GNUNET_NO,
148  NULL, NULL);
149 }
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
Definition: conversation.h:60
#define GNUNET_NO
Definition: gnunet_common.h:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Internal data structures for the speaker.
Definition: speaker.c:36
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_memcpy(dst, src, n)
Message to transmit the audio (between client and helpers).
Definition: conversation.h:55
static char buf[2048]
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:46
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:660
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
Here is the call graph for this function:
Here is the caller graph for this function: