[mythtv] How does the rewind function work?

Geoffrey Hausheer ou401cru02 at sneakemail.com
Tue Jul 15 14:08:46 EDT 2003


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).
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)

I would have written this code something like:
keyPos = 0;
while (keyIndex > 0) {
    if (positionMap->find(keyIndex) != positionMap->end())
    {
         keyPos = (*positionMap)[keyIndex];
         break;
     }
     keyIndex--;
}
diff = keyPos - curPosition;
...

Am I missing something here?  Doing this wouild make the DoRewind and
DoFastForward functions a lot more similar (which would help me out)

Thanks,
.Geoff
-- 
  Geoffrey Hausheer
  XXXXXXXXXXXXXXXXXXXXX


More information about the mythtv-dev mailing list