Skip to content

Conversation

@johanvos
Copy link
Collaborator

@johanvos johanvos commented Jul 2, 2025

After JDK-8287822 (https://bugs.openjdk.org/browse/JDK-8287822), mpeg file content is no longer played via GSTPlatform but via OSXPlatform.
We need to correctly handle data in case the source is a file inside a jar, in which case CJavaInputStreamCallbacks is used.

The 2 changes I made are:

  1. Use ConnectionHolder instead of Locator for CJavaInputStreamCallbacks in case a jar resource is used.
  2. In case of random access datasource, use readBlock instead of readNextBlock in AVMediaPlayer

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8357714: AudioClip.play crash on macOS when loading resource from jar (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1839/head:pull/1839
$ git checkout pull/1839

Update a local copy of the PR:
$ git checkout pull/1839
$ git pull https://git.openjdk.org/jfx.git pull/1839/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1839

View PR using the GUI difftool:
$ git pr show -t 1839

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1839.diff

Using Webrev

Link to Webrev Comment

In case of random access datasource, use readBlock instead of readNextBlock
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 2, 2025

👋 Welcome back jvos! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 2, 2025

@johanvos This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8357714: AudioClip.play crash on macOS when loading resource from jar

Reviewed-by: angorya, almatvee

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 2 new commits pushed to the master branch:

  • 6029e3e: 8359387: Bump minimum JDK version for JavaFX to JDK 23
  • 639a595: 8357584: [XWayland] [OL10] Robot.mousePress() is delivered to wrong place

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Ready for review label Jul 2, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 2, 2025

Webrevs

@johanvos
Copy link
Collaborator Author

johanvos commented Jul 3, 2025

@sashamatveev can you review this?

@andy-goryachev-oracle
Copy link
Contributor

/reviewers 2

@openjdk
Copy link

openjdk bot commented Jul 3, 2025

@andy-goryachev-oracle
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

unsigned int blockSize = locatorStream->GetCallbacks()->ReadNextBlock();
unsigned int blockSize = -1;
if (isRandomAccess) {
blockSize = locatorStream->GetCallbacks()->ReadBlock(pos, size);
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to declare a local variable for locatorStream->GetCallbacks() ?
or do we assume the compiler is smart enough to do that?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, but do not see a need from performance point view.

@andy-goryachev-oracle
Copy link
Contributor

Would it be possible to come up with a system test?

unsigned int blockSize = locatorStream->GetCallbacks()->ReadNextBlock();
unsigned int blockSize = -1;
if (isRandomAccess) {
blockSize = locatorStream->GetCallbacks()->ReadBlock(pos, size);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure, but do not see a need from performance point view.

@sashamatveev
Copy link
Member

Looks good overall.

  • Undo changed in AVFMediaPlayer.mm. There is no need for it and this code will never execute.
  • Add NULL pointer check and deletion of callbacks if not NULL.
  • Change title for issue to something like MediaPlayer and AudioClip can crash when playing media files over "jar" and "jrt" protocols via OSXPlatform.

@sashamatveev
Copy link
Member

8357714.0.patch

  • Patch which does not do seek with random access and it will read data starting from dataRequest.requestedOffset.
  • For size requestedLength is used. I do not see a need to use anything else. It will be limited to requested length or 1 Megabyte.
  • Added NULL checks and callbacks release.

Add null checks
Fix errors in position and length calculations
@johanvos
Copy link
Collaborator Author

johanvos commented Jul 8, 2025

@sashamatveev Thanks a lot. That all makes sense, and it seems to work indeed with the corrected position/length calculations.

CJavaInputStreamCallbacks *callbacks = new (nothrow) CJavaInputStreamCallbacks();
if (callbacks == NULL) {
jobject jConnectionHolder = CLocator::CreateConnectionHolder(env, jLocator);
if (callbacks == NULL || jConnectionHolder == NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

Extra space after callbacks == NULL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@johanvos
Copy link
Collaborator Author

Would it be possible to come up with a system test?

It would be great to have a system test, but we currently have no framework for testing media in the system tests. It would be good to create this, but I expect it to be lots of work (dealing with native code and different frameworks based on platform), so I think it's better in a separate issue

@kevinrushforth
Copy link
Member

Would it be possible to come up with a system test?

It would be great to have a system test, but we currently have no framework for testing media in the system tests. It would be good to create this, but I expect it to be lots of work (dealing with native code and different frameworks based on platform), so I think it's better in a separate issue

Correct. We do not have such a framework, and it would be out of scope for this issue.

@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Jul 10, 2025

Got a reproducer for you: added AudioClip page to the Monkey Tester
https://github.com/andy-goryachev-oracle/MonkeyTest

Build a jar and run it. Select AudioClip page, then pressing "Play XX" button would play .wav or .mp3 file from the said jar.

edit: it works!

@andy-goryachev-oracle
Copy link
Contributor

Unrelated to this PR:

  • Changing the rate property for mp3 has no effect (but does change the rate for a .wav). Changing the volume property does work. I wonder if this should be documented.
  • AudioClip properties specify no default values, we may need to address that.

I'll create a separate ticket later.

@andy-goryachev-oracle
Copy link
Contributor

My apologies - forgot to build with -PCOMPILE_MEDIA=true.

The fixed code plays .mp3 from a jar without crashing.

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

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

  • the fix works with jdk23 or jdk24.
  • native code changes look ok to me

@andy-goryachev-oracle
Copy link
Contributor

Should we test with other audio formats, or everything is piped through the same code path?

@sashamatveev
Copy link
Member

sashamatveev commented Jul 10, 2025

Should we test with other audio formats, or everything is piped through the same code path?

I tested with all supported formats.

@openjdk openjdk bot added the ready Ready to be integrated label Jul 10, 2025
@johanvos
Copy link
Collaborator Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 11, 2025

Going to push as commit 203c049.
Since your change was applied there have been 4 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 11, 2025
@openjdk openjdk bot closed this Jul 11, 2025
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Jul 11, 2025
@openjdk
Copy link

openjdk bot commented Jul 11, 2025

@johanvos Pushed as commit 203c049.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants