Skip to content

Commit

Permalink
Initial changes for native window callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
caprica committed Feb 2, 2024
1 parent 5ea1596 commit 1629e4d
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 86 deletions.
56 changes: 56 additions & 0 deletions src/main/java/uk/co/caprica/vlcj/player/base/MouseButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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-2024 Caprica Software Limited.
*/

package uk.co.caprica.vlcj.player.base;

import java.util.HashMap;
import java.util.Map;

/**
* Enumeration of video output mouse buttons.
*/
public enum MouseButton {

LEFT ( 0),
MIDDLE( 1),
RIGHT ( 2);

private static final Map<Integer, MouseButton> INT_MAP = new HashMap<Integer, MouseButton>();

static {
for (MouseButton value : MouseButton.values()) {
INT_MAP.put(value.intValue, value);
}
}

public static MouseButton mouseButton(int intValue) {
return INT_MAP.get(intValue);
}

private final int intValue;

MouseButton(int intValue) {
this.intValue = intValue;
}

public int intValue() {
return intValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
* 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.
* Copyright 2009-2024 Caprica Software Limited.
*/

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

import com.sun.jna.Pointer;
import uk.co.caprica.vlcj.binding.internal.ReportSizeChanged;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_resize_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_color_primaries_e;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_color_space_e;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_getProcAddress_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_makeCurrent_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_orient_t;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_cfg_t;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_cleanup_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_set_resize_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_mouse_move_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_mouse_press_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_mouse_release_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_set_window_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_setup_cb;
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 @@ -39,7 +42,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 uk.co.caprica.vlcj.player.embedded.videosurface.videoengine.VideoEngineWindowCallbackHandler;

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

Expand All @@ -63,16 +66,16 @@ public final class VideoEngineVideoSurface extends VideoSurface {

private final libvlc_video_output_setup_cb setup = new SetupCallback();
private final libvlc_video_output_cleanup_cb cleanup = new CleanupCallback();
private final libvlc_video_output_set_resize_cb setResize = new SetResizeCallback();
private final libvlc_video_output_set_window_cb setWindowCallback = new SetWindowCallback();
private final libvlc_video_update_output_cb updateOutput = new UpdateOutputCallback();
private final libvlc_video_swap_cb swap = new SwapCallback();
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.
* Handler to bridge the native video engine resize and mouse event callback.
*/
private VideoEngineResizeCallbackHandler resizeCallbackHandler;
private VideoEngineWindowCallbackHandler windowCallbackHandler;

/**
* Create a video surface.
Expand All @@ -95,7 +98,7 @@ public void attach(MediaPlayer mediaPlayer) {
engine.intValue(),
setup,
cleanup,
setResize,
setWindowCallback,
updateOutput,
swap,
makeCurrent,
Expand All @@ -119,11 +122,11 @@ public void cleanup(Pointer opaque) {
}
}

private final class SetResizeCallback implements libvlc_video_output_set_resize_cb {
private final class SetWindowCallback implements libvlc_video_output_set_window_cb {
@Override
public void setResizeCallback(Pointer opaque, ReportSizeChanged report_size_change, Pointer report_opaque) {
VideoEngineVideoSurface.this.resizeCallbackHandler = new VideoEngineResizeCallbackHandler(opaque, report_opaque, report_size_change);
callback.onSetResizeCallback(resizeCallbackHandler);
public void setWindowCallback(Pointer opaque, libvlc_video_output_resize_cb report_size_change, libvlc_video_output_mouse_move_cb report_mouse_move, libvlc_video_output_mouse_press_cb report_mouse_pressed , libvlc_video_output_mouse_release_cb report_mouse_released, Pointer report_opaque) {
VideoEngineVideoSurface.this.windowCallbackHandler = new VideoEngineWindowCallbackHandler(opaque, report_opaque, report_size_change, report_mouse_move, report_mouse_pressed, report_mouse_released);
callback.onSetWindowCallback(windowCallbackHandler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public interface VideoEngineCallback {
void onCleanup(Pointer opaque);

/**
* Set the resize callback.
* Set the window callback.
* <p>
* 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).
* due to a window resize event). It can also be used to send mouse events.
*
* @param resizeCallback resize callback
* @param windowCallback window callback
*/
void onSetResizeCallback(VideoEngineResizeCallback resizeCallback);
void onSetWindowCallback(VideoEngineWindowCallback windowCallback);

/**
* Update the video output with new dimensions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onCleanup(Pointer opaque) {
}

@Override
public void onSetResizeCallback(VideoEngineResizeCallback resizeCallback) {
public void onSetWindowCallback(VideoEngineWindowCallback windowCallback) {
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* 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.
* Copyright 2009-2024 Caprica Software Limited.
*/

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

import uk.co.caprica.vlcj.player.base.MouseButton;

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

/**
* Set the new window size.
Expand All @@ -31,4 +34,26 @@ public interface VideoEngineResizeCallback {
* @param height new height
*/
void setSize(int width, int height);

/**
* Report the new mouse position.
*
* @param x new x position
* @param y new y position
*/
void mouseMoved(int x, int y);

/**
* Report mouse pressed.
*
* @param mouseButton button that was pressed
*/
void mousePressed(MouseButton mouseButton);

/**
* Report mouse released.
*
* @param mouseButton button that was released
*/
void mouseReleased(MouseButton mouseButton);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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-2024 Caprica Software Limited.
*/

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

import com.sun.jna.Pointer;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_resize_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_mouse_move_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_mouse_press_cb;
import uk.co.caprica.vlcj.binding.internal.libvlc_video_output_mouse_release_cb;
import uk.co.caprica.vlcj.player.base.MouseButton;

/**
* Handler component that bridges a vlcj application with the native video engine window callback.
*/
public final class VideoEngineWindowCallbackHandler implements VideoEngineWindowCallback {

/**
* 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 libvlc_video_output_resize_cb resize;

private final libvlc_video_output_mouse_move_cb mouseMove;

private final libvlc_video_output_mouse_press_cb mousePress;

private final libvlc_video_output_mouse_release_cb mouseRelease;

/**
* Create a window callback handler.
*
* @param opaque opaque pointer associated with the callbacks
* @param reportOpaque opaque pointer for the native report callbacks
* @param resize native callback for window resizes
* @param mouseMove native callback for mouse moves
* @param mousePress native callback for mouse presses
* @param mouseRelease native callback for mouse releases
*/
public VideoEngineWindowCallbackHandler(Pointer opaque, Pointer reportOpaque, libvlc_video_output_resize_cb resize, libvlc_video_output_mouse_move_cb mouseMove, libvlc_video_output_mouse_press_cb mousePress, libvlc_video_output_mouse_release_cb mouseRelease) {
this.opaque = opaque;
this.reportOpaque = reportOpaque;
this.resize = resize;
this.mouseMove = mouseMove;
this.mousePress = mousePress;
this.mouseRelease = mouseRelease;
}

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

@Override
public void mouseMoved(int x, int y) {
if (mouseMove != null) {
mouseMove.mouseMove(reportOpaque, x, y);
}
}

@Override
public void mousePressed(MouseButton mouseButton) {
if (mousePress != null) {
mousePress.mousePress(reportOpaque, mouseButton.intValue());
}
}

@Override
public void mouseReleased(MouseButton mouseButton) {
if (mouseRelease != null) {
mouseRelease.mouseRelease(reportOpaque, mouseButton.intValue());
}
}
}

0 comments on commit 1629e4d

Please sign in to comment.