[FFmpeg-devel,v4] avformat/pcm: decrease delay when reading PCM streams.

Submitted by Philipp M. Scholl on March 7, 2018, 2:30 p.m.

Details

Message ID 20180307143023.GA4532@pluto.informatik.privat
State New
Headers show

Commit Message

Philipp M. Scholl March 7, 2018, 2:30 p.m.
Here is the fourth version of the PCM patch with updated testcases.

 The blocksize of the PCM decoder is hard-coded. This creates
unnecessary delay when reading low-rate (<100Hz) streams. This creates
issues when multiplexing multiple streams, since other inputs are only
opened/read after a low-rate input block was completely read.

 This patch decreases the blocksize for low-rate inputs, so
approximately a block is read every 40ms. This decreases the startup
delay when multiplexing inputs with different rates.

Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
---
 libavformat/pcm.c         | 16 ++++++++++++----
 tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------------------
 tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------------------
 3 files changed, 54 insertions(+), 46 deletions(-)

Comments

Michael Niedermayer March 9, 2018, 12:40 a.m.
On Wed, Mar 07, 2018 at 03:30:37PM +0100, Philipp M. Scholl wrote:
>  Here is the fourth version of the PCM patch with updated testcases.
> 
>  The blocksize of the PCM decoder is hard-coded. This creates
> unnecessary delay when reading low-rate (<100Hz) streams. This creates
> issues when multiplexing multiple streams, since other inputs are only
> opened/read after a low-rate input block was completely read.
> 
>  This patch decreases the blocksize for low-rate inputs, so
> approximately a block is read every 40ms. This decreases the startup
> delay when multiplexing inputs with different rates.
> 
> Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
> ---
>  libavformat/pcm.c         | 16 ++++++++++++----
>  tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------------------
>  tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------------------
>  3 files changed, 54 insertions(+), 46 deletions(-)
> 
> diff --git a/libavformat/pcm.c b/libavformat/pcm.c
> index 806f91b6b..1ea15a9e8 100644
> --- a/libavformat/pcm.c
> +++ b/libavformat/pcm.c
> @@ -28,13 +28,21 @@
>  
>  int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
>  {
> -    int ret, size;
> +    int ret, size = INT_MAX;
> +    AVCodecParameters *par = s->streams[0]->codecpar;
>  
> -    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
> -    if (size <= 0)
> +    if (par->block_align <= 0)
>          return AVERROR(EINVAL);
>  
> -    ret= av_get_packet(s->pb, pkt, size);
> +    /*
> +     * Compute read size to complete a read every 40ms.  Clamp to RAW_SAMPLES if
> +     * larger. Use power of two as readsize for I/O efficiency.
> +     */

> +    size = FFMAX(par->sample_rate/25, 1);

division is a bit slowish, and this is done per (small) packet.
Maybe a >>4 or >>5 could be used ? (this is a minor issue)


> +    size = FFMIN(size, RAW_SAMPLES) * par->block_align;
> +    size = 1 << ff_log2(size);
> +
> +    ret = av_get_packet(s->pb, pkt, size);

what if block_align is not a power of 2?

for example with 6 channels there could be a reasonable block size
that is not a multiple of 2.
or am i missing something ?
[...]
Tomas Härdin March 9, 2018, 10:18 a.m.
On 2018-03-09 01:40, Michael Niedermayer wrote:
> On Wed, Mar 07, 2018 at 03:30:37PM +0100, Philipp M. Scholl wrote:
>>   Here is the fourth version of the PCM patch with updated testcases.
>>
>>   The blocksize of the PCM decoder is hard-coded. This creates
>> unnecessary delay when reading low-rate (<100Hz) streams. This creates
>> issues when multiplexing multiple streams, since other inputs are only
>> opened/read after a low-rate input block was completely read.
>>
>>   This patch decreases the blocksize for low-rate inputs, so
>> approximately a block is read every 40ms. This decreases the startup
>> delay when multiplexing inputs with different rates.
>>
>> Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
>> ---
>>   libavformat/pcm.c         | 16 ++++++++++++----
>>   tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------------------
>>   tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------------------
>>   3 files changed, 54 insertions(+), 46 deletions(-)
>>
>> diff --git a/libavformat/pcm.c b/libavformat/pcm.c
>> index 806f91b6b..1ea15a9e8 100644
>> --- a/libavformat/pcm.c
>> +++ b/libavformat/pcm.c
>> @@ -28,13 +28,21 @@
>>   
>>   int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
>>   {
>> -    int ret, size;
>> +    int ret, size = INT_MAX;
>> +    AVCodecParameters *par = s->streams[0]->codecpar;
>>   
>> -    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
>> -    if (size <= 0)
>> +    if (par->block_align <= 0)
>>           return AVERROR(EINVAL);
>>   
>> -    ret= av_get_packet(s->pb, pkt, size);
>> +    /*
>> +     * Compute read size to complete a read every 40ms.  Clamp to RAW_SAMPLES if
>> +     * larger. Use power of two as readsize for I/O efficiency.
>> +     */
>> +    size = FFMAX(par->sample_rate/25, 1);
> division is a bit slowish, and this is done per (small) packet.
> Maybe a >>4 or >>5 could be used ? (this is a minor issue)

It's not the 80's any more

>> +    size = FFMIN(size, RAW_SAMPLES) * par->block_align;
>> +    size = 1 << ff_log2(size);
>> +
>> +    ret = av_get_packet(s->pb, pkt, size);
> what if block_align is not a power of 2?
>
> for example with 6 channels there could be a reasonable block size
> that is not a multiple of 2.
> or am i missing something ?

Good catch. Yes, this is a problem. Should probably round down before 
multiplying by block_align

/Tomas
Michael Niedermayer March 9, 2018, 6:02 p.m.
On Fri, Mar 09, 2018 at 11:18:38AM +0100, Tomas Härdin wrote:
> On 2018-03-09 01:40, Michael Niedermayer wrote:
> >On Wed, Mar 07, 2018 at 03:30:37PM +0100, Philipp M. Scholl wrote:
> >>  Here is the fourth version of the PCM patch with updated testcases.
> >>
> >>  The blocksize of the PCM decoder is hard-coded. This creates
> >>unnecessary delay when reading low-rate (<100Hz) streams. This creates
> >>issues when multiplexing multiple streams, since other inputs are only
> >>opened/read after a low-rate input block was completely read.
> >>
> >>  This patch decreases the blocksize for low-rate inputs, so
> >>approximately a block is read every 40ms. This decreases the startup
> >>delay when multiplexing inputs with different rates.
> >>
> >>Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
> >>---
> >>  libavformat/pcm.c         | 16 ++++++++++++----
> >>  tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------------------
> >>  tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------------------
> >>  3 files changed, 54 insertions(+), 46 deletions(-)
> >>
> >>diff --git a/libavformat/pcm.c b/libavformat/pcm.c
> >>index 806f91b6b..1ea15a9e8 100644
> >>--- a/libavformat/pcm.c
> >>+++ b/libavformat/pcm.c
> >>@@ -28,13 +28,21 @@
> >>  int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
> >>  {
> >>-    int ret, size;
> >>+    int ret, size = INT_MAX;
> >>+    AVCodecParameters *par = s->streams[0]->codecpar;
> >>-    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
> >>-    if (size <= 0)
> >>+    if (par->block_align <= 0)
> >>          return AVERROR(EINVAL);
> >>-    ret= av_get_packet(s->pb, pkt, size);
> >>+    /*
> >>+     * Compute read size to complete a read every 40ms.  Clamp to RAW_SAMPLES if
> >>+     * larger. Use power of two as readsize for I/O efficiency.
> >>+     */
> >>+    size = FFMAX(par->sample_rate/25, 1);
> >division is a bit slowish, and this is done per (small) packet.
> >Maybe a >>4 or >>5 could be used ? (this is a minor issue)
> 
> It's not the 80's any more

i do not think this comment is appropriate in a patch review.

The goal is not to be different from fast code for the sake of
being different from fast code. Or?

If a /25 is better than a >>4 or >>5 then it may make sense to
keep /25. But to me it seemed the value was completely arbitrary
so a /16 or /32 would do equally 

[...]
Hendrik Leppkes March 9, 2018, 6:23 p.m.
On Fri, Mar 9, 2018 at 7:02 PM, Michael Niedermayer
<michael@niedermayer.cc> wrote:
> On Fri, Mar 09, 2018 at 11:18:38AM +0100, Tomas Härdin wrote:
>> On 2018-03-09 01:40, Michael Niedermayer wrote:
>> >On Wed, Mar 07, 2018 at 03:30:37PM +0100, Philipp M. Scholl wrote:
>> >>  Here is the fourth version of the PCM patch with updated testcases.
>> >>
>> >>  The blocksize of the PCM decoder is hard-coded. This creates
>> >>unnecessary delay when reading low-rate (<100Hz) streams. This creates
>> >>issues when multiplexing multiple streams, since other inputs are only
>> >>opened/read after a low-rate input block was completely read.
>> >>
>> >>  This patch decreases the blocksize for low-rate inputs, so
>> >>approximately a block is read every 40ms. This decreases the startup
>> >>delay when multiplexing inputs with different rates.
>> >>
>> >>Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
>> >>---
>> >>  libavformat/pcm.c         | 16 ++++++++++++----
>> >>  tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------------------
>> >>  tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------------------
>> >>  3 files changed, 54 insertions(+), 46 deletions(-)
>> >>
>> >>diff --git a/libavformat/pcm.c b/libavformat/pcm.c
>> >>index 806f91b6b..1ea15a9e8 100644
>> >>--- a/libavformat/pcm.c
>> >>+++ b/libavformat/pcm.c
>> >>@@ -28,13 +28,21 @@
>> >>  int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
>> >>  {
>> >>-    int ret, size;
>> >>+    int ret, size = INT_MAX;
>> >>+    AVCodecParameters *par = s->streams[0]->codecpar;
>> >>-    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
>> >>-    if (size <= 0)
>> >>+    if (par->block_align <= 0)
>> >>          return AVERROR(EINVAL);
>> >>-    ret= av_get_packet(s->pb, pkt, size);
>> >>+    /*
>> >>+     * Compute read size to complete a read every 40ms.  Clamp to RAW_SAMPLES if
>> >>+     * larger. Use power of two as readsize for I/O efficiency.
>> >>+     */
>> >>+    size = FFMAX(par->sample_rate/25, 1);
>> >division is a bit slowish, and this is done per (small) packet.
>> >Maybe a >>4 or >>5 could be used ? (this is a minor issue)
>>
>> It's not the 80's any more
>
> i do not think this comment is appropriate in a patch review.
>
> The goal is not to be different from fast code for the sake of
> being different from fast code. Or?
>
> If a /25 is better than a >>4 or >>5 then it may make sense to
> keep /25. But to me it seemed the value was completely arbitrary
> so a /16 or /32 would do equally
>

Many common sample rates (ie. 22050, 44100, 88200, etc) don't evenly
divide by 16 or 32 - they do however by 25.
You would get oddly sized frames, which is not really advantageous.
40ms sounds like a nice round number.

- Hendrik
Michael Niedermayer March 9, 2018, 11:33 p.m.
On Fri, Mar 09, 2018 at 07:23:02PM +0100, Hendrik Leppkes wrote:
> On Fri, Mar 9, 2018 at 7:02 PM, Michael Niedermayer
> <michael@niedermayer.cc> wrote:
> > On Fri, Mar 09, 2018 at 11:18:38AM +0100, Tomas Härdin wrote:
> >> On 2018-03-09 01:40, Michael Niedermayer wrote:
> >> >On Wed, Mar 07, 2018 at 03:30:37PM +0100, Philipp M. Scholl wrote:
> >> >>  Here is the fourth version of the PCM patch with updated testcases.
> >> >>
> >> >>  The blocksize of the PCM decoder is hard-coded. This creates
> >> >>unnecessary delay when reading low-rate (<100Hz) streams. This creates
> >> >>issues when multiplexing multiple streams, since other inputs are only
> >> >>opened/read after a low-rate input block was completely read.
> >> >>
> >> >>  This patch decreases the blocksize for low-rate inputs, so
> >> >>approximately a block is read every 40ms. This decreases the startup
> >> >>delay when multiplexing inputs with different rates.
> >> >>
> >> >>Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
> >> >>---
> >> >>  libavformat/pcm.c         | 16 ++++++++++++----
> >> >>  tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------------------
> >> >>  tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------------------
> >> >>  3 files changed, 54 insertions(+), 46 deletions(-)
> >> >>
> >> >>diff --git a/libavformat/pcm.c b/libavformat/pcm.c
> >> >>index 806f91b6b..1ea15a9e8 100644
> >> >>--- a/libavformat/pcm.c
> >> >>+++ b/libavformat/pcm.c
> >> >>@@ -28,13 +28,21 @@
> >> >>  int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
> >> >>  {
> >> >>-    int ret, size;
> >> >>+    int ret, size = INT_MAX;
> >> >>+    AVCodecParameters *par = s->streams[0]->codecpar;
> >> >>-    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
> >> >>-    if (size <= 0)
> >> >>+    if (par->block_align <= 0)
> >> >>          return AVERROR(EINVAL);
> >> >>-    ret= av_get_packet(s->pb, pkt, size);
> >> >>+    /*
> >> >>+     * Compute read size to complete a read every 40ms.  Clamp to RAW_SAMPLES if
> >> >>+     * larger. Use power of two as readsize for I/O efficiency.
> >> >>+     */
> >> >>+    size = FFMAX(par->sample_rate/25, 1);
> >> >division is a bit slowish, and this is done per (small) packet.
> >> >Maybe a >>4 or >>5 could be used ? (this is a minor issue)
> >>
> >> It's not the 80's any more
> >
> > i do not think this comment is appropriate in a patch review.
> >
> > The goal is not to be different from fast code for the sake of
> > being different from fast code. Or?
> >
> > If a /25 is better than a >>4 or >>5 then it may make sense to
> > keep /25. But to me it seemed the value was completely arbitrary
> > so a /16 or /32 would do equally
> >
> 
> Many common sample rates (ie. 22050, 44100, 88200, etc) don't evenly
> divide by 16 or 32 - they do however by 25.
> You would get oddly sized frames, which is not really advantageous.

ok, that is an argument to favor /25

thx

[...]
Rostislav Pehlivanov March 10, 2018, 1:10 p.m.
On 9 March 2018 at 23:33, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Fri, Mar 09, 2018 at 07:23:02PM +0100, Hendrik Leppkes wrote:
> > On Fri, Mar 9, 2018 at 7:02 PM, Michael Niedermayer
> > <michael@niedermayer.cc> wrote:
> > > On Fri, Mar 09, 2018 at 11:18:38AM +0100, Tomas Härdin wrote:
> > >> On 2018-03-09 01:40, Michael Niedermayer wrote:
> > >> >On Wed, Mar 07, 2018 at 03:30:37PM +0100, Philipp M. Scholl wrote:
> > >> >>  Here is the fourth version of the PCM patch with updated
> testcases.
> > >> >>
> > >> >>  The blocksize of the PCM decoder is hard-coded. This creates
> > >> >>unnecessary delay when reading low-rate (<100Hz) streams. This
> creates
> > >> >>issues when multiplexing multiple streams, since other inputs are
> only
> > >> >>opened/read after a low-rate input block was completely read.
> > >> >>
> > >> >>  This patch decreases the blocksize for low-rate inputs, so
> > >> >>approximately a block is read every 40ms. This decreases the startup
> > >> >>delay when multiplexing inputs with different rates.
> > >> >>
> > >> >>Signed-off-by: Philipp M. Scholl <pscholl@bawue.de>
> > >> >>---
> > >> >>  libavformat/pcm.c         | 16 ++++++++++++----
> > >> >>  tests/ref/seek/lavf-alaw  | 42 +++++++++++++++++++++---------
> ------------
> > >> >>  tests/ref/seek/lavf-mulaw | 42 +++++++++++++++++++++---------
> ------------
> > >> >>  3 files changed, 54 insertions(+), 46 deletions(-)
> > >> >>
> > >> >>diff --git a/libavformat/pcm.c b/libavformat/pcm.c
> > >> >>index 806f91b6b..1ea15a9e8 100644
> > >> >>--- a/libavformat/pcm.c
> > >> >>+++ b/libavformat/pcm.c
> > >> >>@@ -28,13 +28,21 @@
> > >> >>  int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
> > >> >>  {
> > >> >>-    int ret, size;
> > >> >>+    int ret, size = INT_MAX;
> > >> >>+    AVCodecParameters *par = s->streams[0]->codecpar;
> > >> >>-    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
> > >> >>-    if (size <= 0)
> > >> >>+    if (par->block_align <= 0)
> > >> >>          return AVERROR(EINVAL);
> > >> >>-    ret= av_get_packet(s->pb, pkt, size);
> > >> >>+    /*
> > >> >>+     * Compute read size to complete a read every 40ms.  Clamp to
> RAW_SAMPLES if
> > >> >>+     * larger. Use power of two as readsize for I/O efficiency.
> > >> >>+     */
> > >> >>+    size = FFMAX(par->sample_rate/25, 1);
> > >> >division is a bit slowish, and this is done per (small) packet.
> > >> >Maybe a >>4 or >>5 could be used ? (this is a minor issue)
> > >>
> > >> It's not the 80's any more
> > >
> > > i do not think this comment is appropriate in a patch review.
> > >
> > > The goal is not to be different from fast code for the sake of
> > > being different from fast code. Or?
> > >
> > > If a /25 is better than a >>4 or >>5 then it may make sense to
> > > keep /25. But to me it seemed the value was completely arbitrary
> > > so a /16 or /32 would do equally
> > >
> >
> > Many common sample rates (ie. 22050, 44100, 88200, etc) don't evenly
> > divide by 16 or 32 - they do however by 25.
> > You would get oddly sized frames, which is not really advantageous.
>
> ok, that is an argument to favor /25
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> What does censorship reveal? It reveals fear. -- Julian Assange
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
Besides, pretty much all compilers will optimize that to a multiply + a
right shift.

Patch hide | download patch | download mbox

diff --git a/libavformat/pcm.c b/libavformat/pcm.c
index 806f91b6b..1ea15a9e8 100644
--- a/libavformat/pcm.c
+++ b/libavformat/pcm.c
@@ -28,13 +28,21 @@ 
 
 int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    int ret, size;
+    int ret, size = INT_MAX;
+    AVCodecParameters *par = s->streams[0]->codecpar;
 
-    size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
-    if (size <= 0)
+    if (par->block_align <= 0)
         return AVERROR(EINVAL);
 
-    ret= av_get_packet(s->pb, pkt, size);
+    /*
+     * Compute read size to complete a read every 40ms.  Clamp to RAW_SAMPLES if
+     * larger. Use power of two as readsize for I/O efficiency.
+     */
+    size = FFMAX(par->sample_rate/25, 1);
+    size = FFMIN(size, RAW_SAMPLES) * par->block_align;
+    size = 1 << ff_log2(size);
+
+    ret = av_get_packet(s->pb, pkt, size);
 
     pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
     pkt->stream_index = 0;
diff --git a/tests/ref/seek/lavf-alaw b/tests/ref/seek/lavf-alaw
index 4b1f8fbc0..b61e687a4 100644
--- a/tests/ref/seek/lavf-alaw
+++ b/tests/ref/seek/lavf-alaw
@@ -1,53 +1,53 @@ 
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:0  ts:-1.000000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.894150 pts: 1.894150 pos:  41766 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.894150 pts: 1.894150 pos:  41766 size:   512
 ret: 0         st: 0 flags:0  ts: 0.788345
-ret: 0         st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos:  17383 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos:  17383 size:   512
 ret: 0         st: 0 flags:1  ts:-0.317506
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:0  ts: 2.576668
 ret:-EOF
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos:  32432 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos:  32432 size:   512
 ret: 0         st: 0 flags:0  ts: 0.364989
-ret: 0         st: 0 flags:1 dts: 0.364989 pts: 0.364989 pos:   8048 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.364989 pts: 0.364989 pos:   8048 size:   512
 ret: 0         st: 0 flags:1  ts:-0.740816
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:0  ts: 2.153336
 ret:-EOF
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 1.047483 pts: 1.047483 pos:  23097 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.047483 pts: 1.047483 pos:  23097 size:   512
 ret: 0         st: 0 flags:0  ts:-0.058322
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:1  ts: 2.835828
 ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 1.730023 pts: 1.730023 pos:  38147 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.730023 pts: 1.730023 pos:  38147 size:   512
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos:  13763 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos:  13763 size:   512
 ret: 0         st: 0 flags:0  ts:-0.481678
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:1  ts: 2.412517
 ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos:  28812 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos:  28812 size:   512
 ret: 0         st:-1 flags:1  ts: 0.200839
-ret: 0         st: 0 flags:1 dts: 0.200816 pts: 0.200816 pos:   4428 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.200816 pts: 0.200816 pos:   4428 size:   512
 ret: 0         st: 0 flags:0  ts:-0.904989
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:1  ts: 1.989161
 ret: 0         st: 0 flags:1 dts: 1.989161 pts: 1.989161 pos:  43861 size:   239
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.883356 pts: 0.883356 pos:  19478 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.883356 pts: 0.883356 pos:  19478 size:   512
 ret: 0         st:-1 flags:1  ts:-0.222493
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:0  ts: 2.671655
 ret:-EOF
 ret: 0         st: 0 flags:1  ts: 1.565850
-ret: 0         st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos:  34527 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos:  34527 size:   512
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos:  10143 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos:  10143 size:   512
 ret: 0         st:-1 flags:1  ts:-0.645825
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
diff --git a/tests/ref/seek/lavf-mulaw b/tests/ref/seek/lavf-mulaw
index 4b1f8fbc0..b61e687a4 100644
--- a/tests/ref/seek/lavf-mulaw
+++ b/tests/ref/seek/lavf-mulaw
@@ -1,53 +1,53 @@ 
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:0  ts:-1.000000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.894150 pts: 1.894150 pos:  41766 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.894150 pts: 1.894150 pos:  41766 size:   512
 ret: 0         st: 0 flags:0  ts: 0.788345
-ret: 0         st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos:  17383 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos:  17383 size:   512
 ret: 0         st: 0 flags:1  ts:-0.317506
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:0  ts: 2.576668
 ret:-EOF
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos:  32432 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos:  32432 size:   512
 ret: 0         st: 0 flags:0  ts: 0.364989
-ret: 0         st: 0 flags:1 dts: 0.364989 pts: 0.364989 pos:   8048 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.364989 pts: 0.364989 pos:   8048 size:   512
 ret: 0         st: 0 flags:1  ts:-0.740816
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st:-1 flags:0  ts: 2.153336
 ret:-EOF
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 1.047483 pts: 1.047483 pos:  23097 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.047483 pts: 1.047483 pos:  23097 size:   512
 ret: 0         st: 0 flags:0  ts:-0.058322
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:1  ts: 2.835828
 ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 1.730023 pts: 1.730023 pos:  38147 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.730023 pts: 1.730023 pos:  38147 size:   512
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos:  13763 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos:  13763 size:   512
 ret: 0         st: 0 flags:0  ts:-0.481678
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:1  ts: 2.412517
 ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos:  28812 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos:  28812 size:   512
 ret: 0         st:-1 flags:1  ts: 0.200839
-ret: 0         st: 0 flags:1 dts: 0.200816 pts: 0.200816 pos:   4428 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.200816 pts: 0.200816 pos:   4428 size:   512
 ret: 0         st: 0 flags:0  ts:-0.904989
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:1  ts: 1.989161
 ret: 0         st: 0 flags:1 dts: 1.989161 pts: 1.989161 pos:  43861 size:   239
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.883356 pts: 0.883356 pos:  19478 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.883356 pts: 0.883356 pos:  19478 size:   512
 ret: 0         st:-1 flags:1  ts:-0.222493
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512
 ret: 0         st: 0 flags:0  ts: 2.671655
 ret:-EOF
 ret: 0         st: 0 flags:1  ts: 1.565850
-ret: 0         st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos:  34527 size:  1024
+ret: 0         st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos:  34527 size:   512
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos:  10143 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos:  10143 size:   512
 ret: 0         st:-1 flags:1  ts:-0.645825
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  1024
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   512