Skip to content

Commit c17b8cf

Browse files
antbobjerboaa
authored andcommittedDec 4, 2023
8320655: awt screencast robot spin and sync issues with native libpipewire api
Reviewed-by: azvegint
1 parent ed5b8c3 commit c17b8cf

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed
 

‎src/java.desktop/unix/native/libawt_xawt/awt/screencast_pipewire.c

+30-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ int DEBUG_SCREENCAST_ENABLED = FALSE;
4343
(*env)->ExceptionDescribe(env); \
4444
}
4545

46-
static volatile gboolean sessionClosed = TRUE;
46+
static gboolean hasPipewireFailed = FALSE;
47+
static gboolean sessionClosed = TRUE;
4748
static GString *activeSessionToken;
4849

4950
struct ScreenSpace screenSpace = {0};
@@ -171,6 +172,7 @@ static gboolean initScreencast(const gchar *token,
171172
}
172173

173174
gtk->g_string_printf(activeSessionToken, "%s", token);
175+
hasPipewireFailed = FALSE;
174176
sessionClosed = FALSE;
175177
return TRUE;
176178
}
@@ -338,6 +340,8 @@ static void onStreamProcess(void *userdata) {
338340

339341
DEBUG_SCREEN_PREFIX(screen, "data ready\n", NULL);
340342
fp_pw_stream_queue_buffer(data->stream, pwBuffer);
343+
344+
fp_pw_thread_loop_signal(pw.loop, FALSE);
341345
}
342346

343347
static void onStreamStateChanged(
@@ -351,6 +355,12 @@ static void onStreamStateChanged(
351355
old, fp_pw_stream_state_as_string(old),
352356
state, fp_pw_stream_state_as_string(state),
353357
error);
358+
if (state == PW_STREAM_STATE_ERROR
359+
|| state == PW_STREAM_STATE_UNCONNECTED) {
360+
361+
hasPipewireFailed = TRUE;
362+
fp_pw_thread_loop_signal(pw.loop, FALSE);
363+
}
354364
}
355365

356366
static const struct pw_stream_events streamEvents = {
@@ -473,15 +483,18 @@ static gboolean connectStream(int index) {
473483

474484
while (!data->hasFormat) {
475485
fp_pw_thread_loop_wait(pw.loop);
486+
fp_pw_thread_loop_accept(pw.loop);
487+
if (hasPipewireFailed) {
488+
fp_pw_thread_loop_unlock(pw.loop);
489+
return FALSE;
490+
}
476491
}
477492

478493
DEBUG_SCREEN_PREFIX(data->screenProps,
479494
"frame size: %dx%d\n",
480495
data->rawFormat.size.width, data->rawFormat.size.height
481496
);
482497

483-
fp_pw_thread_loop_accept(pw.loop);
484-
485498
return TRUE;
486499
}
487500

@@ -539,7 +552,12 @@ static void onCoreError(
539552
"!!! pipewire error: id %u, seq: %d, res: %d (%s): %s\n",
540553
id, seq, res, strerror(res), message
541554
);
542-
fp_pw_thread_loop_unlock(pw.loop);
555+
if (id == PW_ID_CORE) {
556+
fp_pw_thread_loop_lock(pw.loop);
557+
hasPipewireFailed = TRUE;
558+
fp_pw_thread_loop_signal(pw.loop, FALSE);
559+
fp_pw_thread_loop_unlock(pw.loop);
560+
}
543561
}
544562

545563
static const struct pw_core_events coreEvents = {
@@ -904,7 +922,15 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_getRGBPixelsImpl
904922
}
905923

906924
while (!isAllDataReady()) {
925+
fp_pw_thread_loop_lock(pw.loop);
907926
fp_pw_thread_loop_wait(pw.loop);
927+
if (hasPipewireFailed) {
928+
fp_pw_thread_loop_unlock(pw.loop);
929+
doCleanup();
930+
releaseToken(env, jtoken, token);
931+
return RESULT_ERROR;
932+
}
933+
fp_pw_thread_loop_unlock(pw.loop);
908934
}
909935

910936
DEBUG_SCREENCAST("\nall data ready\n", NULL);

0 commit comments

Comments
 (0)
Please sign in to comment.