Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- GstElement *pipeline, *source, *muxer, *encoder, *conv, *sink;
- GstCaps *audio;
- static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
- {
- GMainLoop *loop = (GMainLoop *) data;
- switch (GST_MESSAGE_TYPE (msg))
- {
- case GST_MESSAGE_EOS:
- g_print ("End-of-stream\n");
- g_main_loop_quit (loop);
- break;
- case GST_MESSAGE_ERROR:
- {
- gchar *debug;
- GError *err;
- gst_message_parse_error (msg, &err, &debug);
- g_free (debug);
- g_print ("Error: %s\n", err->message);
- g_error_free (err);
- g_main_loop_quit (loop);
- break;
- }
- default:
- break;
- }
- return TRUE;
- }
- int main (void)
- {
- GMainLoop *loop;
- GstBus *bus;
- /* initialize GStreamer */
- gst_init (NULL, NULL);
- loop = g_main_loop_new (NULL, FALSE);
- /* create elements */
- pipeline = gst_pipeline_new ("audio-player");
- source = gst_element_factory_make ("pulsesrc", "pulse-source");
- conv = gst_element_factory_make ("audioconvert", "converter");
- encoder = gst_element_factory_make ("lamemp3enc", "mp3-muxer");
- sink = gst_element_factory_make ("filesink", "file-output");
- if (!pipeline || !source || !conv || !encoder || !sink)
- {
- g_print ("One element could not be created\n");
- return -1;
- }
- /* set device property on the pulsesource. Also add a message handler. */
- g_object_set (G_OBJECT (source), "device", "alsa_input.pci-0000_00_1b.0.analog-stereo", NULL);
- g_object_set (G_OBJECT (encoder), "target", 1, "bitrate", 128, "cbr", TRUE, NULL);
- g_object_set (G_OBJECT (sink), "location", "audio.mp3", NULL);
- bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
- gst_bus_add_watch (bus, bus_call, loop);
- gst_object_unref (bus);
- /* put all elements in a bin */
- gst_bin_add_many (GST_BIN (pipeline), source, conv, encoder, sink, NULL);
- /* set to playing and iterate. */
- g_print ("Setting to PLAYING\n");
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
- g_print ("Running\n");
- g_main_loop_run (loop);
- /* clean up*/
- g_print ("Returned, stopping playback\n");
- gst_element_set_state (pipeline, GST_STATE_NULL);
- g_print ("Deleting pipeline\n");
- gst_object_unref (GST_OBJECT (pipeline));
- return 0;
- }
Add Comment
Please, Sign In to add comment