Another seek fix by Aholst from the enigma2-devel ml
authorghost <andreas.monzner@multimedia-labs.de>
Fri, 27 Aug 2010 08:42:16 +0000 (10:42 +0200)
committerghost <andreas.monzner@multimedia-labs.de>
Fri, 27 Aug 2010 08:42:16 +0000 (10:42 +0200)
------------------------------------------------------------------
And one more fix on this theme: rewind and higher than 8 times forward
doesn't work for some movies.

It turns out that when I and Felix communicated about the "accurate
speed winding" that he eventually implemented, introducing the .sc
files, we both made a false assumption (sorry if I lead you into it),
that it was enough to jump to an I-frame picture start. However, it
appears that (for an SD-movie that is) one should jump to the sequence
start instead. (This is actually what the c++-code already does when
dealing with the .ap-file, but not for the .sc) Since most movies have
the sequence and picture start in the same ts-frame it usually doesn't
matter. But there are movies out there with the sequence start in a
ts-frame before the picture start, and for them rewind and very fast
forward currently just freezes playback instead.

The below patch fixes that. It just backs up through .sc to the previous
sequence start once the picture start is found. Also, alignment has to
be done here again and not in dvb.cpp, to get the right winding
speed. Please ask me for the full technical details if something is
unclear.
------------------------------------------------------------------
refs bug #570

lib/dvb/tstools.cpp

index d5ad249..a0e4eb1 100644 (file)
@@ -698,9 +698,23 @@ int eDVBTSTools::findFrame(off_t &_offset, size_t &len, int &direction, int fram
                else if (direction == +1)
                        direction = 0;
        }
-                       /* let's find the next frame after the given offset */
        off_t start = offset;
 
+                       /* backtrack to find the previous sequence start, in case of MPEG2 */
+       if ((data & 0xFF) == 0x00) {
+               do {
+                       --start;
+                       if (m_streaminfo.getStructureEntry(start, data, 0))
+                       {
+                               eDebug("get previous failed");
+                               return -1;
+                       }
+               } while (((data & 0xFF) != 9) && ((data & 0xFF) != 0x00) && ((data & 0xFF) != 0xB3)); /* sequence start or previous frame */
+               if ((data & 0xFF) != 0xB3)
+                       start = offset;  /* Failed to find corresponding sequence start, so never mind */
+       }
+
+                       /* let's find the next frame after the given offset */
        do {
                if (m_streaminfo.getStructureEntry(offset, data, 1))
                {
@@ -716,8 +730,8 @@ int eDVBTSTools::findFrame(off_t &_offset, size_t &len, int &direction, int fram
        } while (((data & 0xFF) != 9) && ((data & 0xFF) != 0x00)); /* next frame */
 
                        /* align to TS pkt start */
-//     start = start - (start % 188);
-//     offset = offset - (offset % 188);
+       start = start - (start % 188);
+       offset = offset - (offset % 188);
 
        len = offset - start;
        _offset = start;