GNUnet 0.22.2
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.

59{
60 struct Speaker *spe = cls;
61 static char *playback_helper_argv[] = {
62 (char*) "gnunet-helper-audio-playback",
63 NULL
64 };
65
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(const struct GNUNET_OS_ProjectData *pd, 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
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Internal data structures for the speaker.
Definition: speaker.c:38
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:47

References _, GNUNET_ERROR_TYPE_ERROR, GNUNET_HELPER_start(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_project_data_gnunet(), 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 88 of file speaker.c.

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}
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:501
#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 110 of file speaker.c.

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

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 128 of file speaker.c.

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);
146 &am->header,
147 GNUNET_NO,
148 NULL, NULL);
149}
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, bool can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:615
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#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

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: