[mythtv] How does the rewind function work?

Isaac Richards ijr at po.cwru.edu
Tue Jul 15 15:50:47 EDT 2003


On Tuesday 15 July 2003 02:08 pm, Geoffrey Hausheer wrote:
> In nuppeldecoder.cpp, I see this in 'DoRewind'
>     long long keyPos = (*positionMap)[keyIndex];
>     long long curPosition = ringBuffer->GetTotalReadPosition();
>     long long diff = keyPos - curPosition;
>
>     while (ringBuffer->GetFreeSpaceWithReadChange(diff) < 0)
>     {
>         lastKey += keyframedist;
>         keyIndex++;
>         keyPos = (*positionMap)[keyIndex];
>         if (keyPos == 0)
>             continue;
>         diff = keyPos - curPosition;
>
> ...
>
> Now in general, positionMap[keyIndex] may not exist, in which case the Qt
> docs say an empty value will be inserted into the QMap (' Another
> approach uses the operator[]. But be warned: if the map does not contain
> an entry for the element you are looking for, operator[] inserts a
> default value.').  So this doesn't seem right (now there are a bunch of
> elements in the positionMap with '0' positions).

The positionMap is guaranteed to be filled for all entries previous to the 
current position.

> Also, the keyIndex is being incremented rather than decremented.  This
> makes no sense to me.  It means I may not actualy seek to the desired
> frame as far as I can tell. (lastKey/keyIndex is previously set to the
> keyframe just prior to desiredFrame)

This bit of code is dealing with the ring buffer in live tv mode -- you don't 
want to seek too far back, else you'll overlap where it's currently writing 
to.  All this snippet does is make sure you haven't gone too far back (the 
GetFreeSpaceWithReadChange), and finds the first valid keyframe after the 
current write position.

Isaac


More information about the mythtv-dev mailing list