diff options
Diffstat (limited to 'src/conversation/speaker.c')
-rw-r--r-- | src/conversation/speaker.c | 120 |
1 files changed, 59 insertions, 61 deletions
diff --git a/src/conversation/speaker.c b/src/conversation/speaker.c index e2ace9115..96fd42b8d 100644 --- a/src/conversation/speaker.c +++ b/src/conversation/speaker.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -33,8 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Internal data structures for the speaker. | 34 | * Internal data structures for the speaker. |
35 | */ | 35 | */ |
36 | struct Speaker | 36 | struct Speaker { |
37 | { | ||
38 | /** | 37 | /** |
39 | * Our configuration. | 38 | * Our configuration. |
40 | */ | 39 | */ |
@@ -44,7 +43,6 @@ struct Speaker | |||
44 | * Handle for the playback helper | 43 | * Handle for the playback helper |
45 | */ | 44 | */ |
46 | struct GNUNET_HELPER_Handle *playback_helper; | 45 | struct GNUNET_HELPER_Handle *playback_helper; |
47 | |||
48 | }; | 46 | }; |
49 | 47 | ||
50 | 48 | ||
@@ -55,7 +53,7 @@ struct Speaker | |||
55 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 53 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
56 | */ | 54 | */ |
57 | static int | 55 | static int |
58 | enable (void *cls) | 56 | enable(void *cls) |
59 | { | 57 | { |
60 | struct Speaker *spe = cls; | 58 | struct Speaker *spe = cls; |
61 | static char *playback_helper_argv[] = | 59 | static char *playback_helper_argv[] = |
@@ -64,17 +62,17 @@ enable (void *cls) | |||
64 | NULL | 62 | NULL |
65 | }; | 63 | }; |
66 | 64 | ||
67 | spe->playback_helper = GNUNET_HELPER_start (GNUNET_NO, | 65 | spe->playback_helper = GNUNET_HELPER_start(GNUNET_NO, |
68 | "gnunet-helper-audio-playback", | 66 | "gnunet-helper-audio-playback", |
69 | playback_helper_argv, | 67 | playback_helper_argv, |
70 | NULL, | 68 | NULL, |
71 | NULL, spe); | 69 | NULL, spe); |
72 | if (NULL == spe->playback_helper) | 70 | if (NULL == spe->playback_helper) |
73 | { | 71 | { |
74 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 72 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
75 | _("Could not start playback audio helper.\n")); | 73 | _("Could not start playback audio helper.\n")); |
76 | return GNUNET_SYSERR; | 74 | return GNUNET_SYSERR; |
77 | } | 75 | } |
78 | return GNUNET_OK; | 76 | return GNUNET_OK; |
79 | } | 77 | } |
80 | 78 | ||
@@ -85,18 +83,18 @@ enable (void *cls) | |||
85 | * @param cls closure with the `struct Speaker` | 83 | * @param cls closure with the `struct Speaker` |
86 | */ | 84 | */ |
87 | static void | 85 | static void |
88 | disable (void *cls) | 86 | disable(void *cls) |
89 | { | 87 | { |
90 | struct Speaker *spe = cls; | 88 | struct Speaker *spe = cls; |
91 | 89 | ||
92 | if (NULL == spe->playback_helper) | 90 | if (NULL == spe->playback_helper) |
93 | { | 91 | { |
94 | GNUNET_break (0); | 92 | GNUNET_break(0); |
95 | return; | 93 | return; |
96 | } | 94 | } |
97 | GNUNET_break (GNUNET_OK == | 95 | GNUNET_break(GNUNET_OK == |
98 | GNUNET_HELPER_kill (spe->playback_helper, GNUNET_NO)); | 96 | GNUNET_HELPER_kill(spe->playback_helper, GNUNET_NO)); |
99 | GNUNET_HELPER_destroy (spe->playback_helper); | 97 | GNUNET_HELPER_destroy(spe->playback_helper); |
100 | spe->playback_helper = NULL; | 98 | spe->playback_helper = NULL; |
101 | } | 99 | } |
102 | 100 | ||
@@ -107,12 +105,12 @@ disable (void *cls) | |||
107 | * @param cls closure with the `struct Speaker` | 105 | * @param cls closure with the `struct Speaker` |
108 | */ | 106 | */ |
109 | static void | 107 | static void |
110 | destroy (void *cls) | 108 | destroy(void *cls) |
111 | { | 109 | { |
112 | struct Speaker *spe = cls; | 110 | struct Speaker *spe = cls; |
113 | 111 | ||
114 | if (NULL != spe->playback_helper) | 112 | if (NULL != spe->playback_helper) |
115 | disable (spe); | 113 | disable(spe); |
116 | } | 114 | } |
117 | 115 | ||
118 | 116 | ||
@@ -125,27 +123,27 @@ destroy (void *cls) | |||
125 | * opaque to the API but should be OPUS. | 123 | * opaque to the API but should be OPUS. |
126 | */ | 124 | */ |
127 | static void | 125 | static void |
128 | play (void *cls, | 126 | play(void *cls, |
129 | size_t data_size, | 127 | size_t data_size, |
130 | const void *data) | 128 | const void *data) |
131 | { | 129 | { |
132 | struct Speaker *spe = cls; | 130 | struct Speaker *spe = cls; |
133 | char buf[sizeof (struct AudioMessage) + data_size]; | 131 | char buf[sizeof(struct AudioMessage) + data_size]; |
134 | struct AudioMessage *am; | 132 | struct AudioMessage *am; |
135 | 133 | ||
136 | if (NULL == spe->playback_helper) | 134 | if (NULL == spe->playback_helper) |
137 | { | 135 | { |
138 | GNUNET_break (0); | 136 | GNUNET_break(0); |
139 | return; | 137 | return; |
140 | } | 138 | } |
141 | am = (struct AudioMessage *) buf; | 139 | am = (struct AudioMessage *)buf; |
142 | am->header.size = htons (sizeof (struct AudioMessage) + data_size); | 140 | am->header.size = htons(sizeof(struct AudioMessage) + data_size); |
143 | am->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 141 | am->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
144 | GNUNET_memcpy (&am[1], data, data_size); | 142 | GNUNET_memcpy(&am[1], data, data_size); |
145 | (void) GNUNET_HELPER_send (spe->playback_helper, | 143 | (void)GNUNET_HELPER_send(spe->playback_helper, |
146 | &am->header, | 144 | &am->header, |
147 | GNUNET_NO, | 145 | GNUNET_NO, |
148 | NULL, NULL); | 146 | NULL, NULL); |
149 | } | 147 | } |
150 | 148 | ||
151 | 149 | ||
@@ -157,14 +155,14 @@ play (void *cls, | |||
157 | * @return NULL on error | 155 | * @return NULL on error |
158 | */ | 156 | */ |
159 | struct GNUNET_SPEAKER_Handle * | 157 | struct GNUNET_SPEAKER_Handle * |
160 | GNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg) | 158 | GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg) |
161 | { | 159 | { |
162 | struct GNUNET_SPEAKER_Handle *speaker; | 160 | struct GNUNET_SPEAKER_Handle *speaker; |
163 | struct Speaker *spe; | 161 | struct Speaker *spe; |
164 | 162 | ||
165 | spe = GNUNET_new (struct Speaker); | 163 | spe = GNUNET_new(struct Speaker); |
166 | spe->cfg = cfg; | 164 | spe->cfg = cfg; |
167 | speaker = GNUNET_new (struct GNUNET_SPEAKER_Handle); | 165 | speaker = GNUNET_new(struct GNUNET_SPEAKER_Handle); |
168 | speaker->cls = spe; | 166 | speaker->cls = spe; |
169 | speaker->enable_speaker = &enable; | 167 | speaker->enable_speaker = &enable; |
170 | speaker->play = &play; | 168 | speaker->play = &play; |
@@ -180,10 +178,10 @@ GNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *c | |||
180 | * @param speaker speaker to destroy | 178 | * @param speaker speaker to destroy |
181 | */ | 179 | */ |
182 | void | 180 | void |
183 | GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker) | 181 | GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker) |
184 | { | 182 | { |
185 | speaker->destroy_speaker (speaker->cls); | 183 | speaker->destroy_speaker(speaker->cls); |
186 | GNUNET_free (speaker); | 184 | GNUNET_free(speaker); |
187 | } | 185 | } |
188 | 186 | ||
189 | /* end of speaker.c */ | 187 | /* end of speaker.c */ |