23
23
#include <sys/stat.h>
24
24
#include <unistd.h>
27
static void error_cb(GstBus *bus, GstMessage *message, gpointer user_data)
31
show_error_dialog (GtkWindow *win, const gchar *dbg, const gchar * format, ...)
37
va_start (args, format);
38
s = g_strdup_vprintf (format, args);
41
dialog = gtk_message_dialog_new (win,
42
GTK_DIALOG_DESTROY_WITH_PARENT,
49
g_printerr ("ERROR: %s\nDEBUG MESSAGE: %s\n", s, dbg);
52
gtk_dialog_run (GTK_DIALOG (dialog));
53
gtk_widget_destroy (dialog);
58
show_missing_known_element_error (GtkWindow *win, gchar *description,
59
gchar *element, gchar *plugin, gchar *module)
61
show_error_dialog (win, NULL,
62
_("Could not create the GStreamer %s element.\n"
63
"Please install the '%s' plugin from the '%s' module.\n"
64
"Verify that the installation is correct by running\n"
65
" gst-inspect-0.10 %s\n"
66
"and then restart gnome-sound-recorder."),
67
description, plugin, module, element);
71
show_profile_error (GtkWindow *win, gchar *debug, gchar *description,
76
first = g_strdup_printf (description, profile);
77
show_error_dialog (win, debug, "%s%s", first,
78
_("Please verify its settings.\n"
79
"You may be missing the necessary plugins."));
83
static void pipeline_error_cb(GstBus *bus, GstMessage *message, gpointer user_data)
29
85
GError *error = NULL;
30
86
GstElement *pipeline = user_data;
38
94
g_error_free(error);
98
level_message_handler_cb (GstBus *bus, GstMessage *message, gpointer user_data)
100
if (message->type == GST_MESSAGE_ELEMENT) {
101
const GstStructure *s = gst_message_get_structure (message);
102
const gchar *name = gst_structure_get_name (s);
104
if (g_str_equal (name, "level")) {
112
/* we can get the number of channels as the length of any of the value
115
list = gst_structure_get_value (s, "rms");
116
channels = gst_value_list_get_size (list);
118
for (i = 0; i < channels; ++i) {
119
list = gst_structure_get_value (s, "peak");
120
value = gst_value_list_get_value (list, i);
121
peak_dB = g_value_get_double (value);
122
myind = exp (peak_dB / 20);
125
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (level), myind);
129
/* we handled the message we want, and ignored the ones we didn't want.
130
* so the core can unref the message for us */
42
135
recording_start(const char* filename)
44
137
GMAudioProfile *profile;
45
GstElement *pipeline, *source, *encoder, *filesink;
46
pipeline = source = encoder = filesink = NULL;
138
const gchar *profile_pipeline_desc;
139
GstElement *pipeline, *source, *encoder, *filesink, *level;
140
pipeline = source = encoder = filesink = level = NULL;
142
gchar *pipeline_desc;
145
source = gst_element_factory_make ("gconfaudiosrc", "gconfaudiosource");
146
if (source == NULL) {
147
show_missing_known_element_error (NULL,
148
_("GConf audio recording"), "gconfaudiosrc",
149
"gconfelements", "gst-plugins-good");
153
if (!gst_element_set_state (source, GST_STATE_READY)) {
154
show_error_dialog (NULL, NULL,
155
_("Your audio capture settings are invalid. "
156
"Please correct them with the \"Sound Preferences\" "
157
"under the System Preferences menu."));
161
filesink = gst_element_factory_make ("filesink", "sink");
162
if (filesink == NULL)
164
show_missing_known_element_error (NULL,
165
_("file output"), "filesink", "coreelements",
167
gst_object_unref (source);
171
pipeline = gst_pipeline_new("gnomeradio-record-pipeline");
173
gst_bin_add (GST_BIN (pipeline), source);
175
level = gst_element_factory_make ("level", "level");
178
show_missing_known_element_error (NULL,
179
_("level"), "level", "level",
181
gst_object_unref (source);
184
gst_element_set_name (level, "level");
48
186
profile = gm_audio_profile_lookup(rec_settings.profile);
49
187
g_assert(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"));
190
profile_pipeline_desc = gm_audio_profile_get_pipeline (profile);
191
name = gm_audio_profile_get_name (profile);
193
GST_DEBUG ("encoder profile pipeline: '%s'",
194
GST_STR_NULL (profile_pipeline_desc));
196
pipeline_desc = g_strdup_printf ("audioconvert ! %s", profile_pipeline_desc);
197
GST_DEBUG ("making encoder bin from description '%s'", pipeline_desc);
198
encoder = gst_parse_bin_from_description (pipeline_desc, TRUE, &err);
199
g_free (pipeline_desc);
200
pipeline_desc = NULL;
203
show_profile_error (NULL, err->message,
204
_("Could not parse the '%s' audio profile. "), name);
205
g_printerr ("Failed to create GStreamer encoder plugins [%s]: %s\n",
206
profile_pipeline_desc, err->message);
208
gst_object_unref (pipeline);
209
gst_object_unref (filesink);
214
gst_bin_add (GST_BIN (pipeline), level);
215
gst_bin_add (GST_BIN (pipeline), encoder);
216
gst_bin_add (GST_BIN (pipeline), filesink);
218
if (!(gst_element_link_many (source, level, encoder, NULL))) {
219
show_profile_error (NULL, NULL,
220
_("Could not capture using the '%s' audio profile. "),
222
gst_object_unref (pipeline);
227
if (!gst_element_link (encoder, filesink)) {
228
show_profile_error (NULL, NULL,
229
_("Could not write to a file using the '%s' audio profile. "),
231
gst_object_unref (pipeline);
63
236
GstBus *bus = gst_element_get_bus(pipeline);
64
237
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");
239
g_signal_connect(G_OBJECT(bus), "message::error",
240
G_CALLBACK(pipeline_error_cb),
243
g_signal_connect (G_OBJECT(bus), "message::element",
244
G_CALLBACK (level_message_handler_cb),
92
247
char* path = g_strdup_printf("%s.%s", filename, gm_audio_profile_get_extension(profile));
93
248
g_object_set(G_OBJECT(filesink), "location", path, NULL);