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

[player] Fix player hanging when terminate #498

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

legerch
Copy link
Contributor

@legerch legerch commented Dec 4, 2024

This PR is meant to fix player from hanging when demuxer terminate method is called.
More details on this issue will be find inside : #497

Very particular path to reproduce the issue :
- Server must stop sending RTSP stream
- Player::stop() and Player::setSources() call after

Reasons:
When source is set, demuxer is "terminated" (method used to reset it). But this method will hang in this particular case, for 10/15 seconds, due to `av_read_frame` (called by auto packet = demuxer.read()` inside `QAVPlayer::doDemux` method)

It seems that FFMPEG doesn't provide a non-blocking equivalent method (flag AVIO_FLAG_NONBLOCK exist but support is really experimental : https://ffmpeg-devel.ffmpeg.narkive.com/k3jOJEmZ/av-read-frame-question-about-blocking).

According to multiple thread on this issue :
- https://stackoverflow.com/questions/14558172/ffmpeg-av-read-frame-need-very-long-time-to-stop
- https://stackoverflow.com/questions/65408224/using-asio-to-implement-interrupt-callback-for-ffmpeg
Using a custom `AVFormatContext::interrupt_callback` is the way to do, good thing is that `QAvDemuxer` already provide it and also already provide an option to perform the `abort`.

So, be sure to enable `abort` property before explicitly ask to wait for the demuxer to finish

(note that setting sources isn't the only way to trigger it, simply destroying player, which call terminate, will trigger this behaviour)

demuxer.abort();
demuxerFuture.waitForFinished();
demuxer.abort(false);
Copy link
Owner

Choose a reason for hiding this comment

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

interesting why second call is needed there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added it to "reset" to his previous state (since abort is false by default). Thus, other methods from FFmpeg will not be prematurely aborted (thinking about TEARDOWN signals not being sent for example).

Copy link
Owner

Choose a reason for hiding this comment

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

oh, forgot that can reset the flag. As I see it is reset already in onLoad, so should work without this line.

@valbok valbok merged commit 27566fc into valbok:master Dec 4, 2024
7 checks passed
legerch added a commit to legerch/qtavplayer that referenced this pull request Dec 5, 2024
Work initially started here : 3bf856a

Then 2 PRs in the mainline project has been done related to this subject:
- valbok/QtAVPlayer#498
- valbok/QtAVPlayer#500
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.

2 participants