From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/conversation/gnunet-helper-audio-record-gst.c | 385 +++++++++++----------- 1 file changed, 197 insertions(+), 188 deletions(-) (limited to 'src/conversation/gnunet-helper-audio-record-gst.c') diff --git a/src/conversation/gnunet-helper-audio-record-gst.c b/src/conversation/gnunet-helper-audio-record-gst.c index f41f529ea..a3607014e 100644 --- a/src/conversation/gnunet-helper-audio-record-gst.c +++ b/src/conversation/gnunet-helper-audio-record-gst.c @@ -102,61 +102,63 @@ static int dump_pure_ogg; #endif static void -quit() +quit () { if (NULL != pipeline) - gst_element_set_state(pipeline, GST_STATE_NULL); + gst_element_set_state (pipeline, GST_STATE_NULL); } static gboolean -bus_call(GstBus *bus, GstMessage *msg, gpointer data) +bus_call (GstBus *bus, GstMessage *msg, gpointer data) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bus message\n"); - switch (GST_MESSAGE_TYPE(msg)) - { - case GST_MESSAGE_EOS: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "End of stream\n"); - quit(); - break; - - case GST_MESSAGE_ERROR: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bus message\n"); + switch (GST_MESSAGE_TYPE (msg)) + { + case GST_MESSAGE_EOS: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "End of stream\n"); + quit (); + break; + + case GST_MESSAGE_ERROR: { gchar *debug; GError *error; - gst_message_parse_error(msg, &error, &debug); - g_free(debug); + gst_message_parse_error (msg, &error, &debug); + g_free (debug); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error: %s\n", error->message); - g_error_free(error); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error: %s\n", error->message); + g_error_free (error); - quit(); + quit (); break; } - default: - break; - } + default: + break; + } return TRUE; } void -source_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) +source_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, + gpointer user_data) { - if (GST_IS_AUDIO_BASE_SRC(object)) - g_object_set(object, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); + if (GST_IS_AUDIO_BASE_SRC (object)) + g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", + (gint64) LATENCY_TIME, NULL); } static void -signalhandler(int s) +signalhandler (int s) { - quit(); + quit (); } int -main(int argc, char **argv) +main (int argc, char **argv) { GstElement *source, *filter, *encoder, *conv, *resampler, *sink, *oggmux; GstCaps *caps; @@ -168,214 +170,221 @@ main(int argc, char **argv) typedef void (*SignalHandlerPointer) (int); SignalHandlerPointer inthandler, termhandler; - inthandler = signal(SIGINT, signalhandler); - termhandler = signal(SIGTERM, signalhandler); + inthandler = signal (SIGINT, signalhandler); + termhandler = signal (SIGTERM, signalhandler); #ifdef DEBUG_RECORD_PURE_OGG - dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; + dump_pure_ogg = getenv ("GNUNET_RECORD_PURE_OGG") ? 1 : 0; #endif /* Initialisation */ - gst_init(&argc, &argv); + gst_init (&argc, &argv); - GNUNET_assert(GNUNET_OK == - GNUNET_log_setup("gnunet-helper-audio-record", - "WARNING", - NULL)); + GNUNET_assert (GNUNET_OK == + GNUNET_log_setup ("gnunet-helper-audio-record", + "WARNING", + NULL)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Audio source starts\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Audio source starts\n"); - audio_message.header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); + audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); /* Create gstreamer elements */ - pipeline = gst_pipeline_new("audio-recorder"); - source = gst_element_factory_make("autoaudiosrc", "audiosource"); - filter = gst_element_factory_make("capsfilter", "filter"); - conv = gst_element_factory_make("audioconvert", "converter"); - resampler = gst_element_factory_make("audioresample", "resampler"); - encoder = gst_element_factory_make("opusenc", "opus-encoder"); - oggmux = gst_element_factory_make("oggmux", "ogg-muxer"); - sink = gst_element_factory_make("appsink", "audio-output"); - - if (!pipeline || !filter || !source || !conv || !resampler || !encoder || !oggmux || !sink) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "One element could not be created. Exiting.\n"); - return -1; - } - - g_signal_connect(source, "child-added", G_CALLBACK(source_child_added), NULL); + pipeline = gst_pipeline_new ("audio-recorder"); + source = gst_element_factory_make ("autoaudiosrc", "audiosource"); + filter = gst_element_factory_make ("capsfilter", "filter"); + conv = gst_element_factory_make ("audioconvert", "converter"); + resampler = gst_element_factory_make ("audioresample", "resampler"); + encoder = gst_element_factory_make ("opusenc", "opus-encoder"); + oggmux = gst_element_factory_make ("oggmux", "ogg-muxer"); + sink = gst_element_factory_make ("appsink", "audio-output"); + + if (! pipeline || ! filter || ! source || ! conv || ! resampler || + ! encoder || ! oggmux || ! sink) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "One element could not be created. Exiting.\n"); + return -1; + } + + g_signal_connect (source, "child-added", G_CALLBACK (source_child_added), + NULL); /* Set up the pipeline */ - caps = gst_caps_new_simple("audio/x-raw", - "format", G_TYPE_STRING, "S16LE", + caps = gst_caps_new_simple ("audio/x-raw", + "format", G_TYPE_STRING, "S16LE", /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ - "channels", G_TYPE_INT, OPUS_CHANNELS, + "channels", G_TYPE_INT, OPUS_CHANNELS, /* "layout", G_TYPE_STRING, "interleaved",*/ - NULL); - g_object_set(G_OBJECT(filter), - "caps", caps, - NULL); - gst_caps_unref(caps); + NULL); + g_object_set (G_OBJECT (filter), + "caps", caps, + NULL); + gst_caps_unref (caps); - g_object_set(G_OBJECT(encoder), + g_object_set (G_OBJECT (encoder), /* "bitrate", 64000, */ /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ - "inband-fec", INBAND_FEC_MODE, - "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, - "max-payload-size", MAX_PAYLOAD_SIZE, - "audio", FALSE, /* VoIP, not audio */ - "frame-size", OPUS_FRAME_SIZE, - NULL); - - g_object_set(G_OBJECT(oggmux), - "max-delay", OGG_MAX_DELAY, - "max-page-delay", OGG_MAX_PAGE_DELAY, - NULL); + "inband-fec", INBAND_FEC_MODE, + "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, + "max-payload-size", MAX_PAYLOAD_SIZE, + "audio", FALSE, /* VoIP, not audio */ + "frame-size", OPUS_FRAME_SIZE, + NULL); + + g_object_set (G_OBJECT (oggmux), + "max-delay", OGG_MAX_DELAY, + "max-page-delay", OGG_MAX_PAGE_DELAY, + NULL); /* we add a message handler */ - bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); - bus_watch_id = gst_bus_add_watch(bus, bus_call, pipeline); - gst_object_unref(bus); + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + bus_watch_id = gst_bus_add_watch (bus, bus_call, pipeline); + gst_object_unref (bus); /* we add all elements into the pipeline */ /* audiosource | converter | resampler | opus-encoder | audio-output */ - gst_bin_add_many(GST_BIN(pipeline), source, filter, conv, resampler, encoder, - oggmux, sink, NULL); + gst_bin_add_many (GST_BIN (pipeline), source, filter, conv, resampler, + encoder, + oggmux, sink, NULL); /* we link the elements together */ - gst_element_link_many(source, filter, conv, resampler, encoder, oggmux, sink, NULL); + gst_element_link_many (source, filter, conv, resampler, encoder, oggmux, sink, + NULL); /* Set the pipeline to "playing" state*/ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Now playing\n"); - gst_element_set_state(pipeline, GST_STATE_PLAYING); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now playing\n"); + gst_element_set_state (pipeline, GST_STATE_PLAYING); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running...\n"); /* Iterate */ - while (!abort_send) + while (! abort_send) + { + GstSample *s; + GstBuffer *b; + GstMapInfo m; + size_t len, msg_size; + const char *ptr; + int phase; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); + s = gst_app_sink_pull_sample (GST_APP_SINK (sink)); + if (NULL == s) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); + break; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); { - GstSample *s; - GstBuffer *b; - GstMapInfo m; - size_t len, msg_size; - const char *ptr; - int phase; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); - s = gst_app_sink_pull_sample(GST_APP_SINK(sink)); - if (NULL == s) + const GstStructure *si; + char *si_str; + GstCaps *s_caps; + char *caps_str; + si = gst_sample_get_info (s); + if (si) + { + si_str = gst_structure_to_string (si); + if (si_str) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); - break; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); + g_free (si_str); } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); - { - const GstStructure *si; - char *si_str; - GstCaps *s_caps; - char *caps_str; - si = gst_sample_get_info(s); - if (si) - { - si_str = gst_structure_to_string(si); - if (si_str) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); - g_free(si_str); - } - } - else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); - s_caps = gst_sample_get_caps(s); - if (s_caps) - { - caps_str = gst_caps_to_string(s_caps); - if (caps_str) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str); - g_free(caps_str); - } - } - else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); } - b = gst_sample_get_buffer(s); - if (NULL == b || !gst_buffer_map(b, &m, GST_MAP_READ)) + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); + s_caps = gst_sample_get_caps (s); + if (s_caps) + { + caps_str = gst_caps_to_string (s_caps); + if (caps_str) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); - gst_sample_unref(s); - continue; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", + caps_str); + g_free (caps_str); } + } + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); + } + b = gst_sample_get_buffer (s); + if ((NULL == b) || ! gst_buffer_map (b, &m, GST_MAP_READ)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "got NULL buffer %p or failed to map the buffer\n", b); + gst_sample_unref (s); + continue; + } - len = m.size; - if (len > UINT16_MAX - sizeof(struct AudioMessage)) - { - GNUNET_break(0); - len = UINT16_MAX - sizeof(struct AudioMessage); - } - msg_size = sizeof(struct AudioMessage) + len; - audio_message.header.size = htons((uint16_t)msg_size); + len = m.size; + if (len > UINT16_MAX - sizeof(struct AudioMessage)) + { + GNUNET_break (0); + len = UINT16_MAX - sizeof(struct AudioMessage); + } + msg_size = sizeof(struct AudioMessage) + len; + audio_message.header.size = htons ((uint16_t) msg_size); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending %u bytes of audio data\n", (unsigned int)msg_size); - for (phase = 0; phase < 2; phase++) - { - size_t offset; - size_t to_send; - ssize_t ret; - if (0 == phase) - { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u bytes of audio data\n", (unsigned int) msg_size); + for (phase = 0; phase < 2; phase++) + { + size_t offset; + size_t to_send; + ssize_t ret; + if (0 == phase) + { #ifdef DEBUG_RECORD_PURE_OGG - if (dump_pure_ogg) - continue; + if (dump_pure_ogg) + continue; #endif - ptr = (const char *)&audio_message; - to_send = sizeof(audio_message); - } - else - { - ptr = (const char *)m.data; - to_send = len; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending %u bytes on phase %d\n", (unsigned int)to_send, phase); - for (offset = 0; offset < to_send; offset += ret) - { - ret = write(1, &ptr[offset], to_send - offset); - if (0 >= ret) - { - if (-1 == ret) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", - (unsigned int)(to_send - offset), - (unsigned int)offset, - (unsigned int)(to_send + offset), - phase, - strerror(errno)); - abort_send = 1; - break; - } - } - if (abort_send) - break; + ptr = (const char *) &audio_message; + to_send = sizeof(audio_message); + } + else + { + ptr = (const char *) m.data; + to_send = len; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u bytes on phase %d\n", (unsigned int) to_send, + phase); + for (offset = 0; offset < to_send; offset += ret) + { + ret = write (1, &ptr[offset], to_send - offset); + if (0 >= ret) + { + if (-1 == ret) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", + (unsigned int) (to_send - offset), + (unsigned int) offset, + (unsigned int) (to_send + offset), + phase, + strerror (errno)); + abort_send = 1; + break; } - gst_buffer_unmap(b, &m); - gst_sample_unref(s); + } + if (abort_send) + break; } + gst_buffer_unmap (b, &m); + gst_sample_unref (s); + } - signal(SIGINT, inthandler); - signal(SIGINT, termhandler); + signal (SIGINT, inthandler); + signal (SIGINT, termhandler); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); - quit(); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); + quit (); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); - gst_object_unref(GST_OBJECT(pipeline)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); + gst_object_unref (GST_OBJECT (pipeline)); pipeline = NULL; - g_source_remove(bus_watch_id); + g_source_remove (bus_watch_id); return 0; } -- cgit v1.2.3