devendradhanal

Untitled

Aug 29th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1.  
  2. #include <string.h>
  3. #include <math.h>
  4. #include <gst/gst.h>
  5. #include <glib.h>
  6.  
  7. static gboolean bus_call (GstBus *bus,GstMessage *msg, gpointer data){
  8. GMainLoop *loop = (GMainLoop *) data;
  9.  
  10. switch (GST_MESSAGE_TYPE (msg)) {
  11.  
  12. case GST_MESSAGE_EOS:
  13. g_print ("Stream Ends\n");
  14. g_main_loop_quit (loop);
  15. break;
  16.  
  17. case GST_MESSAGE_ERROR: {
  18. gchar *debug;
  19. GError *error;
  20.  
  21. gst_message_parse_error (msg, &error, &debug);
  22. g_free (debug);
  23.  
  24. g_printerr ("Error: %s\n", error->message);
  25. g_error_free (error);
  26.  
  27. g_main_loop_quit (loop);
  28. break;
  29. }
  30. default:
  31. break;
  32. }
  33.  
  34. return TRUE;
  35. }
  36.  
  37. static void on_pad_added (GstElement *element, GstPad *pad, gpointer data){
  38.  
  39. GstPad *sinkpad;
  40. GstElement *decoder = (GstElement *) data;
  41.  
  42. /* We can now link this pad with the rtsp-decoder sink pad */
  43. g_print ("Dynamic pad created, linking source/demuxer\n");
  44.  
  45. sinkpad = gst_element_get_static_pad (decoder, "sink");
  46.  
  47. gst_pad_link (pad, sinkpad);
  48.  
  49. gst_object_unref (sinkpad);
  50. }
  51.  
  52. int main (int argc, char *argv[])
  53. {
  54. GMainLoop *loop;
  55. GstBus *bus;
  56. GstElement *source;
  57. GstElement *decoder;
  58. GstElement *sink;
  59. GstElement *pipeline;
  60. GstElement *demux;
  61. GstElement *colorspace;
  62.  
  63. /* Initializing GStreamer */
  64. gst_init (&argc, &argv);
  65. loop = g_main_loop_new (NULL, FALSE);
  66.  
  67. //gst-launch-0.10 rtspsrc location=rtsp://<ip> ! decodebin ! ffmpegcolorspace ! autovideosink
  68. //gst-launch -v rtspsrc location="rtsp://<ip> ! rtpmp4vdepay ! mpeg4videoparse ! ffdec_mpeg4 ! ffmpegcolorspace! autovideosink
  69. //gst-launch -v rtspsrc location="rtsp://<ip> ! rtpmp4vdepay ! ffdec_mpeg4 ! ffmpegcolorspace! autovideosink
  70. /* Create Pipe's Elements */
  71. pipeline = gst_pipeline_new ("video player");
  72. g_assert (pipeline);
  73. source = gst_element_factory_make ("rtspsrc", "Source");
  74. g_assert (source);
  75. demux = gst_element_factory_make ("rtpmp4vdepay", "Depay");
  76. g_assert (demux);
  77. decoder = gst_element_factory_make ("ffdec_mpeg4", "Decoder");
  78. g_assert (decoder);
  79. colorspace = gst_element_factory_make ("ffmpegcolorspace", "Colorspace");
  80. g_assert(colorspace);
  81. sink = gst_element_factory_make ("autovideosink", "Output");
  82. g_assert (sink);
  83.  
  84. /*Make sure: Every elements was created ok*/
  85. if (!pipeline || !source || !demux || !decoder || !colorspace || !sink) {
  86. g_printerr ("One of the elements wasn't create... Exiting\n");
  87. return -1;
  88. }
  89.  
  90. g_print(" \nPipeline is Part(A) ->(dynamic/runtime link) Part(B)[ Part(B-1) -> Part(B-2) -> Part(B-3) ]\n\n");
  91. g_print(" [source](dynamic)->(dynamic)[demux]->[decoder]->[colorspace]->[videosink] \n\n");
  92.  
  93. /* Set video Source */
  94. g_object_set (G_OBJECT (source), "location", argv[1], NULL);
  95. //g_object_set (G_OBJECT (source), "do-rtcp", TRUE, NULL);
  96. g_object_set (G_OBJECT (source), "latency", 0, NULL);
  97.  
  98. /* Putting a Message handler */
  99. bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  100. gst_bus_add_watch (bus, bus_call, loop);
  101. gst_object_unref (bus);
  102.  
  103. /* Add Elements to the Bin */
  104. gst_bin_add_many (GST_BIN (pipeline), source, demux, decoder, colorspace, sink, NULL);
  105.  
  106. /* Link confirmation */
  107. if (!gst_element_link_many (demux, decoder, colorspace, sink, NULL)){
  108. g_warning ("Linking part (B) Fail...");
  109. }
  110.  
  111. g_print("\nNote that the source will be linked to the demuxer(depayload) dynamically.\n\
  112. The reason is that rtspsrc may contain various elements (for example\n\
  113. audio and video). The source pad(s) will be created at run time,\n\
  114. by the rtspsrc when it detects the amount and nature of elements.\n\
  115. Therefore we connect a callback function which will be executed\n\
  116. when the \"pad-added\" is emitted.\n");
  117.  
  118. /* Dynamic Pad Creation */
  119. if(! g_signal_connect (source, "pad-added", G_CALLBACK (on_pad_added),demux))
  120. {
  121. g_warning ("Linking part (A) with part (B) Fail...");
  122. }
  123. /* Run the pipeline */
  124. g_print ("Playing: %s\n", argv[1]);
  125. gst_element_set_state (pipeline, GST_STATE_PLAYING);
  126. g_main_loop_run (loop);
  127.  
  128. /* Ending Playback */
  129. g_print ("End of the Streaming... ending the playback\n");
  130. gst_element_set_state (pipeline, GST_STATE_NULL);
  131.  
  132. /* Eliminating Pipeline */
  133. g_print ("Eliminating Pipeline\n");
  134. gst_object_unref (GST_OBJECT (pipeline));
  135.  
  136. return 0;
  137. }
Add Comment
Please, Sign In to add comment