diff options
Diffstat (limited to 'src/conversation/gnunet_gst.c')
-rw-r--r-- | src/conversation/gnunet_gst.c | 1217 |
1 files changed, 619 insertions, 598 deletions
diff --git a/src/conversation/gnunet_gst.c b/src/conversation/gnunet_gst.c index c08468996..5db0d350c 100644 --- a/src/conversation/gnunet_gst.c +++ b/src/conversation/gnunet_gst.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2016 GNUnet e.V. | 3 | Copyright (C) 2016 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 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet_gst.c | 21 | * @file conversation/gnunet_gst.c |
22 | * @brief FIXME | 22 | * @brief FIXME |
@@ -38,23 +38,26 @@ dump_buffer(unsigned n, const unsigned char* buf) | |||
38 | 38 | ||
39 | end = buf + n; | 39 | end = buf + n; |
40 | 40 | ||
41 | for (i = 0; ; i += 16) { | 41 | for (i = 0; ; i += 16) |
42 | p = buf + i; | 42 | { |
43 | for (j = 0; j < 16; j++) { | 43 | p = buf + i; |
44 | fprintf(stderr, "%02X ", p[j]); | 44 | for (j = 0; j < 16; j++) |
45 | if (p + j >= end) | 45 | { |
46 | goto BREAKOUT; | 46 | fprintf(stderr, "%02X ", p[j]); |
47 | } | 47 | if (p + j >= end) |
48 | fprintf(stderr, " "); | 48 | goto BREAKOUT; |
49 | p = buf + i; | 49 | } |
50 | for (j = 0; j < 16; j++) { | 50 | fprintf(stderr, " "); |
51 | fprintf(stderr, "%c", isprint(p[j]) ? p[j] : | 51 | p = buf + i; |
52 | '.'); | 52 | for (j = 0; j < 16; j++) |
53 | if (p + j >= end) | 53 | { |
54 | goto BREAKOUT; | 54 | fprintf(stderr, "%c", isprint(p[j]) ? p[j] : |
55 | '.'); | ||
56 | if (p + j >= end) | ||
57 | goto BREAKOUT; | ||
58 | } | ||
59 | fprintf(stderr, "\n"); | ||
55 | } | 60 | } |
56 | fprintf(stderr, "\n"); | ||
57 | } | ||
58 | BREAKOUT: | 61 | BREAKOUT: |
59 | return; | 62 | return; |
60 | } | 63 | } |
@@ -66,7 +69,8 @@ void | |||
66 | gg_load_configuration(GNUNET_gstData * d) | 69 | gg_load_configuration(GNUNET_gstData * d) |
67 | { | 70 | { |
68 | char *audiobackend_string; | 71 | char *audiobackend_string; |
69 | cfg = GNUNET_CONFIGURATION_create(); | 72 | |
73 | cfg = GNUNET_CONFIGURATION_create(); | ||
70 | GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf"); | 74 | GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf"); |
71 | 75 | ||
72 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in); | 76 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in); |
@@ -74,77 +78,88 @@ gg_load_configuration(GNUNET_gstData * d) | |||
74 | 78 | ||
75 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string); | 79 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string); |
76 | 80 | ||
77 | // printf("abstring: %s \n", audiobackend_string); | 81 | // printf("abstring: %s \n", audiobackend_string); |
78 | 82 | ||
79 | if (0 == strcasecmp (audiobackend_string, "AUTO")) | 83 | if (0 == strcasecmp(audiobackend_string, "AUTO")) |
80 | { | 84 | { |
81 | d->audiobackend = AUTO; | 85 | d->audiobackend = AUTO; |
82 | } else if (0 == strcasecmp (audiobackend_string, "JACK")) | 86 | } |
83 | { | 87 | else if (0 == strcasecmp(audiobackend_string, "JACK")) |
84 | d->audiobackend = JACK; | 88 | { |
85 | } else if (0 == strcasecmp (audiobackend_string, "ALSA")) | 89 | d->audiobackend = JACK; |
86 | { | 90 | } |
87 | d->audiobackend = ALSA; | 91 | else if (0 == strcasecmp(audiobackend_string, "ALSA")) |
88 | } else if (0 == strcasecmp (audiobackend_string, "FAKE")) | 92 | { |
89 | { | 93 | d->audiobackend = ALSA; |
90 | d->audiobackend = FAKE; | 94 | } |
91 | } else if (0 == strcasecmp (audiobackend_string, "TEST")) | 95 | else if (0 == strcasecmp(audiobackend_string, "FAKE")) |
92 | { | 96 | { |
93 | d->audiobackend = TEST; | 97 | d->audiobackend = FAKE; |
94 | } else | 98 | } |
95 | { | 99 | else if (0 == strcasecmp(audiobackend_string, "TEST")) |
96 | d->audiobackend = AUTO; | 100 | { |
97 | } | 101 | d->audiobackend = TEST; |
102 | } | ||
103 | else | ||
104 | { | ||
105 | d->audiobackend = AUTO; | ||
106 | } | ||
98 | 107 | ||
99 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES) | 108 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES) |
100 | { | 109 | { |
101 | d->dropsilence = TRUE; | 110 | d->dropsilence = TRUE; |
102 | } else { | 111 | } |
103 | d->dropsilence = FALSE; | 112 | else |
104 | } | 113 | { |
114 | d->dropsilence = FALSE; | ||
115 | } | ||
105 | 116 | ||
106 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES) | 117 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES) |
107 | { | 118 | { |
108 | d->pure_ogg = TRUE; | 119 | d->pure_ogg = TRUE; |
109 | } else { | 120 | } |
110 | d->pure_ogg = FALSE; | 121 | else |
111 | } | 122 | { |
123 | d->pure_ogg = FALSE; | ||
124 | } | ||
112 | 125 | ||
113 | 126 | ||
114 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES) | 127 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES) |
115 | { | 128 | { |
116 | d->usertp = TRUE; | 129 | d->usertp = TRUE; |
117 | } else { | 130 | } |
118 | d->usertp = FALSE; | 131 | else |
119 | } | 132 | { |
133 | d->usertp = FALSE; | ||
134 | } | ||
120 | 135 | ||
121 | // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); | 136 | // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); |
122 | |||
123 | } | 137 | } |
124 | 138 | ||
125 | static void | 139 | static void |
126 | write_data (const char *ptr, size_t msg_size) | 140 | write_data(const char *ptr, size_t msg_size) |
127 | { | 141 | { |
128 | ssize_t ret; | 142 | ssize_t ret; |
129 | size_t off; | 143 | size_t off; |
144 | |||
130 | off = 0; | 145 | off = 0; |
131 | while (off < msg_size) | 146 | while (off < msg_size) |
132 | { | ||
133 | ret = write (1, &ptr[off], msg_size - off); | ||
134 | if (0 >= ret) | ||
135 | { | 147 | { |
136 | if (-1 == ret) | 148 | ret = write(1, &ptr[off], msg_size - off); |
137 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write"); | 149 | if (0 >= ret) |
150 | { | ||
151 | if (-1 == ret) | ||
152 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "write"); | ||
138 | // quit (2); | 153 | // quit (2); |
154 | } | ||
155 | off += ret; | ||
139 | } | 156 | } |
140 | off += ret; | ||
141 | } | ||
142 | } | 157 | } |
143 | 158 | ||
144 | 159 | ||
145 | 160 | ||
146 | extern GstFlowReturn | 161 | extern GstFlowReturn |
147 | on_appsink_new_sample (GstElement * element, GNUNET_gstData * d) | 162 | on_appsink_new_sample(GstElement * element, GNUNET_gstData * d) |
148 | { | 163 | { |
149 | //size of message including gnunet header | 164 | //size of message including gnunet header |
150 | size_t msg_size; | 165 | size_t msg_size; |
@@ -152,72 +167,70 @@ on_appsink_new_sample (GstElement * element, GNUNET_gstData * d) | |||
152 | GstSample *s; | 167 | GstSample *s; |
153 | GstBuffer *b; | 168 | GstBuffer *b; |
154 | GstMapInfo map; | 169 | GstMapInfo map; |
170 | |||
155 | /* | 171 | /* |
156 | const GstStructure *si; | 172 | const GstStructure *si; |
157 | char *si_str; | 173 | char *si_str; |
158 | GstCaps *s_caps; | 174 | GstCaps *s_caps; |
159 | char *caps_str; | 175 | char *caps_str; |
160 | */ | 176 | */ |
161 | 177 | ||
162 | if (gst_app_sink_is_eos(GST_APP_SINK(element))) | 178 | if (gst_app_sink_is_eos(GST_APP_SINK(element))) |
163 | return GST_FLOW_OK; | 179 | return GST_FLOW_OK; |
164 | 180 | ||
165 | //pull sample from appsink | 181 | //pull sample from appsink |
166 | s = gst_app_sink_pull_sample (GST_APP_SINK(element)); | 182 | s = gst_app_sink_pull_sample(GST_APP_SINK(element)); |
167 | 183 | ||
168 | if (s == NULL) | 184 | if (s == NULL) |
169 | return GST_FLOW_OK; | 185 | return GST_FLOW_OK; |
170 | 186 | ||
171 | if (!GST_IS_SAMPLE (s)) | 187 | if (!GST_IS_SAMPLE(s)) |
172 | return GST_FLOW_OK; | 188 | return GST_FLOW_OK; |
173 | 189 | ||
174 | b = gst_sample_get_buffer(s); | 190 | b = gst_sample_get_buffer(s); |
175 | 191 | ||
176 | GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s)); | 192 | GST_WARNING("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s)); |
177 | 193 | ||
178 | 194 | ||
179 | 195 | ||
180 | gst_buffer_map (b, &map, GST_MAP_READ); | 196 | gst_buffer_map(b, &map, GST_MAP_READ); |
181 | 197 | ||
182 | size_t len; | 198 | size_t len; |
183 | len = map.size; | 199 | len = map.size; |
184 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) | 200 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) |
185 | { | 201 | { |
186 | // this should never happen? | 202 | // this should never happen? |
187 | printf("GSTREAMER sample too big! \n"); | 203 | printf("GSTREAMER sample too big! \n"); |
188 | exit(20); | 204 | exit(20); |
189 | len = UINT16_MAX - sizeof (struct AudioMessage); | 205 | len = UINT16_MAX - sizeof(struct AudioMessage); |
190 | } | 206 | } |
191 | 207 | ||
192 | msg_size = sizeof (struct AudioMessage) + len; | 208 | msg_size = sizeof(struct AudioMessage) + len; |
193 | 209 | ||
194 | // copy the data into audio_message | 210 | // copy the data into audio_message |
195 | GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len); | 211 | GNUNET_memcpy(((char *)&(d->audio_message)[1]), map.data, len); |
196 | (d->audio_message)->header.size = htons ((uint16_t) msg_size); | 212 | (d->audio_message)->header.size = htons((uint16_t)msg_size); |
197 | if (d->pure_ogg) | 213 | if (d->pure_ogg) |
198 | // write the audio_message without the gnunet headers | 214 | // write the audio_message without the gnunet headers |
199 | write_data ((const char *) &(d->audio_message)[1], len); | 215 | write_data((const char *)&(d->audio_message)[1], len); |
200 | else | 216 | else |
201 | write_data ((const char *) d->audio_message, msg_size); | 217 | write_data((const char *)d->audio_message, msg_size); |
202 | 218 | ||
203 | gst_sample_unref(s); | 219 | gst_sample_unref(s); |
204 | return GST_FLOW_OK; | 220 | return GST_FLOW_OK; |
205 | } | 221 | } |
206 | 222 | ||
207 | /*** | 223 | /*** |
208 | * Dump a pipeline graph | 224 | * Dump a pipeline graph |
209 | */ | 225 | */ |
210 | extern void | 226 | extern void |
211 | pl_graph(GstElement * pipeline) | 227 | pl_graph(GstElement * pipeline) |
212 | { | 228 | { |
213 | |||
214 | #ifdef IS_SPEAKER | 229 | #ifdef IS_SPEAKER |
215 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot"); | 230 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot"); |
216 | |||
217 | #endif | 231 | #endif |
218 | #ifdef IS_MIC | 232 | #ifdef IS_MIC |
219 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot"); | 233 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot"); |
220 | |||
221 | #endif | 234 | #endif |
222 | 235 | ||
223 | 236 | ||
@@ -227,142 +240,145 @@ pl_graph(GstElement * pipeline) | |||
227 | 240 | ||
228 | 241 | ||
229 | extern gboolean | 242 | extern gboolean |
230 | gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data) | 243 | gnunet_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) |
231 | { | 244 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
233 | "Bus message\n"); | 246 | "Bus message\n"); |
234 | switch (GST_MESSAGE_TYPE (msg)) | 247 | switch (GST_MESSAGE_TYPE(msg)) |
235 | { | 248 | { |
236 | case GST_MESSAGE_EOS: | 249 | case GST_MESSAGE_EOS: |
237 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 250 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
238 | "End of stream\n"); | 251 | "End of stream\n"); |
239 | exit (10); | 252 | exit(10); |
240 | break; | 253 | break; |
241 | 254 | ||
242 | case GST_MESSAGE_ERROR: | 255 | case GST_MESSAGE_ERROR: |
243 | { | 256 | { |
244 | gchar *debug; | 257 | gchar *debug; |
245 | GError *error; | 258 | GError *error; |
246 | 259 | ||
247 | gst_message_parse_error (msg, &error, &debug); | 260 | gst_message_parse_error(msg, &error, &debug); |
248 | g_free (debug); | 261 | g_free(debug); |
249 | 262 | ||
250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 263 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
251 | "Error: %s\n", | 264 | "Error: %s\n", |
252 | error->message); | 265 | error->message); |
253 | g_error_free (error); | 266 | g_error_free(error); |
254 | 267 | ||
255 | exit (10); | 268 | exit(10); |
269 | break; | ||
270 | } | ||
271 | |||
272 | default: | ||
256 | break; | 273 | break; |
257 | } | 274 | } |
258 | default: | ||
259 | break; | ||
260 | } | ||
261 | 275 | ||
262 | return TRUE; | 276 | return TRUE; |
263 | } | 277 | } |
264 | 278 | ||
265 | /* called when pipeline changes state */ | 279 | /* called when pipeline changes state */ |
266 | extern void | 280 | extern void |
267 | state_changed_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * d) | 281 | state_changed_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * d) |
268 | { | 282 | { |
269 | GstState old_state, new_state, pending_state; | 283 | GstState old_state, new_state, pending_state; |
270 | 284 | ||
271 | gst_message_parse_state_changed (msg, &old_state, &new_state, | 285 | gst_message_parse_state_changed(msg, &old_state, &new_state, |
272 | &pending_state); | 286 | &pending_state); |
273 | switch (new_state) | 287 | switch (new_state) |
274 | { | 288 | { |
275 | |||
276 | case GST_STATE_READY: | 289 | case GST_STATE_READY: |
277 | // printf("ready.... \n"); | 290 | // printf("ready.... \n"); |
278 | //pl_graph(GST_ELEMENT(d->pipeline)); | 291 | //pl_graph(GST_ELEMENT(d->pipeline)); |
279 | break; | 292 | break; |
293 | |||
280 | case GST_STATE_PLAYING: | 294 | case GST_STATE_PLAYING: |
281 | 295 | ||
282 | //GST_LOG ("caps are %" GST_PTR_FORMAT, caps); | 296 | //GST_LOG ("caps are %" GST_PTR_FORMAT, caps); |
283 | 297 | ||
284 | // printf("Playing.... \n"); | 298 | // printf("Playing.... \n"); |
285 | pl_graph(GST_ELEMENT(d->pipeline)); | 299 | pl_graph(GST_ELEMENT(d->pipeline)); |
286 | break; | 300 | break; |
301 | |||
287 | case GST_STATE_VOID_PENDING: | 302 | case GST_STATE_VOID_PENDING: |
288 | // printf("void_pending.... \n"); | 303 | // printf("void_pending.... \n"); |
289 | //pl_graph(GST_ELEMENT(d->pipeline)); | 304 | //pl_graph(GST_ELEMENT(d->pipeline)); |
290 | break; | 305 | break; |
306 | |||
291 | case GST_STATE_NULL: | 307 | case GST_STATE_NULL: |
292 | // printf("null.... \n"); | 308 | // printf("null.... \n"); |
293 | //pl_graph(GST_ELEMENT(d->pipeline)); | 309 | //pl_graph(GST_ELEMENT(d->pipeline)); |
294 | break; | 310 | break; |
295 | 311 | ||
296 | case GST_STATE_PAUSED: | 312 | case GST_STATE_PAUSED: |
297 | // printf("paused.... \n"); | 313 | // printf("paused.... \n"); |
298 | //pl_graph(GST_ELEMENT(d->pipeline)); | 314 | //pl_graph(GST_ELEMENT(d->pipeline)); |
299 | break; | 315 | break; |
300 | } | 316 | } |
301 | } | 317 | } |
302 | 318 | ||
303 | static void | 319 | static void |
304 | application_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 320 | application_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) |
305 | { | 321 | { |
306 | // printf("application cb"); | 322 | // printf("application cb"); |
307 | return; | 323 | return; |
308 | } | 324 | } |
309 | 325 | ||
310 | static void | 326 | static void |
311 | error_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 327 | error_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) |
312 | { | 328 | { |
313 | // printf("error cb"); | 329 | // printf("error cb"); |
314 | return; | 330 | return; |
315 | } | 331 | } |
316 | 332 | ||
317 | static void | 333 | static void |
318 | eos_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 334 | eos_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) |
319 | { | 335 | { |
320 | // printf("eos cb"); | 336 | // printf("eos cb"); |
321 | return; | 337 | return; |
322 | } | 338 | } |
323 | 339 | ||
324 | extern void | 340 | extern void |
325 | gg_setup_gst_bus (GNUNET_gstData * d) | 341 | gg_setup_gst_bus(GNUNET_gstData * d) |
326 | { | 342 | { |
327 | GstBus *bus; | 343 | GstBus *bus; |
328 | bus = gst_element_get_bus (GST_ELEMENT(d->pipeline)); | ||
329 | gst_bus_add_signal_watch (bus); | ||
330 | g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb, | ||
331 | d); | ||
332 | g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb, | ||
333 | d); | ||
334 | g_signal_connect (G_OBJECT (bus), "message::state-changed", | ||
335 | (GCallback) state_changed_cb, d); | ||
336 | g_signal_connect (G_OBJECT (bus), "message::application", | ||
337 | (GCallback) application_cb, d); | ||
338 | g_signal_connect (G_OBJECT (bus), "message::about-to-finish", | ||
339 | (GCallback) application_cb, d); | ||
340 | gst_object_unref (bus); | ||
341 | 344 | ||
345 | bus = gst_element_get_bus(GST_ELEMENT(d->pipeline)); | ||
346 | gst_bus_add_signal_watch(bus); | ||
347 | g_signal_connect(G_OBJECT(bus), "message::error", (GCallback)error_cb, | ||
348 | d); | ||
349 | g_signal_connect(G_OBJECT(bus), "message::eos", (GCallback)eos_cb, | ||
350 | d); | ||
351 | g_signal_connect(G_OBJECT(bus), "message::state-changed", | ||
352 | (GCallback)state_changed_cb, d); | ||
353 | g_signal_connect(G_OBJECT(bus), "message::application", | ||
354 | (GCallback)application_cb, d); | ||
355 | g_signal_connect(G_OBJECT(bus), "message::about-to-finish", | ||
356 | (GCallback)application_cb, d); | ||
357 | gst_object_unref(bus); | ||
342 | } | 358 | } |
343 | 359 | ||
344 | /* | 360 | /* |
345 | * take buffer from gstreamer and feed it to gnunet | 361 | * take buffer from gstreamer and feed it to gnunet |
346 | */ | 362 | */ |
347 | /* | 363 | /* |
348 | extern int | 364 | extern int |
349 | feed_buffer_to_gnunet (GNUNET_gstData * d) | 365 | feed_buffer_to_gnunet (GNUNET_gstData * d) |
350 | { | 366 | { |
351 | GstSample *s; | 367 | GstSample *s; |
352 | GstBuffer *b; | 368 | GstBuffer *b; |
353 | GstMapInfo m; | 369 | GstMapInfo m; |
354 | size_t len, msg_size; | 370 | size_t len, msg_size; |
355 | const char *ptr; | 371 | const char *ptr; |
356 | int phase; | 372 | int phase; |
357 | 373 | ||
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); | 374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); |
359 | s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink)); | 375 | s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink)); |
360 | if (NULL == s) | 376 | if (NULL == s) |
361 | { | 377 | { |
362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); | 378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); |
363 | return OK; | 379 | return OK; |
364 | } | 380 | } |
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); | 381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); |
366 | 382 | ||
367 | const GstStructure *si; | 383 | const GstStructure *si; |
368 | char *si_str; | 384 | char *si_str; |
@@ -393,39 +409,39 @@ feed_buffer_to_gnunet (GNUNET_gstData * d) | |||
393 | else | 409 | else |
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); |
395 | 411 | ||
396 | b = gst_sample_get_buffer (s); | 412 | b = gst_sample_get_buffer (s); |
397 | if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ)) | 413 | if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ)) |
398 | { | 414 | { |
399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); | 415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); |
400 | gst_sample_unref (s); | 416 | gst_sample_unref (s); |
401 | return FAIL; | 417 | return FAIL; |
402 | } | 418 | } |
403 | 419 | ||
404 | len = m.size; | 420 | len = m.size; |
405 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) | 421 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) |
406 | { | 422 | { |
407 | GNUNET_break (0); | 423 | GNUNET_break (0); |
408 | len = UINT16_MAX - sizeof (struct AudioMessage); | 424 | len = UINT16_MAX - sizeof (struct AudioMessage); |
409 | } | 425 | } |
410 | msg_size = sizeof (struct AudioMessage) + len; | 426 | msg_size = sizeof (struct AudioMessage) + len; |
411 | audio_message.header.size = htons ((uint16_t) msg_size); | 427 | audio_message.header.size = htons ((uint16_t) msg_size); |
412 | 428 | ||
413 | 429 | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
415 | "Sending %u bytes of audio data\n", (unsigned int) msg_size); | 431 | "Sending %u bytes of audio data\n", (unsigned int) msg_size); |
416 | for (phase = 0; phase < 2; phase++) | 432 | for (phase = 0; phase < 2; phase++) |
417 | { | 433 | { |
418 | size_t offset; | 434 | size_t offset; |
419 | size_t to_send; | 435 | size_t to_send; |
420 | ssize_t ret; | 436 | ssize_t ret; |
421 | if (0 == phase && !d->pure_ogg) | 437 | if (0 == phase && !d->pure_ogg) |
422 | { | 438 | { |
423 | //#ifdef DEBUG_RECORD_PURE_OGG | 439 | //#ifdef DEBUG_RECORD_PURE_OGG |
424 | 440 | ||
425 | // if (d->pure_ogg) | 441 | // if (d->pure_ogg) |
426 | // break; | 442 | // break; |
427 | 443 | ||
428 | //#endif | 444 | //#endif |
429 | ptr = (const char *) &audio_message; | 445 | ptr = (const char *) &audio_message; |
430 | to_send = sizeof (audio_message); | 446 | to_send = sizeof (audio_message); |
431 | } | 447 | } |
@@ -451,65 +467,68 @@ feed_buffer_to_gnunet (GNUNET_gstData * d) | |||
451 | } | 467 | } |
452 | } | 468 | } |
453 | 469 | ||
454 | // if (abort_send) | 470 | // if (abort_send) |
455 | // break; | 471 | // break; |
456 | 472 | ||
457 | } | 473 | } |
458 | gst_buffer_unmap (b, &m); | 474 | gst_buffer_unmap (b, &m); |
459 | gst_sample_unref (s); | 475 | gst_sample_unref (s); |
460 | } | 476 | } |
461 | */ | 477 | */ |
462 | 478 | ||
463 | 479 | ||
464 | extern int | 480 | extern int |
465 | feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData * d) | 481 | feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData * d) |
466 | { | 482 | { |
467 | GstBuffer *b; | 483 | GstBuffer *b; |
468 | gchar *bufspace; | 484 | gchar *bufspace; |
469 | GstFlowReturn flow; | 485 | GstFlowReturn flow; |
470 | 486 | ||
471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 487 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
472 | "Feeding %u bytes to GStreamer\n", | 488 | "Feeding %u bytes to GStreamer\n", |
473 | (unsigned int) b_len); | 489 | (unsigned int)b_len); |
474 | 490 | ||
475 | bufspace = g_memdup (audio, b_len); | 491 | bufspace = g_memdup(audio, b_len); |
476 | b = gst_buffer_new_wrapped (bufspace, b_len); | 492 | b = gst_buffer_new_wrapped(bufspace, b_len); |
477 | if (NULL == b) | 493 | if (NULL == b) |
478 | { | 494 | { |
479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
480 | "Failed to wrap a buffer\n"); | 496 | "Failed to wrap a buffer\n"); |
481 | g_free (bufspace); | 497 | g_free(bufspace); |
482 | return GNUNET_SYSERR; | 498 | return GNUNET_SYSERR; |
483 | } | 499 | } |
484 | if (GST_APP_SRC(d->appsrc) == NULL) | 500 | if (GST_APP_SRC(d->appsrc) == NULL) |
485 | exit(10); | 501 | exit(10); |
486 | flow = gst_app_src_push_buffer (GST_APP_SRC(d->appsrc), b); | 502 | flow = gst_app_src_push_buffer(GST_APP_SRC(d->appsrc), b); |
487 | /* They all return GNUNET_OK, because currently player stops when | 503 | /* They all return GNUNET_OK, because currently player stops when |
488 | * data stops coming. This might need to be changed for the player | 504 | * data stops coming. This might need to be changed for the player |
489 | * to also stop when pipeline breaks. | 505 | * to also stop when pipeline breaks. |
490 | */ | 506 | */ |
491 | switch (flow) | 507 | switch (flow) |
492 | { | 508 | { |
493 | case GST_FLOW_OK: | 509 | case GST_FLOW_OK: |
494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 510 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
495 | "Fed %u bytes to the pipeline\n", | 511 | "Fed %u bytes to the pipeline\n", |
496 | (unsigned int) b_len); | 512 | (unsigned int)b_len); |
497 | break; | 513 | break; |
498 | case GST_FLOW_FLUSHING: | 514 | |
499 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ | 515 | case GST_FLOW_FLUSHING: |
500 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 516 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ |
501 | "Dropped a buffer\n"); | 517 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
502 | break; | 518 | "Dropped a buffer\n"); |
503 | case GST_FLOW_EOS: | 519 | break; |
504 | /* end of stream */ | 520 | |
505 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 521 | case GST_FLOW_EOS: |
506 | "EOS\n"); | 522 | /* end of stream */ |
507 | break; | 523 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
508 | default: | 524 | "EOS\n"); |
509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 525 | break; |
510 | "Unexpected push result\n"); | 526 | |
511 | break; | 527 | default: |
512 | } | 528 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
529 | "Unexpected push result\n"); | ||
530 | break; | ||
531 | } | ||
513 | return GNUNET_OK; | 532 | return GNUNET_OK; |
514 | } | 533 | } |
515 | 534 | ||
@@ -518,35 +537,37 @@ feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData * d) | |||
518 | /** | 537 | /** |
519 | * debug making elements | 538 | * debug making elements |
520 | */ | 539 | */ |
521 | extern GstElement * | 540 | extern GstElement * |
522 | gst_element_factory_make_debug( gchar *factoryname, gchar *name) | 541 | gst_element_factory_make_debug(gchar *factoryname, gchar *name) |
523 | { | 542 | { |
524 | GstElement *element; | 543 | GstElement *element; |
525 | 544 | ||
526 | element = gst_element_factory_make(factoryname,name); | 545 | element = gst_element_factory_make(factoryname, name); |
527 | |||
528 | if (element == NULL) { | ||
529 | 546 | ||
530 | printf ("\n Failed to create element - type: %s name: %s \n", factoryname, name); | 547 | if (element == NULL) |
531 | exit(10); | 548 | { |
532 | return element; | 549 | printf("\n Failed to create element - type: %s name: %s \n", factoryname, name); |
533 | } else { | 550 | exit(10); |
534 | return element; | 551 | return element; |
535 | } | 552 | } |
553 | else | ||
554 | { | ||
555 | return element; | ||
556 | } | ||
536 | } | 557 | } |
537 | 558 | ||
538 | /* | 559 | /* |
539 | static gboolean | 560 | static gboolean |
540 | gst_element_link_many_debug(...) | 561 | gst_element_link_many_debug(...) |
541 | { | 562 | { |
542 | va_list arguments; | 563 | va_list arguments; |
543 | gst_element_link_many(argptr); | 564 | gst_element_link_many(argptr); |
544 | } | 565 | } |
545 | 566 | ||
546 | #define gst_element_link_many(...) \ | 567 | #define gst_element_link_many(...) \ |
547 | gst_element_link_many_debug(__VA_ARGS__) | 568 | gst_element_link_many_debug(__VA_ARGS__) |
548 | */ | 569 | */ |
549 | extern void | 570 | extern void |
550 | lf(char * msg) | 571 | lf(char * msg) |
551 | { | 572 | { |
552 | printf("linking elements failed: %s", msg); | 573 | printf("linking elements failed: %s", msg); |
@@ -557,26 +578,26 @@ lf(char * msg) | |||
557 | * used to set properties on autoaudiosink's chosen sink | 578 | * used to set properties on autoaudiosink's chosen sink |
558 | */ | 579 | */ |
559 | static void | 580 | static void |
560 | autoaudiosink_child_added (GstChildProxy *child_proxy, | 581 | autoaudiosink_child_added(GstChildProxy *child_proxy, |
561 | GObject *object, | 582 | GObject *object, |
562 | gchar *name, | 583 | gchar *name, |
563 | gpointer user_data) | 584 | gpointer user_data) |
564 | { | 585 | { |
565 | if (GST_IS_AUDIO_BASE_SRC (object)) | 586 | if (GST_IS_AUDIO_BASE_SRC(object)) |
566 | g_object_set (object, | 587 | g_object_set(object, |
567 | "buffer-time", (gint64) BUFFER_TIME, | 588 | "buffer-time", (gint64)BUFFER_TIME, |
568 | "latency-time", (gint64) LATENCY_TIME, | 589 | "latency-time", (gint64)LATENCY_TIME, |
569 | NULL); | 590 | NULL); |
570 | } | 591 | } |
571 | 592 | ||
572 | /*** | 593 | /*** |
573 | * used to set properties on autoaudiosource's chosen sink | 594 | * used to set properties on autoaudiosource's chosen sink |
574 | */ | 595 | */ |
575 | static void | 596 | static void |
576 | autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) | 597 | autoaudiosource_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) |
577 | { | 598 | { |
578 | if (GST_IS_AUDIO_BASE_SRC (object)) | 599 | if (GST_IS_AUDIO_BASE_SRC(object)) |
579 | g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL); | 600 | g_object_set(object, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); |
580 | } | 601 | } |
581 | 602 | ||
582 | 603 | ||
@@ -585,66 +606,67 @@ get_pipeline(GstElement *element) | |||
585 | { | 606 | { |
586 | GstPipeline *p; | 607 | GstPipeline *p; |
587 | 608 | ||
588 | p = GST_PIPELINE (gst_object_get_parent(GST_OBJECT (element))); | 609 | p = GST_PIPELINE(gst_object_get_parent(GST_OBJECT(element))); |
589 | 610 | ||
590 | return GST_ELEMENT (p); | 611 | return GST_ELEMENT(p); |
591 | } | 612 | } |
592 | 613 | ||
593 | static void | 614 | static void |
594 | decoder_ogg_pad_added (GstElement *element, | 615 | decoder_ogg_pad_added(GstElement *element, |
595 | GstPad *pad, | 616 | GstPad *pad, |
596 | gpointer data) | 617 | gpointer data) |
597 | { | 618 | { |
598 | GstPad *sinkpad; | 619 | GstPad *sinkpad; |
599 | GstElement *decoder = (GstElement *) data; | 620 | GstElement *decoder = (GstElement *)data; |
600 | 621 | ||
601 | printf("==== ogg pad added callback \n"); | 622 | printf("==== ogg pad added callback \n"); |
602 | /* We can now link this pad with the opus-decoder sink pad */ | 623 | /* We can now link this pad with the opus-decoder sink pad */ |
603 | // pl_graph(get_pipeline(element)); | 624 | // pl_graph(get_pipeline(element)); |
604 | sinkpad = gst_element_get_static_pad (decoder, "sink"); | 625 | sinkpad = gst_element_get_static_pad(decoder, "sink"); |
605 | 626 | ||
606 | gst_pad_link (pad, sinkpad); | 627 | gst_pad_link(pad, sinkpad); |
607 | gst_element_link_many(element, decoder, NULL); | 628 | gst_element_link_many(element, decoder, NULL); |
608 | gst_object_unref (sinkpad); | 629 | gst_object_unref(sinkpad); |
609 | } | 630 | } |
610 | 631 | ||
611 | 632 | ||
612 | int | 633 | int |
613 | gnunet_read (GNUNET_gstData * d) | 634 | gnunet_read(GNUNET_gstData * d) |
614 | { | 635 | { |
615 | char readbuf[MAXLINE]; | 636 | char readbuf[MAXLINE]; |
616 | int ret; | 637 | int ret; |
638 | |||
617 | printf("read \n"); | 639 | printf("read \n"); |
618 | ret = read (0, readbuf, sizeof (readbuf)); | 640 | ret = read(0, readbuf, sizeof(readbuf)); |
619 | if (0 > ret) | 641 | if (0 > ret) |
620 | { | 642 | { |
621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 643 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
622 | _("Read error from STDIN: %d %s\n"), | 644 | _("Read error from STDIN: %d %s\n"), |
623 | ret, strerror (errno)); | 645 | ret, strerror(errno)); |
624 | return FAIL; | 646 | return FAIL; |
625 | } | 647 | } |
626 | //toff += ret; | 648 | //toff += ret; |
627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 649 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
628 | "Received %d bytes of audio data\n", | 650 | "Received %d bytes of audio data\n", |
629 | (int) ret); | 651 | (int)ret); |
630 | if (0 == ret) | 652 | if (0 == ret) |
631 | return FAIL; | 653 | return FAIL; |
632 | //#ifdef DEBUG_READ_PURE_OGG | 654 | //#ifdef DEBUG_READ_PURE_OGG |
633 | 655 | ||
634 | if (d->pure_ogg) | 656 | if (d->pure_ogg) |
635 | { | 657 | { |
636 | feed_buffer_to_gst (readbuf, ret, d); | 658 | feed_buffer_to_gst(readbuf, ret, d); |
637 | } | 659 | } |
638 | else | 660 | else |
639 | { | 661 | { |
640 | //#endif | 662 | //#endif |
641 | GNUNET_MST_from_buffer (d->stdin_mst, | 663 | GNUNET_MST_from_buffer(d->stdin_mst, |
642 | readbuf, | 664 | readbuf, |
643 | ret, | 665 | ret, |
644 | GNUNET_NO, | 666 | GNUNET_NO, |
645 | GNUNET_NO); | 667 | GNUNET_NO); |
646 | } | 668 | } |
647 | return 0; | 669 | return 0; |
648 | } | 670 | } |
649 | 671 | ||
650 | /** | 672 | /** |
@@ -656,29 +678,30 @@ gnunet_read (GNUNET_gstData * d) | |||
656 | * #GNUNET_SYSERR to stop further processing due to error | 678 | * #GNUNET_SYSERR to stop further processing due to error |
657 | */ | 679 | */ |
658 | static int | 680 | static int |
659 | stdin_receiver (void *cls, | 681 | stdin_receiver(void *cls, |
660 | const struct GNUNET_MessageHeader *msg) | 682 | const struct GNUNET_MessageHeader *msg) |
661 | { | 683 | { |
662 | struct AudioMessage *audio; | 684 | struct AudioMessage *audio; |
663 | size_t b_len; | 685 | size_t b_len; |
664 | 686 | ||
665 | printf("stdin receiver \n "); | 687 | printf("stdin receiver \n "); |
666 | dump_buffer (sizeof(msg), | 688 | dump_buffer(sizeof(msg), |
667 | (const unsigned char *) msg); | 689 | (const unsigned char *)msg); |
668 | 690 | ||
669 | switch (ntohs (msg->type)) | 691 | switch (ntohs(msg->type)) |
670 | { | 692 | { |
671 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 693 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
672 | audio = (struct AudioMessage *) msg; | 694 | audio = (struct AudioMessage *)msg; |
673 | 695 | ||
674 | b_len = ntohs (audio->header.size) - sizeof (struct AudioMessage); | 696 | b_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); |
675 | printf("feeding buffer to gst \n "); | 697 | printf("feeding buffer to gst \n "); |
676 | feed_buffer_to_gst ((const char *) &audio[1], b_len, cls); | 698 | feed_buffer_to_gst((const char *)&audio[1], b_len, cls); |
677 | break; | 699 | break; |
678 | default: | 700 | |
679 | printf("No audio message: %u \n ", ntohs(msg->type)); | 701 | default: |
680 | break; | 702 | printf("No audio message: %u \n ", ntohs(msg->type)); |
681 | } | 703 | break; |
704 | } | ||
682 | return GNUNET_OK; | 705 | return GNUNET_OK; |
683 | } | 706 | } |
684 | 707 | ||
@@ -689,92 +712,92 @@ get_app(GNUNET_gstData *d, int type) | |||
689 | GstBin *bin; | 712 | GstBin *bin; |
690 | GstPad *pad, *ghostpad; | 713 | GstPad *pad, *ghostpad; |
691 | 714 | ||
692 | if ( type == SOURCE ) | 715 | if (type == SOURCE) |
693 | { | 716 | { |
694 | bin = GST_BIN(gst_bin_new("Gnunet appsrc")); | 717 | bin = GST_BIN(gst_bin_new("Gnunet appsrc")); |
695 | 718 | ||
696 | 719 | ||
697 | GNUNET_assert (GNUNET_OK == | 720 | GNUNET_assert(GNUNET_OK == |
698 | GNUNET_log_setup ("gnunet-helper-audio-playback", | 721 | GNUNET_log_setup("gnunet-helper-audio-playback", |
699 | "WARNING", | 722 | "WARNING", |
700 | NULL)); | 723 | NULL)); |
701 | 724 | ||
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 725 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
703 | "Audio playback starts\n"); | 726 | "Audio playback starts\n"); |
704 | printf(" creating appsrc \n "); | 727 | printf(" creating appsrc \n "); |
705 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 728 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
706 | 729 | ||
707 | // d->audio_message = GNUNET_malloc (UINT16_MAX); | 730 | // d->audio_message = GNUNET_malloc (UINT16_MAX); |
708 | // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); | 731 | // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); |
709 | // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); | 732 | // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); |
710 | 733 | ||
711 | 734 | ||
712 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 735 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
713 | 736 | ||
714 | 737 | ||
715 | d->stdin_mst = GNUNET_MST_create (&stdin_receiver, d); | 738 | d->stdin_mst = GNUNET_MST_create(&stdin_receiver, d); |
716 | 739 | ||
717 | if ( d->stdin_mst == NULL) | 740 | if (d->stdin_mst == NULL) |
718 | printf("stdin_mst = NULL"); | 741 | printf("stdin_mst = NULL"); |
719 | 742 | ||
720 | d->appsrc = gst_element_factory_make ("appsrc", "appsrc"); | 743 | d->appsrc = gst_element_factory_make("appsrc", "appsrc"); |
721 | 744 | ||
722 | gst_bin_add_many( bin, d->appsrc, NULL); | 745 | gst_bin_add_many(bin, d->appsrc, NULL); |
723 | // gst_element_link_many ( encoder, muxer, NULL); | 746 | // gst_element_link_many ( encoder, muxer, NULL); |
724 | 747 | ||
725 | pad = gst_element_get_static_pad (d->appsrc, "src"); | 748 | pad = gst_element_get_static_pad(d->appsrc, "src"); |
726 | ghostpad = gst_ghost_pad_new ("src", pad); | 749 | ghostpad = gst_ghost_pad_new("src", pad); |
727 | } | 750 | } |
728 | if ( type == SINK ) | 751 | if (type == SINK) |
729 | { | 752 | { |
730 | bin = GST_BIN(gst_bin_new("Gnunet appsink")); | 753 | bin = GST_BIN(gst_bin_new("Gnunet appsink")); |
731 | 754 | ||
732 | 755 | ||
733 | GNUNET_assert (GNUNET_OK == | 756 | GNUNET_assert(GNUNET_OK == |
734 | GNUNET_log_setup ("gnunet-helper-audio-record", | 757 | GNUNET_log_setup("gnunet-helper-audio-record", |
735 | "WARNING", | 758 | "WARNING", |
736 | NULL)); | 759 | NULL)); |
737 | 760 | ||
738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
739 | "Audio source starts\n"); | 762 | "Audio source starts\n"); |
740 | 763 | ||
741 | d->appsink = gst_element_factory_make ("appsink", "appsink"); | 764 | d->appsink = gst_element_factory_make("appsink", "appsink"); |
742 | 765 | ||
743 | // Move this out of here! | 766 | // Move this out of here! |
744 | d->audio_message = GNUNET_malloc (UINT16_MAX); | 767 | d->audio_message = GNUNET_malloc(UINT16_MAX); |
745 | (d->audio_message)->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 768 | (d->audio_message)->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
746 | g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL); | 769 | g_object_set(G_OBJECT(d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL); |
747 | 770 | ||
748 | g_signal_connect (d->appsink, "new-sample", | 771 | g_signal_connect(d->appsink, "new-sample", |
749 | G_CALLBACK (on_appsink_new_sample), &d); | 772 | G_CALLBACK(on_appsink_new_sample), &d); |
750 | 773 | ||
751 | gst_bin_add_many( bin, d->appsink, NULL); | 774 | gst_bin_add_many(bin, d->appsink, NULL); |
752 | // gst_element_link_many ( encoder, muxer, NULL); | 775 | // gst_element_link_many ( encoder, muxer, NULL); |
753 | 776 | ||
754 | pad = gst_element_get_static_pad (d->appsink, "sink"); | 777 | pad = gst_element_get_static_pad(d->appsink, "sink"); |
755 | ghostpad = gst_ghost_pad_new ("sink", pad); | 778 | ghostpad = gst_ghost_pad_new("sink", pad); |
756 | } | 779 | } |
757 | 780 | ||
758 | /* set the bin pads */ | 781 | /* set the bin pads */ |
759 | gst_pad_set_active (ghostpad, TRUE); | 782 | gst_pad_set_active(ghostpad, TRUE); |
760 | gst_element_add_pad (GST_ELEMENT(bin), ghostpad); | 783 | gst_element_add_pad(GST_ELEMENT(bin), ghostpad); |
761 | 784 | ||
762 | gst_object_unref (pad); | 785 | gst_object_unref(pad); |
763 | 786 | ||
764 | return bin; | 787 | return bin; |
765 | } | 788 | } |
766 | 789 | ||
767 | extern GstBin * | 790 | extern GstBin * |
768 | get_coder(GNUNET_gstData *d , int type) | 791 | get_coder(GNUNET_gstData *d, int type) |
769 | { | 792 | { |
770 | GstBin *bin; | 793 | GstBin *bin; |
771 | GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad; | 794 | GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad; |
772 | GstCaps *rtpcaps; | 795 | GstCaps *rtpcaps; |
773 | GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter; | 796 | GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter; |
774 | 797 | ||
775 | if ( d->usertp == TRUE ) | 798 | if (d->usertp == TRUE) |
776 | { | 799 | { |
777 | /* | 800 | /* |
778 | * application/x-rtp, media=(string)audio, clock-rate=(int)48000, encoding-name=(string)OPUS, sprop-maxcapturerate=(string)48000, sprop-stereo=(string)0, payload=(int)96, encoding-params=(string)2, ssrc=(uint)630297634, timestamp-offset=(uint)678334141, seqnum-offset=(uint)16938 */ | 801 | * application/x-rtp, media=(string)audio, clock-rate=(int)48000, encoding-name=(string)OPUS, sprop-maxcapturerate=(string)48000, sprop-stereo=(string)0, payload=(int)96, encoding-params=(string)2, ssrc=(uint)630297634, timestamp-offset=(uint)678334141, seqnum-offset=(uint)16938 */ |
779 | /* | 802 | /* |
780 | rtpcaps = gst_caps_new_simple ("application/x-rtp", | 803 | rtpcaps = gst_caps_new_simple ("application/x-rtp", |
@@ -785,110 +808,110 @@ get_coder(GNUNET_gstData *d , int type) | |||
785 | "sprop-stereo", G_TYPE_STRING, "0", | 808 | "sprop-stereo", G_TYPE_STRING, "0", |
786 | "encoding-params", G_TYPE_STRING, "2", | 809 | "encoding-params", G_TYPE_STRING, "2", |
787 | NULL); | 810 | NULL); |
788 | */ | 811 | */ |
789 | rtpcaps = gst_caps_new_simple ("application/x-rtp", | 812 | rtpcaps = gst_caps_new_simple("application/x-rtp", |
790 | "media", G_TYPE_STRING, "audio", | 813 | "media", G_TYPE_STRING, "audio", |
791 | "clock-rate", G_TYPE_INT, SAMPLING_RATE, | 814 | "clock-rate", G_TYPE_INT, SAMPLING_RATE, |
792 | "encoding-name", G_TYPE_STRING, "OPUS", | 815 | "encoding-name", G_TYPE_STRING, "OPUS", |
793 | "payload", G_TYPE_INT, 96, | 816 | "payload", G_TYPE_INT, 96, |
794 | "sprop-stereo", G_TYPE_STRING, "0", | 817 | "sprop-stereo", G_TYPE_STRING, "0", |
795 | "encoding-params", G_TYPE_STRING, "2", | 818 | "encoding-params", G_TYPE_STRING, "2", |
796 | NULL); | 819 | NULL); |
797 | 820 | ||
798 | 821 | ||
799 | rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter"); | 822 | rtpcapsfilter = gst_element_factory_make("capsfilter", "rtpcapsfilter"); |
800 | 823 | ||
801 | g_object_set (G_OBJECT (rtpcapsfilter), | 824 | g_object_set(G_OBJECT(rtpcapsfilter), |
802 | "caps", rtpcaps, | 825 | "caps", rtpcaps, |
803 | NULL); | 826 | NULL); |
804 | gst_caps_unref (rtpcaps); | 827 | gst_caps_unref(rtpcaps); |
805 | 828 | } | |
806 | } | ||
807 | |||
808 | 829 | ||
809 | if ( type == ENCODER ) | ||
810 | { | ||
811 | bin = GST_BIN(gst_bin_new("Gnunet audioencoder")); | ||
812 | 830 | ||
813 | encoder = gst_element_factory_make ("opusenc", "opus-encoder"); | 831 | if (type == ENCODER) |
814 | if ( d->usertp == TRUE ) | ||
815 | { | 832 | { |
816 | muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader"); | 833 | bin = GST_BIN(gst_bin_new("Gnunet audioencoder")); |
817 | } else { | ||
818 | muxer = gst_element_factory_make ("oggmux", "ogg-muxer"); | ||
819 | } | ||
820 | g_object_set (G_OBJECT (encoder), | ||
821 | /* "bitrate", 64000, */ | ||
822 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | ||
823 | "inband-fec", INBAND_FEC_MODE, | ||
824 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | ||
825 | "max-payload-size", MAX_PAYLOAD_SIZE, | ||
826 | "audio", TRUE, /* VoIP, not audio */ | ||
827 | "frame-size", OPUS_FRAME_SIZE, | ||
828 | NULL); | ||
829 | |||
830 | if ( d->usertp != TRUE) | ||
831 | { | ||
832 | g_object_set (G_OBJECT (muxer), | ||
833 | "max-delay", OGG_MAX_DELAY, | ||
834 | "max-page-delay", OGG_MAX_PAGE_DELAY, | ||
835 | NULL); | ||
836 | } | ||
837 | 834 | ||
838 | gst_bin_add_many( bin, encoder, muxer, NULL); | 835 | encoder = gst_element_factory_make("opusenc", "opus-encoder"); |
839 | gst_element_link_many ( encoder, muxer, NULL); | 836 | if (d->usertp == TRUE) |
840 | sinkpad = gst_element_get_static_pad(encoder, "sink"); | 837 | { |
841 | sinkghostpad = gst_ghost_pad_new ("sink", sinkpad); | 838 | muxer = gst_element_factory_make("rtpopuspay", "rtp-payloader"); |
842 | 839 | } | |
843 | srcpad = gst_element_get_static_pad(muxer, "src"); | 840 | else |
844 | srcghostpad = gst_ghost_pad_new ("src", srcpad); | 841 | { |
842 | muxer = gst_element_factory_make("oggmux", "ogg-muxer"); | ||
843 | } | ||
844 | g_object_set(G_OBJECT(encoder), | ||
845 | /* "bitrate", 64000, */ | ||
846 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | ||
847 | "inband-fec", INBAND_FEC_MODE, | ||
848 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | ||
849 | "max-payload-size", MAX_PAYLOAD_SIZE, | ||
850 | "audio", TRUE, /* VoIP, not audio */ | ||
851 | "frame-size", OPUS_FRAME_SIZE, | ||
852 | NULL); | ||
853 | |||
854 | if (d->usertp != TRUE) | ||
855 | { | ||
856 | g_object_set(G_OBJECT(muxer), | ||
857 | "max-delay", OGG_MAX_DELAY, | ||
858 | "max-page-delay", OGG_MAX_PAGE_DELAY, | ||
859 | NULL); | ||
860 | } | ||
845 | 861 | ||
846 | } | 862 | gst_bin_add_many(bin, encoder, muxer, NULL); |
847 | if ( type == DECODER ) | 863 | gst_element_link_many(encoder, muxer, NULL); |
848 | { | 864 | sinkpad = gst_element_get_static_pad(encoder, "sink"); |
849 | bin = GST_BIN(gst_bin_new("Gnunet audiodecoder")); | 865 | sinkghostpad = gst_ghost_pad_new("sink", sinkpad); |
850 | 866 | ||
851 | // decoder | 867 | srcpad = gst_element_get_static_pad(muxer, "src"); |
852 | if ( d->usertp == TRUE ) | 868 | srcghostpad = gst_ghost_pad_new("src", srcpad); |
853 | { | ||
854 | |||
855 | demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer"); | ||
856 | jitterbuffer = gst_element_factory_make ("rtpjitterbuffer", "rtpjitterbuffer"); | ||
857 | } else { | ||
858 | demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); | ||
859 | } | 869 | } |
860 | decoder = gst_element_factory_make ("opusdec", "opus-decoder"); | 870 | if (type == DECODER) |
861 | |||
862 | if ( d->usertp == TRUE ) | ||
863 | { | 871 | { |
864 | gst_bin_add_many( bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | 872 | bin = GST_BIN(gst_bin_new("Gnunet audiodecoder")); |
865 | gst_element_link_many ( rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | ||
866 | sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink"); | ||
867 | 873 | ||
874 | // decoder | ||
875 | if (d->usertp == TRUE) | ||
876 | { | ||
877 | demuxer = gst_element_factory_make("rtpopusdepay", "ogg-demuxer"); | ||
878 | jitterbuffer = gst_element_factory_make("rtpjitterbuffer", "rtpjitterbuffer"); | ||
879 | } | ||
880 | else | ||
881 | { | ||
882 | demuxer = gst_element_factory_make("oggdemux", "ogg-demuxer"); | ||
883 | } | ||
884 | decoder = gst_element_factory_make("opusdec", "opus-decoder"); | ||
868 | 885 | ||
869 | } else { | 886 | if (d->usertp == TRUE) |
870 | gst_bin_add_many( bin, demuxer, decoder, NULL); | 887 | { |
871 | 888 | gst_bin_add_many(bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | |
872 | g_signal_connect (demuxer, | 889 | gst_element_link_many(rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); |
873 | "pad-added", | 890 | sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink"); |
874 | G_CALLBACK (decoder_ogg_pad_added), | 891 | } |
875 | decoder); | 892 | else |
893 | { | ||
894 | gst_bin_add_many(bin, demuxer, decoder, NULL); | ||
876 | 895 | ||
877 | sinkpad = gst_element_get_static_pad(demuxer, "sink"); | 896 | g_signal_connect(demuxer, |
878 | } | 897 | "pad-added", |
879 | sinkghostpad = gst_ghost_pad_new ("sink", sinkpad); | 898 | G_CALLBACK(decoder_ogg_pad_added), |
899 | decoder); | ||
880 | 900 | ||
881 | srcpad = gst_element_get_static_pad(decoder, "src"); | 901 | sinkpad = gst_element_get_static_pad(demuxer, "sink"); |
882 | srcghostpad = gst_ghost_pad_new ("src", srcpad); | 902 | } |
903 | sinkghostpad = gst_ghost_pad_new("sink", sinkpad); | ||
883 | 904 | ||
884 | } | 905 | srcpad = gst_element_get_static_pad(decoder, "src"); |
906 | srcghostpad = gst_ghost_pad_new("src", srcpad); | ||
907 | } | ||
885 | 908 | ||
886 | // add pads to the bin | 909 | // add pads to the bin |
887 | gst_pad_set_active (sinkghostpad, TRUE); | 910 | gst_pad_set_active(sinkghostpad, TRUE); |
888 | gst_element_add_pad (GST_ELEMENT(bin), sinkghostpad); | 911 | gst_element_add_pad(GST_ELEMENT(bin), sinkghostpad); |
889 | 912 | ||
890 | gst_pad_set_active (srcghostpad, TRUE); | 913 | gst_pad_set_active(srcghostpad, TRUE); |
891 | gst_element_add_pad (GST_ELEMENT(bin), srcghostpad); | 914 | gst_element_add_pad(GST_ELEMENT(bin), srcghostpad); |
892 | 915 | ||
893 | 916 | ||
894 | return bin; | 917 | return bin; |
@@ -896,82 +919,80 @@ get_coder(GNUNET_gstData *d , int type) | |||
896 | 919 | ||
897 | 920 | ||
898 | extern GstBin * | 921 | extern GstBin * |
899 | get_audiobin(GNUNET_gstData *d , int type) | 922 | get_audiobin(GNUNET_gstData *d, int type) |
900 | { | 923 | { |
901 | GstBin *bin; | 924 | GstBin *bin; |
902 | GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter; | 925 | GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter; |
903 | GstPad *pad, *ghostpad; | 926 | GstPad *pad, *ghostpad; |
904 | GstCaps *caps; | 927 | GstCaps *caps; |
905 | if ( type == SINK ) { | ||
906 | |||
907 | bin = GST_BIN(gst_bin_new("Gnunet audiosink")); | ||
908 | 928 | ||
909 | /* Create all the elements */ | 929 | if (type == SINK) |
910 | if ( d->dropsilence == TRUE ) | ||
911 | { | 930 | { |
912 | queue = gst_element_factory_make ("queue", "queue"); | 931 | bin = GST_BIN(gst_bin_new("Gnunet audiosink")); |
913 | removesilence = gst_element_factory_make ("removesilence", "removesilence"); | ||
914 | } | ||
915 | 932 | ||
916 | conv = gst_element_factory_make ("audioconvert", "converter"); | 933 | /* Create all the elements */ |
917 | resampler= gst_element_factory_make ("audioresample", "resampler"); | 934 | if (d->dropsilence == TRUE) |
918 | 935 | { | |
919 | if ( d->audiobackend == AUTO ) | 936 | queue = gst_element_factory_make("queue", "queue"); |
920 | { | 937 | removesilence = gst_element_factory_make("removesilence", "removesilence"); |
921 | sink = gst_element_factory_make ("autoaudiosink", "audiosink"); | 938 | } |
922 | g_signal_connect (sink, "child-added", G_CALLBACK (autoaudiosink_child_added), NULL); | ||
923 | 939 | ||
924 | } | 940 | conv = gst_element_factory_make("audioconvert", "converter"); |
941 | resampler = gst_element_factory_make("audioresample", "resampler"); | ||
925 | 942 | ||
926 | if ( d->audiobackend == ALSA ) | 943 | if (d->audiobackend == AUTO) |
927 | { | 944 | { |
928 | sink = gst_element_factory_make ("alsaaudiosink", "audiosink"); | 945 | sink = gst_element_factory_make("autoaudiosink", "audiosink"); |
929 | } | 946 | g_signal_connect(sink, "child-added", G_CALLBACK(autoaudiosink_child_added), NULL); |
947 | } | ||
930 | 948 | ||
931 | if ( d->audiobackend == JACK ) | 949 | if (d->audiobackend == ALSA) |
932 | { | 950 | { |
933 | sink = gst_element_factory_make ("jackaudiosink", "audiosink"); | 951 | sink = gst_element_factory_make("alsaaudiosink", "audiosink"); |
952 | } | ||
934 | 953 | ||
935 | g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL); | 954 | if (d->audiobackend == JACK) |
955 | { | ||
956 | sink = gst_element_factory_make("jackaudiosink", "audiosink"); | ||
936 | 957 | ||
937 | if (g_object_class_find_property | 958 | g_object_set(G_OBJECT(sink), "client-name", "gnunet", NULL); |
938 | (G_OBJECT_GET_CLASS (sink), "port-pattern")) | ||
939 | { | ||
940 | 959 | ||
960 | if (g_object_class_find_property | ||
961 | (G_OBJECT_GET_CLASS(sink), "port-pattern")) | ||
962 | { | ||
941 | // char *portpattern = "system"; | 963 | // char *portpattern = "system"; |
942 | 964 | ||
943 | g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out, | 965 | g_object_set(G_OBJECT(sink), "port-pattern", d->jack_pp_out, |
944 | NULL); | 966 | NULL); |
945 | } | 967 | } |
946 | 968 | } | |
947 | } | ||
948 | 969 | ||
949 | if ( d->audiobackend == FAKE ) | 970 | if (d->audiobackend == FAKE) |
950 | { | 971 | { |
951 | sink = gst_element_factory_make ("fakesink", "audiosink"); | 972 | sink = gst_element_factory_make("fakesink", "audiosink"); |
952 | } | 973 | } |
953 | 974 | ||
954 | g_object_set (sink, | 975 | g_object_set(sink, |
955 | "buffer-time", (gint64) BUFFER_TIME, | 976 | "buffer-time", (gint64)BUFFER_TIME, |
956 | "latency-time", (gint64) LATENCY_TIME, | 977 | "latency-time", (gint64)LATENCY_TIME, |
957 | NULL); | 978 | NULL); |
958 | 979 | ||
959 | if ( d->dropsilence == TRUE ) | 980 | if (d->dropsilence == TRUE) |
960 | { | 981 | { |
961 | // Do not remove silence by default | 982 | // Do not remove silence by default |
962 | g_object_set( removesilence, "remove", FALSE, NULL); | 983 | g_object_set(removesilence, "remove", FALSE, NULL); |
963 | g_object_set( queue, "max-size-buffers", 12, NULL); | 984 | g_object_set(queue, "max-size-buffers", 12, NULL); |
964 | /* | 985 | /* |
965 | g_signal_connect (source, | 986 | g_signal_connect (source, |
966 | "need-data", | 987 | "need-data", |
967 | G_CALLBACK(appsrc_need_data), | 988 | G_CALLBACK(appsrc_need_data), |
968 | NULL); | 989 | NULL); |
969 | 990 | ||
970 | g_signal_connect (source, | 991 | g_signal_connect (source, |
971 | "enough-data", | 992 | "enough-data", |
972 | G_CALLBACK(appsrc_enough_data), | 993 | G_CALLBACK(appsrc_enough_data), |
973 | NULL); | 994 | NULL); |
974 | */ | 995 | */ |
975 | /* | 996 | /* |
976 | g_signal_connect (queue, | 997 | g_signal_connect (queue, |
977 | "notify::current-level-bytes", | 998 | "notify::current-level-bytes", |
@@ -998,109 +1019,109 @@ get_audiobin(GNUNET_gstData *d , int type) | |||
998 | G_CALLBACK(queue_pushing), | 1019 | G_CALLBACK(queue_pushing), |
999 | NULL); | 1020 | NULL); |
1000 | */ | 1021 | */ |
1022 | } | ||
1001 | 1023 | ||
1002 | } | ||
1003 | |||
1004 | |||
1005 | |||
1006 | |||
1007 | |||
1008 | gst_bin_add_many (bin , conv, resampler, sink, NULL); | ||
1009 | gst_element_link_many ( conv, resampler, sink, NULL); | ||
1010 | |||
1011 | if ( d->dropsilence == TRUE ) | ||
1012 | { | ||
1013 | gst_bin_add_many (bin , queue ,removesilence , NULL); | ||
1014 | |||
1015 | if ( !gst_element_link_many ( queue, removesilence, conv, NULL) ) | ||
1016 | lf ("queue, removesilence, conv "); | ||
1017 | |||
1018 | pad = gst_element_get_static_pad (queue, "sink"); | ||
1019 | 1024 | ||
1020 | } else { | ||
1021 | 1025 | ||
1022 | pad = gst_element_get_static_pad(conv, "sink"); | ||
1023 | 1026 | ||
1024 | } | ||
1025 | 1027 | ||
1026 | ghostpad = gst_ghost_pad_new ("sink", pad); | 1028 | gst_bin_add_many(bin, conv, resampler, sink, NULL); |
1029 | gst_element_link_many(conv, resampler, sink, NULL); | ||
1027 | 1030 | ||
1028 | } else { | 1031 | if (d->dropsilence == TRUE) |
1029 | // SOURCE | 1032 | { |
1033 | gst_bin_add_many(bin, queue, removesilence, NULL); | ||
1030 | 1034 | ||
1031 | bin = GST_BIN(gst_bin_new("Gnunet audiosource")); | 1035 | if (!gst_element_link_many(queue, removesilence, conv, NULL)) |
1036 | lf("queue, removesilence, conv "); | ||
1032 | 1037 | ||
1033 | // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla"); | 1038 | pad = gst_element_get_static_pad(queue, "sink"); |
1039 | } | ||
1040 | else | ||
1041 | { | ||
1042 | pad = gst_element_get_static_pad(conv, "sink"); | ||
1043 | } | ||
1034 | 1044 | ||
1035 | if (d->audiobackend == AUTO ) | 1045 | ghostpad = gst_ghost_pad_new("sink", pad); |
1036 | { | ||
1037 | source = gst_element_factory_make ("autoaudiosrc", "audiosource"); | ||
1038 | } | ||
1039 | if (d->audiobackend == ALSA ) | ||
1040 | { | ||
1041 | source = gst_element_factory_make ("alsasrc", "audiosource"); | ||
1042 | } | ||
1043 | if (d->audiobackend == JACK ) | ||
1044 | { | ||
1045 | source = gst_element_factory_make ("jackaudiosrc", "audiosource"); | ||
1046 | } | 1046 | } |
1047 | if (d->audiobackend == TEST ) | 1047 | else |
1048 | { | 1048 | { |
1049 | source = gst_element_factory_make ("audiotestsrc", "audiosource"); | 1049 | // SOURCE |
1050 | } | ||
1051 | 1050 | ||
1052 | filter = gst_element_factory_make ("capsfilter", "filter"); | 1051 | bin = GST_BIN(gst_bin_new("Gnunet audiosource")); |
1053 | conv = gst_element_factory_make ("audioconvert", "converter"); | ||
1054 | resampler= gst_element_factory_make ("audioresample", "resampler"); | ||
1055 | 1052 | ||
1056 | if (d->audiobackend == AUTO ) { | 1053 | // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla"); |
1057 | g_signal_connect (source, "child-added", G_CALLBACK (autoaudiosource_child_added), NULL); | ||
1058 | 1054 | ||
1059 | } else { | 1055 | if (d->audiobackend == AUTO) |
1060 | if (GST_IS_AUDIO_BASE_SRC (source)) | 1056 | { |
1061 | g_object_set (source, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL); | 1057 | source = gst_element_factory_make("autoaudiosrc", "audiosource"); |
1062 | if ( d->audiobackend == JACK ) { | 1058 | } |
1063 | g_object_set (G_OBJECT (source), "client-name", "gnunet", NULL); | 1059 | if (d->audiobackend == ALSA) |
1064 | if (g_object_class_find_property | 1060 | { |
1065 | (G_OBJECT_GET_CLASS (source), "port-pattern")) | 1061 | source = gst_element_factory_make("alsasrc", "audiosource"); |
1062 | } | ||
1063 | if (d->audiobackend == JACK) | ||
1064 | { | ||
1065 | source = gst_element_factory_make("jackaudiosrc", "audiosource"); | ||
1066 | } | ||
1067 | if (d->audiobackend == TEST) | ||
1066 | { | 1068 | { |
1069 | source = gst_element_factory_make("audiotestsrc", "audiosource"); | ||
1070 | } | ||
1067 | 1071 | ||
1068 | char *portpattern = "moc"; | 1072 | filter = gst_element_factory_make("capsfilter", "filter"); |
1073 | conv = gst_element_factory_make("audioconvert", "converter"); | ||
1074 | resampler = gst_element_factory_make("audioresample", "resampler"); | ||
1069 | 1075 | ||
1070 | g_object_set (G_OBJECT (source), "port-pattern", portpattern, | 1076 | if (d->audiobackend == AUTO) |
1071 | NULL); | 1077 | { |
1078 | g_signal_connect(source, "child-added", G_CALLBACK(autoaudiosource_child_added), NULL); | ||
1079 | } | ||
1080 | else | ||
1081 | { | ||
1082 | if (GST_IS_AUDIO_BASE_SRC(source)) | ||
1083 | g_object_set(source, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); | ||
1084 | if (d->audiobackend == JACK) | ||
1085 | { | ||
1086 | g_object_set(G_OBJECT(source), "client-name", "gnunet", NULL); | ||
1087 | if (g_object_class_find_property | ||
1088 | (G_OBJECT_GET_CLASS(source), "port-pattern")) | ||
1089 | { | ||
1090 | char *portpattern = "moc"; | ||
1091 | |||
1092 | g_object_set(G_OBJECT(source), "port-pattern", portpattern, | ||
1093 | NULL); | ||
1094 | } | ||
1095 | } | ||
1072 | } | 1096 | } |
1073 | } | ||
1074 | } | ||
1075 | |||
1076 | caps = gst_caps_new_simple ("audio/x-raw", | ||
1077 | /* "format", G_TYPE_STRING, "S16LE", */ | ||
1078 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ | ||
1079 | "channels", G_TYPE_INT, OPUS_CHANNELS, | ||
1080 | /* "layout", G_TYPE_STRING, "interleaved",*/ | ||
1081 | NULL); | ||
1082 | 1097 | ||
1083 | g_object_set (G_OBJECT (filter), | 1098 | caps = gst_caps_new_simple("audio/x-raw", |
1084 | "caps", caps, | 1099 | /* "format", G_TYPE_STRING, "S16LE", */ |
1085 | NULL); | 1100 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ |
1086 | gst_caps_unref (caps); | 1101 | "channels", G_TYPE_INT, OPUS_CHANNELS, |
1102 | /* "layout", G_TYPE_STRING, "interleaved",*/ | ||
1103 | NULL); | ||
1087 | 1104 | ||
1088 | gst_bin_add_many (bin , source, filter, conv, resampler, NULL); | 1105 | g_object_set(G_OBJECT(filter), |
1089 | gst_element_link_many ( source, filter, conv, resampler, NULL); | 1106 | "caps", caps, |
1107 | NULL); | ||
1108 | gst_caps_unref(caps); | ||
1090 | 1109 | ||
1091 | pad = gst_element_get_static_pad (resampler, "src"); | 1110 | gst_bin_add_many(bin, source, filter, conv, resampler, NULL); |
1111 | gst_element_link_many(source, filter, conv, resampler, NULL); | ||
1092 | 1112 | ||
1113 | pad = gst_element_get_static_pad(resampler, "src"); | ||
1093 | 1114 | ||
1094 | /* pads */ | ||
1095 | ghostpad = gst_ghost_pad_new ("src", pad); | ||
1096 | 1115 | ||
1097 | } | 1116 | /* pads */ |
1117 | ghostpad = gst_ghost_pad_new("src", pad); | ||
1118 | } | ||
1098 | 1119 | ||
1099 | /* set the bin pads */ | 1120 | /* set the bin pads */ |
1100 | gst_pad_set_active (ghostpad, TRUE); | 1121 | gst_pad_set_active(ghostpad, TRUE); |
1101 | gst_element_add_pad (GST_ELEMENT(bin), ghostpad); | 1122 | gst_element_add_pad(GST_ELEMENT(bin), ghostpad); |
1102 | 1123 | ||
1103 | gst_object_unref (pad); | 1124 | gst_object_unref(pad); |
1104 | 1125 | ||
1105 | return bin; | 1126 | return bin; |
1106 | } | 1127 | } |