Embed VLC video output into a Scene Graph

Mario Torre neugens.limasoftware at gmail.com
Mon Jul 16 02:21:13 PDT 2012


2012/7/15 Eli Tsikel <Eli.Tsikel at sandisk.com>:
> Hello,
>
> I'm trying to embed a VLC player in a JavaFX 2.2 application.
> For that I'm using the libvlc.dll library's API.
>
> VLC provided two ways to render a video:
> 1. Call API function that takes HWND: libvlc_media_player_set_hwnd (libvlc_media_player_t *p_mi, void *drawable) Set a Win32/Win64 API window handle (HWND) where the media player should render its video output.
> 2. Register a callback that gets called every time a frame should be rendered: libvlc_video_display_cb (void *opaque, void *picture) Callback prototype to display a picture.
>
> With the HWND approach, I managed to extract an HWND pointer of the Scene using Glass framework, causing the video to render on the whole scene, no other nodes are visible.
> With the Callback approach, and by using JavaFX 2.2 new javafx.scene.canvas.Canvas node, I was able to throw pixels at the canvas, but it turns to be very inefficient in terms of memory and thread usage.
>
> I would love to have a solution as with AWT + JNA: the HWND can be extracted from java.awt.Canvas component (using JNA), and be given to libvlc API function. This canvas can be placed anywhere in the frame, not occupying all the entire window.

I'm not the right person to suggest an approach since it's quite some
time I don't use JavaFX and I don't know what additions have been made
the the 2.2 API to facilitate custom rendering, however, we did
something similar for our ThingFX project to allow Swing inside JavaFX
(the other way around what it's usually possible).

We render the Swing components as "snapshots" inside a JavaFX Image
node. Image didn't offer us a way to update a specific portion of the
underlying buffered image, but I don't think this is an issue for a
video since the video will likely render the full frame each time.

Here is the example:

https://github.com/thingsfx/ThingsFX/blob/master/src/main/java/com/thingsfx/widget/swing/BufferedImageView.java

As you see is pretty straightforward.

Here is an example of the things we did:

http://www.jroller.com/neugens/entry/jfreechartfx
http://www.jroller.com/neugens/entry/javafx_as_image_processing_library

Btw, I'm not suggesting to use Swing BufferedImages (which would be
very useful if you need to perform some custom rendering outside what
JavaFX allows you to do already on the nodes) but to exploit JavaFX
Images.

Cheers,
Mario
-- 
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

IcedRobot: www.icedrobot.org
Proud GNU Classpath developer: http://www.classpath.org/
Read About us at: http://planet.classpath.org
OpenJDK: http://openjdk.java.net/projects/caciocavallo/

Please, support open standards:
http://endsoftpatents.org/


More information about the openjfx-dev mailing list