2013-10-30 58 views
1

我使用videomixer顯示multiplr在一個窗口圖像我使用下面的代碼做GStreamer的管道是否顯示圖片

#include <gst/gst.h> 
#include <glib.h> 




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 *error; 

     gst_message_parse_error (msg, &error, &debug); 
     g_free (debug); 

     g_printerr ("Error: %s\n", error->message); 
     g_error_free (error); 

     g_main_loop_quit (loop); 
     break; 
    } 
    default: 
     break; 
    } 
    return TRUE; 
} 

static void 
on_pad_added (GstElement *element, 
       GstPad  *pad, 
       gpointer data) 
{ 
    GstPad *sinkpad; 
    GstElement *decoder = (GstElement *) data; 

    /* We can now link this pad with the vorbis-decoder sink pad */ 
    g_print ("Dynamic pad created, linking demuxer/decoder\n"); 

    sinkpad = gst_element_get_static_pad (decoder, "sink"); 

    gst_pad_link (pad, sinkpad); 
    gst_object_unref (sinkpad); 
} 

int 
main (int argc, 
     char *argv[]) { 

GMainLoop *loop; 

GstElement *pipeline,*freeze,*clrspace; 
GstElement *source1; 
GstElement *source2; 
GstElement *videobox1,*videobox2; 
GstElement *mixer,*sink,*queuevideo; 
GstBus *bus; 

loop = g_main_loop_new (NULL, FALSE); 

/* Create gstreamer elements */ 
pipeline = gst_pipeline_new ("player"); 
source1 = gst_element_factory_make ("playbin2", "dec1"); 
source2 = gst_element_factory_make ("playbin2", "dec2"); 
freeze = gst_element_factory_make ("imagefreeze", "fr"); 
//videobox1 = gst_element_factory_make ("videobox",  "videobox1"); 
//videobox2 = gst_element_factory_make ("videobox",  "videobox2"); 
clrspace = gst_element_factory_make ("ffmpegcolorspace",  "clrspace"); 
mixer = gst_element_factory_make ("videomixer",  "mixer"); 
queuevideo = gst_element_factory_make ("queue", "queue-video"); 
sink  = gst_element_factory_make ("xvimagesink", "sink"); 


if (!pipeline || !source1 || !source2 || !sink || !mixer ||!freeze || !clrspace || !queuevideo) { 
    g_printerr ("One element could not be created. Exiting.\n"); 
    exit(1); 
} 

g_object_set (source1, "uri", "http://www.logotheque.fr/6396-2/logo+RMC+INFO.jpg", NULL); 
g_object_set (source2, "uri", "http://www.logotheque.fr/6396-2/logo+RMC+INFO.jpg", NULL); 

// g_object_set(videobox1,"border-alpha",0,"top",0,"left",0,NULL); 
// g_object_set(videobox2,"border-alpha",0,"top",0,"left",-200,NULL); 

/* we add a message handler */ 
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); 
gst_bus_add_watch (bus, bus_call, loop); 
gst_object_unref (bus); 

/* we add all elements into the pipeline */ 
gst_bin_add_many (GST_BIN (pipeline), 
        source1,mixer, clrspace, freeze, sink, source2, NULL); 

/* we link the elements together */ 
gst_element_link_many (source1, mixer, clrspace, freeze,sink,source2, NULL); 
//gst_element_link_many (source[1], mixer, NULL); 

g_signal_connect (source1, "pad-added", G_CALLBACK (on_pad_added), queuevideo); 
g_signal_connect (source2, "pad-added", G_CALLBACK (on_pad_added), queuevideo); 


/* Set the pipeline to "playing" state*/ 
gst_element_set_state (pipeline, GST_STATE_PLAYING); 

/* Iterate */ 
g_print ("Running...\n"); 
g_main_loop_run (loop); 

/* Out of the main loop, clean up nicely */ 
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)); 
} 

我沒有錯誤,編譯但是當我運行它,我什麼都不顯示和我有以下警告

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 
One element could not be created. Exiting. 

有人能幫助我嗎?

+0

[顯示圖像使用gstreamer與c API]可能的重複(http://stackoverflow.com/questions/19685022/display-image-using-gstreamer-with-c-api) – abelenky

回答