Skip to content
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

[Crash] Default Player crash with MTAudioProcessingTapCallbacks #2420

Merged

Conversation

danielebogo
Copy link
Contributor

Related to #1711

An attempt to fix the crashes related to MTAudioProcessingTapCallbacks.

As a tap can not be synchronously stopped, I suspect we try to access the unretained instance already deallocated.

This solution introduces basically 3 things:

  • An AudioProcessingTapProxy which wraps as weak the reference to the current player
  • When the MTAudioProcessingTapCallbacks is created, the clientInfo is now an UnsafeMutableRawPointer created with the retained instance of the proxy
  • We now implement the finalize closure where we release the previously retained tap instance

To test

  • CI must be 🟢
  • Try to play and change episodes while playing
  • When the system decides to finalize the tap you will see 2 logs in this order:
  1. The log from the finalize closure: [AudioProcessingTapProxy] Finalize tap: <MTAudioProcessingTap 0x6000030513b0> Retain count 3 Created with i/f/p/u/t callbacks = {0x10aa14448/0x10aa14600/0x10aa149b4/0x10aa14d08/0x10aa15330} flags = 0x1
  2. The log from the proxy deinit: [AudioProcessingTapProxy] Deinit proxy
    • Switch the FF off to check everything still works as before

Checklist

  • I have considered if this change warrants user-facing release notes and have added them to CHANGELOG.md if necessary.
  • I have considered adding unit tests for my changes.
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@danielebogo danielebogo added the [Type] Bug Used for issues where something is not functioning as intended. label Nov 13, 2024
@danielebogo danielebogo added this to the 7.77 ❄️ milestone Nov 13, 2024
@danielebogo danielebogo requested a review from a team as a code owner November 13, 2024 20:47
@danielebogo danielebogo requested review from bjtitus and SergioEstevao and removed request for a team November 13, 2024 20:47
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 13, 2024

1 Warning
⚠️ This PR is assigned to the milestone 7.77 ❄️. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@@ -342,7 +386,14 @@ class DefaultPlayer: PlaybackProtocol, Hashable {
}

let tapProcess: MTAudioProcessingTapProcessCallback = { tap, numberFrames, _, bufferListInOut, numberFramesOut, flagsOut in
var referenceToSelf = Unmanaged<DefaultPlayer>.fromOpaque(MTAudioProcessingTapGetStorage(tap)).takeUnretainedValue()
let referenceToSelf: DefaultPlayer
if FeatureFlag.useDefaultPlayerTapCookie.enabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we encapsulate the code bellow to method and used on all places above?
Something like: getPlayerFromTap(_) -> DefaultPlayer

@SergioEstevao SergioEstevao self-requested a review November 14, 2024 11:43
Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

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

Tested this on device and it's working correctly, just left a suggestion for code improvement.

@danielebogo
Copy link
Contributor Author

Thanks @SergioEstevao . Added a static function in 22c2c8d

Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

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

:shipit:

@danielebogo danielebogo merged commit e2f6d1d into release/7.77 Nov 14, 2024
4 of 6 checks passed
@danielebogo danielebogo deleted the danieleb/issues/attempt-fix-crash-defaultplayer branch November 14, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug Used for issues where something is not functioning as intended.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants