Skip to content

Add support for avplayer to play files in the application sandbox in openHarmony #18538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025

Conversation

lynnllh
Copy link
Contributor

@lynnllh lynnllh commented Mar 31, 2025

Add support for avplayer to play files in the application sandbox, avoiding stuttering due to decoding and resampling when playing large files.

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

…oiding stuttering due to decoding and resampling when playing large files.
Copy link

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1002411 bytes 1002411 bytes ✅ 0 bytes
2D All (legacy pipeline) 2663845 bytes 2663845 bytes ✅ 0 bytes
2D All (new pipeline) 2751265 bytes 2751265 bytes ✅ 0 bytes
(2D + 3D) All 10004545 bytes 10004545 bytes ✅ 0 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16917045 bytes 16917045 bytes ✅ 0 bytes

Interface Check Report

This pull request does not change any public interfaces !

@dumganhar dumganhar requested a review from qiuguohua April 2, 2025 06:27
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY
int fd = fileno(fp);
if (fd > 0) {
assetFd = dup(fd);
Copy link
Contributor

Choose a reason for hiding this comment

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

@lynnllh Will dup the fd cause fd memory leak?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lynnllh Will dup the fd cause fd memory leak?

  1. In fact, when playing large files, AVPlayer is used for playback. After playback ends, the OH_AVPlayer_Release interface is called, which releases the file descriptor (fd) held by it. Therefore, under normal circumstances, playing large files will not cause FD leakage.
  2. However, when playing small files, they are parsed into PCM streams for playback, and at this time, the FD handle is not released, causing leakage.
  3. However, in reality, within the branch where audioFilePath[0]!= '/', fileUtils->getRawFileDescriptor is called. This method calls OH_ResourceManager_GetRawFileDescriptor64 to obtain the FD. This method also has a corresponding method OH_ResourceManager_ReleaseRawFileDescriptor64 that needs to be called to release the FD. However, this call is not made in the code, so FD leakage also occurs when playing small files. I will consider both scenarios together to see how to handle them appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lynnllh Will dup the fd cause fd memory leak?

image
Sorry, I rechecked the code and found that there is a close operation for FD in the destructor of AssetFD, so it should not cause FD leakage.

@qiuguohua qiuguohua requested a review from star-e May 8, 2025 08:46
@star-e star-e merged commit 91ad6da into cocos:v3.8.7 May 8, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants