Skip to content

Commit

Permalink
8320655: awt screencast robot spin and sync issues with native libpip…
Browse files Browse the repository at this point in the history
…ewire api

Reviewed-by: azvegint
  • Loading branch information
antbob authored and jerboaa committed Dec 4, 2023
1 parent ed5b8c3 commit c17b8cf
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/java.desktop/unix/native/libawt_xawt/awt/screencast_pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ int DEBUG_SCREENCAST_ENABLED = FALSE;
(*env)->ExceptionDescribe(env); \
}

static volatile gboolean sessionClosed = TRUE;
static gboolean hasPipewireFailed = FALSE;
static gboolean sessionClosed = TRUE;
static GString *activeSessionToken;

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

gtk->g_string_printf(activeSessionToken, "%s", token);
hasPipewireFailed = FALSE;
sessionClosed = FALSE;
return TRUE;
}
Expand Down Expand Up @@ -338,6 +340,8 @@ static void onStreamProcess(void *userdata) {

DEBUG_SCREEN_PREFIX(screen, "data ready\n", NULL);
fp_pw_stream_queue_buffer(data->stream, pwBuffer);

fp_pw_thread_loop_signal(pw.loop, FALSE);
}

static void onStreamStateChanged(
Expand All @@ -351,6 +355,12 @@ static void onStreamStateChanged(
old, fp_pw_stream_state_as_string(old),
state, fp_pw_stream_state_as_string(state),
error);
if (state == PW_STREAM_STATE_ERROR
|| state == PW_STREAM_STATE_UNCONNECTED) {

hasPipewireFailed = TRUE;
fp_pw_thread_loop_signal(pw.loop, FALSE);
}
}

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

while (!data->hasFormat) {
fp_pw_thread_loop_wait(pw.loop);
fp_pw_thread_loop_accept(pw.loop);
if (hasPipewireFailed) {
fp_pw_thread_loop_unlock(pw.loop);
return FALSE;
}
}

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

fp_pw_thread_loop_accept(pw.loop);

return TRUE;
}

Expand Down Expand Up @@ -539,7 +552,12 @@ static void onCoreError(
"!!! pipewire error: id %u, seq: %d, res: %d (%s): %s\n",
id, seq, res, strerror(res), message
);
fp_pw_thread_loop_unlock(pw.loop);
if (id == PW_ID_CORE) {
fp_pw_thread_loop_lock(pw.loop);
hasPipewireFailed = TRUE;
fp_pw_thread_loop_signal(pw.loop, FALSE);
fp_pw_thread_loop_unlock(pw.loop);
}
}

static const struct pw_core_events coreEvents = {
Expand Down Expand Up @@ -904,7 +922,15 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_getRGBPixelsImpl
}

while (!isAllDataReady()) {
fp_pw_thread_loop_lock(pw.loop);
fp_pw_thread_loop_wait(pw.loop);
if (hasPipewireFailed) {
fp_pw_thread_loop_unlock(pw.loop);
doCleanup();
releaseToken(env, jtoken, token);
return RESULT_ERROR;
}
fp_pw_thread_loop_unlock(pw.loop);
}

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

3 comments on commit c17b8cf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on c17b8cf Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr the backport was successfully created on the branch backport-TheRealMDoerr-c17b8cfa-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit c17b8cfa from the openjdk/jdk repository.

The commit being backported was authored by Anton Bobrov on 4 Dec 2023 and was reviewed by Alexander Zvegintsev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-TheRealMDoerr-c17b8cfa-master:backport-TheRealMDoerr-c17b8cfa-master
$ git checkout backport-TheRealMDoerr-c17b8cfa-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-TheRealMDoerr-c17b8cfa-master

Please sign in to comment.