From: Kaj-Michael Lang Date: Wed, 17 Oct 2007 08:05:54 +0000 (+0300) Subject: Some more work on audio note play/record backend X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67034c18e43d79e3702b0ba97bd6f08943663c4c;p=mapper Some more work on audio note play/record backend --- diff --git a/src/audio-note.c b/src/audio-note.c index 643aa27..1ff76aa 100644 --- a/src/audio-note.c +++ b/src/audio-note.c @@ -1,3 +1,23 @@ +/* + * This file is part of mapper + * + * Copyright (C) 2007 Kaj-Michael Lang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + /* * Quick record audio notes on the road. */ @@ -21,13 +41,38 @@ struct _note_pipeline { GstElement *src; GstElement *sink; GstElement *filter; + gboolean rec; }; static note_pipeline note_play; static note_pipeline note_record; +static GstBus *bus; + static gboolean -audio_bus_cb() +audio_note_bus_cb(GstBus *bus, GstMessage *msg, gpointer data) { +gchar *debug; +GError *err; + +switch (GST_MESSAGE_TYPE (msg)) { + case GST_MESSAGE_EOS: + g_print ("EOS\n"); + break; + case GST_MESSAGE_ERROR: + gst_message_parse_error (msg, &err, &debug); + g_free(debug); + + g_printf("Error: %s\n", err->message); + g_error_free(err); + break; + case GST_MESSAGE_STATE_CHANGED: + g_printf("State changed\n"); + break; + default: + g_printf("GST: %s\n", gst_message_type_get_name(GST_MESSAGE_TYPE(msg))); + break; + } +return TRUE; } static gboolean @@ -44,6 +89,7 @@ if (rec==TRUE) { np->filter=gst_element_factory_make("wavenc", "filter"); np->sink=gst_element_factory_make(AUDIO_SINK, "sink"); } +np->rec=rec; g_assert(np->src); g_assert(np->sink); g_assert(np->filter); @@ -66,6 +112,10 @@ gboolean audio_note_play(gchar *file) { audio_set_filename(note_play.src, file); +if (gst_element_set_state (note_play.pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { + g_printf("Failed to play file %s\n", file); + return FALSE; +} return TRUE; } @@ -75,7 +125,11 @@ return TRUE; gboolean audio_note_record(gchar *file) { -audio_set_filename(note_play.sink, file); +audio_set_filename(note_record.sink, file); +if (gst_element_set_state (note_record.pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { + g_printf("Failed to record to file %s\n", file); + return FALSE; +} return TRUE; } @@ -87,11 +141,24 @@ audio_note_init(void) { audio_create_pipeline(¬e_play, FALSE); audio_create_pipeline(¬e_record, TRUE); + +bus=gst_pipeline_get_bus(GST_PIPELINE(note_play.pipeline)); +g_assert(bus); +gst_bus_add_watch(bus, audio_note_bus_cb, NULL); + +bus=gst_pipeline_get_bus(GST_PIPELINE(note_record.pipeline)); +g_assert(bus); +gst_bus_add_watch(bus, audio_note_bus_cb, NULL); + return TRUE; } void audio_note_deinit(void) { +gst_element_set_state(note_play.pipeline, GST_STATE_NULL); +gst_object_unref(note_play.pipeline); +gst_element_set_state(note_record.pipeline, GST_STATE_NULL); +gst_object_unref(note_record.pipeline); } diff --git a/src/audio-note.h b/src/audio-note.h index e526472..911f4c6 100644 --- a/src/audio-note.h +++ b/src/audio-note.h @@ -1,3 +1,23 @@ +/* + * This file is part of mapper + * + * Copyright (C) 2007 Kaj-Michael Lang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + #ifndef _AUDIO_NOTE_H #define _AUDIO_NOTE_H