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

Don't set _playerNode to nil before assignment #553

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions Sources/CSFBAudioEngine/Player/SFBAudioPlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -931,23 +931,22 @@ - (BOOL)configureProcessingGraphForFormat:(AVAudioFormat *)format forceUpdate:(B
if(_playerNode) {
playerNodeOutputConnectionPoint = [[_engine outputConnectionPointsForNode:_playerNode outputBus:0] firstObject];
[_engine detachNode:_playerNode];

// When an audio player node is deallocated the destructor synchronously waits
// for decoder cancelation (if there is an active decoder) and then for any
// final events to be processed and delegate messages sent.
// The potential therefore exists to block the calling thread for a perceptible amount
// of time, especially if the delegate callouts take longer than ideal.
//
// In my measurements the baseline with an empty delegate implementation of
// -audioPlayer:decoderCanceled:framesRendered: seems to be around 100 µsec
//
// Assuming there are no external references to the audio player node,
// setting it to nil here sends -dealloc
_playerNode = nil;
}

[_engine attachNode:playerNode];

// When an audio player node is deallocated the destructor synchronously waits
// for decoder cancelation (if there is an active decoder) and then for any
// final events to be processed and delegate messages sent.
// The potential therefore exists to block the calling thread for a perceptible amount
// of time, especially if the delegate callouts take longer than ideal.
//
// In my measurements the baseline with an empty delegate implementation of
// -audioPlayer:decoderCanceled:framesRendered: seems to be around 100 µsec
//
// Assuming there are no external references to the audio player node,
// setting it here sends -dealloc
_playerNode = playerNode;
[_engine attachNode:_playerNode];

// Reconnect the player node to the next node in the processing chain
// This is the mixer node in the default configuration, but additional nodes may
Expand Down Expand Up @@ -991,9 +990,8 @@ - (BOOL)configureProcessingGraphForFormat:(AVAudioFormat *)format forceUpdate:(B
audioUnit.maximumFramesToRender = maximumFramesToRender;

NSError *error;
if(renderResourcesAllocated && ![audioUnit allocateRenderResourcesAndReturnError:&error]) {
if(renderResourcesAllocated && ![audioUnit allocateRenderResourcesAndReturnError:&error])
os_log_error(_audioPlayerLog, "Error allocating AUAudioUnit render resources for SFBAudioPlayerNode: %{public}@", error);
}
}
}

Expand Down