Advertisement
herrpaco

Adding overlay

Nov 15th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <gst/gst.h>
  2.  
  3. static GstPad *videosrc_blockpad;
  4. static GstElement *videosrc, *videosink, *pipeline, *textoverlay;
  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.  
  11. /* adding the textoverlay */
  12. textoverlay = gst_element_factory_make("textoverlay", NULL);
  13. g_object_set(G_OBJECT (textoverlay), "text", "Hello World!", NULL);
  14. gst_bin_add(GST_BIN(pipeline), textoverlay);
  15.  
  16. /* inserting the text overlay */
  17. gst_element_link_many(videosrc, textoverlay, videosink, NULL);
  18.  
  19. /* Setting new linked elements to GST_STATE_PLAYING */
  20. gst_element_set_state(videosink, GST_STATE_PLAYING);
  21. gst_element_set_state(textoverlay, GST_STATE_PLAYING);
  22.  
  23. gst_debug_set_threshold_from_string ("*:5", TRUE);
  24.  
  25. /* This removes the blocking probe of videotestsrc:src */
  26. return GST_PAD_PROBE_REMOVE;
  27. }
  28.  
  29. static gboolean timeout_cb (gpointer user_data){
  30.  
  31. gst_pad_add_probe (videosrc_blockpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_probe_videosrc_cb, user_data, NULL);
  32. return FALSE;
  33. }
  34.  
  35. int main (int argc, char **argv){
  36. GMainLoop *loop;
  37.  
  38. /* init GStreamer */
  39. gst_init (&argc, &argv);
  40. loop = g_main_loop_new (NULL, FALSE);
  41.  
  42. videosrc = gst_element_factory_make("videotestsrc", NULL);
  43. videosrc_blockpad = gst_element_get_static_pad(videosrc, "src");
  44.  
  45. videosink = gst_element_factory_make("ximagesink", NULL);
  46.  
  47. pipeline = gst_pipeline_new("pipeline");
  48.  
  49. gst_bin_add_many(GST_BIN(pipeline), videosrc, videosink, NULL);
  50.  
  51. gst_element_link_many(videosrc, videosink, NULL);
  52.  
  53. gst_element_set_state(pipeline, GST_STATE_PLAYING);
  54.  
  55. g_timeout_add_seconds (5, timeout_cb, loop);
  56.  
  57. g_main_loop_run (loop);
  58.  
  59. gst_element_set_state (pipeline, GST_STATE_NULL);
  60.  
  61. gst_object_unref (pipeline);
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement