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

Infinite Loop in Media Buffer #46

Closed
ghaith100994 opened this issue Jul 25, 2021 · 11 comments
Closed

Infinite Loop in Media Buffer #46

ghaith100994 opened this issue Jul 25, 2021 · 11 comments

Comments

@ghaith100994
Copy link

When I start Playing Udp stream video and After 5 minutes of streaming the App enter Infinite Loop in Media Buffer function that has been called in Screamer() function in this part

if (requiresBuffering)
                {
                    totalBytes = decoder.VideoDemuxer.TotalBytes + decoder.AudioDemuxer.TotalBytes + decoder.SubtitlesDemuxer.TotalBytes;
                    videoBytes = decoder.VideoDemuxer.VideoBytes + decoder.AudioDemuxer.VideoBytes + decoder.SubtitlesDemuxer.VideoBytes;
                    audioBytes = decoder.VideoDemuxer.AudioBytes + decoder.AudioDemuxer.AudioBytes + decoder.SubtitlesDemuxer.AudioBytes;

                    MediaBuffer();
                    requiresBuffering = false;
                    if (seeks.Count != 0) continue;
                    if (vFrame == null) { Log("MediaBuffer() no video frame"); break; }
                }

vFrame is null and no statement is true in this part

else
                {
                    if (!decoder.VideoDecoder.IsRunning && !isVideoSwitch) { Log("[SCREAMER] Video Exhausted"); shouldStop= true; }
                    if (vFrame != null && !gotAudio && (!decoder.AudioDecoder.IsRunning || decoder.AudioDecoder.Demuxer.Status == MediaFramework.MediaDemuxer.Status.QueueFull)) { 
                        Log("[SCREAMER] Audio Exhausted"); gotAudio  = true; }
                }
@ghaith100994
Copy link
Author

Note:
decoder.VideoDecoder.Frames.Count is 0
vFrame is null

@SuRGeoNix
Copy link
Owner

What protocol do you use? Rtsp? Is it live? Does the stream ends and it doesnt informs the decoder?

@ghaith100994
Copy link
Author

Live stream with udp protocol.
No stream doesn't end

@SuRGeoNix
Copy link
Owner

I've found one dead lock issue when switching streams but this one doesnt sound like it. If you could pause and see the threads at that time and check what does the video demuxer and decoder thread doing. You could also enable ffmpeg logging to see if its a problem with the other side. I will try to reproduce it meanwhile.

@SuRGeoNix
Copy link
Owner

I've seen that on hls protocol after switching streams and seeking. It's like it misses the segments. Maybe by reducing the max packets in the demuxer with the latest update will fix it. Udp is not reliable, try to use tcp if possible and let me know.

SuRGeoNix added a commit that referenced this issue Jul 27, 2021
- Adds demuxer timeouts (open/read/seek/close) to the configuration
- Resets MaxQueueSize to 100
- Fixes hanging issues on av_read_frame/av_seek_frame by changing the interrupt implementation (possible fix also for #46)
@ghaith100994
Copy link
Author

Thanks the loop has stop but the stream stop always after 4.19 minutes

[02.04.53.399] [#1] [Player] [SCREAMER] No video frames
[02.04.53.406] [#1] [Player] [SCREAMER] Buffering ...
[02.04.55.275] [FFmpeg] [mpegts @ 0000028ef2f7fb40] PES packet size mismatch
[02.04.55.277] [FFmpeg] [mpegts @ 0000028ef2f7fb40] Packet corrupt (stream = 0, dts = 5640024880)
[02.04.55.279] [FFmpeg] [mpegts @ 0000028ef2f7fb40] , dropping it.
[02.04.55.280] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.55.287] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.56.997] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.004] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.012] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.020] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.027] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.034] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.041] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.049] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.056] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.064] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.071] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.079] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.087] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.095] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.103] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.115] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.125] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.134] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.142] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.149] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.157] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.164] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.172] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.181] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.188] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.196] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.203] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.210] [#1] [Demuxer: Video] [ERROR-2] Immediate exit requested (-1414092869)
[02.04.57.212] [#1] [Demuxer: Video] [ERROR-0] Too many errors!
[02.04.57.214] [#1] [Demuxer: Video] Demuxing
[02.04.57.215] [#1] [Demuxer: Video] Paused
[02.04.57.227] [#1] [Decoder: Audio] Demuxer is not running [Demuxer Status: Paused]
[02.04.57.230] [#1] [Decoder: Video] Demuxer is not running [Demuxer Status: Paused]
[02.04.57.230] [#1] [Decoder: Audio] Pausing
[02.04.57.232] [#1] [Decoder: Video] Pausing
[02.04.57.234] [#1] [Decoder: Audio] Paused
[02.04.57.236] [#1] [Decoder: Video] Paused
[02.04.57.240] [#1] [Player] [SCREAMER] Video Exhausted
[02.04.57.252] [#1] [Player] [SCREAMER] Stopped
[02.04.57.254] [#1] [Player] MediaBuffer() no video frame
[02.04.57.255] [#1] [Player] [SCREAMER] Finished -> 00:04:19:854

if I set play stream then it give me the same error but if i reopen the stream by pasting url then it is continue because it is live stream

@SuRGeoNix
Copy link
Owner

Yes this seems that it was happening with the interrupts/timeouts and should be fixed at the current version. Which one did you use? Uncomment also the logging in the InterruptClbk in the DemuxerBase.cs. You probably were getting a read timeout that I increased the values at last version.

@ghaith100994
Copy link
Author

3.1.14

@SuRGeoNix
Copy link
Owner

SuRGeoNix commented Jul 28, 2021

Not sure how I can help. I've just tested a udp rtsp camera without any issues. Can you provide the udp url for debugging (even privately / email). Not sure which protocol you use, not sure what configuration you use. Did you change the default config?

defaults.Add("reconnect",           "1");                                       // auto reconnect after disconnect before EOF
defaults.Add("reconnect_streamed",  "1");                                       // auto reconnect streamed / non seekable streams
defaults.Add("reconnect_delay_max", "5");                                       // max reconnect delay in seconds after which to give up
defaults.Add("rtsp_transport",      "tcp");                                     // Seems UDP causing issues (use this by default?)
config.demuxer.VideoFormatOpt.Add("probesize",(50 * (long)1024 * 1024).ToString());
config.demuxer.VideoFormatOpt.Add("analyzeduration",(10 * (long)1000 * 1000).ToString());

And you might need to add more options/flags for your case eg:

config.demuxer.VideoFormatOpt.Add("reconnect_at_eof", "1");
config.demuxer.ReadTimeout = 40 * 1000 * 10000;
config.demuxer.ReadLiveTimeout = 40 * 1000 * 10000;

@SuRGeoNix
Copy link
Owner

Long time to check this one, if you still have issues with v3.2.1 probably means that is another similar bug that I had to manually patch ffmpeg libraries. Re-open it if you can provide more details.

@ghaith100994
Copy link
Author

Thanks for support ,It's Work perfectly

SuRGeoNix added a commit that referenced this issue Aug 25, 2021
- Adds demuxer timeouts (open/read/seek/close) to the configuration
- Resets MaxQueueSize to 100
- Fixes hanging issues on av_read_frame/av_seek_frame by changing the interrupt implementation (possible fix also for #46)
SuRGeoNix added a commit that referenced this issue Aug 25, 2021
- Adds demuxer timeouts (open/read/seek/close) to the configuration
- Resets MaxQueueSize to 100
- Fixes hanging issues on av_read_frame/av_seek_frame by changing the interrupt implementation (possible fix also for #46)
SuRGeoNix added a commit that referenced this issue Aug 25, 2021
- Adds demuxer timeouts (open/read/seek/close) to the configuration
- Resets MaxQueueSize to 100
- Fixes hanging issues on av_read_frame/av_seek_frame by changing the interrupt implementation (possible fix also for #46)


Former-commit-id: a7179bf
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

No branches or pull requests

2 participants