I'm not surprised this causes problems, as it is almost certainly not
thread-safe.
FWIW, this impl_ method is already inaccessible in JDK 9 because it
returns a type that is not exported from the javafx.media module.
Further, this methods will go away very soon as part of the ongoing
encapsulation of all impl_ methods.
Can you file an RFE for a public API to do this? We can consider it for
a future version of JavaFX.
-- Kevin
Chris Newland wrote:
Hi,
This is really just an FYI as I'm doing funky stuff with multiple
MediaPlayers and using the deprecated impl_getLatestFrame() method to grab
frames.
I can grab frames fine with a single MediaPlayer instance but when I use
multiple MediaPlayer objects each with an AnimationTimer calling this
code:
public void snapshotVideo()
{
VideoDataBuffer buf = player.impl_getLatestFrame();
if (buf != null)
{
VideoFormat newFormat = VideoFormat.BGRA_PRE;
buf = buf.convertToFormat(newFormat);
ByteBuffer bb =
buf.getBufferForPlane(VideoDataBuffer.PACKED_FORMAT_PLANE);
int pixel = 0;
int max = bb.remaining() / 4;
for (int i = 0; i < max; i++)
{
rawFrameData[pixel++] = bb.getInt();
}
buf.releaseFrame();
}
}
then it crashes hard on OSX El Capitan with AMD Radeon HD 6970M with this
dump:
https://gist.github.com/chriswhocodes/5516d24078205dc218dead870853e018
I'm guessing the native frame conversion from YCbCr_422 to BGRA_PRE is not
thread-safe but some naive attempts to lock around this haven't solved the
problem.
This same code + videos works fine on a MacBook Pro with Intel Iris
graphics so it's a tiny hardware+OS corner case but thought it might be
worth a mention.
The only thing I'd add is that I'd love to have an official API for
grabbing single frames from video. I've been doing some cool real-time
video effects in JavaFX and it's a shame to have to use a deprecated
method which will probably go away.
Cheers,
Chris