GNUnet 0.22.2
speaker.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
28#include "platform.h"
29
30#include "gnunet_speaker_lib.h"
31#include "conversation.h"
32
33
37struct Speaker
38{
43
48};
49
50
57static int
58enable (void *cls)
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}
80
81
87static void
88disable (void *cls)
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}
102
103
109static void
110destroy (void *cls)
111{
112 struct Speaker *spe = cls;
113
114 if (NULL != spe->playback_helper)
115 disable (spe);
116}
117
118
127static void
128play (void *cls,
129 size_t data_size,
130 const void *data)
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}
150
151
162{
164 struct Speaker *spe;
165
166 spe = GNUNET_new (struct Speaker);
167 spe->cfg = cfg;
169 speaker->cls = spe;
171 speaker->play = &play;
174 return speaker;
175}
176
177
183void
185{
188}
189
190
191/* end of speaker.c */
constants for network protocols
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
API to access an audio speaker; provides access to hardware speakers.
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
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
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
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#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.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
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:160
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:184
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
static void disable(void *cls)
Function that disables a speaker.
Definition: speaker.c:88
static int enable(void *cls)
Function that enables a speaker.
Definition: speaker.c:58
static void destroy(void *cls)
Function to destroy a speaker.
Definition: speaker.c:110
static void play(void *cls, size_t data_size, const void *data)
Function to cause a speaker to play audio data.
Definition: speaker.c:128
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
The handle to a helper process.
Definition: helper.c:77
A speaker is a device that can play or record audio data.
GNUNET_SPEAKER_DestroyCallback destroy_speaker
Destroy the speaker.
void * cls
Closure for the callbacks.
GNUNET_SPEAKER_PlayCallback play
Play audio.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.
GNUNET_SPEAKER_DisableCallback disable_speaker
Turn the speaker off.
Internal data structures for the speaker.
Definition: speaker.c:38
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: speaker.c:42
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:47