diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml index 31a958e76..1f95a7014 100644 --- a/.github/actions/publish/action.yml +++ b/.github/actions/publish/action.yml @@ -83,7 +83,7 @@ runs: PROFILES: ${{ inputs.profiles }} SKIP_UPLOAD: ${{ inputs.skip-upload }} run: > - mvn -B deploy -pl .,webrtc,webrtc-media,webrtc-javafx -DskipTests + mvn -B deploy -pl .,webrtc,webrtc-media,webrtc-swing,webrtc-javafx -DskipTests -Dmaven.repository.credentialScope=id ${PROFILES:+-P$PROFILES} -Dnatives.dir="$PWD/natives" diff --git a/.github/actions/test-natives/action.yml b/.github/actions/test-natives/action.yml index 22cfb8103..585e002ad 100644 --- a/.github/actions/test-natives/action.yml +++ b/.github/actions/test-natives/action.yml @@ -132,17 +132,27 @@ runs: "$JAVA_HOME/bin/jar" xf "$WEBRTC_JAR" rm -rf META-INF ls -l + cd - > /dev/null + + # The Swing module's tests need only webrtc-java's natives, and read + # them from a directory of the same name for the same reason. + mkdir -p webrtc-swing/target/natives + cd webrtc-swing/target/natives + "$JAVA_HOME/bin/jar" xf "$WEBRTC_JAR" + rm -rf META-INF + ls -l shell: bash - # One reactor for both, so that webrtc-java-media resolves webrtc-java - # from it. Testing rather than installing: webrtc attaches the host + # One reactor for all, so that webrtc-java-media and webrtc-java-swing + # resolve webrtc-java from it. The Swing view paints into images, which + # needs no display. Testing rather than installing: webrtc attaches the host # natives from webrtc-jni/target during its package phase, and on a runner # that only downloaded them there is no such directory. # # The native build is off: these natives were cross compiled by another # job, and this runner is here to run them, not to build them again. - name: Test - run: mvn -B -pl webrtc,webrtc-media test -DskipNativeBuild -P${{ inputs.profile }} -Dsurefire.timeout=1800 + run: mvn -B -pl webrtc,webrtc-media,webrtc-swing test -DskipNativeBuild -P${{ inputs.profile }} -Dsurefire.timeout=1800 shell: bash # What failed, for runners that cannot be reproduced locally. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef93063cc..9e36b3433 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -224,6 +224,7 @@ jobs: echo '```' ls -1 webrtc/target/*.jar webrtc/target/*.asc \ webrtc-media/target/*.jar webrtc-media/target/*.asc \ + webrtc-swing/target/*.jar webrtc-swing/target/*.asc \ webrtc-javafx/target/*.jar webrtc-javafx/target/*.asc \ natives/*.asc 2>/dev/null || true echo '```' @@ -241,6 +242,9 @@ jobs: webrtc-media/target/central-*/** webrtc-media/target/*.jar webrtc-media/target/*.asc + webrtc-swing/target/central-*/** + webrtc-swing/target/*.jar + webrtc-swing/target/*.asc webrtc-javafx/target/central-*/** webrtc-javafx/target/*.jar webrtc-javafx/target/*.asc diff --git a/README.md b/README.md index 5db7d7812..7f395d08f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The library provides a comprehensive set of Java classes that map to the WebRTC - **[Cameras and microphones](https://jrtc.dev/guide/media/media-devices)** - Capture from any local device - **[Screen sharing](https://jrtc.dev/guide/video/desktop-capture)** - Share the full desktop or single application windows - **[Video processing](https://jrtc.dev/guide/video/camera-capture#changing-frames-before-they-are-sent)** - Blur a background, draw an overlay or blank out part of the screen before frames are sent -- **[Video views](https://jrtc.dev/guide/client-api#handlers-on-the-ui-thread)** - Ready-made components that show video in Swing, or in JavaFX with the `webrtc-java-javafx` module +- **[Video views](https://jrtc.dev/guide/client-api#handlers-on-the-ui-thread)** - Ready-made components that show video in Swing with the `webrtc-java-swing` module, or in JavaFX with the `webrtc-java-javafx` module **Codecs and encoded media** diff --git a/design/client-api.md b/design/client-api.md index b8c7222f8..15a7f1957 100644 --- a/design/client-api.md +++ b/design/client-api.md @@ -815,6 +815,8 @@ Next: - `VideoView` for JavaFX lives in the `webrtc-java-javafx` module, package `dev.onvoid.webrtc.client.javafx`, compiled for Java 11 since OpenJFX is; JavaFX is an optional dependency the application brings. `JavaFxCameraExample` in `webrtc-examples` uses it. +- `VideoView` for Swing lives in the `webrtc-java-swing` module, package + `dev.onvoid.webrtc.client.swing`, so that the core module does not need `java.desktop`. - phase 2 is done: `Whip.to(...).publish(rtc)` and `Whep.from(...).play(rtc)` return sessions over `java.net.http.HttpClient`, and `VideoView` is in `dev.onvoid.webrtc.client.swing`; diff --git a/docs/guide/client-api.md b/docs/guide/client-api.md index 7fcaa1fbe..396cd0b11 100644 --- a/docs/guide/client-api.md +++ b/docs/guide/client-api.md @@ -287,7 +287,17 @@ hangUpButton.addActionListener(event -> peer.close()); // never blocks the EDT The order of each peer's events is kept with any executor, including a thread pool. Frame handlers stay on their own threads even then, since frames come far too often for a UI thread. -`VideoView` in `dev.onvoid.webrtc.client.swing` shows video in a Swing window. It converts each frame on the frame's own thread and leaves only the painting to the EDT. It keeps the picture's aspect ratio and rotation, and can mirror a local camera preview: +The `webrtc-java-swing` module has a `VideoView` in `dev.onvoid.webrtc.client.swing` that shows video in a Swing window. The core `webrtc-java` module does not depend on `java.desktop`, so headless applications and trimmed runtime images need neither AWT nor Swing: + +```xml + + dev.onvoid.webrtc + webrtc-java-swing + {{ VERSION }} + +``` + +The view converts each frame on the frame's own thread and leaves only the painting to the EDT. It keeps the picture's aspect ratio and rotation, and can mirror a local camera preview: ```java import dev.onvoid.webrtc.client.swing.VideoView; diff --git a/docs/guide/examples.md b/docs/guide/examples.md index 8b4445ee5..4011bc6a7 100644 --- a/docs/guide/examples.md +++ b/docs/guide/examples.md @@ -118,7 +118,7 @@ The [`MediaFilePlayerExample`](https://github.com/devopvoid/webrtc-java/blob/mas - Running the peers' handlers on the Swing event dispatch thread - Keeping audio and video in sync by sending both tracks in the same media stream - Raising the video sender's maximum bitrate once it is connected, so a high-resolution file is not held to a fraction of its size -- Rendering received video in the Swing `VideoView` +- Rendering received video in the Swing `VideoView` of the `webrtc-java-swing` module - Showing the source's format, the playback position, and live receive metrics (codec, resolution, frame rate, bitrate, packet loss, jitter, audio level) read from `onStats` - Recording the received tracks into a Matroska file with `MediaRecorder` - Closing the peers, then the tracks, then the source on Stop diff --git a/pom.xml b/pom.xml index c628056c7..721fc41a0 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,7 @@ webrtc-jni webrtc webrtc-media + webrtc-swing webrtc-javafx webrtc-examples diff --git a/webrtc-examples/pom.xml b/webrtc-examples/pom.xml index cbc1014cf..d1fc441f8 100644 --- a/webrtc-examples/pom.xml +++ b/webrtc-examples/pom.xml @@ -76,6 +76,11 @@ webrtc-java-media ${project.version} + + ${project.groupId} + webrtc-java-swing + ${project.version} + ${project.groupId} webrtc-java-javafx diff --git a/webrtc-examples/src/main/java/module-info.java b/webrtc-examples/src/main/java/module-info.java index d01dc012b..a00a3e6c3 100644 --- a/webrtc-examples/src/main/java/module-info.java +++ b/webrtc-examples/src/main/java/module-info.java @@ -9,6 +9,7 @@ requires org.eclipse.jetty.websocket.server; requires webrtc.java; requires webrtc.java.javafx; + requires webrtc.java.swing; requires webrtc.java.media; exports dev.onvoid.webrtc.examples.web.client; diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt index 424504df4..76e25bcfa 100644 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt @@ -15,7 +15,6 @@ target_sources(${PROJECT_NAME} include/JavaClassLoader.h include/JavaClassUtils.h include/JavaContext.h - include/JavaDimension.h include/JavaEnum.h include/JavaEnums.h include/JavaError.h @@ -29,7 +28,6 @@ target_sources(${PROJECT_NAME} include/JavaNullPointerException.h include/JavaObject.h include/JavaPrimitive.h - include/JavaRectangle.h include/JavaRef.h include/JavaRuntimeException.h include/JavaString.h @@ -44,13 +42,11 @@ target_sources(${PROJECT_NAME} src/JavaClassLoader.cpp src/JavaClassUtils.cpp src/JavaContext.cpp - src/JavaDimension.cpp src/JavaHashMap.cpp src/JavaIterable.cpp src/JavaList.cpp src/JavaMapIterator.cpp src/JavaObject.cpp - src/JavaRectangle.cpp src/JavaString.cpp src/JavaThreadEnv.cpp src/JavaThrowable.cpp diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/include/JavaDimension.h b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/include/JavaDimension.h deleted file mode 100644 index d8b73e55d..000000000 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/include/JavaDimension.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019, Alex Andres. All rights reserved. - * - * Use of this source code is governed by the 3-Clause BSD license that can be - * found in the LICENSE file in the root of the source tree. - */ - -#ifndef JNI_JAVA_DIMENSION_H_ -#define JNI_JAVA_DIMENSION_H_ - -#include "JavaClass.h" -#include "JavaRef.h" - -#include - -namespace jni -{ - class JavaDimension : public JavaClass - { - public: - explicit JavaDimension(JNIEnv * env); - - static JavaLocalRef toJava(JNIEnv * env, const int & width, const int & height); - - private: - jclass cls; - jmethodID ctor; - }; -} - -#endif \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/include/JavaRectangle.h b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/include/JavaRectangle.h deleted file mode 100644 index fd059c7dd..000000000 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/include/JavaRectangle.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019, Alex Andres. All rights reserved. - * - * Use of this source code is governed by the 3-Clause BSD license that can be - * found in the LICENSE file in the root of the source tree. - */ - -#ifndef JNI_JAVA_RECTANGLE_H_ -#define JNI_JAVA_RECTANGLE_H_ - -#include "JavaClass.h" -#include "JavaRef.h" - -#include - -namespace jni -{ - class JavaRectangle : public JavaClass - { - public: - explicit JavaRectangle(JNIEnv * env); - - static JavaLocalRef toJava(JNIEnv * env, const int & x, const int & y, const int & width, const int & height); - - private: - jclass cls; - jmethodID ctor; - }; -} - -#endif \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaDimension.cpp b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaDimension.cpp deleted file mode 100644 index 14753cbd4..000000000 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaDimension.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019, Alex Andres. All rights reserved. - * - * Use of this source code is governed by the 3-Clause BSD license that can be - * found in the LICENSE file in the root of the source tree. - */ - -#include "JavaDimension.h" -#include "JavaClasses.h" -#include "JavaUtils.h" - -namespace jni -{ - JavaDimension::JavaDimension(JNIEnv * env) - { - cls = FindClass(env, "java/awt/Dimension"); - - ctor = GetMethod(env, cls, "", "(II)V"); - } - - JavaLocalRef JavaDimension::toJava(JNIEnv * env, const int & width, const int & height) - { - const auto javaClass = JavaClasses::get(env); - - jobject object = env->NewObject(javaClass->cls, javaClass->ctor, - static_cast(width), static_cast(height) - ); - - return JavaLocalRef(env, object); - } -} \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaRectangle.cpp b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaRectangle.cpp deleted file mode 100644 index a190e47ed..000000000 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaRectangle.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2019, Alex Andres. All rights reserved. - * - * Use of this source code is governed by the 3-Clause BSD license that can be - * found in the LICENSE file in the root of the source tree. - */ - -#include "JavaRectangle.h" -#include "JavaClasses.h" -#include "JavaUtils.h" - -namespace jni -{ - JavaRectangle::JavaRectangle(JNIEnv * env) - { - cls = FindClass(env, "java/awt/Rectangle"); - - ctor = GetMethod(env, cls, "", "(IIII)V"); - } - - JavaLocalRef JavaRectangle::toJava(JNIEnv * env, const int & x, const int & y, const int & width, const int & height) - { - const auto javaClass = JavaClasses::get(env); - - jobject object = env->NewObject(javaClass->cls, javaClass->ctor, - static_cast(x), static_cast(y), - static_cast(width), static_cast(height) - ); - - return JavaLocalRef(env, object); - } -} \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCaptureCallback.cpp b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCaptureCallback.cpp index d54a27b87..e7009406d 100644 --- a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCaptureCallback.cpp +++ b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCaptureCallback.cpp @@ -15,7 +15,6 @@ */ #include "media/video/desktop/DesktopCaptureCallback.h" -#include "media/video/desktop/DesktopFrame.h" #include "api/WebRTCUtils.h" #include "JavaClasses.h" #include "JavaEnums.h" diff --git a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopFrame.cpp b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopFrame.cpp deleted file mode 100644 index d6212416b..000000000 --- a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopFrame.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2019 Alex Andres - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "media/video/desktop/DesktopFrame.h" -#include "JavaClasses.h" -#include "JavaDimension.h" -#include "JavaRectangle.h" -#include "JNI_WebRTC.h" - -namespace jni -{ - namespace DesktopFrame - { - JavaLocalRef toJava(JNIEnv * env, const webrtc::DesktopFrame * frame) - { - if (frame == nullptr) { - return nullptr; - } - - const webrtc::DesktopRect & rect = frame->rect(); - const webrtc::DesktopSize & size = frame->size(); - - const auto javaClass = JavaClasses::get(env); - - jobject buffer = env->NewDirectByteBuffer(frame->data(), frame->stride() * frame->size().height()); - - jobject object = env->NewObject(javaClass->cls, javaClass->ctor, - JavaRectangle::toJava(env, rect.left(), rect.top(), rect.width(), rect.height()).get(), - JavaDimension::toJava(env, size.width(), size.height()).get(), - static_cast(frame->scale_factor()), - static_cast(frame->stride()), - buffer); - - return JavaLocalRef(env, object); - } - - JavaDesktopFrameClass::JavaDesktopFrameClass(JNIEnv * env) - { - cls = FindClass(env, PKG_DESKTOP"DesktopFrame"); - - ctor = GetMethod(env, cls, "", "(Ljava/awt/Rectangle;Ljava/awt/Dimension;FI" BYTE_BUFFER_SIG ")V"); - } - } -} \ No newline at end of file diff --git a/webrtc-swing/pom.xml b/webrtc-swing/pom.xml new file mode 100644 index 000000000..568467e13 --- /dev/null +++ b/webrtc-swing/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + + dev.onvoid.webrtc + webrtc-java-parent + 0.21.0-SNAPSHOT + + + webrtc-java-swing + + webrtc-java-swing + + Swing extension for webrtc-java. Shows the video of the client API in Swing windows. + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + ${project.build.directory}/natives + + + + + + + + + dev.onvoid.webrtc + webrtc-java + ${project.version} + + + diff --git a/webrtc/src/main/java/dev/onvoid/webrtc/client/swing/VideoView.java b/webrtc-swing/src/main/java/dev/onvoid/webrtc/client/swing/VideoView.java similarity index 100% rename from webrtc/src/main/java/dev/onvoid/webrtc/client/swing/VideoView.java rename to webrtc-swing/src/main/java/dev/onvoid/webrtc/client/swing/VideoView.java diff --git a/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopFrame.h b/webrtc-swing/src/main/java/module-info.java similarity index 51% rename from webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopFrame.h rename to webrtc-swing/src/main/java/module-info.java index bfa0f3fb4..97ad598d9 100644 --- a/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopFrame.h +++ b/webrtc-swing/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Alex Andres + * Copyright 2026 Alex Andres * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,32 +14,14 @@ * limitations under the License. */ -#ifndef JNI_WEBRTC_MEDIA_DESKTOP_FRAME_H_ -#define JNI_WEBRTC_MEDIA_DESKTOP_FRAME_H_ - -#include "JavaClass.h" -#include "JavaRef.h" - -#include "modules/desktop_capture/desktop_frame.h" - -#include -#include +/** + * Shows the video of the webrtc-java client API in Swing windows. + */ +module webrtc.java.swing { -namespace jni -{ - namespace DesktopFrame - { - class JavaDesktopFrameClass : public JavaClass - { - public: - explicit JavaDesktopFrameClass(JNIEnv * env); + requires transitive webrtc.java; + requires transitive java.desktop; - jclass cls; - jmethodID ctor; - }; + exports dev.onvoid.webrtc.client.swing; - JavaLocalRef toJava(JNIEnv * env, const webrtc::DesktopFrame * frame); - } } - -#endif \ No newline at end of file diff --git a/webrtc/src/test/java/dev/onvoid/webrtc/client/VideoViewTests.java b/webrtc-swing/src/test/java/dev/onvoid/webrtc/client/swing/VideoViewTests.java similarity index 79% rename from webrtc/src/test/java/dev/onvoid/webrtc/client/VideoViewTests.java rename to webrtc-swing/src/test/java/dev/onvoid/webrtc/client/swing/VideoViewTests.java index afd92bc55..0f2ac89e7 100644 --- a/webrtc/src/test/java/dev/onvoid/webrtc/client/VideoViewTests.java +++ b/webrtc-swing/src/test/java/dev/onvoid/webrtc/client/swing/VideoViewTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.onvoid.webrtc.client; +package dev.onvoid.webrtc.client.swing; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,17 +26,53 @@ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.nio.ByteBuffer; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import dev.onvoid.webrtc.client.swing.VideoView; +import dev.onvoid.webrtc.client.AudioMode; +import dev.onvoid.webrtc.client.CustomVideo; +import dev.onvoid.webrtc.client.Peer; +import dev.onvoid.webrtc.client.PeerOptions; +import dev.onvoid.webrtc.client.Signaling; +import dev.onvoid.webrtc.client.SignalingPair; +import dev.onvoid.webrtc.client.WebRtc; import dev.onvoid.webrtc.media.video.NativeI420Buffer; import dev.onvoid.webrtc.media.video.VideoFrame; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; -class VideoViewTests extends ClientTestBase { +@Execution(ExecutionMode.SAME_THREAD) +class VideoViewTests { + + private static final long TIMEOUT_SECONDS = 15; + + private final List errors = new CopyOnWriteArrayList<>(); + + private WebRtc rtc; + + + @BeforeEach + void createRuntime() { + // Also loads the native library the frames need. + rtc = WebRtc.builder() + .audio(AudioMode.HEADLESS) + .errorHandler(errors::add) + .build(); + } + + @AfterEach + void closeRuntime() { + rtc.close(); + + assertTrue(errors.isEmpty(), () -> "Errors: " + errors); + } @Test void showsFrame() { @@ -129,6 +165,22 @@ void showsRemoteVideo() throws Exception { assertEquals(320, snapshot.getWidth()); } + private Peer[] pair() { + SignalingPair link = Signaling.loopback(); + + Peer caller = rtc.createPeer(PeerOptions.builder() + .name("caller") + .signaling(link.first()) + .build()); + Peer callee = rtc.createPeer(PeerOptions.builder() + .name("callee") + .signaling(link.second()) + .polite(true) + .build()); + + return new Peer[] { caller, callee }; + } + /** The pixels a 64x48 view paints of a 64x48 two-tone frame with the given rotation. */ private static int[] rotated(int rotation) { VideoView view = new VideoView(); diff --git a/webrtc/pom.xml b/webrtc/pom.xml index 5c6de9328..272738e66 100644 --- a/webrtc/pom.xml +++ b/webrtc/pom.xml @@ -14,14 +14,36 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-testCompile + + + --add-modules + java.desktop + --add-reads + webrtc.java=java.desktop + + + + + org.apache.maven.plugins maven-surefire-plugin + extension modules use to reach the native sources. + add-reads: see the test compilation above. --> + --add-modules java.desktop + --add-reads webrtc.java=java.desktop --add-exports webrtc.java/dev.onvoid.webrtc.internal=ALL-UNNAMED --add-opens webrtc.java/dev.onvoid.webrtc=ALL-UNNAMED --add-opens webrtc.java/dev.onvoid.webrtc.logging=ALL-UNNAMED @@ -70,6 +92,8 @@ -Xcheck:jni + --add-modules java.desktop + --add-reads webrtc.java=java.desktop --add-exports webrtc.java/dev.onvoid.webrtc.internal=ALL-UNNAMED --add-opens webrtc.java/dev.onvoid.webrtc=ALL-UNNAMED --add-opens webrtc.java/dev.onvoid.webrtc.logging=ALL-UNNAMED diff --git a/webrtc/src/main/java/dev/onvoid/webrtc/media/video/desktop/DesktopFrame.java b/webrtc/src/main/java/dev/onvoid/webrtc/media/video/desktop/DesktopFrame.java deleted file mode 100644 index 727246bd3..000000000 --- a/webrtc/src/main/java/dev/onvoid/webrtc/media/video/desktop/DesktopFrame.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2019 Alex Andres - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.onvoid.webrtc.media.video.desktop; - -import java.awt.Dimension; -import java.awt.Rectangle; -import java.nio.ByteBuffer; -import java.util.StringJoiner; - -/** - * Represents a desktop frame captured from a screen or window. - * - * @author Alex Andres - */ -public class DesktopFrame { - - /** The rectangle in full desktop coordinates. */ - public final Rectangle frameRect; - - /** The size of the frame in full desktop coordinate space. */ - public final Dimension frameSize; - - /** The scale factor from DIPs to physical pixels of the frame. */ - public final float scale; - - /** Distance in the buffer between two neighboring rows in bytes. */ - public final int stride; - - /** The underlying frame buffer. */ - public final ByteBuffer buffer; - - - /** - * Creates a new desktop frame with the specified properties. - * - * @param frameRect The rectangle in full desktop coordinates. - * @param frameSize The size of the frame in full desktop coordinate space. - * @param scale The scale factor from DIPs to physical pixels of the frame. - * @param stride Distance in the buffer between two neighboring rows in bytes. - * @param buffer The underlying frame buffer. - */ - public DesktopFrame(Rectangle frameRect, Dimension frameSize, float scale, int stride, ByteBuffer buffer) { - this.frameRect = frameRect; - this.frameSize = frameSize; - this.scale = scale; - this.stride = stride; - this.buffer = buffer; - } - - @Override - public String toString() { - return new StringJoiner(", ", - DesktopFrame.class.getSimpleName() + "[", "]") - .add("frameRect=" + frameRect) - .add("frameSize=" + frameSize) - .add("scale=" + scale) - .add("stride=" + stride) - .add("buffer=" + buffer) - .toString(); - } -} diff --git a/webrtc/src/main/java/module-info.java b/webrtc/src/main/java/module-info.java index 283d54acf..8a613027c 100644 --- a/webrtc/src/main/java/module-info.java +++ b/webrtc/src/main/java/module-info.java @@ -3,12 +3,10 @@ @SuppressWarnings("module") module webrtc.java { - requires java.desktop; requires java.net.http; exports dev.onvoid.webrtc; exports dev.onvoid.webrtc.client; - exports dev.onvoid.webrtc.client.swing; exports dev.onvoid.webrtc.logging; exports dev.onvoid.webrtc.media; exports dev.onvoid.webrtc.media.audio; diff --git a/webrtc/src/main/resources/META-INF/native-image/reflect-config.json b/webrtc/src/main/resources/META-INF/native-image/reflect-config.json index d555c869b..bca72ec75 100644 --- a/webrtc/src/main/resources/META-INF/native-image/reflect-config.json +++ b/webrtc/src/main/resources/META-INF/native-image/reflect-config.json @@ -161,9 +161,6 @@ { "name": "dev.onvoid.webrtc.media.video.desktop.DesktopCaptureCallback" }, - { - "name": "dev.onvoid.webrtc.media.video.desktop.DesktopFrame" - }, { "name": "dev.onvoid.webrtc.media.video.desktop.DesktopSource" } diff --git a/webrtc/src/test/java/dev/onvoid/webrtc/ModuleTests.java b/webrtc/src/test/java/dev/onvoid/webrtc/ModuleTests.java new file mode 100644 index 000000000..82acc54e2 --- /dev/null +++ b/webrtc/src/test/java/dev/onvoid/webrtc/ModuleTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2026 Alex Andres + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.onvoid.webrtc; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.lang.module.ModuleDescriptor; + +import org.junit.jupiter.api.Test; + +class ModuleTests { + + @Test + void needsNoDesktopModule() { + // The tests themselves read java.desktop, so the descriptor tells what + // applications get, not the module the tests run in. + ModuleDescriptor descriptor = PeerConnectionFactory.class.getModule().getDescriptor(); + + assertNotNull(descriptor, "Not run as a named module"); + assertFalse(descriptor.requires().stream().anyMatch(r -> r.name().equals("java.desktop")), + "webrtc.java requires java.desktop"); + assertFalse(descriptor.exports().stream() + .anyMatch(e -> e.source().equals("dev.onvoid.webrtc.client.swing")), + "The Swing view belongs to webrtc.java.swing"); + } + +}