Robert
Robert

Reputation: 1708

JavaFX media player burns resources

I am currently using Javafx 2 for a project, where I might need to play a video in an infinite loop for a long time. On windows, when the video is playing my proifiler tool shows pretty normal pictures, cpu load is not very hard (running on 2 cores it is around 2x40-50%), and memory usage spikes around 250 MB, wich is normal. But, when I deploy the application on an Ubuntu machine, cpu load is spiking around 70% per core (altough it is a dual core atom processor, so let's say this is normal), and memory usage increases continually, while finally killing the JVM, and the device itself, under like 1,5-2 hours. I really need a solution, or at least a workaround to this issue, because it is a showstopper right now.

I am currently thinking to hack around the infinite loop, and create a new Media/MediaPlayer object for each loop, but I am not sure, if it would solve the issue.

Can you give me some insight on the issue?

My code for initializing the MediaView:

final Media m = new Media(new File(new ClientParameters().getProperty("video.path", String.class)).toURI()
                .toString());
        final MediaPlayer player = new MediaPlayer(m);
        player.setMute(true);
        player.setCycleCount(MediaPlayer.INDEFINITE);
        player.setOnError(new Runnable() {
            @Override
            public void run() {
                log.warn("Video error", player.getError());
                Main.loadAcceptablePrompt(Main.getCurrentLocaleResources().getString("Video_Hiba"),
                        FxmlView.START_SCREEN, Main.DEFAULT_LOCALE, ScreenSaverVideoController.this);
            }
        });

        m.setOnError(new Runnable() {
            @Override
            public void run() {
                showLoader();
                Main.getScheduler().submit(new Runnable() {
                    @Override
                    public void run() {
                        log.warn("Video error", player.getError());
                        Main.loadAcceptablePrompt(Main.getCurrentLocaleResources().getString("Video_Hiba"),
                                FxmlView.START_SCREEN, Main.getCurrentLocale(), ScreenSaverVideoController.this);
                    }
                });
            }
        });
        video.setMediaPlayer(player);
        video.getMediaPlayer().play();

Main.getScheduler() returns this Scheduler object:

private static final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1);

Main.loadAcceptablePrompt first calls the following function, than loads a new fxml view:

if (timeoutFuture == null || timeoutFuture.isCancelled() || timeoutFuture.isDone()) return false;
        return timeoutFuture.cancel(true);

This is a function from a super class, and timeoutFuture is null in this case. Anyways, the function is not called in this scenario.

EDIT: Peak memory usage looks to crawl up slowly on my Windows machine also, but nowhere near the rate on the Ubuntu machine. Right now I'm leaving it run for the night, after that, I'll update on the situation.

EDIT 2: After running the application on Windows for the night, it still ran, without any problems.

I have tried to reload the media player page every time the video ended, but nothing changed, memory is still used up in like 2 hours.

I have created a new jar, only with a MediaView on the start page, and nothing else in it, packed the jfxrt.jar file I use on my Windows machine into it, and it still leaks.

The JRE used on the machine is the one that oracle-java7-installer package installs. I have tried to use OpenJDK, but it failed to run the application.

The library used to play the video is installed by the libavformat53 package. Without it, there is an exception when triing to play the video. As far as I know, this package is used by VLC, with no error, so I'm getting pretty annoyed.

Upvotes: 0

Views: 844

Answers (1)

1813222
1813222

Reputation: 312

When I last installed Linux (Ubuntu or Debian) on my desktop PC maybe 3 or 4 years ago I had similar problems with anything that needed the graphics card. Reason was that for graphics applications both Linux distributions would only work fast & reliably with NVidia adapters; for ATI there where only generic drivers available (because they refused to reveal their source code). Maybe the situation is different today - but as first step I´d certainly make sure I had the most suitable graphics driver installed with Linux...

Upvotes: 0

Related Questions