Skip to content

Commit

Permalink
Change video engine resize callback API to encapsulate JNA
Browse files Browse the repository at this point in the history
  • Loading branch information
caprica committed Jan 13, 2023
1 parent cc0b650 commit f1ea125
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import uk.co.caprica.vlcj.player.base.MediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.videoengine.VideoEngine;
import uk.co.caprica.vlcj.player.embedded.videosurface.videoengine.VideoEngineCallback;
import uk.co.caprica.vlcj.player.embedded.videosurface.videoengine.VideoEngineResizeCallbackHandler;

import static uk.co.caprica.vlcj.binding.lib.LibVlc.libvlc_video_set_output_callbacks;

Expand Down Expand Up @@ -68,6 +69,11 @@ public final class VideoEngineVideoSurface extends VideoSurface {
private final libvlc_video_makeCurrent_cb makeCurrent = new MakeCurrentCallback();
private final libvlc_video_getProcAddress_cb getProcAddress = new GetProcAddressCallback();

/**
* Handler to bridge the native video engine resize callback.
*/
private VideoEngineResizeCallbackHandler resizeCallbackHandler;

/**
* Create a video surface.
*
Expand Down Expand Up @@ -116,7 +122,8 @@ public void cleanup(Pointer opaque) {
private final class SetResizeCallback implements libvlc_video_output_set_resize_cb {
@Override
public void setResizeCallback(Pointer opaque, ReportSizeChanged report_size_change, Pointer report_opaque) {
callback.onSetResizeCallback(opaque, report_size_change, report_opaque);
VideoEngineVideoSurface.this.resizeCallbackHandler = new VideoEngineResizeCallbackHandler(opaque, report_opaque, report_size_change);
callback.onSetResizeCallback(resizeCallbackHandler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package uk.co.caprica.vlcj.player.embedded.videosurface.videoengine;

import com.sun.jna.Pointer;
import uk.co.caprica.vlcj.binding.internal.ReportSizeChanged;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_cfg_t;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_render_cfg_t;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_setup_device_cfg_t;
Expand Down Expand Up @@ -54,11 +53,9 @@ public interface VideoEngineCallback {
* The resize callback must be invoked by the application when the size of the video display surface changes (e.g.
* due to a window resize event).
*
* @param opaque opaque data pointer
* @param report_size_change callback
* @param report_opaque opaque data pointer for the callback
* @param resizeCallback resize callback
*/
void onSetResizeCallback(Pointer opaque, ReportSizeChanged report_size_change, Pointer report_opaque);
void onSetResizeCallback(VideoEngineResizeCallback resizeCallback);

/**
* Update the video output with new dimensions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package uk.co.caprica.vlcj.player.embedded.videosurface.videoengine;

import com.sun.jna.Pointer;
import uk.co.caprica.vlcj.binding.internal.ReportSizeChanged;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_cfg_t;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_render_cfg_t;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_setup_device_cfg_t;
Expand All @@ -43,7 +42,7 @@ public void onCleanup(Pointer opaque) {
}

@Override
public void onSetResizeCallback(Pointer opaque, ReportSizeChanged report_size_change, Pointer report_opaque) {
public void onSetResizeCallback(VideoEngineResizeCallback resizeCallback) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of VLCJ.
*
* VLCJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VLCJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VLCJ. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2009-2022 Caprica Software Limited.
*/

package uk.co.caprica.vlcj.player.embedded.videosurface.videoengine;

/**
* Specification for a component that informs the video engine when the size of the hosted video window changes.
*/
public interface VideoEngineResizeCallback {

/**
* Set the new window size.
*
* @param width new width
* @param height new height
*/
void setSize(int width, int height);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of VLCJ.
*
* VLCJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VLCJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VLCJ. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2009-2022 Caprica Software Limited.
*/

package uk.co.caprica.vlcj.player.embedded.videosurface.videoengine;

import com.sun.jna.Pointer;
import uk.co.caprica.vlcj.binding.internal.ReportSizeChanged;

/**
* Handler component that bridges a vlcj application with the native video engine resize callback.
*/
public final class VideoEngineResizeCallbackHandler implements VideoEngineResizeCallback {

/**
* Opaque pointer associated with the callbacks.
*/
private final Pointer opaque;

/**
* Opaque pointer for the native report size changed callback.
* <p>
* This pointer <strong>must</strong> be passed with the native callback method.
*/
private final Pointer reportOpaque;

/**
* Native callback.
*/
private final ReportSizeChanged reportSizeChanged;

/**
* Create a resize callback handler.
*
* @param opaque opaque pointer associated with the callbacks
* @param reportOpaque opaque pointer for the native report size changed callback
* @param reportSizeChanged native callback
*/
public VideoEngineResizeCallbackHandler(Pointer opaque, Pointer reportOpaque, ReportSizeChanged reportSizeChanged) {
this.opaque = opaque;
this.reportOpaque = reportOpaque;
this.reportSizeChanged = reportSizeChanged;
}

@Override
public void setSize(int width, int height) {
if (reportSizeChanged != null) {
reportSizeChanged.reportSizeChanged(reportOpaque, width, height);
}
}
}

0 comments on commit f1ea125

Please sign in to comment.