2014-09-02 51 views
1

首先,我只是gstreamer的初学者,我正在开发一个应用程序,它将视频数据发送给监听器,监听器将其解码并播放。为此我正在使用gstreamer。 但之前,我试图了解gstreamer。使用typefind播放Gstreamer

我有一个独立的代码,它产生一个pad-added信号并且回叫被打。Iam使用I.MX6板进行播放。

我用gst-launch使用下面的命令播放“ts文件和mp4文件”,它可以工作。

gst-launch-0.10 filesrc location=/opt/zu/test/stream2.ts typefind=true ! aiurdemux name=demux demux. ! queue ! beepdec ! audioconvert ! autoaudiosink demux. ! queue ! vpudec! mfw_v4lsink 

然后我把它带入代码,完美地使用了分流器和所需的元件。

这里我发现设置了“typefind = true”,我不确定如何将它带入代码。据我所知,typefind在找到CAP后设置了src焊盘。 这就是我使用独立的typefind。

<?xml version="1.0"?> 
<Capabilities> 
<Caps1>video/mpegts, systemstream=(boolean)true, packetsize=(int)188</Caps1> 
</Capabilities> 

上限=视频/ MPEGTS

在运行我的GStreamer独立播放TS文件,我得到了以下信息

“管道状态改变从NULL到READY:” 和它不播放。它只是继续运行。以下是我的独立代码

data.source = gst_element_factory_make ("filesrc", "source"); 
g_object_set (data.source, "location", argv[1], NULL); 
data.typefind = gst_element_factory_make ("typefind", "typefinder"); 
data.demuxer = gst_element_factory_make ("aiurdemux", "demuxer"); 
data.audioqueue = gst_element_factory_make("queue","audioqueue"); 
data.videoqueue = gst_element_factory_make("queue","videoqueue"); 
data.audio_decoder = gst_element_factory_make ("beepdec", "audio_decoder"); 
data.audio_convert = gst_element_factory_make ("audioconvert", "audio_convert"); 
data.audio_sink = gst_element_factory_make ("autoaudiosink", "audio_sink"); 
data.video_decoder = gst_element_factory_make("vpudec","video_decoder"); 
data.video_sink = gst_element_factory_make("mfw_v4lsink","video_sink"); 

    if (!gst_element_link(data.source,data.demuxer)) { 
       g_printerr ("Elements could not be linked.\n"); 
       gst_object_unref (data.pipeline); 
       return -1; 
     } 

if (!gst_element_link_many (data.audioqueue,data.audio_decoder,data.audio_convert, data.audio_sink,NULL)) { 
       g_printerr (" audio Elements could not be linked.\n"); 
       gst_object_unref (data.pipeline); 
       return -1; 
     } 
    if (!gst_element_link_many(data.videoqueue,data.video_decoder, data.video_sink,NULL)) { 
       g_printerr("video Elements could not be linked.\n"); 
       gst_object_unref(data.pipeline); 
       return -1; 
     } 

//g_object_set (data.source, "location", argv[1], NULL); 
     g_signal_connect (data.demuxer, "pad-added", G_CALLBACK (pad_added_handler), &data); 
     /* Start playing */ 


// CALLBACK FUNCTION 

static void pad_added_handler (GstElement *src, GstPad *new_pad, CustomData *data) { 
     g_print("Inside the pad_added_handler method \n"); 
     printf("Inside the pad_added_handler method \n"); 
     GstPad *sink_pad_audio = gst_element_get_static_pad (data->audioqueue, "sink"); 
     GstPad *sink_pad_video = gst_element_get_static_pad (data->videoqueue, "sink"); 

     GstPadLinkReturn ret; 
     GstCaps *new_pad_caps = NULL; 
     GstStructure *new_pad_struct = NULL; 
     const gchar *new_pad_type = NULL; 
     g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (new_pad), GST_ELEMENT_NAME (src)); 
     new_pad_caps = gst_pad_get_caps (new_pad); 
     new_pad_struct = gst_caps_get_structure (new_pad_caps, 0); 
     new_pad_type = gst_structure_get_name (new_pad_struct); 
     if (g_str_has_prefix (new_pad_type,/*"audio/x-vorbis"*/ "audio/mpeg")) 
     { 
       ret = gst_pad_link (new_pad, sink_pad_audio); 
       if (GST_PAD_LINK_FAILED (ret)) 
       { 
         g_print (" Type is '%s' but link failed.\n", new_pad_type); 
       } 
       else 
       { 
         g_print (" Link succeeded (type '%s').\n", new_pad_type); 
       } 
     } 

     //else if (g_str_has_prefix (new_pad_type, /*"video/x-theora"*/"video/x-h264")) 
     else if (g_str_has_prefix (new_pad_type, /*"video/x-theora"*/"video/mpegts")) 
     { 
       ret = gst_pad_link (new_pad, sink_pad_video); 

       if (GST_PAD_LINK_FAILED (ret)) 
       { 
         g_print (" Type is '%s' but link failed.\n", new_pad_type); 
       } 
       else 
       { 
         g_print (" Link succeeded (type '%s').\n", new_pad_type); 
       } 
     } 


     else { 
       g_print (" It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type); 
       goto exit; 
     } 
exit: 
     if (new_pad_caps != NULL) 
       gst_caps_unref (new_pad_caps); 
     gst_object_unref (sink_pad_audio); 
     gst_object_unref (sink_pad_video); 

} 

我减少了一些代码。你能指导Iam在这里失踪吗?.. Iam不知道如何将类型查找带入代码。

谢谢

回答

0

我已经解决了这个问题,而不使用typefind。

如果有人遇到这个帖子,希望这对他们有用。

它看起来像typefind是没有必要的,我用下面的代码。

GstCaps *caps; 
/* for mp4 playback use "video/quicktime", if it is ts file use "video/mpegts" , likewise corresponding to other files. You can find what to use as caps using gst-discoverer command for the file*/ 
caps = gst_caps_new_simple("video/quicktime",NULL); 
//After creating caps link using link_filtered to the demuxer 
if (!gst_element_link_filtered(data.source,data.demuxer,caps)) 
     g_printerr ("Elements could not be linked.\n"); 
       gst_object_unref (data.pipeline); 
       return -1; 
     } 
gst_caps_unref(caps); //unref after use, then the normal code continues with generating //pad-added signal. 

而不是使用truefind找到上限,上面的代码手动设置上限。 希望这可以帮助别人。

相关问题