Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#12196 closed Bug Report - General (fixed)

Invalid bitrate from AVFormat can stall reads from the RingBuffer

Reported by: david.madsen@… Owned by: Jean-Yves Avenard <jyavenard@…>
Priority: minor Milestone: 0.27
Component: MythTV - General Version: Unspecified
Severity: medium Keywords:
Cc: Ticket locked: no

Description

I've had trouble recently with some recordings that can't be played back in the frontend or commflagged.

The bitrate returned from AVFormat is incorrect because of a glitch near the end of the recording which reset the PTS near the end. This cause AVFormat to have an entirely invalid bitrate, which was then propagated to the RingBuffer? via the following code:

AVFormatDecoder::ScanStreams?() in libmythtv/avformatdecoder.cpp

    if (ic && ((uint)ic->bit_rate > bitrate))
        bitrate = (uint)ic->bit_rate;

    if (bitrate > 0)
    {
        bitrate = (bitrate + 999) / 1000;
        if (ringBuffer)
            ringBuffer->UpdateRawBitrate(bitrate);
    }

This ended up setting the fill_min in the RingBuffer? larger than the full size of the buffer, and consequently blocking reads from the RingBuffer? since this condition never becomes true:

        if ((0 == read_return) || (numfailures > 5) ||
            (readsallowed != (used >= fill_min || ateof ||
                              setswitchtonext || commserror)))
        {

I've attached a patch where I just capped the bitrate returned from AVFormat to exclude the erroneous values, though I'm not sure that's the best way to fix the problem. Maybe a safeguard in the RingBuffer? itself on the value of fill_min would be a better method.

Attachments (2)

mythtv_fix_avf_bitrate.patch (1.2 KB) - added by david.madsen@… 5 years ago.
mythtv_fix_avf_bitrate.2.patch (1.1 KB) - added by david.madsen@… 5 years ago.
Cleaned up patch to avoid null pointer

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by david.madsen@…

Changed 5 years ago by david.madsen@…

Cleaned up patch to avoid null pointer

comment:1 Changed 5 years ago by Jean-Yves Avenard <jyavenard@…>

Owner: set to Jean-Yves Avenard <jyavenard@…>
Resolution: fixed
Status: newclosed

In 83050ac67d40a449bc5433e0edda2c41d75eb45f/mythtv:

Limit bitrate to 100Mbit/s and fill_min to half the size of the ringbuffer

Under some circumstances, FFmpeg can returns rubbish bitrates, set a maximum value of 100Mbit. This is almost twice the maximum bitrate permissible on a bluray.

Fixes #12196

comment:2 Changed 5 years ago by Jean-Yves Avenard <jyavenard@…>

In db46c6a71c53bccebc640331ad35f0481c4c7fc2/mythtv:

Limit bitrate to 100Mbit/s and fill_min to half the size of the ringbuffer

Under some circumstances, FFmpeg can returns rubbish bitrates, set a maximum value of 100Mbit. This is almost twice the maximum bitrate permissible on a bluray.

Fixes #12196

(cherry picked from commit 83050ac67d40a449bc5433e0edda2c41d75eb45f)

comment:3 Changed 5 years ago by paulh

Milestone: unknown0.27
Note: See TracTickets for help on using tickets.