pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

alvinator private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Alvin Delagon on Thu 9 Apr 14:52
report abuse | download | new post

  1. /*
  2.  * File: mp3player.c
  3.  * Author: Alvin Delagon
  4.  * Summary: A command-line mp3 player using gstreamer
  5.  */
  6.  
  7. #include <gst/gst.h>
  8.  
  9. int main (int argc, char *argv[])
  10. {
  11.   GstElement *pipeline;
  12.   GstElement *filesrc, *mad, *audioconvert, *alsasink;
  13.  
  14.   /* initialize gst */
  15.   const gchar *nano_str;
  16.   guint major, minor, micro, nano;
  17.   gst_version (&major, &minor, &micro, &nano);
  18.   if (nano == 1)
  19.     nano_str = "(CVS)";
  20.   else if (nano == 2)
  21.     nano_str = "(Prerelease)";
  22.   else
  23.     nano_str = "";
  24.   g_print ("Using gstreamer version: %d.%d.%d %s\n", major, minor, micro, nano_str);
  25.   gst_init (&argc, &argv);
  26.  
  27.   g_print ("Creating elements...\n");
  28.   /* Create Elements */
  29.   filesrc = gst_element_factory_make ("filesrc", "source");
  30.   if (filesrc == NULL)
  31.     {
  32.       g_print ("Failed to create filesrc element");
  33.       return -1;
  34.     }
  35.   mad = gst_element_factory_make ("mad", "decoder");
  36.   if (mad == NULL)
  37.     {
  38.       g_print ("Failed to create mad element");
  39.       return -1;
  40.     }
  41.   audioconvert = gst_element_factory_make ("audioconvert", "converter");
  42.   if (audioconvert == NULL)
  43.     {
  44.       g_print ("Failed to create audioconvert element");
  45.       return -1;
  46.     }
  47.   alsasink = gst_element_factory_make ("alsasink", "sink");
  48.   if (alsasink == NULL)
  49.     {
  50.       g_print ("Failed to create alsasink element");
  51.       return -1;
  52.     }
  53.  
  54.   g_print ("Building pipeline...\n");
  55.   /* Add Elements to pipeline*/
  56.   pipeline = gst_pipeline_new ("mp3-pipeline");
  57.   gst_bin_add_many (GST_BIN (pipeline), filesrc, mad, audioconvert, alsasink, NULL);
  58.  
  59.   g_print ("Linking elements...\n");
  60.   /* Link Elements */
  61.   if (!gst_element_link_many (filesrc, mad, audioconvert, alsasink, NULL))
  62.     g_warning ("Failed to link elements!\n");
  63.  
  64.   /* Set filesrc location property */
  65.   if (argv[1] == NULL)
  66.     {
  67.       g_print ("mp3 file is not provided. usage: mp3player [file]\n");
  68.       return -1;
  69.     }
  70.   g_print ("Playing file: %s\n", argv[1]);
  71.   g_object_set (filesrc, "location", argv[1], NULL);
  72.  
  73.  
  74.   /* Set pipeline state to PLAYING */
  75.   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  76.  
  77.   /* Application loop (We'll use gtk_main() here soon) */
  78.   while (1)
  79.     {
  80.       g_usleep(G_USEC_PER_SEC);
  81.       g_print (".");
  82.     }
  83.  
  84.   return 0;
  85. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post