/* profile callbacks */ static void on_profile_changed (GMAudioProfile *profile, const GMAudioSettingMask *mask, GtkWidget *tree_view) { GtkListStore *list_store; GtkTreeIter iter; GtkTreeModel *tree_model; gboolean valid; if (mask->name) { tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); list_store = GTK_LIST_STORE (tree_model); /* Get the first iter in the list */ valid = gtk_tree_model_get_iter_first (tree_model, &iter); while (valid) { /* Walk through the list, reading each row */ GMAudioProfile *model_profile; /* Make sure you terminate calls to gtk_tree_model_get() * with a '-1' value */ gtk_tree_model_get (tree_model, &iter, COLUMN_PROFILE_OBJECT, &model_profile, -1); if (profile == model_profile) { /* bingo ! */ gtk_list_store_set (list_store, &iter, COLUMN_NAME, gm_audio_profile_get_name (profile), -1); } valid = gtk_tree_model_iter_next (tree_model, &iter); } } }
static void build_pipeline (NscGStreamer *gstreamer) { NscGStreamerPrivate *priv; GstBus *bus; g_return_if_fail (NSC_IS_GSTREAMER (gstreamer)); priv = NSC_GSTREAMER_GET_PRIVATE (gstreamer); if (priv->pipeline != NULL) { gst_object_unref (GST_OBJECT (priv->pipeline)); } priv->pipeline = gst_pipeline_new ("pipeline"); bus = gst_element_get_bus (priv->pipeline); gst_bus_add_signal_watch (bus); /* Connect the signals we want to listen to on the bus */ g_signal_connect (G_OBJECT (bus), "message::error", G_CALLBACK (error_cb), gstreamer); g_signal_connect (G_OBJECT (bus), "message::eos", G_CALLBACK (eos_cb), gstreamer); /* Read from disk */ priv->filesrc = gst_element_factory_make (FILE_SOURCE, "file_src"); if (priv->filesrc == NULL) { g_set_error (&priv->construct_error, NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, _("Could not create GStreamer file input")); return; } /* Decode */ priv->decode = gst_element_factory_make ("decodebin", "decode"); if (priv->decode == NULL) { g_set_error (&priv->construct_error, NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, _("Could not create GStreamer file input")); return; } /* Encode */ priv->encode = build_encoder (gstreamer); if (priv->encode == NULL) { g_set_error (&priv->construct_error, NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, _("Could not create GStreamer encoders for %s"), gm_audio_profile_get_name (priv->profile)); return; } /* Decodebin uses dynamic pads, so lets set up a callback. */ g_signal_connect (G_OBJECT (priv->decode), "new-decoded-pad", G_CALLBACK (connect_decodebin_cb), priv->encode); /* Write to disk */ priv->filesink = gst_element_factory_make (FILE_SINK, "file_sink"); if (priv->filesink == NULL) { g_set_error (&priv->construct_error, NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, _("Could not create GStreamer file output")); return; } /* * TODO: Eventually, we should ask the user if they want to * overwrite any existing file. */ g_signal_connect (G_OBJECT (priv->filesink), "allow-overwrite", G_CALLBACK (just_say_yes), gstreamer); /* Add the elements to the pipeline */ gst_bin_add_many (GST_BIN (priv->pipeline), priv->filesrc, priv->decode, priv->encode, priv->filesink, NULL); /* Link filessrc and decoder */ if (!gst_element_link_many (priv->filesrc, priv->decode, NULL)) { g_set_error (&priv->construct_error, NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, _("Could not link pipeline")); return; } /* Link the rest */ if (!gst_element_link (priv->encode, priv->filesink)) { g_set_error (&priv->construct_error, NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, _("Could not link pipeline")); return; } priv->rebuild_pipeline = FALSE; }
static void new_profile_response_callback (GtkWidget *new_profile_dialog, int response_id, GMAudioProfilesEdit *dialog) { if (response_id == GTK_RESPONSE_ACCEPT) { GtkWidget *name_entry; char *name; char *id; /*GtkWidget *base_option_menu;*/ GMAudioProfile *new_profile; GList *profiles; GList *tmp; GtkWindow *transient_parent; GError *error; name_entry = g_object_get_data (G_OBJECT (new_profile_dialog), "name_entry"); name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1); g_strstrip (name); /* name will be non empty after stripping */ profiles = gm_audio_profile_get_list (); for (tmp = profiles; tmp != NULL; tmp = tmp->next) { GMAudioProfile *profile = tmp->data; if (strcmp (name, gm_audio_profile_get_name (profile)) == 0) break; } if (tmp) { gmp_util_run_error_dialog (GTK_WINDOW (new_profile_dialog), _("You already have a profile called \"%s\""), name); goto cleanup; } g_list_free (profiles); /* base_option_menu = g_object_get_data (G_OBJECT (new_profile_dialog), "base_option_menu"); base_profile = profile_optionmenu_get_selected (base_option_menu); if (base_profile == NULL) { terminal_util_show_error_dialog (GTK_WINDOW (new_profile_dialog), NULL, _("The profile you selected as a base for your new profile no longer exists")); goto cleanup; } */ transient_parent = gtk_window_get_transient_for (GTK_WINDOW (new_profile_dialog)); error = NULL; id = gm_audio_profile_create (name, dialog->priv->conf, &error); if (error) { g_print ("ERROR: %s\n", error->message); gmp_util_run_error_dialog (GTK_WINDOW (transient_parent), _("MateConf Error (FIXME): %s\n"), error->message); g_error_free (error); goto cleanup; } gtk_widget_destroy (new_profile_dialog); /* FIXME: hm, not very proud of having to unstatic this function */ GST_DEBUG ("new profile callback: syncing list\n"); //FIXME: in mate-terminal, it's TRUE, &n, which then gets overruled // by some other sync call with the new list //audio_profile_sync_list (TRUE, &n); gm_audio_profile_sync_list (FALSE, NULL); refill_profile_treeview (dialog->priv->manage_profiles_list); new_profile = gm_audio_profile_lookup (id); g_assert (new_profile != NULL); //audio_profile_edit (new_profile, transient_parent); cleanup: g_free (name); } else { gtk_widget_destroy (new_profile_dialog); } GST_DEBUG ("done creating new profile\n"); }
static void delete_button_clicked (GtkWidget *button, GMAudioProfilesEdit *dialog) { GtkTreeSelection *selection; GList *deleted_profiles; GtkWidget *confirm_dialog; GString *str; GList *tmp; int count; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->manage_profiles_list)); deleted_profiles = NULL; gtk_tree_selection_selected_foreach (selection, list_selected_profiles_func, &deleted_profiles); count = g_list_length (deleted_profiles); if (count > 1) { str = g_string_new (NULL); /* the first argument will never be used since we only run for count > 1 */ g_string_printf (str, ngettext ("Delete this profile?\n", "Delete these %d profiles?\n", count), count); tmp = deleted_profiles; while (tmp != NULL) { g_string_append (str, " "); g_string_append (str, gm_audio_profile_get_name (tmp->data)); if (tmp->next) g_string_append (str, "\n"); tmp = tmp->next; } } else { str = g_string_new (NULL); g_string_printf (str, _("Delete profile \"%s\"?"), gm_audio_profile_get_name (deleted_profiles->data)); } confirm_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", str->str); g_string_free (str, TRUE); gtk_dialog_add_buttons (GTK_DIALOG (confirm_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_default_response (GTK_DIALOG (confirm_dialog), GTK_RESPONSE_ACCEPT); gtk_window_set_title (GTK_WINDOW (confirm_dialog), _("Delete Profile")); gtk_window_set_resizable (GTK_WINDOW (confirm_dialog), FALSE); /* FIXME: what's this ? */ dialog->priv->deleted_profiles_list = deleted_profiles; g_signal_connect (G_OBJECT (confirm_dialog), "response", G_CALLBACK (delete_confirm_response), dialog); g_return_if_fail (confirm_dialog != NULL); gtk_widget_show_all (confirm_dialog); gtk_dialog_run (GTK_DIALOG (confirm_dialog)); }
/* refill profile treeview * recreates the profile tree view from scratch */ static void refill_profile_treeview (GtkWidget *tree_view) { GList *profiles; GList *tmp; GtkTreeSelection *selection; GtkListStore *model; GList *selected_profiles; GtkTreeIter iter; GST_DEBUG ("refill_profile_treeview: start\n"); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); selected_profiles = NULL; gtk_tree_selection_selected_foreach (selection, list_selected_profiles_func, &selected_profiles); gtk_list_store_clear (model); profiles = gm_audio_profile_get_list (); tmp = profiles; while (tmp != NULL) { GMAudioProfile *profile = tmp->data; GST_DEBUG ("refill: appending profile with name %s\n", gm_audio_profile_get_name (profile)); gtk_list_store_append (model, &iter); /* We are assuming the list store will hold a reference to * the profile object, otherwise we would be in danger of disappearing * profiles. */ gtk_list_store_set (model, &iter, COLUMN_NAME, gm_audio_profile_get_name (profile), COLUMN_PROFILE_OBJECT, profile, -1); if (g_list_find (selected_profiles, profile) != NULL) gtk_tree_selection_select_iter (selection, &iter); tmp = tmp->next; } if (selected_profiles == NULL) { /* Select first row */ GtkTreePath *path; path = gtk_tree_path_new (); gtk_tree_path_append_index (path, 0); gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), path); gtk_tree_path_free (path); } free_profiles_list (selected_profiles); GST_DEBUG ("refill_profile_treeview: stop\n"); }
Recording* recording_start(const char* filename) { GMAudioProfile *profile; GstElement *pipeline, *oss_src, *encoder, *filesink; pipeline = oss_src = encoder = filesink = NULL; profile = gm_audio_profile_lookup(rec_settings.profile); g_assert(profile); pipeline = gst_pipeline_new("gnomeradio-record-pipeline"); if (!pipeline) { show_error_message(_("Could not create GStreamer pipeline."), _("Check your Gstreamer installation!")); goto error; } oss_src = gst_element_factory_make("osssrc", "oss-source"); if (!oss_src) { show_error_message(_("Could not open Gstreamer OSS Source."), _("Verify your Gstreamer OSS subsystem installation!")); goto error; } GstBus *bus = gst_element_get_bus(pipeline); gst_bus_add_signal_watch(bus); g_signal_connect(G_OBJECT(bus), "message::error", G_CALLBACK(error_cb), pipeline); char* pipeline_str = g_strdup_printf("audioconvert ! %s", gm_audio_profile_get_pipeline(profile)); encoder = my_gst_gconf_render_bin_from_description(pipeline_str); g_free(pipeline_str); if (!encoder) { char *caption = g_strdup_printf(_("Could not create encoder \"%s\"."), gm_audio_profile_get_name (profile)); show_error_message(caption, _("Verify your Gstreamer plugins installation!")); g_free(caption); goto error; } /* Write to disk */ filesink = gst_element_factory_make("filesink", "file-sink"); if (!filesink) { show_error_message(_("Could not create Gstreamer filesink."), _("Check your Gstreamer installation!")); goto error; } /* Add the elements to the pipeline */ gst_bin_add_many(GST_BIN(pipeline), oss_src, encoder, filesink, NULL); /* Link it all together */ if (!gst_element_link_many(oss_src, encoder, filesink, NULL)) { g_warning("Could not link elements. This is bad!\n"); goto error; } char* path = g_strdup_printf("%s.%s", filename, gm_audio_profile_get_extension(profile)); g_object_set(G_OBJECT(filesink), "location", path, NULL); gst_element_set_state(pipeline, GST_STATE_PLAYING); Recording *recording = g_malloc0(sizeof(Recording)); recording->filename = path; recording->pipeline = pipeline; return recording; error: if (pipeline) gst_object_unref(GST_OBJECT(pipeline)); if (oss_src) gst_object_unref(GST_OBJECT(oss_src)); if (encoder) gst_object_unref(GST_OBJECT(encoder)); if (filesink) gst_object_unref(GST_OBJECT(filesink)); return NULL; }
static void test_clicked_cb (GtkButton *button, GtkWidget *combo) { GstStateChangeReturn ret; gchar *partialpipe = NULL; gchar *extension = NULL; gchar *pipeline_desc; GError *error = NULL; GMAudioProfile *profile; GstElement *pipeline = NULL; GstMessage *msg = NULL; GstBus *bus = NULL; profile = gm_audio_profile_choose_get_active (combo); g_return_if_fail (profile != NULL); gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE); extension = g_strdup (gm_audio_profile_get_extension (profile)); partialpipe = g_strdup (gm_audio_profile_get_pipeline (profile)); g_print ("You chose profile with name %s and pipeline %s\n", gm_audio_profile_get_name (profile), gm_audio_profile_get_pipeline (profile)); pipeline_desc = g_strdup_printf ("audiotestsrc wave=sine num-buffers=4096 " " ! audioconvert " " ! %s " " ! filesink location=test.%s", partialpipe, extension); g_print ("Going to run pipeline %s\n", pipeline_desc); pipeline = gst_parse_launch (pipeline_desc, &error); if (error) { g_warning ("Error parsing pipeline: %s", error->message); goto done; } bus = gst_element_get_bus (pipeline); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* wait for state change to complete or to have failed */ ret = gst_element_get_state (pipeline, NULL, NULL, -1); if (ret == GST_STATE_CHANGE_FAILURE) { /* check if an error was posted on the bus */ if ((msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0))) { gst_message_parse_error (msg, &error, NULL); } g_warning ("Error starting pipeline: %s", (error) ? error->message : "UNKNOWN ERROR"); goto done; } g_print ("Writing test sound to test.%s ...\n", extension); /* wait for it finish (error or EOS), but no more than 30 secs */ msg = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 30*GST_SECOND); if (msg) { switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("Test finished successfully.\n"); break; case GST_MESSAGE_ERROR: gst_message_parse_error (msg, &error, NULL); g_warning ("Error starting pipeline: %s", (error) ? error->message : "UNKNOWN ERROR"); break; default: g_assert_not_reached (); } } else { g_warning ("Test did not finish within 30 seconds!\n"); } done: g_print ("==============================================================\n"); if (error) g_error_free (error); if (pipeline) { gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); } if (msg) gst_message_unref (msg); if (bus) gst_object_unref (bus); g_free (pipeline_desc); g_free (partialpipe); g_free (extension); gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE); }