使用typefind播放Gstreamer

时间:2014-09-02 12:17:44

标签: video arm signals gstreamer playback

首先,我只是gstreamer的初学者,我正处于开发应用程序的过程中,该应用程序将视频数据发送给侦听器,并且侦听器对其进行解码以进行播放。对于这个使用gstreamer。 但在此之前,我试图了解gstreamer。

我有一个独立的代码,它生成一个添加了pad的信号,并且回调被命中。 我使用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 pad。 这就是我使用独立的typefind。

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

Cap = video / 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);

}

我减少了一些代码。你能指导我在这里失踪的东西。?.. 我不确定如何将类型查找带入代码。

谢谢

1 个答案:

答案 0 :(得分:1)

我终于在不使用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查找大写字母,而是手动设置大写字母。 希望这有助于某人。