<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><br><div id="isForwardContent"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div><b>Hi,All</b></div><div><b><br></b></div><div><b>I am pushing my PC camera and microphone to rtmp server by using lamemp3enc element</b><span class="op_dict_text1 c-gap-right"><b>. Currently,</b></span><b>it can only push video h264 to rtmp server,</b><b>but the time-delay is over 5 seconds,how to reduce it  . After I  add
 audio code into the project, VLC player failed to pull video/audio 
stream </b><b>. Could you help   me find the bug ? Code as following.</b></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div><b><br></b></div><div><b>Thanks a lot!</b></div><div><b><br></b></div><div><br><div><br></div><pre style="background-color:#ffffff;color:#000000;font-family:'Courier 10 Pitch';font-size:12.0pt;"><span style="color:#808000;">#include </span><span style="color:#008000;font-weight:bold;"><gst/gst.h><br></span><span style="color:#008000;font-weight:bold;"></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#000080;font-weight:bold;">typedef struct </span><span style="color:#008080;">_CustomData </span>{<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">pipeline</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">vsource</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">vconvert</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">x264enc</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">h264parse</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">vcapsfilter</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">vsink</span>;<br><br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">asource</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">aconvert</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">amp3enc</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">acapfilter</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">ampegaudiopaser</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">asink</span>;<br><br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">vqueue</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">aqueue</span>;<br><br><br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">video_enc_queue</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">audio_enc_queue</span>;<br><br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">flvmuxer</span>;<br>    <span style="color:#371f80;">GstElement </span>*<span style="color:#660e7a;">rtmpsink</span>;<br><br>} <span style="color:#371f80;">CustomData</span>;<br><br><span style="color:#000080;font-weight:bold;">int </span>main(<span style="color:#000080;font-weight:bold;">int </span>argc, <span style="color:#000080;font-weight:bold;">char </span>*argv[]) {<br>    <span style="color:#371f80;">CustomData </span>data;<br>    <span style="color:#371f80;">GstBus </span>*bus;<br>    <span style="color:#371f80;">GstMessage </span>*msg;<br>    <span style="color:#371f80;">GstStateChangeReturn </span>ret;<br>    <span style="color:#371f80;">gboolean </span>terminate = <span style="color:#1f542e;font-weight:bold;">FALSE</span>;<br><br>    <span style="color:#808080;font-style:italic;">/* Initialize GStreamer */<br></span><span style="color:#808080;font-style:italic;">    //gst_init (&argc, &argv);<br></span><span style="color:#808080;font-style:italic;">    </span>gst_init(<span style="color:#1f542e;font-weight:bold;">NULL</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br>    <span style="color:#808080;font-style:italic;">/* Create the elements */<br></span><span style="color:#808080;font-style:italic;">    //"video/x-raw, width=(int)160, height=(int)120, framerate=(fraction)30/1, format=I420, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive"<br></span><span style="color:#808080;font-style:italic;">    </span>data.<span style="color:#660e7a;">vsource </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"v4l2src"</span>, <span style="color:#008000;font-weight:bold;">"camera-source"</span>);<span style="color:#808080;font-style:italic;">//autovideosrc v4l2src<br></span><span style="color:#808080;font-style:italic;">    </span>data.<span style="color:#660e7a;">vconvert </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"videoconvert"</span>, <span style="color:#008000;font-weight:bold;">"convert"</span>);<br>    data.<span style="color:#660e7a;">vsink </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"ximagesink"</span>, <span style="color:#008000;font-weight:bold;">"camera-sink"</span>);<br>    data.<span style="color:#660e7a;">vqueue </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"queue"</span>, <span style="color:#008000;font-weight:bold;">"camera-queue"</span>);<br>    data.<span style="color:#660e7a;">x264enc </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"x264enc"</span>, <span style="color:#008000;font-weight:bold;">"x264-encoder"</span>);<br>    data.<span style="color:#660e7a;">vcapsfilter </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"capsfilter"</span>, <span style="color:#008000;font-weight:bold;">"video-filter"</span>);<br>    data.<span style="color:#660e7a;">h264parse </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"h264parse"</span>, <span style="color:#008000;font-weight:bold;">"mux-video-parser"</span>);;<br><br><br>    data.<span style="color:#660e7a;">asource </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"alsasrc"</span>, <span style="color:#008000;font-weight:bold;">"audio-alsa-source"</span>);<br>    data.<span style="color:#660e7a;">aconvert </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"audioconvert"</span>, <span style="color:#008000;font-weight:bold;">"audio-converter"</span>);<br>    data.<span style="color:#660e7a;">amp3enc </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"lamemp3enc"</span>, <span style="color:#008000;font-weight:bold;">"mp3-encode"</span>);<br>    data.<span style="color:#660e7a;">acapfilter </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"capsfilter"</span>, <span style="color:#008000;font-weight:bold;">"audio-capsfilter"</span>);<br>    data.<span style="color:#660e7a;">asink </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"filesink"</span>, <span style="color:#008000;font-weight:bold;">"file-sink"</span>);<br>    data.<span style="color:#660e7a;">aqueue </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"queue"</span>, <span style="color:#008000;font-weight:bold;">"audio-queue"</span>);<br>    data.<span style="color:#660e7a;">ampegaudiopaser </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"mpegaudioparse"</span>, <span style="color:#008000;font-weight:bold;">"audio-paser"</span>);<br><br>    data.<span style="color:#660e7a;">flvmuxer </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"flvmux"</span>, <span style="color:#008000;font-weight:bold;">"mux-flvmux"</span>);<br>    data.<span style="color:#660e7a;">rtmpsink </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"rtmpsink"</span>, <span style="color:#008000;font-weight:bold;">"rtmp-sink"</span>);<br><br>    data.<span style="color:#660e7a;">video_enc_queue </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"queue"</span>, <span style="color:#008000;font-weight:bold;">"video_enc_queue"</span>);<br>    data.<span style="color:#660e7a;">audio_enc_queue </span>= gst_element_factory_make(<span style="color:#008000;font-weight:bold;">"queue"</span>, <span style="color:#008000;font-weight:bold;">"audio_enc_queue"</span>);<br><br>    g_object_set(<span style="color:#1f542e;font-weight:bold;">G_OBJECT</span>(data.<span style="color:#660e7a;">rtmpsink</span>), <span style="color:#008000;font-weight:bold;">"location"</span>, <span style="color:#008000;font-weight:bold;">"rtmp://localhost:1935/live/movie"</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br>    g_object_set(<span style="color:#1f542e;font-weight:bold;">G_OBJECT</span>(data.<span style="color:#660e7a;">flvmuxer</span>), <span style="color:#008000;font-weight:bold;">"streamable"</span>, <span style="color:#000080;font-weight:bold;">true</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br><br>    <span style="color:#808080;font-style:italic;">/* Create the empty pipeline */<br></span><span style="color:#808080;font-style:italic;">    </span>data.<span style="color:#660e7a;">pipeline </span>= gst_pipeline_new(<span style="color:#008000;font-weight:bold;">"push-pipeline"</span>);<br><br>    <span style="color:#000080;font-weight:bold;">if </span>(!data.<span style="color:#660e7a;">pipeline<br></span><span style="color:#660e7a;">        </span>|| !data.<span style="color:#660e7a;">vsource </span>|| !data.<span style="color:#660e7a;">vconvert </span>|| !data.<span style="color:#660e7a;">vqueue </span>|| !data.<span style="color:#660e7a;">x264enc </span>|| !data.<span style="color:#660e7a;">vcapsfilter </span>|| !data.<span style="color:#660e7a;">vsink<br></span><span style="color:#660e7a;">        </span>|| !data.<span style="color:#660e7a;">asource </span>|| !data.<span style="color:#660e7a;">aconvert </span>|| !data.<span style="color:#660e7a;">amp3enc </span>|| !data.<span style="color:#660e7a;">acapfilter </span>|| !data.<span style="color:#660e7a;">asink </span>|| !data.<span style="color:#660e7a;">aqueue</span>) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Not all elements could be created.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br><br>    gst_bin_add_many(<span style="color:#1f542e;font-weight:bold;">GST_BIN</span>(data.<span style="color:#660e7a;">pipeline</span>), data.<span style="color:#660e7a;">asource</span>, data.<span style="color:#660e7a;">aqueue</span>, data.<span style="color:#660e7a;">aconvert</span>, data.<span style="color:#660e7a;">amp3enc</span>, data.<span style="color:#660e7a;">acapfilter</span>,<br>                     data.<span style="color:#660e7a;">ampegaudiopaser</span>, data.<span style="color:#660e7a;">audio_enc_queue</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br>    gst_bin_add_many(<span style="color:#1f542e;font-weight:bold;">GST_BIN</span>(data.<span style="color:#660e7a;">pipeline</span>), data.<span style="color:#660e7a;">vsource</span>, data.<span style="color:#660e7a;">vqueue</span>, data.<span style="color:#660e7a;">vconvert</span>, data.<span style="color:#660e7a;">x264enc</span>, data.<span style="color:#660e7a;">vcapsfilter</span>,<br>                     data.<span style="color:#660e7a;">h264parse</span>, data.<span style="color:#660e7a;">video_enc_queue</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br>    gst_bin_add_many(<span style="color:#1f542e;font-weight:bold;">GST_BIN</span>(data.<span style="color:#660e7a;">pipeline</span>), data.<span style="color:#660e7a;">rtmpsink</span>, data.<span style="color:#660e7a;">flvmuxer</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br><br><br>    <span style="color:#808080;font-style:italic;">//"video/x-h264, width=(int)640, height=(int)480, framerate=(fraction)30/1, stream-format=avc, alignment=au, profile=main"<br></span><span style="color:#808080;font-style:italic;">    </span><span style="color:#371f80;">GstCaps </span>*filtercaps = gst_caps_new_simple(<span style="color:#008000;font-weight:bold;">"video/x-h264"</span>,<br>                                              <span style="color:#008000;font-weight:bold;">"stream-format"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_STRING</span>, <span style="color:#008000;font-weight:bold;">"byte-stream"</span>,<span style="color:#808080;font-style:italic;">//avc,byte-stream<br></span><span style="color:#808080;font-style:italic;">                                              </span><span style="color:#008000;font-weight:bold;">"width"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_INT</span>, <span style="color:#0000ff;">320</span>,<br>                                              <span style="color:#008000;font-weight:bold;">"height"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_INT</span>, <span style="color:#0000ff;">240</span>,<br>                                              <span style="color:#008000;font-weight:bold;">"framerate"</span>, <span style="color:#1f542e;font-weight:bold;">GST_TYPE_FRACTION</span>, <span style="color:#0000ff;">30</span>, <span style="color:#0000ff;">1</span>,<br>                                              <span style="color:#008000;font-weight:bold;">"alignment"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_STRING</span>, <span style="color:#008000;font-weight:bold;">"au"</span>,<br>                                              <span style="color:#008000;font-weight:bold;">"profile"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_STRING</span>, <span style="color:#008000;font-weight:bold;">"main"</span>,<br>                                              <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br><br>    g_object_set(<span style="color:#1f542e;font-weight:bold;">G_OBJECT </span>(data.<span style="color:#660e7a;">vcapsfilter</span>), <span style="color:#008000;font-weight:bold;">"caps"</span>, filtercaps, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br><br><br>    <span style="color:#000080;font-weight:bold;">bool </span>v1 = gst_element_link(data.<span style="color:#660e7a;">vsource</span>, data.<span style="color:#660e7a;">vconvert</span>);<br><br>    <span style="color:#000080;font-weight:bold;">if </span>(!gst_element_link(data.<span style="color:#660e7a;">vconvert</span>, data.<span style="color:#660e7a;">vqueue</span>)) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Elements could not be linked.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br>    <span style="color:#000080;font-weight:bold;">if </span>(!gst_element_link(data.<span style="color:#660e7a;">vqueue</span>, data.<span style="color:#660e7a;">x264enc</span>)) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Elements could not be linked.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br><br>    <span style="color:#000080;font-weight:bold;">if </span>(!gst_element_link(data.<span style="color:#660e7a;">x264enc</span>, data.<span style="color:#660e7a;">vcapsfilter</span>)) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Elements could not be linked.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br>    <span style="color:#000080;font-weight:bold;">if </span>(!gst_element_link(data.<span style="color:#660e7a;">vcapsfilter</span>, data.<span style="color:#660e7a;">h264parse</span>)) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Elements could not be linked.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br>    <span style="color:#000080;font-weight:bold;">if </span>(!gst_element_link(data.<span style="color:#660e7a;">h264parse</span>, data.<span style="color:#660e7a;">video_enc_queue</span>)) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Elements could not be linked.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br><br><span style="color:#808080;font-style:italic;">//"audio/mpeg, mpegversion=1, layer=3, rate=(int)11025, channels=(int)2"<br></span><span style="color:#808080;font-style:italic;">    </span><span style="color:#371f80;">GstCaps </span>*fcaps = gst_caps_new_simple(<span style="color:#008000;font-weight:bold;">"audio/mpeg"</span>,<br>                                         <span style="color:#008000;font-weight:bold;">"stream-format"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_STRING</span>, <span style="color:#008000;font-weight:bold;">"byte-stream"</span>,<br>                                         <span style="color:#008000;font-weight:bold;">"mpegversion"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_INT</span>, <span style="color:#0000ff;">1</span>,<br>                                         <span style="color:#008000;font-weight:bold;">"layer"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_INT</span>, <span style="color:#0000ff;">3</span>,<br>                                         <span style="color:#008000;font-weight:bold;">"rate"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_INT</span>, <span style="color:#0000ff;">11025</span>,<span style="color:#808080;font-style:italic;">//44100<br></span><span style="color:#808080;font-style:italic;">                                         </span><span style="color:#008000;font-weight:bold;">"channels"</span>, <span style="color:#1f542e;font-weight:bold;">G_TYPE_INT</span>, <span style="color:#0000ff;">2</span>,<br>                                         <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br><br>    g_object_set(<span style="color:#1f542e;font-weight:bold;">G_OBJECT</span>(data.<span style="color:#660e7a;">acapfilter</span>), <span style="color:#008000;font-weight:bold;">"caps"</span>, fcaps, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br>    <span style="color:#808080;font-style:italic;">//g_object_set(G_OBJECT(data.asink), "location", "/home/greg/pre-push1.mp3", NULL);<br></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#808080;font-style:italic;">    </span><span style="color:#000080;font-weight:bold;">bool </span>a0 = gst_element_link(data.<span style="color:#660e7a;">asource</span>, data.<span style="color:#660e7a;">aqueue</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>a1 = gst_element_link(data.<span style="color:#660e7a;">aqueue</span>, data.<span style="color:#660e7a;">aconvert</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>a2 = gst_element_link(data.<span style="color:#660e7a;">aconvert</span>, data.<span style="color:#660e7a;">amp3enc</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>a3 = gst_element_link(data.<span style="color:#660e7a;">amp3enc</span>, data.<span style="color:#660e7a;">acapfilter</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>aa = gst_element_link(data.<span style="color:#660e7a;">acapfilter</span>, data.<span style="color:#660e7a;">ampegaudiopaser</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>xz = gst_element_link(data.<span style="color:#660e7a;">ampegaudiopaser</span>, data.<span style="color:#660e7a;">audio_enc_queue</span>);<br><br>    <span style="color:#000080;font-weight:bold;">bool </span>c1 = gst_element_link(data.<span style="color:#660e7a;">audio_enc_queue</span>, data.<span style="color:#660e7a;">flvmuxer</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>c2 = gst_element_link(data.<span style="color:#660e7a;">video_enc_queue</span>, data.<span style="color:#660e7a;">flvmuxer</span>);<br>    <span style="color:#000080;font-weight:bold;">bool </span>c3 = gst_element_link(data.<span style="color:#660e7a;">flvmuxer</span>, data.<span style="color:#660e7a;">rtmpsink</span>);<br><br>    <span style="color:#808080;font-style:italic;">/* Set  device=/dev/video0 */<br></span><span style="color:#808080;font-style:italic;">    </span>g_object_set(data.<span style="color:#660e7a;">vsource</span>, <span style="color:#008000;font-weight:bold;">"device"</span>, <span style="color:#008000;font-weight:bold;">"/dev/video0"</span>, <span style="color:#1f542e;font-weight:bold;">NULL</span>);<br><br><span style="color:#808080;font-style:italic;">//    g_object_set(G_OBJECT(data.amp3enc) , "target"  , 1       , NULL) ;<br></span><span style="color:#808080;font-style:italic;">//    g_object_set(G_OBJECT(data.amp3enc) , "cbr"     , true    , NULL) ; // CBR<br></span><span style="color:#808080;font-style:italic;">//    g_object_set(G_OBJECT(data.amp3enc) , "bitrate" , 64 , NULL) ; // CBR<br></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#808080;font-style:italic;">    </span>ret = gst_element_set_state(data.<span style="color:#660e7a;">pipeline</span>, <span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_STATE_PLAYING</span>);<br>    <span style="color:#000080;font-weight:bold;">if </span>(ret == <span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_STATE_CHANGE_FAILURE</span>) {<br>        g_printerr(<span style="color:#008000;font-weight:bold;">"Unable to set the pipeline to the playing state.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>        gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>        <span style="color:#000080;font-weight:bold;">return </span>-<span style="color:#0000ff;">1</span>;<br>    }<br><br>    <span style="color:#808080;font-style:italic;">/* Listen to the bus */<br></span><span style="color:#808080;font-style:italic;">    </span>bus = gst_element_get_bus(data.<span style="color:#660e7a;">pipeline</span>);<br>    <span style="color:#000080;font-weight:bold;">do </span>{<br>        msg = gst_bus_timed_pop_filtered(bus, <span style="color:#1f542e;font-weight:bold;">GST_CLOCK_TIME_NONE</span>,<br>                                         (<span style="color:#371f80;">GstMessageType</span>) (<span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_MESSAGE_STATE_CHANGED </span>| <span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_MESSAGE_ERROR </span>|<br>                                                           <span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_MESSAGE_EOS</span>));<br><br>        <span style="color:#808080;font-style:italic;">/* Parse message */<br></span><span style="color:#808080;font-style:italic;">        </span><span style="color:#000080;font-weight:bold;">if </span>(msg != <span style="color:#1f542e;font-weight:bold;">NULL</span>) {<br>            <span style="color:#371f80;">GError </span>*err;<br>            <span style="color:#371f80;">gchar </span>*debug_info;<br><br>            <span style="color:#000080;font-weight:bold;">switch </span>(<span style="color:#1f542e;font-weight:bold;">GST_MESSAGE_TYPE </span>(msg)) {<br>                <span style="color:#000080;font-weight:bold;">case </span><span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_MESSAGE_ERROR</span>:<br>                    gst_message_parse_error(msg, &err, &debug_info);<br>                    g_printerr(<span style="color:#008000;font-weight:bold;">"Error received from element </span><span style="color:#000080;font-weight:bold;">%s</span><span style="color:#008000;font-weight:bold;">: </span><span style="color:#000080;font-weight:bold;">%s\n</span><span style="color:#008000;font-weight:bold;">"</span>, <span style="color:#1f542e;font-weight:bold;">GST_OBJECT_NAME </span>(msg-><span style="color:#660e7a;">src</span>), err-><span style="color:#660e7a;">message</span>);<br>                    g_printerr(<span style="color:#008000;font-weight:bold;">"Debugging information: </span><span style="color:#000080;font-weight:bold;">%s\n</span><span style="color:#008000;font-weight:bold;">"</span>, debug_info ? debug_info : <span style="color:#008000;font-weight:bold;">"none"</span>);<br>                    g_clear_error(&err);<br>                    g_free(debug_info);<br>                    terminate = <span style="color:#1f542e;font-weight:bold;">TRUE</span>;<br>                    <span style="color:#000080;font-weight:bold;">break</span>;<br>                <span style="color:#000080;font-weight:bold;">case </span><span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_MESSAGE_EOS</span>:<br>                    g_print(<span style="color:#008000;font-weight:bold;">"End-Of-Stream reached.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>                    terminate = <span style="color:#1f542e;font-weight:bold;">TRUE</span>;<br>                    <span style="color:#000080;font-weight:bold;">break</span>;<br>                <span style="color:#000080;font-weight:bold;">case </span><span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_MESSAGE_STATE_CHANGED</span>:<br>                    <span style="color:#808080;font-style:italic;">/* We are only interested in state-changed messages from the pipeline */<br></span><span style="color:#808080;font-style:italic;">                    </span><span style="color:#000080;font-weight:bold;">if </span>(<span style="color:#1f542e;font-weight:bold;">GST_MESSAGE_SRC </span>(msg) == <span style="color:#1f542e;font-weight:bold;">GST_OBJECT </span>(data.<span style="color:#660e7a;">pipeline</span>)) {<br>                        <span style="color:#371f80;">GstState </span>old_state, new_state, pending_state;<br>                        gst_message_parse_state_changed(msg, &old_state, &new_state, &pending_state);<br>                        g_print(<span style="color:#008000;font-weight:bold;">"Pipeline state changed from </span><span style="color:#000080;font-weight:bold;">%s</span><span style="color:#008000;font-weight:bold;"> to </span><span style="color:#000080;font-weight:bold;">%s</span><span style="color:#008000;font-weight:bold;">:</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>,<br>                                gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));<br>                    }<br>                    <span style="color:#000080;font-weight:bold;">break</span>;<br>                <span style="color:#000080;font-weight:bold;">default</span>:<br>                    <span style="color:#808080;font-style:italic;">/* We should not reach here */<br></span><span style="color:#808080;font-style:italic;">                    </span>g_printerr(<span style="color:#008000;font-weight:bold;">"Unexpected message received.</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">"</span>);<br>                    <span style="color:#000080;font-weight:bold;">break</span>;<br>            }<br>            gst_message_unref(msg);<br>        }<br>    } <span style="color:#000080;font-weight:bold;">while </span>(!terminate);<br><br>    <span style="color:#808080;font-style:italic;">/* Free resources */<br></span><span style="color:#808080;font-style:italic;">    </span>gst_object_unref(bus);<br>    gst_element_set_state(data.<span style="color:#660e7a;">pipeline</span>, <span style="color:#660e7a;font-weight:bold;font-style:italic;">GST_STATE_NULL</span>);<br>    gst_object_unref(data.<span style="color:#660e7a;">pipeline</span>);<br>    <span style="color:#000080;font-weight:bold;">return </span><span style="color:#0000ff;">0</span>;<br>}</pre></div></div></div><br><br><span title="neteasefooter"><p> </p></span></div></div><br><br><span title="neteasefooter"><p> </p></span>