souphttpsrc: fix possible data corruption after seeking
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 14 May 2012 14:51:29 +0000 (15:51 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Wed, 16 May 2012 07:31:15 +0000 (08:31 +0100)
commit95f6e0dbe440cc0399a54221d672f11e4e1d6ee8
treed62add36b3585f2f6e7eb88b8e7b08802b40947a
parent5203e5500e04d951101fb1e04398ba2df6874a58
souphttpsrc: fix possible data corruption after seeking

Consider a downstream element that may issue seeks in very short
succession (e.g. queue2), depending on the access pattern of
the downstream element (e.g. qtdemux with audio/video chunks
interleaved so that there's always a sizeable gap between the
current chunks for each stream). In this case, queue2 will maintain
two ranges, and even when it serves a chunk from memory, it will
switch ranges and make souphttpsrc seek to the end of the available
data for that range, assuming that that's where we'll want to
continue reading from next.

This may lead to the following seek request pattern:

 - source reading position A
 - seek to B
 - now reading position still A, requested_postion is B
 - streaming thread to be restarted to continue from B
 - seek to A, before streaming thread had time to do the seek
 - do_seek() now sees reading position == seek position and
   returns early.
 - however, requested position is still B from the earlier
   seek request
 - streaming thread starts up, sees that a seek to B is pending
   and requests data from B from the server, while the GstBaseSrc
   segment has of course been updated/reset to position A, which
   was the last seek request.
 - we will now send data for position B and pretend that's the
   data from position A (via the newsegment event, etc.)
 - this causes data corruption

Reproducible doing seek-emulated fast-forward/backward on 006648.
ext/soup/gstsouphttpsrc.c