From 1629e4d572a19819f26aa478cd7a8a53a3a8b0dd Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Fri, 2 Feb 2024 10:56:33 +0000 Subject: [PATCH] Initial changes for native window callbacks --- .../caprica/vlcj/player/base/MouseButton.java | 56 ++++++++++ .../videosurface/VideoEngineVideoSurface.java | 27 +++-- .../videoengine/VideoEngineCallback.java | 8 +- .../VideoEngineCallbackAdapter.java | 2 +- .../VideoEngineResizeCallbackHandler.java | 66 ----------- ...ck.java => VideoEngineWindowCallback.java} | 31 +++++- .../VideoEngineWindowCallbackHandler.java | 103 ++++++++++++++++++ 7 files changed, 207 insertions(+), 86 deletions(-) create mode 100644 src/main/java/uk/co/caprica/vlcj/player/base/MouseButton.java delete mode 100644 src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallbackHandler.java rename src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/{VideoEngineResizeCallback.java => VideoEngineWindowCallback.java} (58%) create mode 100644 src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallbackHandler.java diff --git a/src/main/java/uk/co/caprica/vlcj/player/base/MouseButton.java b/src/main/java/uk/co/caprica/vlcj/player/base/MouseButton.java new file mode 100644 index 000000000..e3e79700d --- /dev/null +++ b/src/main/java/uk/co/caprica/vlcj/player/base/MouseButton.java @@ -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 . + * + * 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 INT_MAP = new HashMap(); + + 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; + } + +} diff --git a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/VideoEngineVideoSurface.java b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/VideoEngineVideoSurface.java index cdb11a7f4..bee76eb7b 100644 --- a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/VideoEngineVideoSurface.java +++ b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/VideoEngineVideoSurface.java @@ -14,13 +14,13 @@ * You should have received a copy of the GNU General Public License * along with VLCJ. If not, see . * - * 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; @@ -28,7 +28,10 @@ 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; @@ -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; @@ -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. @@ -95,7 +98,7 @@ public void attach(MediaPlayer mediaPlayer) { engine.intValue(), setup, cleanup, - setResize, + setWindowCallback, updateOutput, swap, makeCurrent, @@ -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); } } diff --git a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallback.java b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallback.java index b62c2d514..562e23dee 100644 --- a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallback.java +++ b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallback.java @@ -48,14 +48,14 @@ public interface VideoEngineCallback { void onCleanup(Pointer opaque); /** - * Set the resize callback. + * Set the window callback. *

* 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. diff --git a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallbackAdapter.java b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallbackAdapter.java index 15de23f7f..9bd878c75 100644 --- a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallbackAdapter.java +++ b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineCallbackAdapter.java @@ -42,7 +42,7 @@ public void onCleanup(Pointer opaque) { } @Override - public void onSetResizeCallback(VideoEngineResizeCallback resizeCallback) { + public void onSetWindowCallback(VideoEngineWindowCallback windowCallback) { } @Override diff --git a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallbackHandler.java b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallbackHandler.java deleted file mode 100644 index ed7eb4aa8..000000000 --- a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallbackHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 . - * - * 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. - *

- * This pointer must 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); - } - } -} diff --git a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallback.java b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallback.java similarity index 58% rename from src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallback.java rename to src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallback.java index 6b9233f8c..34fc69cd6 100644 --- a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineResizeCallback.java +++ b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallback.java @@ -14,15 +14,18 @@ * You should have received a copy of the GNU General Public License * along with VLCJ. If not, see . * - * 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. @@ -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); } diff --git a/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallbackHandler.java b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallbackHandler.java new file mode 100644 index 000000000..608f78b40 --- /dev/null +++ b/src/main/java/uk/co/caprica/vlcj/player/embedded/videosurface/videoengine/VideoEngineWindowCallbackHandler.java @@ -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 . + * + * 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. + *

+ * This pointer must 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()); + } + } +}