[vlc-devel] [PATCH] input/stream: do not unconditionally invalidate block on seek

Filip Roséen filip at atch.se
Mon Oct 24 03:31:00 CEST 2016


For starters I should have mentioned that the patch which this email
is a reply to is a *"would be nice to have"*, given that we have modules
that handle caching - though at a broader spectrum.

It is *"would be nice to have"* in the sense that having basic block
handling in terms of seeking in the core for trivial cases is not
exactly complicated, and it can help speed up performance.

On 2016-10-24 02:13, Filip Roséen wrote:

> If a seek request happens to refer to a position within the already
> read block, simply update the block so that it refers to the desired
> data.
> 
> There is really no need for us to discard the block, only to ask the
> underlying stream to give us a new one (when we have the data we want
> already).

I forgot to mention that the patch of course does not take backward
seeking within the current block into account, mostly because that
requires us to store the original value of either `p_block->i_buffer`,
or `p_block->p_buffer`, somewhere (which I thought would belong in a
different patch, starting small - and fixing the other case later).

As a note, one might think that we can just rely on `p_block->p_start`
and `p_block->i_size`, but there is nothing guaranteeing that there is
actually valid data at those locations (which is why we would need to
store the original vlaue of `p_block->i_buffer` or
`p_block->p_buffer`).

Anyhow, I just realized that it's 3:30am.. so I should probably get me
some rest. 

Peace,\
Filip

> ---
>  src/input/stream.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/src/input/stream.c b/src/input/stream.c
> index 6c614f8..a2ef6b6 100644
> --- a/src/input/stream.c
> +++ b/src/input/stream.c
> @@ -576,6 +576,20 @@ int vlc_stream_Seek(stream_t *s, uint64_t offset)
>              return VLC_SUCCESS; /* Nothing to do! */
>      }
>  
> +    if( priv->block &&
> +        priv->offset < offset &&
> +        priv->offset + priv->block->i_buffer > offset )
> +    {
> +        /* seeking within current block */
> +        size_t skipped = offset - priv->offset;
> +
> +        priv->block->p_buffer += skipped;
> +        priv->block->i_buffer -= skipped;
> +        priv->offset = offset;
> +
> +        return VLC_SUCCESS;
> +    }
> +
>      if (s->pf_seek == NULL)
>          return VLC_EGENERIC;
>  
> -- 
> 2.10.0
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20161024/5d157208/attachment.html>


More information about the vlc-devel mailing list