2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU Library General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include <glib/gi18n.h>
21
#include <libgnome-media-profiles/audio-profile.h>
22
#include <sys/types.h>
27
static void error_cb(GstBus *bus, GstMessage *message, gpointer user_data)
30
GstElement *pipeline = user_data;
33
/* Make sure the pipeline is not running any more */
34
gst_element_set_state (pipeline, GST_STATE_NULL);
36
gst_message_parse_error(message, &error, NULL);
37
g_warning(_("GStreamer runtime error: %s\n"), error->message);
42
recording_start(const char* filename)
44
GMAudioProfile *profile;
45
GstElement *pipeline, *source, *encoder, *filesink;
46
pipeline = source = encoder = filesink = NULL;
48
profile = gm_audio_profile_lookup(rec_settings.profile);
51
pipeline = gst_pipeline_new("gnomeradio-record-pipeline");
53
g_warning(_("Could not create GStreamer pipeline. Check your Gstreamer installation!\n"));
57
source = gst_element_factory_make("autoaudiosrc", "audio_source");
59
g_warning(_("Could not open Gstreamer AUDIO Source. Verify your Gstreamer AUDIO subsystem installation!\n"));
63
GstBus *bus = gst_element_get_bus(pipeline);
64
gst_bus_add_signal_watch(bus);
65
g_signal_connect(G_OBJECT(bus), "message::error", G_CALLBACK(error_cb), pipeline);
67
char* pipeline_str = g_strdup_printf("audioconvert ! %s", gm_audio_profile_get_pipeline(profile));
68
encoder = gst_parse_bin_from_description(pipeline_str, TRUE, NULL);
71
char *caption = g_strdup_printf(_("Could not create encoder \"%s\"."), gm_audio_profile_get_name (profile));
72
g_warning(_("%s Verify your Gstreamer plugins installation!\n"), caption);
78
filesink = gst_element_factory_make("filesink", "file-sink");
80
g_warning(_("Could not create Gstreamer filesink. Check your Gstreamer installation!"));
84
/* Add the elements to the pipeline */
85
gst_bin_add_many(GST_BIN(pipeline), source, encoder, filesink, NULL);
87
/* Link it all together */
88
if (!gst_element_link_many(source, encoder, filesink, NULL)) {
89
g_warning("Could not link elements. This is bad!\n");
92
char* path = g_strdup_printf("%s.%s", filename, gm_audio_profile_get_extension(profile));
93
g_object_set(G_OBJECT(filesink), "location", path, NULL);
95
gst_element_set_state(pipeline, GST_STATE_PLAYING);
97
Recording *recording = g_malloc0(sizeof(Recording));
98
recording->filename = path;
99
recording->pipeline = pipeline;
105
gst_object_unref(GST_OBJECT(pipeline));
107
gst_object_unref(GST_OBJECT(source));
109
gst_object_unref(GST_OBJECT(encoder));
111
gst_object_unref(GST_OBJECT(filesink));
117
recording_stop(Recording *recording)
122
gst_element_get_state(recording->pipeline, &state, NULL, GST_CLOCK_TIME_NONE);
123
if (state != GST_STATE_PLAYING) {
126
gst_element_set_state(recording->pipeline, GST_STATE_NULL);
128
gst_object_unref(GST_OBJECT(recording->pipeline));
129
g_free(recording->filename);
130
g_free(recording->station);
135
* Miscellanelous functions
138
int get_file_size(char *filename)
143
if (lstat(filename, &buffer))
145
return (int)buffer.st_size;
148
int check_filename(const char *filename)
154
flags = O_RDWR | O_CREAT | O_APPEND;
156
retval = open(filename, flags, 0664);