What's wrong with this code?

Alberto Lepe dev at alepe.com
Thu Jan 26 21:27:44 PST 2012


On Fri, Jan 27, 2012 at 1:44 PM, Mart Raudsepp <leio at gentoo.org> wrote:
> Hello,
>
> On R, 2012-01-27 at 13:20 +0900, Alberto Lepe wrote:
>> Hello, these commands display the video from a network camera without problems:
>>
>> gst-launch -v gnomevfssrc
>> location="http://admin:12345@192.168.1.100/nphMotionJpeg?Resolution=320x240&Quality=Standard&Framerate=1"
>> do-timestamp=true ! multipartdemux ! jpegdec ! xvimagesink
>>
>> (Using capabilities = same result):
>> gst-launch -v gnomevfssrc
>> location="http://admin:12345@192.168.1.100/nphMotionJpeg?Resolution=320x240&Quality=Standard&Framerate=1"
>> do-timestamp=true ! multipartdemux !
>> image/jpeg,width=320,height=240,framerate=1/1 ! jpegdec !
>> video/x-raw-yuv,framerate=1/1 ! xvimagesink
>
> As an unrelated note, gnome-vfs is deprecated in all modern
> distributions that I know of. Check out GIO and the giosrc element
> instead. The GIO modules provided by the gvfs package in distributions
> offer the support for remote protocols to GIO. That said, for http there
> exists also souphttpsrc directly. That however isn't of course the
> problem in your java or vala code, as it works with gst-launch.
>
>> I'm trying to implement the above in Java and in Vala (for a benchmark):
>>
>> Java Code:
>>
>>     public static void main(String[] args) {
>>         args = Gst.init("VideoTest", args);
>>         final Pipeline pipe = new Pipeline("VideoTest");
>>       final Element videosrc = ElementFactory.make ("gnomevfssrc", "video");
>>       videosrc.set("location","http://admin:12345@192.168.1.100/nphMotionJpeg?Resolution=320x240&Quality=Standard&Framerate=1");
>>       videosrc.set("do-timestamp",true);
>>       final Element filter1 = ElementFactory.make ("multipartdemux", "demuxer");
>>       final Element videofilter1 = ElementFactory.make("capsfilter", "filter1");
>>         videofilter1.setCaps(Caps.fromString("image/jpeg,width=320,height=240,framerate=1/1"));
>>       final Element filter2 = ElementFactory.make ("jpegdec","jpg");
>>       final Element videofilter2 = ElementFactory.make("capsfilter", "filter2");
>>         videofilter2.setCaps(Caps.fromString("video/x-raw-yuv,framerate=1/1"));
>>
>>         SwingUtilities.invokeLater(new Runnable() {
>>
>>             public void run() {
>>                 VideoComponent videoComponent = new VideoComponent();
>>                 Element videosink = videoComponent.getElement();
>>               pipe.addMany(videosrc, filter1, videofilter1, filter2, videofilter2,
>> videosink);
>>               Element.linkMany(videosrc, filter1, videofilter1, filter2,
>> videofilter2, videosink);
>>
>>                 // Now create a JFrame to display the video output
>>                 JFrame frame = new JFrame("Swing Video Test");
>>                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>                 frame.add(videoComponent, BorderLayout.CENTER);
>>                 videoComponent.setPreferredSize(new Dimension(720, 576));
>>                 frame.pack();
>>                 frame.setVisible(true);
>>
>>                 // Start the pipeline processing
>>                 pipe.setState(State.PLAYING);
>>             }
>>         });
>>     }
>>
>> It opens a window and displays a black background (nothing else). I
>> have tried without using the Caps but the result is the same.
>> No errors are displayed.
>
> Are you running a glib mainloop (I suppose there are java bindings for
> doing so) somewhere or implementing the equivalent?
> http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-bus.html  may be of use here.
>
>> Vala Code:
>>
>>     private void setup_gst_pipeline () {
>>         var pipeline = new Pipeline ("mypipeline");
>>         var src = ElementFactory.make ("gnomevfssrc", "video");
>>         var src.set_property("location","http://admin:12345@192.168.1.100/nphMotionJpeg?Resolution=320x240&Quality=Standard&Framerate=1");
>>         var src.set_property("do-timestamp",1);
>>         var filter1 = ElementFactory.make ("multipartdemux","demuxer");
>>         var filter2 = ElementFactory.make ("jpegdec","jpg");
>> //        var filter2.set_property("caps",Caps.from_string("image/jpeg,width=320,height=240,framerate=1/1"));
>>         var sink = ElementFactory.make ("xvimagesink", "sink");
>> //        var sink.set_property("caps",Caps.from_string("video/x-raw-yuv,framerate=1/1"));
>>         pipeline.add_many (src, filter1, filter2, sink);
>>         src.link (filter1);
>>         filter1.link (filter2);
>>         filter2.link (sink);
>>     }
>>
>> I'm not setting any Caps in Vala as I still don't know which is the
>> proper way to do it.
>> It does nothing. No error no image (not even a black background as in Java).
>>
>> I'm sure I'm missing something here. (sorry I'm noob in Gst).
>
> Same question here. Also I assume you are setting the pipeline to
> PLAYING in another place here.
> https://live.gnome.org/Vala/GStreamerSample seems to have a sample with
> the glib mainloop present.
>
> If this was missing, it should get you further. Next up you'll probably
> see problems from trying to link up things statically from the demuxer
> as Nathanael described in the other reply. gst-launch has special code
> via GstParse facilities to handle this via delayed links on its own to
> simplify command line usage - it does the same automatically you'll need
> to do in code (set up pad-added signal handlers, link things up from
> there).
>
> http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-pads.html should describe you how to handle such "Sometimes" pads conceptually and in C.
>
>
> Best,
> Mart Raudsepp
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

Thank you!

I was able to fix it following Nathanael suggestion. It was not easy
to find though.
Thank you for your suggestions Mart, I didn't know that. I tried with
giosrc but didn't work (I will try again later). However it worked
with "souphttpsrc".
Here are the fixed codes, in case someone is interested (I changed the
name of the "filter1" and "filter2" variables to convey a better
meaning):

Java Code changes:

------ Only important part: -------------

        pipe.addMany(videosrc, demux, decoder, videosink);
        demux.connect(new Element.PAD_ADDED() {
            @Override
            public void padAdded(Element element, Pad pad) {
                pad.link(decoder.getSinkPads().get(0));
            }
        });
        videosrc.link(demux);
        decoder.link(videosink);

------------------------

Vala changes:

------ Only important part: -------------

        demux = ElementFactory.make ("multipartdemux","demuxer");
        decoder = ElementFactory.make ("jpegdec","jpg");
        sink = ElementFactory.make ("xvimagesink", "sink");
        pipeline.add_many (src, demux, decoder, sink);
        demux.pad_added.connect((ev, pad) => {
           pad.link(decoder.get_pad("sink"));
        });
        src.link (demux);
        decoder.link (sink);

------------------------

The code looks better in Vala (IMHO) ;)

Thanks again!


More information about the gstreamer-devel mailing list