-
Notifications
You must be signed in to change notification settings - Fork 0
DOC-14148: Limit maximum size of the audio buffer #58
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
uncatched
merged 4 commits into
release/documents
from
bugfix/DOC-14148-audio-player-crash
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -829,7 +829,9 @@ public class RDMPEGPlayer: NSObject { | |
} | ||
} | ||
|
||
framebuffer.atomicSubtitleFramesAccess { | ||
framebuffer.atomicSubtitleFramesAccess { [weak self] in | ||
guard let self = self else { return } | ||
|
||
while let nextSubtitleFrame = self.framebuffer.nextSubtitleFrame { | ||
let nextSubtitleStartTime = nextSubtitleFrame.position | ||
let nextSubtitleEndTime = nextSubtitleStartTime + nextSubtitleFrame.duration | ||
|
@@ -875,7 +877,7 @@ public class RDMPEGPlayer: NSObject { | |
autoreleasepool { | ||
var outData = outData | ||
|
||
if videoStreamExist && correctionInfo == nil { | ||
if self.videoStreamExist && self.correctionInfo == nil { | ||
#if RD_DEBUG_MPEG_PLAYER | ||
L4Logger.logger(forName: "rd.mediaplayer.RDMPEGPlayer").debug("Silence audio while correcting video") | ||
#endif | ||
|
@@ -887,7 +889,7 @@ public class RDMPEGPlayer: NSObject { | |
var numFramesLeft = numFrames | ||
|
||
while numFramesLeft > 0 { | ||
if rawAudioFrame == nil { | ||
if self.rawAudioFrame == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to line 880, this property access in the audio callback doesn't use weak self capture, which could cause retain cycles and crashes during player deallocation. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
var nextAudioFrame: RDMPEGAudioFrame? | ||
var isAudioOutrun = false | ||
var isAudioLags = false | ||
|
@@ -896,7 +898,9 @@ public class RDMPEGPlayer: NSObject { | |
let loggingScope = L4Logger.logger(forName: "rd.mediaplayer.RDMPEGPlayer").loggingScope() | ||
#endif | ||
|
||
framebuffer.atomicAudioFramesAccess { | ||
framebuffer.atomicAudioFramesAccess { [weak self] in | ||
guard let self = self else { return } | ||
|
||
if let nextFrame = self.framebuffer.nextAudioFrame { | ||
let delta = self.correctionInfo?.correctionInterval( | ||
withCurrentTime: nextFrame.position | ||
|
@@ -916,8 +920,8 @@ public class RDMPEGPlayer: NSObject { | |
|
||
nextAudioFrame = self.framebuffer.popAudioFrame() | ||
|
||
if videoStreamExist == false { | ||
currentInternalTime = nextAudioFrame?.position ?? 0 | ||
if self.videoStreamExist == false { | ||
self.currentInternalTime = nextAudioFrame?.position ?? 0 | ||
} | ||
|
||
if delta < -0.1, self.framebuffer.nextAudioFrame != nil { | ||
|
@@ -947,29 +951,29 @@ public class RDMPEGPlayer: NSObject { | |
.debug("Audio frame will be rendered: \(audioFrame.position) \(audioFrame.duration)") | ||
#endif | ||
|
||
rawAudioFrame = RDMPEGRawAudioFrame(rawAudioData: audioFrame.samples) | ||
self.rawAudioFrame = RDMPEGRawAudioFrame(rawAudioData: audioFrame.samples) | ||
|
||
if videoStreamExist == false { | ||
correctionInfo = RDMPEGCorrectionInfo( | ||
if self.videoStreamExist == false { | ||
self.correctionInfo = RDMPEGCorrectionInfo( | ||
playbackStartDate: Date(), | ||
playbackStartTime: currentInternalTime | ||
playbackStartTime: self.currentInternalTime | ||
) | ||
|
||
DispatchQueue.main.async { | ||
self.setBufferingStateIfNeededAndNotify(false) | ||
DispatchQueue.main.async { [weak self] in | ||
self?.setBufferingStateIfNeededAndNotify(false) | ||
} | ||
} | ||
} | ||
else if videoStreamExist == false { | ||
correctionInfo = nil | ||
else if self.videoStreamExist == false { | ||
self.correctionInfo = nil | ||
|
||
DispatchQueue.main.async { | ||
self.setBufferingStateIfNeededAndNotify(true) | ||
DispatchQueue.main.async { [weak self] in | ||
self?.setBufferingStateIfNeededAndNotify(true) | ||
} | ||
} | ||
} | ||
|
||
if let rawAudioFrame = rawAudioFrame { | ||
if let rawAudioFrame = self.rawAudioFrame { | ||
#if RD_DEBUG_MPEG_PLAYER | ||
L4Logger.logger(forName: "rd.mediaplayer.RDMPEGPlayer").debug("Rendering raw audio frame") | ||
#endif | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property access occurs within an audio callback closure but doesn't use weak self capture like other closures in this method. This could lead to a strong reference cycle and potential crashes when the player is deallocated during audio processing.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only closure here is the autoreleasepool. Self has been properly captured as weak below