From 729b1f3d5694f7a2cb306ff077dd639ee926490e Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 29 Feb 2008 16:13:11 +0200 Subject: [PATCH] Add simple position text. Add more checks. --- src/audio-note.c | 71 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/src/audio-note.c b/src/audio-note.c index 4637052..c2f645f 100644 --- a/src/audio-note.c +++ b/src/audio-note.c @@ -36,6 +36,25 @@ static note_pipeline note_record; static GstBus *bus; static gchar *cfile=NULL; +static gboolean +audio_note_position_cb(gpointer data) +{ +GstFormat fmt=GST_FORMAT_TIME; +GstElement *pipe; +gint64 pos, len; +gchar buffer[128]; +audio_note_ui *ui=(audio_note_ui *)data; + +pipe=ui->note_record->pipeline; + +if (gst_element_query_position (pipe, &fmt, &pos) && gst_element_query_duration (pipe, &fmt, &len)) { + g_snprintf(buffer, sizeof(buffer), "Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT, GST_TIME_ARGS (pos), GST_TIME_ARGS (len)); + gtk_label_set_text(ui->lbl_time, buffer); +} + +return TRUE; +} + static gboolean audio_note_record_cb(GtkWidget *widget, gpointer data) { @@ -71,6 +90,7 @@ if (cfile) cfile=g_strdup_printf("%s/an-%s.wav", basedir, buffer); audio_note_record(cfile); +ui->pos_sid=g_timeout_add (250, (GSourceFunc)audio_note_position_cb, ui); MACRO_BANNER_SHOW_INFO(_window, _("Recording...")); @@ -100,6 +120,7 @@ audio_note_new(void) { audio_note_ui *ui; ui=g_slice_new(audio_note_ui); +ui->pos_sid=0; ui->vbox=gtk_vbox_new(FALSE, 0); ui->lbl_time=gtk_label_new(""); ui->btn_record=gtk_button_new_from_stock(GTK_STOCK_MEDIA_RECORD); @@ -153,15 +174,19 @@ return TRUE; static gboolean audio_create_pipeline(note_pipeline *np, gboolean rec) { -np->pipeline=gst_pipeline_new("pipeline"); -bus=gst_pipeline_get_bus(GST_PIPELINE(np->pipeline)); -gst_bus_add_watch(bus, audio_note_bus_cb, np); - if (rec==TRUE) { g_debug("GST: Creating record pipeline"); - np->src=gst_element_factory_make(AUDIO_SRC, "source"); - np->filter=gst_element_factory_make("wavenc", "filter"); - np->sink=gst_element_factory_make("filesink", "sink"); + np->pipeline=gst_pipeline_new("rpipeline"); + g_assert(np->pipeline); + + np->src=gst_element_factory_make(AUDIO_SRC, "asource"); + g_assert(np->src); + + np->filter=gst_element_factory_make("wavenc", "wavfilter"); + g_assert(np->filter); + + np->sink=gst_element_factory_make("filesink", "fsink"); + g_assert(np->sink); gst_bin_add_many(GST_BIN(np->pipeline), np->src, np->filter, np->sink, NULL); @@ -180,19 +205,35 @@ if (rec==TRUE) { gst_element_link(np->src, np->filter); gst_caps_unref(np->srccaps); #else - gst_element_link(np->src, np->filter); + if (!gst_element_link(np->src, np->filter)) + g_printerr("Failed to link source to filter\n"); #endif - gst_element_link(np->filter, np->sink); - + if (!gst_element_link(np->filter, np->sink)) + g_printerr("Failed to link filter to source\n"); } else { g_debug("GST: Creating playback pipeline"); - np->src=gst_element_factory_make("filesrc", "source"); - np->filter=gst_element_factory_make("wavparse", "filter"); - np->sink=gst_element_factory_make(AUDIO_SINK, "sink"); + np->pipeline=gst_pipeline_new("ppipeline"); + g_assert(np->pipeline); + + np->src=gst_element_factory_make("filesrc", "fsource"); + g_assert(np->src); + + np->filter=gst_element_factory_make("wavparse", "wavparse"); + g_assert(np->filter); + + np->sink=gst_element_factory_make(AUDIO_SINK, "asink"); + g_assert(np->sink); + gst_bin_add_many(GST_BIN(np->pipeline), np->src, np->filter, np->sink, NULL); - if (!gst_element_link_many(np->src, np->filter, np->sink, NULL)) - g_printerr("Failed to link play pipeline\n"); + + if (!gst_element_link(np->src, np->filter)) + g_printerr("Failed to link source to filter\n"); + if (!gst_element_link(np->filter, np->sink)) + g_printerr("Failed to link filter to source\n"); } +bus=gst_pipeline_get_bus(GST_PIPELINE(np->pipeline)); +gst_bus_add_watch(bus, audio_note_bus_cb, np); +gst_object_unref(bus); np->rec=rec; np->active=FALSE; return TRUE; -- 2.39.5