Advertisement
herrpaco

Untitled

Nov 22nd, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.99 KB | None | 0 0
  1. #include <gst/gst.h>
  2.  
  3. static GstPad *audiosrc_blockpad;
  4. static GstElement *videosrc, *videosink, *pipeline, *textoverlay, *audiosrc, *audiosink;
  5.  
  6. static GstPadProbeReturn pad_probe_videosrc_cb(GstPad * videosrc_pad, GstPadProbeInfo * info, gpointer user_data){
  7.    
  8.     /* unlink videotestsrc from ximagesink */
  9.     gst_element_set_state(videosink, GST_STATE_NULL);    
  10.     gst_bin_remove(GST_BIN(pipeline), videosink);
  11.    
  12.     /* adding the textoverlay */
  13.     textoverlay = gst_element_factory_make("textoverlay", NULL);
  14.     g_object_set(G_OBJECT (textoverlay), "text", "Hello World!", NULL);
  15.     gst_bin_add_many(GST_BIN(pipeline), textoverlay, videosink, NULL);
  16.    
  17.     /* inserting the text overlay */
  18.     gst_element_link_many(videosrc, textoverlay, videosink, NULL);
  19.    
  20.     gst_element_set_state(textoverlay, GST_STATE_PLAYING);
  21.     gst_element_set_state(videosink, GST_STATE_PLAYING);
  22.    
  23.     //gst_debug_set_threshold_from_string ("*:5", TRUE);
  24.    
  25.     return GST_PAD_PROBE_REMOVE;
  26. }
  27.  
  28. static GstPadProbeReturn pad_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data){
  29.    
  30.     /* remove audio */
  31.     gst_element_set_state(audiosink, GST_STATE_NULL);
  32.     gst_bin_remove(GST_BIN(pipeline), audiosink);
  33.    
  34.     gst_pad_add_probe (gst_element_get_static_pad(videosrc, "src"), GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_probe_videosrc_cb, user_data, NULL);
  35.    
  36.     GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL ,"usecase2-b");
  37.    
  38.     return GST_PAD_PROBE_OK;
  39. }
  40.  
  41. static gboolean timeout_cb (gpointer user_data){
  42.    
  43.     GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL ,"usecase2-a");
  44.    
  45.     gst_pad_add_probe (audiosrc_blockpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_probe_cb, user_data, NULL);
  46.     return FALSE;
  47. }
  48.  
  49. int main (int argc, char **argv){
  50.     GMainLoop *loop;
  51.    
  52.     /* init GStreamer */
  53.     gst_init (&argc, &argv);
  54.     loop = g_main_loop_new (NULL, FALSE);
  55.    
  56.     videosrc = gst_element_factory_make("videotestsrc", NULL);
  57.     videosink = gst_element_factory_make("ximagesink", NULL);
  58.    
  59.     audiosrc = gst_element_factory_make("audiotestsrc", NULL);
  60.     audiosink = gst_element_factory_make("pulsesink", NULL);
  61.     /* We must set provide-clock to FALSE, otherwise, ximagesink loses its clock and freezes */
  62.     g_object_set(G_OBJECT (audiosink), "provide-clock", FALSE, NULL);
  63.    
  64.     audiosrc_blockpad = gst_element_get_static_pad(audiosrc, "src");
  65.    
  66.     pipeline = gst_pipeline_new("pipeline");
  67.    
  68.     gst_bin_add_many(GST_BIN(pipeline), audiosink, audiosrc, videosrc, videosink, NULL);
  69.    
  70.     gst_element_link_many(videosrc, videosink, NULL);
  71.     gst_element_link_many(audiosrc, audiosink, NULL);
  72.    
  73.     gst_element_set_state(pipeline, GST_STATE_PLAYING);
  74.    
  75.    
  76.     g_timeout_add_seconds (5, timeout_cb, loop);
  77.    
  78.     g_main_loop_run (loop);
  79.    
  80.     gst_element_set_state (pipeline, GST_STATE_NULL);
  81.    
  82.     gst_object_unref (pipeline);
  83.    
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement