Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ elseif(LINUX)
pkg_check_modules(DBUS REQUIRED dbus-1)

target_include_directories(${PROJECT_NAME} PUBLIC ${DBUS_INCLUDE_DIRS})
target_compile_definitions(${PROJECT_NAME} PUBLIC WEBRTC_LINUX WEBRTC_POSIX WEBRTC_USE_H264)
target_compile_definitions(${PROJECT_NAME} PUBLIC WEBRTC_LINUX WEBRTC_POSIX WEBRTC_USE_H264 WEBRTC_USE_X11)
target_link_libraries(${PROJECT_NAME} X11 Xfixes Xrandr Xcomposite dbus-1)
elseif(WIN32)
target_compile_definitions(${PROJECT_NAME} PUBLIC WEBRTC_WIN WEBRTC_USE_H264 NOMINMAX WIN32_LEAN_AND_MEAN NDEBUG)
Expand Down
7 changes: 6 additions & 1 deletion webrtc-jni/src/main/cpp/src/JNI_ScreenCapturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_desktop_ScreenCapturer_initialize
(JNIEnv * env, jobject caller)
{
SetHandle(env, caller, new jni::DesktopCapturer(true));
try {
SetHandle(env, caller, new jni::DesktopCapturer(true));
}
catch (...) {
ThrowCxxJavaException(env);
}
}
7 changes: 6 additions & 1 deletion webrtc-jni/src/main/cpp/src/JNI_WindowCapturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_desktop_WindowCapturer_initialize
(JNIEnv * env, jobject caller)
{
SetHandle(env, caller, new jni::DesktopCapturer(false));
try {
SetHandle(env, caller, new jni::DesktopCapturer(false));
}
catch (...) {
ThrowCxxJavaException(env);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "modules/desktop_capture/desktop_capturer.h"
#include "modules/desktop_capture/desktop_capture_options.h"
#include "modules/desktop_capture/desktop_and_cursor_composer.h"
#include "rtc_base/logging.h"

namespace jni
{
Expand All @@ -36,14 +37,22 @@ namespace jni
options.set_allow_directx_capturer(true);
#endif

if (screenCapturer) {
capturer = std::make_unique<webrtc::DesktopAndCursorComposer>(
webrtc::DesktopCapturer::CreateScreenCapturer(options), options);
}
else {
capturer = std::make_unique<webrtc::DesktopAndCursorComposer>(
webrtc::DesktopCapturer::CreateWindowCapturer(options), options);
std::unique_ptr<webrtc::DesktopCapturer> inner = screenCapturer
? webrtc::DesktopCapturer::CreateScreenCapturer(options)
: webrtc::DesktopCapturer::CreateWindowCapturer(options);

if (!inner) {
RTC_LOG(LS_ERROR) << (screenCapturer
? "DesktopCapturer: CreateScreenCapturer returned null. "
"Possible causes: missing X11/XDAMAGE extension, Wayland "
"session without PipeWire support, or snap confinement."
: "DesktopCapturer: CreateWindowCapturer returned null. "
"Possible causes: missing X11/XFIXES extension or snap confinement.");
// Leave capturer as nullptr; callers check via GetSourceList returning false.
return;
}

capturer = std::make_unique<webrtc::DesktopAndCursorComposer>(std::move(inner), options);
}

DesktopCapturer::~DesktopCapturer()
Expand All @@ -53,6 +62,8 @@ namespace jni

void DesktopCapturer::Start(webrtc::DesktopCapturer::Callback * callback)
{
if (!capturer) return;

capturer->Start(callback);

if (focusSelectedSource) {
Expand All @@ -62,16 +73,20 @@ namespace jni

void DesktopCapturer::SetMaxFrameRate(uint32_t max_frame_rate)
{
if (!capturer) return;
capturer->SetMaxFrameRate(max_frame_rate);
}

void DesktopCapturer::SetSharedMemoryFactory(std::unique_ptr<webrtc::SharedMemoryFactory> factory)
{
if (!capturer) return;
capturer->SetSharedMemoryFactory(std::move(factory));
}

void DesktopCapturer::CaptureFrame()
{
if (!capturer) return;

#if defined(WEBRTC_MAC)
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
#endif
Expand All @@ -81,21 +96,25 @@ namespace jni

void DesktopCapturer::SetExcludedWindow(webrtc::WindowId window)
{
if (!capturer) return;
capturer->SetExcludedWindow(window);
}

bool DesktopCapturer::GetSourceList(webrtc::DesktopCapturer::SourceList * sources)
{
if (!capturer) return false;
return capturer->GetSourceList(sources);
}

bool DesktopCapturer::SelectSource(webrtc::DesktopCapturer::SourceId id)
{
if (!capturer) return false;
return capturer->SelectSource(id);
}

bool DesktopCapturer::FocusOnSelectedSource()
{
if (!capturer) return false;
return capturer->FocusOnSelectedSource();
}

Expand All @@ -106,6 +125,7 @@ namespace jni

bool DesktopCapturer::IsOccluded(const webrtc::DesktopVector & pos)
{
if (!capturer) return false;
return capturer->IsOccluded(pos);
}
}
}