[mythtv] Aspect Change problems

D.Charlton lists-dpc-dc-rw at duncancharlton.com
Sat Nov 22 13:40:12 EST 2003


Here's a bit more detail on what I found about the DVB(/ HDTV?) jitter last
week.

The primary cause of the jitter I observed is that avcodec_decode_video()
sometimes provides the same VideoFrame * more than once  without that frame
having been re-obtained through AVCodecContext::get_buffer() in the interim.
This results in multiple pointers to the same frame in the
VideoOutput::availableVideoBuffers/usedVideoBuffers pair. It's then possible
for libavdecodec to fill a frame through one of the pointers to it
while another pointer to it is in usedVideoBuffers awaiting display -
effectively
overwriting the queued frame with one 'from the future' and resulting in an
out of sequence frame. Out of sequence frames will reoccur about once a
second, depending on how many vbuffers are allocated in
VideoOutput::InitBuffers() and how libavcodec fills them.

I believe that, under some circumstances, it may be resonable for
avcodec_decode_video() to do this - it may allow it to optimise the mpeg
decoding process. To deal with this effectively I think that frames should
not be reinserted into VideoOutput::availableVideoBuffers until both
videoOutput::ProcessFrame() and AVCodecContext::release_buffer() has been
called for the frame, neither one of these can be guaranteed to always occur
before the other.

This can be fixed with a 'reference counting' type approach on frames -
however when I tried this I found many occasions on which
AVCodecContext::release_buffer() seemed not be called  and
availableVideoBuffers
became rapidly and rather fatally depleted! That may be due to the broken
mpeg streams I get here because of poor reception, perhaps the libavcodec
error resilience code misses some release_buffers()?

The patch in my earlier email 'works around' the problem by, broadly
speaking, looking for
multiple pointers to the same frame in
availableVideoBuffers/usedVideoBuffers and discarding them. Puke.

I'd imagine that this problem may occur on any system which uses
AvFormatDecoder rather than other DecoderBase derived classes.
I think it showing up on HDTV would be covered by that?

I can make my patch a bit less loathsome if folk think it's worth it. The
better approach, I think, is to fix libavcodec so that the release_buffer()
mechanism works better and then use the reference counting idea but getting
to grips with libavcodec could take (me at least) some considerable time.

duncan





More information about the mythtv-dev mailing list