Re: [libav-devel] [PATCH 1/1] aarch64: vp9: loop filter: replace 'orr; cbn?z' with 'adds; b.{eq,ne};

2016-11-14 Thread Martin Storsjö

On Mon, 14 Nov 2016, Janne Grunau wrote:


The latter is 1 cycle faster on a cortex-53 and since the operands are
bytewise (or larger) bitmask (impossible to overflow to zero) both are
equivalent.
---
libavcodec/aarch64/vp9lpf_neon.S | 31 ---
1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/libavcodec/aarch64/vp9lpf_neon.S b/libavcodec/aarch64/vp9lpf_neon.S
index 392794b..e9c7d9e 100644
--- a/libavcodec/aarch64/vp9lpf_neon.S
+++ b/libavcodec/aarch64/vp9lpf_neon.S
@@ -218,13 +218,15 @@
xtn_sz  v5, v6.8h,  v7.8h,  \sz
and v4\sz,  v4\sz,  v5\sz // fm

+// If no pixels need filtering, just exit as soon as possible
mov x5,  v4.d[0]
.ifc \sz, .16b
mov x6,  v4.d[1]
-orr x5,  x5,  x6
-.endif
-// If no pixels need filtering, just exit as soon as possible
+addsx5,  x5,  x6
+b.eq9f
+.else
cbz x5,  9f
+.endif

.if \wd >= 8
moviv0\sz,  #1
@@ -344,15 +346,17 @@
bit v22\sz, v0\sz,  v5\sz   // if (!hev && fm && 
!flat8in)
bit v25\sz, v2\sz,  v5\sz

+// If no pixels need flat8in, jump to flat8out
+// (or to a writeout of the inner 4 pixels, for wd=8)
.if \wd >= 8
mov x5,  v6.d[0]
.ifc \sz, .16b
mov x6,  v6.d[1]
-orr x5,  x5,  x6
-.endif
-// If no pixels need flat8in, jump to flat8out
-// (or to a writeout of the inner 4 pixels, for wd=8)
+addsx5,  x5,  x6
+b.eq6f
+.else
cbz x5,  6f
+.endif

// flat8in
uaddl_sz\tmp1\().8h, \tmp2\().8h,  v20, v21, \sz
@@ -406,20 +410,25 @@
mov x5,  v2.d[0]
.ifc \sz, .16b
mov x6,  v2.d[1]
-orr x5,  x5,  x6
+adds x5,  x5,  x6
+b.ne1f
+.else
+cbnzx5,  1f
.endif
// If no pixels needed flat8in nor flat8out, jump to a
// writeout of the inner 4 pixels
-cbnzx5,  1f
br  x14
1:
+
mov x5,  v7.d[0]
.ifc \sz, .16b
mov x6,  v7.d[1]
-orr x5,  x5,  x6
+adds x5,  x5,  x6
+b.ne1f
+.else
+cbnzx5,  1f
.endif
// If no pixels need flat8out, jump to a writeout of the inner 6 pixels
-cbnzx5,  1f
br  x15

1:
--
2.10.2


LGTM, thanks!

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/1] aarch64: vp9: loop filter: replace 'orr; cbn?z' with 'adds; b.{eq,ne};

2016-11-14 Thread Janne Grunau
The latter is 1 cycle faster on a cortex-53 and since the operands are
bytewise (or larger) bitmask (impossible to overflow to zero) both are
equivalent.
---
 libavcodec/aarch64/vp9lpf_neon.S | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/libavcodec/aarch64/vp9lpf_neon.S b/libavcodec/aarch64/vp9lpf_neon.S
index 392794b..e9c7d9e 100644
--- a/libavcodec/aarch64/vp9lpf_neon.S
+++ b/libavcodec/aarch64/vp9lpf_neon.S
@@ -218,13 +218,15 @@
 xtn_sz  v5, v6.8h,  v7.8h,  \sz
 and v4\sz,  v4\sz,  v5\sz // fm
 
+// If no pixels need filtering, just exit as soon as possible
 mov x5,  v4.d[0]
 .ifc \sz, .16b
 mov x6,  v4.d[1]
-orr x5,  x5,  x6
-.endif
-// If no pixels need filtering, just exit as soon as possible
+addsx5,  x5,  x6
+b.eq9f
+.else
 cbz x5,  9f
+.endif
 
 .if \wd >= 8
 moviv0\sz,  #1
@@ -344,15 +346,17 @@
 bit v22\sz, v0\sz,  v5\sz   // if (!hev && fm && 
!flat8in)
 bit v25\sz, v2\sz,  v5\sz
 
+// If no pixels need flat8in, jump to flat8out
+// (or to a writeout of the inner 4 pixels, for wd=8)
 .if \wd >= 8
 mov x5,  v6.d[0]
 .ifc \sz, .16b
 mov x6,  v6.d[1]
-orr x5,  x5,  x6
-.endif
-// If no pixels need flat8in, jump to flat8out
-// (or to a writeout of the inner 4 pixels, for wd=8)
+addsx5,  x5,  x6
+b.eq6f
+.else
 cbz x5,  6f
+.endif
 
 // flat8in
 uaddl_sz\tmp1\().8h, \tmp2\().8h,  v20, v21, \sz
@@ -406,20 +410,25 @@
 mov x5,  v2.d[0]
 .ifc \sz, .16b
 mov x6,  v2.d[1]
-orr x5,  x5,  x6
+adds x5,  x5,  x6
+b.ne1f
+.else
+cbnzx5,  1f
 .endif
 // If no pixels needed flat8in nor flat8out, jump to a
 // writeout of the inner 4 pixels
-cbnzx5,  1f
 br  x14
 1:
+
 mov x5,  v7.d[0]
 .ifc \sz, .16b
 mov x6,  v7.d[1]
-orr x5,  x5,  x6
+adds x5,  x5,  x6
+b.ne1f
+.else
+cbnzx5,  1f
 .endif
 // If no pixels need flat8out, jump to a writeout of the inner 6 pixels
-cbnzx5,  1f
 br  x15
 
 1:
-- 
2.10.2

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] libopusdec: fix out-of-bounds read

2016-11-14 Thread Hendrik Leppkes
On Mon, Nov 14, 2016 at 9:55 PM, Andreas Cadhalpun
 wrote:
> On 14.11.2016 20:54, Anton Khirnov wrote:
>> Quoting Andreas Cadhalpun (2016-11-14 20:30:10)
>>> On 14.11.2016 00:01, Luca Barbato wrote:
 On 13/11/2016 19:23, Andreas Cadhalpun wrote:
> avc->channels can be 0.

 0 and less than zero shouldn't be an error?
>>>
>>> Such values should be rejected, wherever they are set.
>>> However, ensuring that is a larger change I'm currently
>>> working on.
>>> Meanwhile, this patch is a trivial fix for the potential
>>> security problem that can easily be backported.
>>
>> channels being zero is perfectly valid, it means the caller does not
>> know the channel count and expects the decoder to read it from the
>> bitstream.
>
> In general code this is correct, however if e.g. the matroska demuxer
> reads an audio stream which claims to have 0 channels, it should
> be rejected as broken.
>

Well, not necessarily. Just because the container info is wrong or
missing does not mean the stream is undecodable - not all containers
have such levels of info after all, or sometimes none (see mpegts).
Compressed codecs are often designed to be independent of container info.

- Hendrik
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] aarch64: vp9: use alternative returns in the core loop filter function

2016-11-14 Thread Martin Storsjö

On Mon, 14 Nov 2016, Janne Grunau wrote:


On 2016-11-14 11:59:39 +0200, Martin Storsjö wrote:

On Mon, 14 Nov 2016, Janne Grunau wrote:


Since aarch64 has enough free general purpose registers use them to
branch to the appropiate storage code. 1-2 cycles faster for the
functions using loop_filter 8/16, ... on a cortex-a53. Mixed results
(up to 2 cycles faster/slower) on a cortex-a57.
---
libavcodec/aarch64/vp9lpf_neon.S | 48 +++-
1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/libavcodec/aarch64/vp9lpf_neon.S b/libavcodec/aarch64/vp9lpf_neon.S
index 995a97d..3a82bd4 100644
--- a/libavcodec/aarch64/vp9lpf_neon.S
+++ b/libavcodec/aarch64/vp9lpf_neon.S
@@ -410,15 +410,19 @@
.endif
   // If no pixels needed flat8in nor flat8out, jump to a
   // writeout of the inner 4 pixels
-cbz x5,  7f
+cbnzx5,  1f
+br  x14
+1:
   mov x5,  v7.d[0]
.ifc \sz, .16b
   mov x6,  v2.d[1]
   orr x5,  x5,  x6
.endif
   // If no pixels need flat8out, jump to a writeout of the inner 6 pixels
-cbz x5,  8f
+cbnzx5,  1f
+br  x15

+1:
   // flat8out
   // This writes all outputs into v2-v17 (skipping v6 and v16).
   // If this part is skipped, the output is read from v21-v26 (which is 
the input
@@ -549,35 +553,24 @@ endfunc

function vp9_loop_filter_8
   loop_filter 8,  .8b,  0,v16, v17, v18, v19, v28, v29, v30, v31
-mov x5,  #0
   ret
6:
-mov x5,  #6
-ret
+br  x13
9:
   br  x10
endfunc


Looks really neat, thanks!

Couldn't you get rid of the 6: label here as well, with something like this?

@@ -352,7 +352,13 @@
 .endif
 // If no pixels need flat8in, jump to flat8out
 // (or to a writeout of the inner 4 pixels, for wd=8)
+.if \wd == 16
 cbz x5,  6f
+.else
+cbnzx5,  6f
+br  x13
+6:
+.endif


I don't think this will have a measurable effect. If anything it could
make branch prediction for the full loop filter worse (static branch
prediction is "conditional branch is not taken"). It also makes the
already complicated loop filter macro a little bit more complicated to
remove mostly clear code after the macro instantiation. So I think we
shouldn't do it.


Right, yes, and at most, it removes one branch step from the return path 
for the already fast-ish early exits.


Patch ok then.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] checkasm: vp9dsp: Benchmark the dc-only version of idct_idct separately

2016-11-14 Thread Martin Storsjö
The dc-only mode is already checked to work correctly above, but this
allows benchmarking this mode for performance tuning, and allows making
sure that it actually is correctly hooked up.
---
 tests/checkasm/vp9dsp.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/tests/checkasm/vp9dsp.c b/tests/checkasm/vp9dsp.c
index 690e0cf..b9d1c73 100644
--- a/tests/checkasm/vp9dsp.c
+++ b/tests/checkasm/vp9dsp.c
@@ -297,6 +297,12 @@ static void check_itxfm(void)
 }
 bench_new(dst, sz * SIZEOF_PIXEL, coef, sz * sz);
 }
+if (txtp == 0 && tx != 4) {
+if (check_func(dsp.itxfm_add[tx][txtp], 
"vp9_inv_%s_%dx%d_dc_add",
+   txtp_types[txtp], sz, sz)) {
+bench_new(dst, sz * SIZEOF_PIXEL, coef, 1);
+}
+}
 }
 }
 report("itxfm");
-- 
2.7.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] aarch64: vp9: use alternative returns in the core loop filter function

2016-11-14 Thread Janne Grunau
On 2016-11-14 11:59:39 +0200, Martin Storsjö wrote:
> On Mon, 14 Nov 2016, Janne Grunau wrote:
> 
> >Since aarch64 has enough free general purpose registers use them to
> >branch to the appropiate storage code. 1-2 cycles faster for the
> >functions using loop_filter 8/16, ... on a cortex-a53. Mixed results
> >(up to 2 cycles faster/slower) on a cortex-a57.
> >---
> >libavcodec/aarch64/vp9lpf_neon.S | 48 
> >+++-
> >1 file changed, 18 insertions(+), 30 deletions(-)
> >
> >diff --git a/libavcodec/aarch64/vp9lpf_neon.S 
> >b/libavcodec/aarch64/vp9lpf_neon.S
> >index 995a97d..3a82bd4 100644
> >--- a/libavcodec/aarch64/vp9lpf_neon.S
> >+++ b/libavcodec/aarch64/vp9lpf_neon.S
> >@@ -410,15 +410,19 @@
> >.endif
> >// If no pixels needed flat8in nor flat8out, jump to a
> >// writeout of the inner 4 pixels
> >-cbz x5,  7f
> >+cbnzx5,  1f
> >+br  x14
> >+1:
> >mov x5,  v7.d[0]
> >.ifc \sz, .16b
> >mov x6,  v2.d[1]
> >orr x5,  x5,  x6
> >.endif
> >// If no pixels need flat8out, jump to a writeout of the inner 6 
> > pixels
> >-cbz x5,  8f
> >+cbnzx5,  1f
> >+br  x15
> >
> >+1:
> >// flat8out
> >// This writes all outputs into v2-v17 (skipping v6 and v16).
> >// If this part is skipped, the output is read from v21-v26 (which 
> > is the input
> >@@ -549,35 +553,24 @@ endfunc
> >
> >function vp9_loop_filter_8
> >loop_filter 8,  .8b,  0,v16, v17, v18, v19, v28, v29, v30, 
> > v31
> >-mov x5,  #0
> >ret
> >6:
> >-mov x5,  #6
> >-ret
> >+br  x13
> >9:
> >br  x10
> >endfunc
> 
> Looks really neat, thanks!
> 
> Couldn't you get rid of the 6: label here as well, with something like this?
> 
> @@ -352,7 +352,13 @@
>  .endif
>  // If no pixels need flat8in, jump to flat8out
>  // (or to a writeout of the inner 4 pixels, for wd=8)
> +.if \wd == 16
>  cbz x5,  6f
> +.else
> +cbnzx5,  6f
> +br  x13
> +6:
> +.endif

I don't think this will have a measurable effect. If anything it could 
make branch prediction for the full loop filter worse (static branch 
prediction is "conditional branch is not taken"). It also makes the 
already complicated loop filter macro a little bit more complicated to 
remove mostly clear code after the macro instantiation. So I think we 
shouldn't do it.

> And similarly for the 9: label for all cases except \wd == 16 (where 
> we need it for the clobbered registers).

the same applies here. I tried a different approach for the \wd == 16 
case: mov x12, x30 and using x10 instead to return to the stack 
clean-up. That ended up 1 cycle slower for the adr x10, 
$stack_clean_label though.

Janne
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] libopusdec: fix out-of-bounds read

2016-11-14 Thread Andreas Cadhalpun
On 14.11.2016 20:54, Anton Khirnov wrote:
> Quoting Andreas Cadhalpun (2016-11-14 20:30:10)
>> On 14.11.2016 00:01, Luca Barbato wrote:
>>> On 13/11/2016 19:23, Andreas Cadhalpun wrote:
 avc->channels can be 0.
>>>
>>> 0 and less than zero shouldn't be an error?
>>
>> Such values should be rejected, wherever they are set.
>> However, ensuring that is a larger change I'm currently
>> working on.
>> Meanwhile, this patch is a trivial fix for the potential
>> security problem that can easily be backported.
> 
> channels being zero is perfectly valid, it means the caller does not
> know the channel count and expects the decoder to read it from the
> bitstream.

In general code this is correct, however if e.g. the matroska demuxer
reads an audio stream which claims to have 0 channels, it should
be rejected as broken.

> This should fail for codecs that do not store this
> information in the bitstream, but work fine otherwise.
> 
> In the case of opus, the channel count is always known -- when the
> extradata is present, the channel count is stored there. Otherwise the
> stream is simple and can be decoded either as mono or stereo, as we
> want.
> 
> The patch does not seem to be doing the right thing -- I think it will
> simply fail on the opus_multistream_decoder_create() call.

Correct.

> What it should do instead is just default to stereo.

OK, patch doing that is attached.

> Even better, you could replace the whole extradata parsing block with
> a call to ff_opus_parse_extradata(), though that would require some
> refactoring.

The fix should be easily backportable, which excludes refactoring.

Best regards,
Andreas
>From d33ded293d15e8ceab666bea834d436f3a225bcc Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun 
Date: Mon, 14 Nov 2016 21:41:45 +0100
Subject: [PATCH] libopusdec: default to stereo for invalid number of channels

This fixes an out-of-bounds read if avc->channels is 0.

Signed-off-by: Andreas Cadhalpun 
---
 libavcodec/libopusdec.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index acc62f1..61f68ed 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -47,6 +47,12 @@ static av_cold int libopus_decode_init(AVCodecContext *avc)
 int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
 
+if (avc->channels <= 0) {
+av_log(avc, AV_LOG_WARNING,
+   "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
+avc->channels = 2;
+}
+
 avc->sample_rate= 48000;
 avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
   AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
-- 
2.10.2

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 1/4] lavu: Add a video section to general documentation

2016-11-14 Thread Diego Biurrun
s/general/Doxygen/

On Thu, Nov 10, 2016 at 03:16:21PM -0500, Vittorio Giovara wrote:
> --- a/libavutil/display.h
> +++ b/libavutil/display.h
> @@ -18,21 +18,37 @@
>  /**
> + * @addtogroup lavu_video
> + * @{
> + *
> + * @defgroup lavu_video_display Display transformation matrix functions
> + * @{
> + */
> +
> +/**
> + * @addtogroup lavu_video_display

Is this @addtogroup necessary? Same below..

Otherwise looks OK.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] libopusdec: fix out-of-bounds read

2016-11-14 Thread Anton Khirnov
Quoting Andreas Cadhalpun (2016-11-14 20:30:10)
> On 14.11.2016 00:01, Luca Barbato wrote:
> > On 13/11/2016 19:23, Andreas Cadhalpun wrote:
> >> avc->channels can be 0.
> > 
> > 0 and less than zero shouldn't be an error?
> 
> Such values should be rejected, wherever they are set.
> However, ensuring that is a larger change I'm currently
> working on.
> Meanwhile, this patch is a trivial fix for the potential
> security problem that can easily be backported.

channels being zero is perfectly valid, it means the caller does not
know the channel count and expects the decoder to read it from the
bitstream. This should fail for codecs that do not store this
information in the bitstream, but work fine otherwise.

In the case of opus, the channel count is always known -- when the
extradata is present, the channel count is stored there. Otherwise the
stream is simple and can be decoded either as mono or stereo, as we
want.

The patch does not seem to be doing the right thing -- I think it will
simply fail on the opus_multistream_decoder_create() call. What it
should do instead is just default to stereo. Even better, you could
replace the whole extradata parsing block with a call to
ff_opus_parse_extradata(), though that would require some refactoring.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] libopusdec: fix out-of-bounds read

2016-11-14 Thread Andreas Cadhalpun
On 14.11.2016 00:01, Luca Barbato wrote:
> On 13/11/2016 19:23, Andreas Cadhalpun wrote:
>> avc->channels can be 0.
> 
> 0 and less than zero shouldn't be an error?

Such values should be rejected, wherever they are set.
However, ensuring that is a larger change I'm currently
working on.
Meanwhile, this patch is a trivial fix for the potential
security problem that can easily be backported.

Best regards,
Andreas

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] fate: Add h264 and hevc extradata reload tests

2016-11-14 Thread Luca Barbato
On 08/11/2016 22:47, Vittorio Giovara wrote:
> Signed-off-by: Vittorio Giovara 
> ---
>  tests/fate/h264.mak  | 5 +
>  tests/fate/hevc.mak  | 5 +
>  tests/ref/fate/h264-extradata-reload | 5 +
>  tests/ref/fate/hevc-extradata-reload | 5 +
>  4 files changed, 20 insertions(+)
>  create mode 100644 tests/ref/fate/h264-extradata-reload
>  create mode 100644 tests/ref/fate/hevc-extradata-reload
> 

Ok.

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] libilbc: support for latest git of libilbc

2016-11-14 Thread Diego Biurrun
From: Gianluigi Tiesi 

In the latest git commits of libilbc developers removed WebRtc_xxx typedefs.
This commit uses int types instead. It's safe to apply also for previous
versions since WebRtc_Word16 was always a typedef of int16_t and
WebRtc_UWord16 a typedef of uint16_t.

Reviewed-by: Timothy Gu 
Signed-off-by: Diego Biurrun 
---
 libavcodec/libilbc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c
index c5053f0..a5b2f3a 100644
--- a/libavcodec/libilbc.c
+++ b/libavcodec/libilbc.c
@@ -95,8 +95,7 @@ static int ilbc_decode_frame(AVCodecContext *avctx, void 
*data,
 return ret;
 }
 
-WebRtcIlbcfix_DecodeImpl((WebRtc_Word16*) frame->data[0],
- (const WebRtc_UWord16*) buf, >decoder, 1);
+WebRtcIlbcfix_DecodeImpl((int16_t *) frame->data[0], (const uint16_t *) 
buf, >decoder, 1);
 
 *got_frame_ptr = 1;
 
@@ -168,7 +167,7 @@ static int ilbc_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 return ret;
 }
 
-WebRtcIlbcfix_EncodeImpl((WebRtc_UWord16*) avpkt->data, (const 
WebRtc_Word16*) frame->data[0], >encoder);
+WebRtcIlbcfix_EncodeImpl((uint16_t *) avpkt->data, (const int16_t *) 
frame->data[0], >encoder);
 
 avpkt->size = s->encoder.no_of_bytes;
 *got_packet_ptr = 1;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] fate: Add h264 and hevc extradata reload tests

2016-11-14 Thread Vittorio Giovara
On Tue, Nov 8, 2016 at 4:47 PM, Vittorio Giovara
 wrote:
> Signed-off-by: Vittorio Giovara 
> ---
>  tests/fate/h264.mak  | 5 +
>  tests/fate/hevc.mak  | 5 +
>  tests/ref/fate/h264-extradata-reload | 5 +
>  tests/ref/fate/hevc-extradata-reload | 5 +
>  4 files changed, 20 insertions(+)
>  create mode 100644 tests/ref/fate/h264-extradata-reload
>  create mode 100644 tests/ref/fate/hevc-extradata-reload
>
> diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
> index 24e0c9c..635abcd 100644
> --- a/tests/fate/h264.mak
> +++ b/tests/fate/h264.mak
> @@ -185,6 +185,10 @@ FATE_H264  := $(FATE_H264:%=fate-h264-conformance-%) 
>\
>
>  FATE_H264-$(call DEMDEC, H264, H264) += $(FATE_H264)
>  FATE_H264-$(call DEMDEC,  MOV, H264) += fate-h264-crop-to-container
> +
> +# this sample has two stsd entries and needs to reload extradata
> +FATE_H264-$(call DEMDEC,  MOV, H264) += fate-h264-extradata-reload
> +
>  FATE_H264-$(call DEMDEC,  MOV, H264) += fate-h264-interlace-crop
>
>  # this sample has invalid reference list modification, but decodes fine
> @@ -384,6 +388,7 @@ fate-h264-conformance-sva_nl2_e:  CMD = 
> framecrc -i $(TARGET_SAM
>  fate-h264-bsf-mp4toannexb:CMD = md5 -i 
> $(TARGET_SAMPLES)/h264/interlaced_crop.mp4 -vcodec copy -bsf h264_mp4toannexb 
> -f h264
>  fate-h264-crop-to-container:  CMD = framemd5 -i 
> $(TARGET_SAMPLES)/h264/crop-to-container-dims-canon.mov
>  fate-h264-direct-bff: CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/direct-bff.mkv
> +fate-h264-extradata-reload:   CMD = framemd5 -i 
> $(TARGET_SAMPLES)/h264/extradata-reload-multi-stsd.mov
>  fate-h264-extreme-plane-pred: CMD = framemd5 -i 
> $(TARGET_SAMPLES)/h264/extreme-plane-pred.h264
>  fate-h264-interlace-crop: CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/interlaced_crop.mp4 -frames:v 3
>  fate-h264-intra-refresh-recovery: CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/intra_refresh.h264 -frames:v 10
> diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
> index fc4ce23..5446969 100644
> --- a/tests/fate/hevc.mak
> +++ b/tests/fate/hevc.mak
> @@ -160,6 +160,11 @@ FATE_HEVC += fate-hevc-paramchange-yuv420p-yuv420p10
>
>  FATE_HEVC-$(call DEMDEC, HEVC, HEVC) += $(FATE_HEVC)
>
> +# this sample has two stsd entries and needs to reload extradata
> +FATE_HEVC-$(call DEMDEC, MOV, HEVC) += fate-hevc-extradata-reload
> +
> +fate-hevc-extradata-reload: CMD = framemd5 -i 
> $(TARGET_SAMPLES)/hevc/extradata-reload-multi-stsd.mov
> +
>  FATE_SAMPLES_AVCONV += $(FATE_HEVC-yes)
>
>  fate-hevc: $(FATE_HEVC-yes)
> diff --git a/tests/ref/fate/h264-extradata-reload 
> b/tests/ref/fate/h264-extradata-reload
> new file mode 100644
> index 000..53e47aa
> --- /dev/null
> +++ b/tests/ref/fate/h264-extradata-reload
> @@ -0,0 +1,5 @@
> +#tb 0: 1/25
> +0,  0,  0,1,49152, 
> ae09c88e87e3ea0aa8ad267ee91222e5
> +0,  1,  1,1,49152, 
> 7ccd8321a6e23ae1f82bd323c8376524
> +0,  2,  2,1,49152, 
> 8ed93ab585ff9848801cc28b75b5e12d
> +0,  3,  3,1,49152, 
> 0049913870ddb62ffc535282018766f4
> diff --git a/tests/ref/fate/hevc-extradata-reload 
> b/tests/ref/fate/hevc-extradata-reload
> new file mode 100644
> index 000..9fcab71
> --- /dev/null
> +++ b/tests/ref/fate/hevc-extradata-reload
> @@ -0,0 +1,5 @@
> +#tb 0: 1/25
> +0,  0,  0,1,24576, 
> 0d01217c5d1ec6799643fc7d75ba2337
> +0,  1,  1,1,24576, 
> f73d9cca9b4c1765d0ead242c3f0c339
> +0,  2,  2,1,24576, 
> 39a8714d763c623ae7f6faae34e107d1
> +0,  3,  3,1,24576, 
> 5db2600aa268b4fd28b64ab28a096f32
> --
> 2.10.0
>

ping
-- 
Vittorio
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] lavu: Add a video section to general documentation

2016-11-14 Thread Vittorio Giovara
On Thu, Nov 10, 2016 at 3:16 PM, Vittorio Giovara
 wrote:
> Fill it with AVStereo3D and AVDisplayMatrix documentation.
> Apply the necessary changes to make verbatim code look good in doxygen.
>
> Signed-off-by: Vittorio Giovara 
> ---
>  libavutil/avutil.h   |  6 ++
>  libavutil/display.h  | 27 +++
>  libavutil/stereo3d.h | 39 +++
>  3 files changed, 72 insertions(+)
>
> diff --git a/libavutil/avutil.h b/libavutil/avutil.h
> index c49685a..2339fe3 100644
> --- a/libavutil/avutil.h
> +++ b/libavutil/avutil.h
> @@ -115,6 +115,12 @@
>   *
>   * @}
>   *
> + * @defgroup lavu_video Video related
> + *
> + * @{
> + *
> + * @}
> + *
>   * @defgroup lavu_audio Audio related
>   *
>   * @{
> diff --git a/libavutil/display.h b/libavutil/display.h
> index dba3b1e..2d869fc 100644
> --- a/libavutil/display.h
> +++ b/libavutil/display.h
> @@ -18,21 +18,37 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>
> +/**
> + * @file
> + * Display matrix
> + */
> +
>  #ifndef AVUTIL_DISPLAY_H
>  #define AVUTIL_DISPLAY_H
>
>  #include 
>
>  /**
> + * @addtogroup lavu_video
> + * @{
> + *
> + * @defgroup lavu_video_display Display transformation matrix functions
> + * @{
> + */
> +
> +/**
> + * @addtogroup lavu_video_display
>   * The display transformation matrix specifies an affine transformation that
>   * should be applied to video frames for correct presentation. It is 
> compatible
>   * with the matrices stored in the ISO/IEC 14496-12 container format.
>   *
>   * The data is a 3x3 matrix represented as a 9-element array:
>   *
> + * @code{.unparsed}
>   *  | a b u |
>   *   (a, b, u, c, d, v, x, y, w) -> | c d v |
>   *  | x y w |
> + * @endcode
>   *
>   * All numbers are stored in native endianness, as 16.16 fixed-point values,
>   * except for u, v and w, which are stored as 2.30 fixed-point values.
> @@ -40,15 +56,21 @@
>   * The transformation maps a point (p, q) in the source (pre-transformation)
>   * frame to the point (p', q') in the destination (post-transformation) 
> frame as
>   * follows:
> + *
> + * @code{.unparsed}
>   *   | a b u |
>   *   (p, q, 1) . | c d v | = z * (p', q', 1)
>   *   | x y w |
> + * @endcode
>   *
>   * The transformation can also be more explicitly written in components as
>   * follows:
> + *
> + * @code{.unparsed}
>   *   p' = (a * p + c * q + x) / z;
>   *   q' = (b * p + d * q + y) / z;
>   *   z  =  u * p + v * q + w
> + * @endcode
>   */
>
>  /**
> @@ -83,4 +105,9 @@ void av_display_rotation_set(int32_t matrix[9], double 
> angle);
>   */
>  void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip);
>
> +/**
> + * @}
> + * @}
> + */
> +
>  #endif /* AVUTIL_DISPLAY_H */
> diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h
> index aea1b70..9c943c0 100644
> --- a/libavutil/stereo3d.h
> +++ b/libavutil/stereo3d.h
> @@ -18,6 +18,11 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>
> +/**
> + * @file
> + * Stereoscopic video
> + */
> +
>  #ifndef AVUTIL_STEREO3D_H
>  #define AVUTIL_STEREO3D_H
>
> @@ -25,6 +30,21 @@
>
>  #include "frame.h"
>
> +/**
> + * @addtogroup lavu_video
> + * @{
> + *
> + * @defgroup lavu_video_stereo3d Stereo3D types and functions
> + * @{
> + */
> +
> +/**
> + * @addtogroup lavu_video_stereo3d
> + * A stereoscopic video file consists in multiple views embedded in a single
> + * frame, usually describing two views of a scene. This file describes all
> + * possible codec-independent view arrangements.
> + * */
> +
>  /**
>   * List of possible 3D Types
>   */
> @@ -37,41 +57,49 @@ enum AVStereo3DType {
>  /**
>   * Views are next to each other.
>   *
> + * @code{.unparsed}
>   *
>   *
>   *
>   *...
> + * @endcode
>   */
>  AV_STEREO3D_SIDEBYSIDE,
>
>  /**
>   * Views are on top of each other.
>   *
> + * @code{.unparsed}
>   *
>   *
>   *
>   *
> + * @endcode
>   */
>  AV_STEREO3D_TOPBOTTOM,
>
>  /**
>   * Views are alternated temporally.
>   *
> + * @code{.unparsed}
>   * frame0   frame1   frame2   ...
>   *  
>   *  
>   *  
>   *...  ...  ...
> + * @endcode
>   */
>  AV_STEREO3D_FRAMESEQUENCE,
>
>  /**
>   * Views are packed in a checkerboard-like structure per pixel.
>   *
> + * @code{.unparsed}
>   *LRLRLRLR
>   *RLRLRLRL
>   *LRLRLRLR
>   *...
> + * @endcode
>   */
>  AV_STEREO3D_CHECKERBOARD,
>
> @@ -79,30 +107,36 @@ enum AVStereo3DType {
>   * Views are next 

Re: [libav-devel] [PATCH 8/8] qsv_h265: Use hardware H.265 plugins by default

2016-11-14 Thread Mark Thompson
On 13/11/16 10:16, Hendrik Leppkes wrote:
> On Sun, Nov 13, 2016 at 11:03 AM, Mark Thompson  wrote:
>> Hardware support is now widespread for both decode (since Braswell)
>> and encode (since Skylake), so change to using the hardware codec
>> plugins by default.
>> ---
>> The previous version only changed the decoder, the encoder should be changed 
>> in the same way too.
> 
> Didn't this still crash on systems where its unsupported?
> That seems like an unfortunate default, unless you can make proper
> runtime selection of a non-crashing mode.

On further consideration I'm going to drop this change for now; being unable to 
test is just fatal to doing anything sensible.

I may come back to it when I have a setup which can reproduce the failure.

Thanks,

- Mark

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Diego Biurrun
On Mon, Nov 14, 2016 at 12:11:47PM +0100, Anton Khirnov wrote:
> Quoting Diego Biurrun (2016-11-14 11:58:34)
> > On Mon, Nov 14, 2016 at 11:40:22AM +0100, Anton Khirnov wrote:
> > > Quoting Diego Biurrun (2016-11-14 10:27:32)
> > > > On Mon, Nov 14, 2016 at 10:12:02AM +0100, Anton Khirnov wrote:
> > > > > Quoting Diego Biurrun (2016-11-14 10:03:43)
> > > > > > On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> > > > > > > Quoting Diego Biurrun (2016-11-14 09:05:33)
> > > > > > > > Fixes a number of warnings of the type
> > > > > > > > libavutil/hmac.c:61:21: warning: assignment from incompatible 
> > > > > > > > pointer type
> > > > > > > 
> > > > > > > No, this does not "fix" anything. It hides real warnings caused 
> > > > > > > by real
> > > > > > > problems. I really wish you stopped fixing warnings and perhaps 
> > > > > > > fixed
> > > > > > > the bugs that cause those warnings instead.
> > > > > > 
> > > > > > Interestingly, this patch is from Kostya. I'm open to your 
> > > > > > suggestion
> > > > > > of the "real fix".
> > > > > 
> > > > > What does it matter who is it from? It is wrong. The compiler prints a
> > > > > warning because you're calling a function using a wrong signature
> > > > > (signed int vs unsigned). Strictly speaking, this is UB. The only 
> > > > > thing
> > > > > this patch does is shut up the warning, but the problem is still 
> > > > > there -
> > > > > you are still calling a function using a wrong signature.
> > > > 
> > > > No, the signed vs. unsigned thing is not the issue and does not affect 
> > > > the
> > > > warning(s).
> > > 
> > > It may not be the _only_ reason for the warnings, but it is certainly
> > > one of the reasons.
> > 
> > You always need a cast to assign non-identical function pointers.
> > 
> > What is it that you suggest should be done? Change the API for sha and
> > md5 take unsigned or size_t as type for the length parameter? We use
> > nt as type for sizes in 99% of all cases throughout the codebase.
> 
> MD5 already takes int, it's just SHA that's unsigned. Ideally all of
> those should be size_t, so breaking API is one possibility.

I've been advocating for size_t for sizes, but I have to admit that it
feels a tad arbitrary to require size_t now given the amount of int-typed
size variables that we have everywhere and that you yourself use even in
current code.

> Another, non-breaking one, would be to add wrappers to hmac.c, similarly
> to what it already does for sha init.

That would be pointless indirection IMO. Notice that the sha init wrappers
pass an extra parameter of a fixed size.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] build: Drop unnecessary libavcodec <-> libavformat object dependencies

2016-11-14 Thread Diego Biurrun
On Mon, Nov 14, 2016 at 01:15:09PM +0100, Guillaume POIRIER wrote:
> On Mon, Jun 27, 2016 at 4:22 PM, Diego Biurrun  wrote:
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -640,28 +640,13 @@ OBJS-$(CONFIG_ISO_MEDIA)   += 
> > mpeg4audio.o mpegaudiodata.o
> >
> >  OBJS-$(CONFIG_ADTS_MUXER)  += mpeg4audio.o
> >  OBJS-$(CONFIG_CAF_DEMUXER) += ac3tab.o
> > -OBJS-$(CONFIG_FLAC_MUXER)  += flac.o flacdata.o
> >  OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o
> > -OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o
> > -OBJS-$(CONFIG_IFF_DEMUXER) += iff.o
> >  OBJS-$(CONFIG_LATM_MUXER)  += mpeg4audio.o
> > -OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)+= mpeg4audio.o  \
> > -  flac.o flacdata.o
> 
> [..]
> 
> Would you mind sharing how you managed to find that these dependencies
> were unneeded? I imagine you didn't do it manually...

IIRC I did a git-grep for the externally visible symbols in those object
files.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 01/13] examples/qsvdec: switch to the hwcontext API

2016-11-14 Thread Luca Barbato
On 10/11/2016 16:51, Anton Khirnov wrote:
> The code now does not depend on VA and will work on windows as well.
> ---
>  configure |   2 +-
>  doc/examples/qsvdec.c | 317 
> --
>  2 files changed, 52 insertions(+), 267 deletions(-)
> 

Sounds good to me.

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] crypto: Add encryption support

2016-11-14 Thread Luca Barbato
On 14/11/2016 13:56, Anton Khirnov wrote:
> Quoting Luca Barbato (2016-11-11 00:49:48)
>> From: Christian Suloway 
>>
>> Signed-off-by: Christian Suloway 
>> Signed-off-by: Michael Niedermayer 
>> Signed-off-by: Luca Barbato 
>> ---
>>
>> Now it is using a av_fast_malloc'd buffer, and all the other nits are
>> addressed as well.
>>
>>  libavformat/crypto.c | 166 
>> ---
>>  1 file changed, 146 insertions(+), 20 deletions(-)
>>
>> diff --git a/libavformat/crypto.c b/libavformat/crypto.c
>> index 55430c4..ba17a5a 100644
>> --- a/libavformat/crypto.c
>> +++ b/libavformat/crypto.c
>> @@ -41,14 +41,32 @@ typedef struct CryptoContext {
>>  int keylen;
>>  uint8_t *iv;
>>  int ivlen;
>> -struct AVAES *aes;
>> +uint8_t *decrypt_key;
>> +int decrypt_keylen;
>> +uint8_t *decrypt_iv;
>> +int decrypt_ivlen;
>> +uint8_t *encrypt_key;
>> +int encrypt_keylen;
>> +uint8_t *encrypt_iv;
>> +int encrypt_ivlen;
>> +struct AVAES *aes_decrypt;
>> +struct AVAES *aes_encrypt;
>> +uint8_t *write_buf;
>> +unsigned int write_buf_size;
>> +uint8_t pad[BLOCKSIZE];
>> +int pad_len;
>>  } CryptoContext;
>>
>>  #define OFFSET(x) offsetof(CryptoContext, x)
>>  #define D AV_OPT_FLAG_DECODING_PARAM
>> +#define E AV_OPT_FLAG_ENCODING_PARAM
>>  static const AVOption options[] = {
>> -{"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, .flags = 
>> D },
>> -{"iv",  "AES decryption initialization vector", OFFSET(iv), 
>> AV_OPT_TYPE_BINARY, .flags = D },
>> +{"key", "AES encryption/decryption key",   OFFSET(key), 
>> AV_OPT_TYPE_BINARY, .flags = D|E },
>> +{"iv",  "AES encryption/decryption initialization vector", OFFSET(iv),  
>> AV_OPT_TYPE_BINARY, .flags = D|E },
>> +{"decryption_key", "AES decryption key",   
>> OFFSET(decrypt_key), AV_OPT_TYPE_BINARY, .flags = D },
>> +{"decryption_iv",  "AES decryption initialization vector", 
>> OFFSET(decrypt_iv),  AV_OPT_TYPE_BINARY, .flags = D },
>> +{"encryption_key", "AES encryption key",   
>> OFFSET(encrypt_key), AV_OPT_TYPE_BINARY, .flags = E },
>> +{"encryption_iv",  "AES encryption initialization vector", 
>> OFFSET(encrypt_iv),  AV_OPT_TYPE_BINARY, .flags = E },
>>  { NULL }
>>  };
>>
>> @@ -59,6 +77,34 @@ static const AVClass crypto_class = {
>>  .version= LIBAVUTIL_VERSION_INT,
>>  };
>>
>> +static int set_aes_arg(URLContext *h, uint8_t **buf, int *buf_len,
>> +   uint8_t *default_buf, int default_buf_len,
>> +   const char *desc)
>> +{
>> +if (!*buf_len) {
>> +if (!default_buf_len) {
>> +av_log(h, AV_LOG_ERROR, "%s not set\n", desc);
>> +return AVERROR(EINVAL);
>> +} else if (default_buf_len != BLOCKSIZE) {
>> +av_log(h, AV_LOG_ERROR,
>> +   "invalid %s size (%d bytes, block size is %d)\n",
>> +   desc, default_buf_len, BLOCKSIZE);
>> +return AVERROR(EINVAL);
>> +}
>> +*buf = av_malloc(default_buf_len);
>> +if (!*buf)
>> +return AVERROR(ENOMEM);
>> +memcpy(*buf, default_buf, default_buf_len);
>> +*buf_len = default_buf_len;
>> +} else if (*buf_len != BLOCKSIZE) {
>> +av_log(h, AV_LOG_ERROR,
>> +   "invalid %s size (%d bytes, block size is %d)\n",
>> +   desc, *buf_len, BLOCKSIZE);
>> +return AVERROR(EINVAL);
>> +}
>> +return 0;
>> +}
>> +
>>  static int crypto_open(URLContext *h, const char *uri, int flags)
>>  {
>>  const char *nested_url;
>> @@ -72,28 +118,52 @@ static int crypto_open(URLContext *h, const char *uri, 
>> int flags)
>>  goto err;
>>  }
>>
>> -if (c->keylen < BLOCKSIZE || c->ivlen < BLOCKSIZE) {
>> -av_log(h, AV_LOG_ERROR, "Key or IV not set\n");
>> -ret = AVERROR(EINVAL);
>> -goto err;
>> +if (flags & AVIO_FLAG_READ) {
>> +if ((ret = set_aes_arg(h, >decrypt_key, >decrypt_keylen,
>> +   c->key, c->keylen, "decryption key")) < 0)
>> +goto err;
>> +if ((ret = set_aes_arg(h, >decrypt_iv, >decrypt_ivlen,
>> +   c->iv, c->ivlen, "decryption IV")) < 0)
>> +goto err;
>>  }
>> +
>>  if (flags & AVIO_FLAG_WRITE) {
>> -av_log(h, AV_LOG_ERROR, "Only decryption is supported currently\n");
>> -ret = AVERROR(ENOSYS);
>> -goto err;
>> +if ((ret = set_aes_arg(h, >encrypt_key, >encrypt_keylen,
>> +   c->key, c->keylen, "encryption key")) < 0)
>> +if (ret < 0)
>> +goto err;
>> +if ((ret = set_aes_arg(h, >encrypt_iv, >encrypt_ivlen,
>> +   c->iv, c->ivlen, 

Re: [libav-devel] [RFC] avpacket: Mark src pointer as constant

2016-11-14 Thread Anton Khirnov
Quoting Vittorio Giovara (2016-11-10 22:13:49)
> (
> 
> On Thu, Nov 10, 2016 at 3:34 PM, Luca Barbato  wrote:
> > On 08/11/2016 21:04, Vittorio Giovara wrote:
> >> Seems right, is that the only instance in the header?
> >
> > Yes, anybody against in adding that as is?
> 
> what about av_packet_clone()?

Yes, should be added to both.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 01/13] examples/qsvdec: switch to the hwcontext API

2016-11-14 Thread Anton Khirnov
ping on the set

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] build: Drop unnecessary libavcodec <-> libavformat object dependencies

2016-11-14 Thread Guillaume POIRIER
Hi Diego,

On Mon, Jun 27, 2016 at 4:22 PM, Diego Biurrun  wrote:
> ---
>  libavcodec/Makefile | 15 ---
>  1 file changed, 15 deletions(-)
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index f86ccb8..ef7f35e 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -640,28 +640,13 @@ OBJS-$(CONFIG_ISO_MEDIA)   += mpeg4audio.o 
> mpegaudiodata.o
>
>  OBJS-$(CONFIG_ADTS_MUXER)  += mpeg4audio.o
>  OBJS-$(CONFIG_CAF_DEMUXER) += ac3tab.o
> -OBJS-$(CONFIG_FLAC_MUXER)  += flac.o flacdata.o
>  OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o
> -OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o
> -OBJS-$(CONFIG_IFF_DEMUXER) += iff.o
>  OBJS-$(CONFIG_LATM_MUXER)  += mpeg4audio.o
> -OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)+= mpeg4audio.o  \
> -  flac.o flacdata.o


[..]



Would you mind sharing how you managed to find that these dependencies
were unneeded? I imagine you didn't do it manually...

Regards,

Guillaume
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 34/35] qcelp: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/qcelpdec.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index e9e7347..9d5e13a 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -31,9 +31,10 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
-#include "get_bits.h"
 #include "qcelpdata.h"
 #include "celp_filters.h"
 #include "acelp_filters.h"
@@ -53,7 +54,7 @@ typedef enum {
 } qcelp_packet_rate;
 
 typedef struct QCELPContext {
-GetBitContext gb;
+BitstreamContext  bc;
 qcelp_packet_rate bitrate;
 QCELPFrameframe;/**< unpacked data frame */
 
@@ -718,12 +719,12 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void 
*data,
  
qcelp_unpacking_bitmaps_lengths[q->bitrate];
 uint8_t *unpacked_data = (uint8_t *)>frame;
 
-init_get_bits(>gb, buf, 8 * buf_size);
+bitstream_init(>bc, buf, 8 * buf_size);
 
 memset(>frame, 0, sizeof(QCELPFrame));
 
 for (; bitmaps < bitmaps_end; bitmaps++)
-unpacked_data[bitmaps->index] |= get_bits(>gb, bitmaps->bitlen) 
<< bitmaps->bitpos;
+unpacked_data[bitmaps->index] |= bitstream_read(>bc, 
bitmaps->bitlen) << bitmaps->bitpos;
 
 // Check for erasures/blanks on rates 1, 1/4 and 1/8.
 if (q->frame.reserved) {
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 32/35] opus: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/opus.h| 6 +++---
 libavcodec/opusdec.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 55c91fa..fbf67c9 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -32,7 +32,7 @@
 #include "libavresample/avresample.h"
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 
 #define MAX_FRAME_SIZE   1275
 #define MAX_FRAMES   48
@@ -92,7 +92,7 @@ typedef struct RawBitsContext {
 } RawBitsContext;
 
 typedef struct OpusRangeCoder {
-GetBitContext gb;
+BitstreamContext bc;
 RawBitsContext rb;
 unsigned int range;
 unsigned int value;
@@ -196,7 +196,7 @@ typedef struct OpusContext {
 static av_always_inline void opus_rc_normalize(OpusRangeCoder *rc)
 {
 while (rc->range <= 1<<23) {
-rc->value = ((rc->value << 8) | (get_bits(>gb, 8) ^ 0xFF)) & ((1u 
<< 31) - 1);
+rc->value = ((rc->value << 8) | (bitstream_read(>bc, 8) ^ 0xFF)) & 
((1u << 31) - 1);
 rc->range  <<= 8;
 rc->total_read_bits += 8;
 }
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index 92e651c..163f0d5 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -43,9 +43,9 @@
 #include "libavresample/avresample.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "celp_filters.h"
 #include "fft.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "mathops.h"
 #include "opus.h"
@@ -80,12 +80,12 @@ static int get_silk_samplerate(int config)
  */
 static int opus_rc_init(OpusRangeCoder *rc, const uint8_t *data, int size)
 {
-int ret = init_get_bits8(>gb, data, size);
+int ret = bitstream_init8(>bc, data, size);
 if (ret < 0)
 return ret;
 
 rc->range = 128;
-rc->value = 127 - get_bits(>gb, 7);
+rc->value = 127 - bitstream_read(>bc, 7);
 rc->total_read_bits = 9;
 opus_rc_normalize(rc);
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 28/35] hq_hqa: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/hq_hqa.c | 48 
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index 98bd596..0d03e59 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -24,8 +24,8 @@
 #include "libavutil/intreadwrite.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "canopus.h"
-#include "get_bits.h"
 #include "internal.h"
 
 #include "hq_hqa.h"
@@ -59,7 +59,7 @@ static inline void put_blocks(HQContext *c, AVFrame *pic,
  pic->linesize[plane] << ilace, block1);
 }
 
-static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64],
+static int hq_decode_block(HQContext *c, BitstreamContext *bc, int16_t 
block[64],
int qsel, int is_chroma, int is_hqa)
 {
 const int32_t *q;
@@ -68,15 +68,15 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, 
int16_t block[64],
 memset(block, 0, 64 * sizeof(*block));
 
 if (!is_hqa) {
-block[0] = get_sbits(gb, 9) << 6;
-q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)];
+block[0] = bitstream_read_signed(bc, 9) << 6;
+q = ff_hq_quants[qsel][is_chroma][bitstream_read(bc, 2)];
 } else {
-q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)];
-block[0] = get_sbits(gb, 9) << 6;
+q = ff_hq_quants[qsel][is_chroma][bitstream_read(bc, 2)];
+block[0] = bitstream_read_signed(bc, 9) << 6;
 }
 
 for (;;) {
-val = get_vlc2(gb, c->hq_ac_vlc.table, 9, 2);
+val = bitstream_read_vlc(bc, c->hq_ac_vlc.table, 9, 2);
 if (val < 0)
 return AVERROR_INVALIDDATA;
 
@@ -91,16 +91,16 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, 
int16_t block[64],
 }
 
 static int hq_decode_mb(HQContext *c, AVFrame *pic,
-GetBitContext *gb, int x, int y)
+BitstreamContext *bc, int x, int y)
 {
 int qgroup, flag;
 int i, ret;
 
-qgroup = get_bits(gb, 4);
-flag = get_bits1(gb);
+qgroup = bitstream_read(bc, 4);
+flag   = bitstream_read_bit(bc);
 
 for (i = 0; i < 8; i++) {
-ret = hq_decode_block(c, gb, c->block[i], qgroup, i >= 4, 0);
+ret = hq_decode_block(c, bc, c->block[i], qgroup, i >= 4, 0);
 if (ret < 0)
 return ret;
 }
@@ -117,7 +117,7 @@ static int hq_decode_frame(HQContext *ctx, AVFrame *pic,
int prof_num, size_t data_size)
 {
 const HQProfile *profile;
-GetBitContext gb;
+BitstreamContext bc;
 const uint8_t *perm, *src = ctx->gbc.buffer;
 uint32_t slice_off[21];
 int slice, start_off, next_off, i, ret;
@@ -160,11 +160,11 @@ static int hq_decode_frame(HQContext *ctx, AVFrame *pic,
"Invalid slice size %zu.\n", data_size);
 break;
 }
-init_get_bits(, src + slice_off[slice],
-  (slice_off[slice + 1] - slice_off[slice]) * 8);
+bitstream_init(, src + slice_off[slice],
+   (slice_off[slice + 1] - slice_off[slice]) * 8);
 
 for (i = 0; i < (next_off - start_off) * profile->tab_w; i++) {
-ret = hq_decode_mb(ctx, pic, , perm[0] * 16, perm[1] * 16);
+ret = hq_decode_mb(ctx, pic, , perm[0] * 16, perm[1] * 16);
 if (ret < 0) {
 av_log(ctx->avctx, AV_LOG_ERROR,
"Error decoding macroblock %d at slice %d.\n", i, 
slice);
@@ -178,12 +178,12 @@ static int hq_decode_frame(HQContext *ctx, AVFrame *pic,
 }
 
 static int hqa_decode_mb(HQContext *c, AVFrame *pic, int qgroup,
- GetBitContext *gb, int x, int y)
+ BitstreamContext *bc, int x, int y)
 {
 int flag = 0;
 int i, ret, cbp;
 
-cbp = get_vlc2(gb, c->hqa_cbp_vlc.table, 5, 1);
+cbp = bitstream_read_vlc(bc, c->hqa_cbp_vlc.table, 5, 1);
 
 for (i = 0; i < 12; i++)
 memset(c->block[i], 0, sizeof(*c->block));
@@ -191,7 +191,7 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int 
qgroup,
 c->block[i][0] = -128 * (1 << 6);
 
 if (cbp) {
-flag = get_bits1(gb);
+flag = bitstream_read_bit(bc);
 
 cbp |= cbp << 4;
 if (cbp & 0x3)
@@ -201,7 +201,7 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int 
qgroup,
 for (i = 0; i < 12; i++) {
 if (!(cbp & (1 << i)))
 continue;
-ret = hq_decode_block(c, gb, c->block[i], qgroup, i >= 8, 1);
+ret = hq_decode_block(c, bc, c->block[i], qgroup, i >= 8, 1);
 if (ret < 0)
 return ret;
 }
@@ -217,7 +217,7 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int 
qgroup,
 return 0;
 }
 
-static int hqa_decode_slice(HQContext *ctx, AVFrame *pic, GetBitContext *gb,
+static int hqa_decode_slice(HQContext *ctx, 

[libav-devel] [PATCH 35/35] qdm2: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/qdm2.c | 200 +++---
 1 file changed, 100 insertions(+), 100 deletions(-)

diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 7a7c149..781999a 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -39,7 +39,7 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 #include "mpegaudio.h"
 #include "mpegaudiodsp.h"
@@ -361,31 +361,31 @@ static av_cold void qdm2_init_vlc(void)
  INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
 }
 
-static int qdm2_get_vlc(GetBitContext *gb, VLC *vlc, int flag, int depth)
+static int qdm2_get_vlc(BitstreamContext *bc, VLC *vlc, int flag, int depth)
 {
 int value;
 
-value = get_vlc2(gb, vlc->table, vlc->bits, depth);
+value = bitstream_read_vlc(bc, vlc->table, vlc->bits, depth);
 
 /* stage-2, 3 bits exponent escape sequence */
 if (value-- == 0)
-value = get_bits(gb, get_bits(gb, 3) + 1);
+value = bitstream_read(bc, bitstream_read(bc, 3) + 1);
 
 /* stage-3, optional */
 if (flag) {
 int tmp = vlc_stage3_values[value];
 
 if ((value & ~3) > 0)
-tmp += get_bits(gb, (value >> 2));
+tmp += bitstream_read(bc, value >> 2);
 value = tmp;
 }
 
 return value;
 }
 
-static int qdm2_get_se_vlc(VLC *vlc, GetBitContext *gb, int depth)
+static int qdm2_get_se_vlc(VLC *vlc, BitstreamContext *bc, int depth)
 {
-int value = qdm2_get_vlc(gb, vlc, 0, depth);
+int value = qdm2_get_vlc(bc, vlc, 0, depth);
 
 return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
 }
@@ -412,35 +412,35 @@ static uint16_t qdm2_packet_checksum(const uint8_t *data, 
int length, int value)
 /**
  * Fill a QDM2SubPacket structure with packet type, size, and data pointer.
  *
- * @param gbbitreader context
+ * @param bcbitreader context
  * @param sub_packetpacket under analysis
  */
-static void qdm2_decode_sub_packet_header(GetBitContext *gb,
+static void qdm2_decode_sub_packet_header(BitstreamContext *bc,
   QDM2SubPacket *sub_packet)
 {
-sub_packet->type = get_bits(gb, 8);
+sub_packet->type = bitstream_read(bc, 8);
 
 if (sub_packet->type == 0) {
 sub_packet->size = 0;
 sub_packet->data = NULL;
 } else {
-sub_packet->size = get_bits(gb, 8);
+sub_packet->size = bitstream_read(bc, 8);
 
 if (sub_packet->type & 0x80) {
 sub_packet->size <<= 8;
-sub_packet->size  |= get_bits(gb, 8);
+sub_packet->size  |= bitstream_read(bc, 8);
 sub_packet->type  &= 0x7f;
 }
 
 if (sub_packet->type == 0x7f)
-sub_packet->type |= (get_bits(gb, 8) << 8);
+sub_packet->type |= bitstream_read(bc, 8) << 8;
 
 // FIXME: this depends on bitreader-internal data
-sub_packet->data = >buffer[get_bits_count(gb) / 8];
+sub_packet->data = >buffer[bitstream_tell(bc) / 8];
 }
 
 av_log(NULL, AV_LOG_DEBUG, "Subpacket: type=%d size=%d start_offs=%x\n",
-   sub_packet->type, sub_packet->size, get_bits_count(gb) / 8);
+   sub_packet->type, sub_packet->size, bitstream_tell(bc) / 8);
 }
 
 /**
@@ -799,12 +799,12 @@ static void fill_coding_method_array(sb_int8_array 
tone_level_idx,
  * sb 8-sb_used.
  *
  * @param q context
- * @param gbbitreader context
+ * @param bcbitreader context
  * @param lengthpacket length in bits
  * @param sb_minlower subband processed (sb_min included)
  * @param sb_maxhigher subband processed (sb_max excluded)
  */
-static void synthfilt_build_sb_samples(QDM2Context *q, GetBitContext *gb,
+static void synthfilt_build_sb_samples(QDM2Context *q, BitstreamContext *bc,
int length, int sb_min, int sb_max)
 {
 int sb, j, k, n, ch, run, channels;
@@ -830,12 +830,12 @@ static void synthfilt_build_sb_samples(QDM2Context *q, 
GetBitContext *gb,
 else if (sb >= 24)
 joined_stereo = 1;
 else
-joined_stereo = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;
+joined_stereo = (bitstream_bits_left(bc) >= 1) ? 
bitstream_read_bit(bc) : 0;
 
 if (joined_stereo) {
-if (get_bits_left(gb) >= 16)
+if (bitstream_bits_left(bc) >= 16)
 for (j = 0; j < 16; j++)
-sign_bits[j] = get_bits1(gb);
+sign_bits[j] = bitstream_read_bit(bc);
 
 for (j = 0; j < 64; j++)
 if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])
@@ -851,22 +851,22 @@ static void synthfilt_build_sb_samples(QDM2Context *q, 
GetBitContext *gb,
 
 for (ch = 0; ch < channels; ch++) {
 FIX_NOISE_IDX(q->noise_idx);
-zero_encoding = (get_bits_left(gb) >= 1) ? 

[libav-devel] [PATCH 30/35] jvdec: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/jvdec.c | 52 ++--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/libavcodec/jvdec.c b/libavcodec/jvdec.c
index c532b75..37a2770 100644
--- a/libavcodec/jvdec.c
+++ b/libavcodec/jvdec.c
@@ -28,8 +28,8 @@
 #include "libavutil/intreadwrite.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "blockdsp.h"
-#include "get_bits.h"
 #include "internal.h"
 
 typedef struct JvContext {
@@ -62,84 +62,84 @@ static av_cold int decode_init(AVCodecContext *avctx)
 /**
  * Decode 2x2 block
  */
-static inline void decode2x2(GetBitContext *gb, uint8_t *dst, int linesize)
+static inline void decode2x2(BitstreamContext *bc, uint8_t *dst, int linesize)
 {
 int i, j, v[2];
 
-switch (get_bits(gb, 2)) {
+switch (bitstream_read(bc, 2)) {
 case 1:
-v[0] = get_bits(gb, 8);
+v[0] = bitstream_read(bc, 8);
 for (j = 0; j < 2; j++)
 memset(dst + j * linesize, v[0], 2);
 break;
 case 2:
-v[0] = get_bits(gb, 8);
-v[1] = get_bits(gb, 8);
+v[0] = bitstream_read(bc, 8);
+v[1] = bitstream_read(bc, 8);
 for (j = 0; j < 2; j++)
 for (i = 0; i < 2; i++)
-dst[j * linesize + i] = v[get_bits1(gb)];
+dst[j * linesize + i] = v[bitstream_read_bit(bc)];
 break;
 case 3:
 for (j = 0; j < 2; j++)
 for (i = 0; i < 2; i++)
-dst[j * linesize + i] = get_bits(gb, 8);
+dst[j * linesize + i] = bitstream_read(bc, 8);
 }
 }
 
 /**
  * Decode 4x4 block
  */
-static inline void decode4x4(GetBitContext *gb, uint8_t *dst, int linesize)
+static inline void decode4x4(BitstreamContext *bc, uint8_t *dst, int linesize)
 {
 int i, j, v[2];
 
-switch (get_bits(gb, 2)) {
+switch (bitstream_read(bc, 2)) {
 case 1:
-v[0] = get_bits(gb, 8);
+v[0] = bitstream_read(bc, 8);
 for (j = 0; j < 4; j++)
 memset(dst + j * linesize, v[0], 4);
 break;
 case 2:
-v[0] = get_bits(gb, 8);
-v[1] = get_bits(gb, 8);
+v[0] = bitstream_read(bc, 8);
+v[1] = bitstream_read(bc, 8);
 for (j = 2; j >= 0; j -= 2) {
 for (i = 0; i < 4; i++)
-dst[j * linesize + i] = v[get_bits1(gb)];
+dst[j * linesize + i] = v[bitstream_read_bit(bc)];
 for (i = 0; i < 4; i++)
-dst[(j + 1) * linesize + i] = v[get_bits1(gb)];
+dst[(j + 1) * linesize + i] = v[bitstream_read_bit(bc)];
 }
 break;
 case 3:
 for (j = 0; j < 4; j += 2)
 for (i = 0; i < 4; i += 2)
-decode2x2(gb, dst + j * linesize + i, linesize);
+decode2x2(bc, dst + j * linesize + i, linesize);
 }
 }
 
 /**
  * Decode 8x8 block
  */
-static inline void decode8x8(GetBitContext *gb, uint8_t *dst, int linesize,
+static inline void decode8x8(BitstreamContext *bc, uint8_t *dst, int linesize,
  BlockDSPContext *bdsp)
 {
 int i, j, v[2];
 
-switch (get_bits(gb, 2)) {
+switch (bitstream_read(bc, 2)) {
 case 1:
-v[0] = get_bits(gb, 8);
+v[0] = bitstream_read(bc, 8);
 bdsp->fill_block_tab[1](dst, v[0], linesize, 8);
 break;
 case 2:
-v[0] = get_bits(gb, 8);
-v[1] = get_bits(gb, 8);
+v[0] = bitstream_read(bc, 8);
+v[1] = bitstream_read(bc, 8);
 for (j = 7; j >= 0; j--)
 for (i = 0; i < 8; i++)
-dst[j * linesize + i] = v[get_bits1(gb)];
+dst[j * linesize + i] = v[bitstream_read_bit(bc)];
 break;
 case 3:
 for (j = 0; j < 8; j += 4)
 for (i = 0; i < 8; i += 4)
-decode4x4(gb, dst + j * linesize + i, linesize);
+decode4x4(bc, dst + j * linesize + i, linesize);
 }
 }
 
@@ -163,12 +163,12 @@ static int decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 }
 
 if (video_type == 0 || video_type == 1) {
-GetBitContext gb;
-init_get_bits(, buf, 8 * FFMIN(video_size, buf_end - buf));
+BitstreamContext bc;
+bitstream_init(, buf, 8 * FFMIN(video_size, buf_end - buf));
 
 for (j = 0; j < avctx->height; j += 8)
 for (i = 0; i < avctx->width; i += 8)
-decode8x8(,
+decode8x8(,
   s->frame->data[0] + j * s->frame->linesize[0] + 
i,
   s->frame->linesize[0], >bdsp);
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 27/35] gsm: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/gsmdec.c  | 11 ++-
 libavcodec/gsmdec_template.c | 34 +-
 libavcodec/msgsmdec.c|  9 +
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/libavcodec/gsmdec.c b/libavcodec/gsmdec.c
index a333e58..d727cf9 100644
--- a/libavcodec/gsmdec.c
+++ b/libavcodec/gsmdec.c
@@ -25,8 +25,9 @@
  */
 
 #include "libavutil/channel_layout.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 #include "msgsmdec.h"
 
@@ -67,7 +68,7 @@ static int gsm_decode_frame(AVCodecContext *avctx, void *data,
 {
 AVFrame *frame = data;
 int res;
-GetBitContext gb;
+BitstreamContext bc;
 const uint8_t *buf = avpkt->data;
 int buf_size = avpkt->size;
 int16_t *samples;
@@ -87,10 +88,10 @@ static int gsm_decode_frame(AVCodecContext *avctx, void 
*data,
 
 switch (avctx->codec_id) {
 case AV_CODEC_ID_GSM:
-init_get_bits(, buf, buf_size * 8);
-if (get_bits(, 4) != 0xd)
+bitstream_init(, buf, buf_size * 8);
+if (bitstream_read(, 4) != 0xd)
 av_log(avctx, AV_LOG_WARNING, "Missing GSM magic!\n");
-res = gsm_decode_block(avctx, samples, , GSM_13000);
+res = gsm_decode_block(avctx, samples, , GSM_13000);
 if (res < 0)
 return res;
 break;
diff --git a/libavcodec/gsmdec_template.c b/libavcodec/gsmdec_template.c
index 2794bd1..7437908 100644
--- a/libavcodec/gsmdec_template.c
+++ b/libavcodec/gsmdec_template.c
@@ -24,17 +24,17 @@
  * GSM decoder
  */
 
-#include "get_bits.h"
+#include "bitstream.h"
 #include "gsm.h"
 #include "gsmdec_data.h"
 
-static void apcm_dequant_add(GetBitContext *gb, int16_t *dst, const int 
*frame_bits)
+static void apcm_dequant_add(BitstreamContext *bc, int16_t *dst, const int 
*frame_bits)
 {
 int i, val;
-int maxidx = get_bits(gb, 6);
+int maxidx = bitstream_read(bc, 6);
 const int16_t *tab = ff_gsm_dequant_tab[maxidx];
 for (i = 0; i < 13; i++) {
-val = get_bits(gb, frame_bits[i]);
+val = bitstream_read(bc, frame_bits[i]);
 dst[3 * i] += tab[ff_gsm_requant_tab[frame_bits[i]][val]];
 }
 }
@@ -120,28 +120,28 @@ static int postprocess(int16_t *data, int msr)
 }
 
 static int gsm_decode_block(AVCodecContext *avctx, int16_t *samples,
-GetBitContext *gb, int mode)
+BitstreamContext *bc, int mode)
 {
 GSMContext *ctx = avctx->priv_data;
 int i;
 int16_t *ref_dst = ctx->ref_buf + 120;
 int *lar = ctx->lar[ctx->lar_idx];
-lar[0] = decode_log_area(get_bits(gb, 6), 13107,  1 << 15);
-lar[1] = decode_log_area(get_bits(gb, 6), 13107,  1 << 15);
-lar[2] = decode_log_area(get_bits(gb, 5), 13107, (1 << 14) + 2048*2);
-lar[3] = decode_log_area(get_bits(gb, 5), 13107, (1 << 14) - 2560*2);
-lar[4] = decode_log_area(get_bits(gb, 4), 19223, (1 << 13) +   94*2);
-lar[5] = decode_log_area(get_bits(gb, 4), 17476, (1 << 13) - 1792*2);
-lar[6] = decode_log_area(get_bits(gb, 3), 31454, (1 << 12) -  341*2);
-lar[7] = decode_log_area(get_bits(gb, 3), 29708, (1 << 12) - 1144*2);
+lar[0] = decode_log_area(bitstream_read(bc, 6), 13107,  1 << 15);
+lar[1] = decode_log_area(bitstream_read(bc, 6), 13107,  1 << 15);
+lar[2] = decode_log_area(bitstream_read(bc, 5), 13107, (1 << 14) + 2048 * 
2);
+lar[3] = decode_log_area(bitstream_read(bc, 5), 13107, (1 << 14) - 2560 * 
2);
+lar[4] = decode_log_area(bitstream_read(bc, 4), 19223, (1 << 13) +   94 * 
2);
+lar[5] = decode_log_area(bitstream_read(bc, 4), 17476, (1 << 13) - 1792 * 
2);
+lar[6] = decode_log_area(bitstream_read(bc, 3), 31454, (1 << 12) -  341 * 
2);
+lar[7] = decode_log_area(bitstream_read(bc, 3), 29708, (1 << 12) - 1144 * 
2);
 
 for (i = 0; i < 4; i++) {
-int lag  = get_bits(gb, 7);
-int gain_idx = get_bits(gb, 2);
-int offset   = get_bits(gb, 2);
+int lag  = bitstream_read(bc, 7);
+int gain_idx = bitstream_read(bc, 2);
+int offset   = bitstream_read(bc, 2);
 lag = av_clip(lag, 40, 120);
 long_term_synth(ref_dst, lag, gain_idx);
-apcm_dequant_add(gb, ref_dst + offset, ff_gsm_apcm_bits[mode][i]);
+apcm_dequant_add(bc, ref_dst + offset, ff_gsm_apcm_bits[mode][i]);
 ref_dst += 40;
 }
 memcpy(ctx->ref_buf, ctx->ref_buf + 160, 120 * sizeof(*ctx->ref_buf));
diff --git a/libavcodec/msgsmdec.c b/libavcodec/msgsmdec.c
index 92b5ae6..c26efa9 100644
--- a/libavcodec/msgsmdec.c
+++ b/libavcodec/msgsmdec.c
@@ -21,6 +21,7 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
+#include "bitstream.h"
 #include "gsm.h"
 #include "msgsmdec.h"
 
@@ -30,10 +31,10 @@ int ff_msgsm_decode_block(AVCodecContext *avctx, int16_t 
*samples,
   const uint8_t *buf, int mode)
 {
 int res;
-

[libav-devel] [PATCH 33/35] pcx: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/pcx.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/pcx.c b/libavcodec/pcx.c
index a2d49b4..ece885e 100644
--- a/libavcodec/pcx.c
+++ b/libavcodec/pcx.c
@@ -23,9 +23,10 @@
  */
 
 #include "libavutil/imgutils.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "internal.h"
 
 #define PCX_HEADER_SIZE 128
@@ -179,15 +180,15 @@ static int pcx_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 goto end;
 }
 } else if (nplanes == 1) {   /* all packed formats, max. 16 colors */
-GetBitContext s;
+BitstreamContext s;
 
 for (y = 0; y < h; y++) {
-init_get_bits(, scanline, bytes_per_scanline << 3);
+bitstream_init(, scanline, bytes_per_scanline << 3);
 
 pcx_rle_decode(, scanline, bytes_per_scanline, compressed);
 
 for (x = 0; x < w; x++)
-ptr[x] = get_bits(, bits_per_pixel);
+ptr[x] = bitstream_read(, bits_per_pixel);
 ptr += stride;
 }
 } else {/* planar, 4, 8 or 16 colors */
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 26/35] g72x: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/g722dec.c   | 13 -
 libavcodec/g723_1dec.c | 72 +-
 libavcodec/g726.c  | 11 
 3 files changed, 49 insertions(+), 47 deletions(-)

diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index c4c0ec8..bfd4b42 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -36,8 +36,9 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "g722.h"
 #include "internal.h"
 
@@ -92,7 +93,7 @@ static int g722_decode_frame(AVCodecContext *avctx, void 
*data,
 int j, ret;
 const int skip = 8 - c->bits_per_codeword;
 const int16_t *quantizer_table = low_inv_quants[skip];
-GetBitContext gb;
+BitstreamContext bc;
 
 /* get output buffer */
 frame->nb_samples = avpkt->size * 2;
@@ -102,15 +103,15 @@ static int g722_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 out_buf = (int16_t *)frame->data[0];
 
-init_get_bits(, avpkt->data, avpkt->size * 8);
+bitstream_init(, avpkt->data, avpkt->size * 8);
 
 for (j = 0; j < avpkt->size; j++) {
 int ilow, ihigh, rlow, rhigh, dhigh;
 int xout[2];
 
-ihigh = get_bits(, 2);
-ilow = get_bits(, 6 - skip);
-skip_bits(, skip);
+ihigh = bitstream_read(, 2);
+ilow  = bitstream_read(, 6 - skip);
+bitstream_skip(, skip);
 
 rlow = av_clip_intp2((c->band[0].scale_factor * quantizer_table[ilow] 
>> 10)
   + c->band[0].s_predictor, 14);
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index f50bed1..2ea3bbf 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -32,8 +32,8 @@
 #define BITSTREAM_READER_LE
 #include "acelp_vectors.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "celp_filters.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "g723_1.h"
 
@@ -68,14 +68,14 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
 static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
 int buf_size)
 {
-GetBitContext gb;
+BitstreamContext bc;
 int ad_cb_len;
 int temp, info_bits, i;
 
-init_get_bits(, buf, buf_size * 8);
+bitstream_init(, buf, buf_size * 8);
 
 /* Extract frame type and rate info */
-info_bits = get_bits(, 2);
+info_bits = bitstream_read(, 2);
 
 if (info_bits == 3) {
 p->cur_frame_type = UNTRANSMITTED_FRAME;
@@ -83,13 +83,13 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
 }
 
 /* Extract 24 bit lsp indices, 8 bit for each band */
-p->lsp_index[2] = get_bits(, 8);
-p->lsp_index[1] = get_bits(, 8);
-p->lsp_index[0] = get_bits(, 8);
+p->lsp_index[2] = bitstream_read(, 8);
+p->lsp_index[1] = bitstream_read(, 8);
+p->lsp_index[0] = bitstream_read(, 8);
 
 if (info_bits == 2) {
 p->cur_frame_type = SID_FRAME;
-p->subframe[0].amp_index = get_bits(, 6);
+p->subframe[0].amp_index = bitstream_read(, 6);
 return 0;
 }
 
@@ -97,23 +97,23 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
 p->cur_rate   = info_bits ? RATE_5300 : RATE_6300;
 p->cur_frame_type = ACTIVE_FRAME;
 
-p->pitch_lag[0] = get_bits(, 7);
+p->pitch_lag[0] = bitstream_read(, 7);
 if (p->pitch_lag[0] > 123)   /* test if forbidden code */
 return -1;
 p->pitch_lag[0] += PITCH_MIN;
-p->subframe[1].ad_cb_lag = get_bits(, 2);
+p->subframe[1].ad_cb_lag = bitstream_read(, 2);
 
-p->pitch_lag[1] = get_bits(, 7);
+p->pitch_lag[1] = bitstream_read(, 7);
 if (p->pitch_lag[1] > 123)
 return -1;
 p->pitch_lag[1] += PITCH_MIN;
-p->subframe[3].ad_cb_lag = get_bits(, 2);
+p->subframe[3].ad_cb_lag = bitstream_read(, 2);
 p->subframe[0].ad_cb_lag = 1;
 p->subframe[2].ad_cb_lag = 1;
 
 for (i = 0; i < SUBFRAMES; i++) {
 /* Extract combined gain */
-temp = get_bits(, 12);
+temp = bitstream_read(, 12);
 ad_cb_len = 170;
 p->subframe[i].dirac_train = 0;
 if (p->cur_rate == RATE_6300 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 
2) {
@@ -130,16 +130,16 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
 }
 }
 
-p->subframe[0].grid_index = get_bits(, 1);
-p->subframe[1].grid_index = get_bits(, 1);
-p->subframe[2].grid_index = get_bits(, 1);
-p->subframe[3].grid_index = get_bits(, 1);
+p->subframe[0].grid_index = bitstream_read(, 1);
+p->subframe[1].grid_index = bitstream_read(, 1);
+p->subframe[2].grid_index = bitstream_read(, 1);
+p->subframe[3].grid_index = bitstream_read(, 1);
 
 if (p->cur_rate == RATE_6300) {
-skip_bits(, 1);  /* skip reserved bit */
+bitstream_skip(, 1); /* skip reserved bit */
 
   

[libav-devel] [PATCH 29/35] hqx: Convert to the new bitstream header

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/hqx.c | 64 
 libavcodec/hqx.h |  5 +++--
 2 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index 7411d3f..3c359e3 100644
--- a/libavcodec/hqx.c
+++ b/libavcodec/hqx.c
@@ -24,8 +24,8 @@
 #include "libavutil/intreadwrite.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "canopus.h"
-#include "get_bits.h"
 #include "internal.h"
 
 #include "hqx.h"
@@ -95,23 +95,23 @@ static inline void put_blocks(HQXContext *ctx, int plane,
  lsize * fields, block1, quant);
 }
 
-static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac,
+static inline void hqx_get_ac(BitstreamContext *bc, const HQXAC *ac,
   int *run, int *lev)
 {
 int val;
 
-val = show_bits(gb, ac->lut_bits);
+val = bitstream_peek(bc, ac->lut_bits);
 if (ac->lut[val].bits == -1) {
-GetBitContext gb2 = *gb;
-skip_bits(, ac->lut_bits);
-val = ac->lut[val].lev + show_bits(, ac->extra_bits);
+BitstreamContext bc2 = *bc;
+bitstream_skip(, ac->lut_bits);
+val = ac->lut[val].lev + bitstream_peek(, ac->extra_bits);
 }
 *run = ac->lut[val].run;
 *lev = ac->lut[val].lev;
-skip_bits(gb, ac->lut[val].bits);
+bitstream_skip(bc, ac->lut[val].bits);
 }
 
-static int decode_block(GetBitContext *gb, VLC *vlc,
+static int decode_block(BitstreamContext *bc, VLC *vlc,
 const int *quants, int dcb,
 int16_t block[64], int *last_dc)
 {
@@ -120,14 +120,14 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
 int run, lev, pos = 1;
 
 memset(block, 0, 64 * sizeof(*block));
-dc = get_vlc2(gb, vlc->table, HQX_DC_VLC_BITS, 2);
+dc = bitstream_read_vlc(bc, vlc->table, HQX_DC_VLC_BITS, 2);
 if (dc < 0)
 return AVERROR_INVALIDDATA;
 *last_dc += dc;
 
 block[0] = sign_extend(*last_dc << (12 - dcb), 12);
 
-q = quants[get_bits(gb, 2)];
+q = quants[bitstream_read(bc, 2)];
 if (q >= 128)
 ac_idx = HQX_AC_Q128;
 else if (q >= 64)
@@ -142,7 +142,7 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
 ac_idx = HQX_AC_Q0;
 
 do {
-hqx_get_ac(gb, _hqx_ac[ac_idx], , );
+hqx_get_ac(bc, _hqx_ac[ac_idx], , );
 pos += run;
 if (pos >= 64)
 break;
@@ -155,24 +155,24 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
 static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
 {
 HQXSlice *slice = >slice[slice_no];
-GetBitContext *gb = >gb;
+BitstreamContext *bc = >bc;
 const int *quants;
 int flag;
 int last_dc;
 int i, ret;
 
 if (ctx->interlaced)
-flag = get_bits1(gb);
+flag = bitstream_read_bit(bc);
 else
 flag = 0;
 
-quants = hqx_quants[get_bits(gb, 4)];
+quants = hqx_quants[bitstream_read(bc, 4)];
 
 for (i = 0; i < 8; i++) {
 int vlc_index = ctx->dcb - 9;
 if (i == 0 || i == 4 || i == 6)
 last_dc = 0;
-ret = decode_block(gb, >dc_vlc[vlc_index], quants,
+ret = decode_block(bc, >dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], _dc);
 if (ret < 0)
 return ret;
@@ -189,14 +189,14 @@ static int hqx_decode_422(HQXContext *ctx, int slice_no, 
int x, int y)
 static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
 {
 HQXSlice *slice = >slice[slice_no];
-GetBitContext *gb = >gb;
+BitstreamContext *bc = >bc;
 const int *quants;
 int flag = 0;
 int last_dc;
 int i, ret;
 int cbp;
 
-cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
+cbp = bitstream_read_vlc(bc, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
 
 for (i = 0; i < 12; i++)
 memset(slice->block[i], 0, sizeof(**slice->block) * 64);
@@ -204,9 +204,9 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, 
int x, int y)
 slice->block[i][0] = -0x800;
 if (cbp) {
 if (ctx->interlaced)
-flag = get_bits1(gb);
+flag = bitstream_read_bit(bc);
 
-quants = hqx_quants[get_bits(gb, 4)];
+quants = hqx_quants[bitstream_read(bc, 4)];
 
 cbp |= cbp << 4; // alpha CBP
 if (cbp & 0x3)   // chroma CBP - top
@@ -218,7 +218,7 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, 
int x, int y)
 last_dc = 0;
 if (cbp & (1 << i)) {
 int vlc_index = ctx->dcb - 9;
-ret = decode_block(gb, >dc_vlc[vlc_index], quants,
+ret = decode_block(bc, >dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], _dc);
 if (ret < 0)
 return ret;
@@ -239,24 +239,24 @@ static int hqx_decode_422a(HQXContext *ctx, int 

[libav-devel] [PATCH 31/35] nellymoser: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/nellymoserdec.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index 355935f..390872c 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -38,8 +38,8 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
+#include "bitstream.h"
 #include "fft.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "nellymoser.h"
 #include "sinewin.h"
@@ -48,7 +48,7 @@
 typedef struct NellyMoserDecodeContext {
 AVCodecContext* avctx;
 AVLFG   random_state;
-GetBitContext   gb;
+BitstreamContext bc;
 float   scale_bias;
 AVFloatDSPContext fdsp;
 FFTContext  imdct_ctx;
@@ -67,14 +67,14 @@ static void nelly_decode_block(NellyMoserDecodeContext *s,
 int bits[NELLY_BUF_LEN];
 unsigned char v;
 
-init_get_bits(>gb, block, NELLY_BLOCK_LEN * 8);
+bitstream_init(>bc, block, NELLY_BLOCK_LEN * 8);
 
 bptr = buf;
 pptr = pows;
-val = ff_nelly_init_table[get_bits(>gb, 6)];
+val = ff_nelly_init_table[bitstream_read(>bc, 6)];
 for (i=0 ; i 0)
-val += ff_nelly_delta_table[get_bits(>gb, 5)];
+val += ff_nelly_delta_table[bitstream_read(>bc, 5)];
 pval = -pow(2, val/2048) * s->scale_bias;
 for (j = 0; j < ff_nelly_band_sizes_table[i]; j++) {
 *bptr++ = val;
@@ -88,8 +88,8 @@ static void nelly_decode_block(NellyMoserDecodeContext *s,
 for (i = 0; i < 2; i++) {
 aptr = audio + i * NELLY_BUF_LEN;
 
-init_get_bits(>gb, block, NELLY_BLOCK_LEN * 8);
-skip_bits_long(>gb, NELLY_HEADER_BITS + i*NELLY_DETAIL_BITS);
+bitstream_init(>bc, block, NELLY_BLOCK_LEN * 8);
+bitstream_skip(>bc, NELLY_HEADER_BITS + i * NELLY_DETAIL_BITS);
 
 for (j = 0; j < NELLY_FILL_LEN; j++) {
 if (bits[j] <= 0) {
@@ -97,7 +97,7 @@ static void nelly_decode_block(NellyMoserDecodeContext *s,
 if (av_lfg_get(>random_state) & 1)
 aptr[j] *= -1.0;
 } else {
-v = get_bits(>gb, bits[j]);
+v = bitstream_read(>bc, bits[j]);
 aptr[j] = 
ff_nelly_dequantization_table[(1<

[libav-devel] [PATCH 21/35] exr: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/exr.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index d10841d..28cee84 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -39,8 +39,8 @@
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "mathops.h"
 #include "thread.h"
@@ -379,16 +379,16 @@ static void huf_canonical_code_table(uint64_t *hcode)
 static int huf_unpack_enc_table(GetByteContext *gb,
 int32_t im, int32_t iM, uint64_t *hcode)
 {
-GetBitContext gbit;
-int ret = init_get_bits8(, gb->buffer, 
bytestream2_get_bytes_left(gb));
+BitstreamContext bc;
+int ret = bitstream_init8(, gb->buffer, bytestream2_get_bytes_left(gb));
 if (ret < 0)
 return ret;
 
 for (; im <= iM; im++) {
-uint64_t l = hcode[im] = get_bits(, 6);
+uint64_t l = hcode[im] = bitstream_read(, 6);
 
 if (l == LONG_ZEROCODE_RUN) {
-int zerun = get_bits(, 8) + SHORTEST_LONG_RUN;
+int zerun = bitstream_read(, 8) + SHORTEST_LONG_RUN;
 
 if (im + zerun > iM + 1)
 return AVERROR_INVALIDDATA;
@@ -410,7 +410,7 @@ static int huf_unpack_enc_table(GetByteContext *gb,
 }
 }
 
-bytestream2_skip(gb, (get_bits_count() + 7) / 8);
+bytestream2_skip(gb, (bitstream_tell() + 7) / 8);
 huf_canonical_code_table(hcode);
 
 return 0;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 19/35] escape124: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/escape124.c | 85 --
 1 file changed, 41 insertions(+), 44 deletions(-)

diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index 6d1b487..879f00a 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -21,7 +21,7 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 typedef union MacroBlock {
@@ -48,8 +48,9 @@ typedef struct Escape124Context {
 CodeBook codebooks[3];
 } Escape124Context;
 
-static int can_safely_read(GetBitContext* gb, int bits) {
-return get_bits_left(gb) >= bits;
+static int can_safely_read(BitstreamContext *bc, int bits)
+{
+return bitstream_bits_left(bc) >= bits;
 }
 
 /**
@@ -86,13 +87,13 @@ static av_cold int escape124_decode_close(AVCodecContext 
*avctx)
 return 0;
 }
 
-static CodeBook unpack_codebook(GetBitContext* gb, unsigned depth,
+static CodeBook unpack_codebook(BitstreamContext *bc, unsigned depth,
  unsigned size)
 {
 unsigned i, j;
 CodeBook cb = { 0 };
 
-if (!can_safely_read(gb, size * 34))
+if (!can_safely_read(bc, size * 34))
 return cb;
 
 if (size >= INT_MAX / sizeof(MacroBlock))
@@ -104,9 +105,9 @@ static CodeBook unpack_codebook(GetBitContext* gb, unsigned 
depth,
 cb.depth = depth;
 cb.size = size;
 for (i = 0; i < size; i++) {
-unsigned mask_bits = get_bits(gb, 4);
-unsigned color0 = get_bits(gb, 15);
-unsigned color1 = get_bits(gb, 15);
+unsigned mask_bits = bitstream_read(bc,  4);
+unsigned color0= bitstream_read(bc, 15);
+unsigned color1= bitstream_read(bc, 15);
 
 for (j = 0; j < 4; j++) {
 if (mask_bits & (1 << j))
@@ -118,47 +119,43 @@ static CodeBook unpack_codebook(GetBitContext* gb, 
unsigned depth,
 return cb;
 }
 
-static unsigned decode_skip_count(GetBitContext* gb)
+static unsigned decode_skip_count(BitstreamContext *bc)
 {
 unsigned value;
 // This function reads a maximum of 23 bits,
 // which is within the padding space
-if (!can_safely_read(gb, 1))
+if (!can_safely_read(bc, 1))
 return -1;
-value = get_bits1(gb);
+value = bitstream_read_bit(bc);
 if (!value)
 return value;
 
-value += get_bits(gb, 3);
+value += bitstream_read(bc, 3);
 if (value != (1 + ((1 << 3) - 1)))
 return value;
 
-value += get_bits(gb, 7);
+value += bitstream_read(bc, 7);
 if (value != (1 + ((1 << 3) - 1)) + ((1 << 7) - 1))
 return value;
 
-return value + get_bits(gb, 12);
+return value + bitstream_read(bc, 12);
 }
 
-static MacroBlock decode_macroblock(Escape124Context* s, GetBitContext* gb,
-int* codebook_index, int superblock_index)
+static MacroBlock decode_macroblock(Escape124Context *s, BitstreamContext *bc,
+int *codebook_index, int superblock_index)
 {
 // This function reads a maximum of 22 bits; the callers
 // guard this function appropriately
 unsigned block_index, depth;
-int value = get_bits1(gb);
+int value = bitstream_read_bit(bc);
 if (value) {
 static const char transitions[3][2] = { {2, 1}, {0, 2}, {1, 0} };
-value = get_bits1(gb);
+value = bitstream_read_bit(bc);
 *codebook_index = transitions[*codebook_index][value];
 }
 
 depth = s->codebooks[*codebook_index].depth;
-
-// depth = 0 means that this shouldn't read any bits;
-// in theory, this is the same as get_bits(gb, 0), but
-// that doesn't actually work.
-block_index = get_bitsz(gb, depth);
+block_index = bitstream_read(bc, depth);
 
 if (*codebook_index == 1) {
 block_index += superblock_index << s->codebooks[1].depth;
@@ -208,7 +205,7 @@ static int escape124_decode_frame(AVCodecContext *avctx,
 Escape124Context *s = avctx->priv_data;
 AVFrame *frame = data;
 
-GetBitContext gb;
+BitstreamContext bc;
 unsigned frame_flags, frame_size;
 unsigned i;
 
@@ -220,15 +217,15 @@ static int escape124_decode_frame(AVCodecContext *avctx,
 unsigned old_stride, new_stride;
 int ret;
 
-init_get_bits(, buf, buf_size * 8);
+bitstream_init(, buf, buf_size * 8);
 
 // This call also guards the potential depth reads for the
 // codebook unpacking.
-if (!can_safely_read(, 64))
+if (!can_safely_read(, 64))
 return -1;
 
-frame_flags = get_bits_long(, 32);
-frame_size  = get_bits_long(, 32);
+frame_flags = bitstream_read(, 32);
+frame_size  = bitstream_read(, 32);
 
 // Leave last frame unchanged
 // FIXME: Is this necessary?  I haven't seen it in any real samples
@@ -251,10 +248,10 @@ static int escape124_decode_frame(AVCodecContext *avctx,
 if (i == 2) {
 // This 

[libav-devel] [PATCH 25/35] g2meet: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/g2meet.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index 7e90916..4a7f5a3 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -31,10 +31,10 @@
 #include "libavutil/intreadwrite.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "blockdsp.h"
 #include "bytestream.h"
 #include "elsdec.h"
-#include "get_bits.h"
 #include "idctdsp.h"
 #include "internal.h"
 #include "jpegtables.h"
@@ -236,7 +236,7 @@ static void jpg_unescape(const uint8_t *src, int src_size,
 *dst_size = dst - dst_start;
 }
 
-static int jpg_decode_block(JPGContext *c, GetBitContext *gb,
+static int jpg_decode_block(JPGContext *c, BitstreamContext *bc,
 int plane, int16_t *block)
 {
 int dc, val, pos;
@@ -244,18 +244,18 @@ static int jpg_decode_block(JPGContext *c, GetBitContext 
*gb,
 const uint8_t *qmat = is_chroma ? chroma_quant : luma_quant;
 
 c->bdsp.clear_block(block);
-dc = get_vlc2(gb, c->dc_vlc[is_chroma].table, 9, 3);
+dc = bitstream_read_vlc(bc, c->dc_vlc[is_chroma].table, 9, 3);
 if (dc < 0)
 return AVERROR_INVALIDDATA;
 if (dc)
-dc = get_xbits(gb, dc);
+dc = bitstream_read_xbits(bc, dc);
 dc= dc * qmat[0] + c->prev_dc[plane];
 block[0]  = dc;
 c->prev_dc[plane] = dc;
 
 pos = 0;
 while (pos < 63) {
-val = get_vlc2(gb, c->ac_vlc[is_chroma].table, 9, 3);
+val = bitstream_read_vlc(bc, c->ac_vlc[is_chroma].table, 9, 3);
 if (val < 0)
 return AVERROR_INVALIDDATA;
 pos += val >> 4;
@@ -265,7 +265,7 @@ static int jpg_decode_block(JPGContext *c, GetBitContext 
*gb,
 if (val) {
 int nbits = val;
 
-val = get_xbits(gb, nbits);
+val = bitstream_read_xbits(bc, 
nbits);
 val*= qmat[ff_zigzag_direct[pos]];
 block[c->scantable.permutated[pos]] = val;
 }
@@ -286,7 +286,7 @@ static int jpg_decode_data(JPGContext *c, int width, int 
height,
const uint8_t *mask, int mask_stride, int num_mbs,
int swapuv)
 {
-GetBitContext gb;
+BitstreamContext bc;
 int mb_w, mb_h, mb_x, mb_y, i, j;
 int bx, by;
 int unesc_size;
@@ -298,7 +298,7 @@ static int jpg_decode_data(JPGContext *c, int width, int 
height,
 return ret;
 jpg_unescape(src, src_size, c->buf, _size);
 memset(c->buf + unesc_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
-init_get_bits(, c->buf, unesc_size * 8);
+bitstream_init(, c->buf, unesc_size * 8);
 
 width = FFALIGN(width, 16);
 mb_w  =  width>> 4;
@@ -325,14 +325,14 @@ static int jpg_decode_data(JPGContext *c, int width, int 
height,
 if (mask && !mask[mb_x * 2 + i + j * mask_stride])
 continue;
 num_mbs--;
-if ((ret = jpg_decode_block(c, , 0,
+if ((ret = jpg_decode_block(c, , 0,
 c->block[i + j * 2])) != 0)
 return ret;
 c->idsp.idct(c->block[i + j * 2]);
 }
 }
 for (i = 1; i < 3; i++) {
-if ((ret = jpg_decode_block(c, , i, c->block[i + 3])) != 0)
+if ((ret = jpg_decode_block(c, , i, c->block[i + 3])) != 0)
 return ret;
 c->idsp.idct(c->block[i + 3]);
 }
@@ -1011,11 +1011,11 @@ static void kempf_restore_buf(const uint8_t *src, int 
len,
   int width, int height,
   const uint8_t *pal, int npal, int tidx)
 {
-GetBitContext gb;
+BitstreamContext bc;
 int i, j, nb, col;
 int align_width = FFALIGN(width, 16);
 
-init_get_bits(, src, len * 8);
+bitstream_init(, src, len * 8);
 
 if (npal <= 2)   nb = 1;
 else if (npal <= 4)  nb = 2;
@@ -1023,16 +1023,16 @@ static void kempf_restore_buf(const uint8_t *src, int 
len,
 else nb = 8;
 
 for (j = 0; j < height; j++, dst += stride, jpeg_tile += tile_stride) {
-if (get_bits(, 8))
+if (bitstream_read(, 8))
 continue;
 for (i = 0; i < width; i++) {
-col = get_bits(, nb);
+col = bitstream_read(, nb);
 if (col != tidx)
 memcpy(dst + i * 3, pal + col * 3, 3);
 else
 memcpy(dst + i * 3, jpeg_tile + i * 3, 3);
 }
-skip_bits_long(, nb * (align_width - width));
+bitstream_skip(, nb * (align_width - width));
 }
 }
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org

[libav-devel] [PATCH 24/35] fraps: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/fraps.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 55051ff..2237991 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -32,7 +32,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "huffman.h"
 #include "bytestream.h"
 #include "bswapdsp.h"
@@ -94,7 +94,7 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, 
int stride, int w,
const int step)
 {
 int i, j, ret;
-GetBitContext gb;
+BitstreamContext bc;
 VLC vlc;
 Node nodes[512];
 
@@ -111,10 +111,10 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t 
*dst, int stride, int w,
 s->bdsp.bswap_buf((uint32_t *) s->tmpbuf,
   (const uint32_t *) src, size >> 2);
 
-init_get_bits(, s->tmpbuf, size * 8);
+bitstream_init(, s->tmpbuf, size * 8);
 for (j = 0; j < h; j++) {
 for (i = 0; i < w*step; i += step) {
-dst[i] = get_vlc2(, vlc.table, VLC_BITS, 3);
+dst[i] = bitstream_read_vlc(, vlc.table, VLC_BITS, 3);
 /* lines are stored as deltas between previous lines
  * and we need to add 0x80 to the first lines of chroma planes
  */
@@ -122,7 +122,7 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t 
*dst, int stride, int w,
 dst[i] += dst[i - stride];
 else if (Uoff)
 dst[i] += 0x80;
-if (get_bits_left() < 0) {
+if (bitstream_bits_left() < 0) {
 ff_free_vlc();
 return AVERROR_INVALIDDATA;
 }
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 23/35] flashsv: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/flashsv.c | 57 ++--
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c
index 2cf8f3f..20fa7bc 100644
--- a/libavcodec/flashsv.c
+++ b/libavcodec/flashsv.c
@@ -38,9 +38,10 @@
 #include 
 
 #include "libavutil/intreadwrite.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "internal.h"
 
 typedef struct BlockInfo {
@@ -175,7 +176,7 @@ static int flashsv2_prime(FlashSVContext *s, uint8_t *src, 
int size)
 }
 
 static int flashsv_decode_block(AVCodecContext *avctx, AVPacket *avpkt,
-GetBitContext *gb, int block_size,
+BitstreamContext *bc, int block_size,
 int width, int height, int x_pos, int y_pos,
 int blk_idx)
 {
@@ -194,7 +195,7 @@ static int flashsv_decode_block(AVCodecContext *avctx, 
AVPacket *avpkt,
 if (ret < 0)
 return ret;
 }
-s->zstream.next_in   = avpkt->data + get_bits_count(gb) / 8;
+s->zstream.next_in   = avpkt->data + bitstream_tell(bc) / 8;
 s->zstream.avail_in  = block_size;
 s->zstream.next_out  = s->tmpblock;
 s->zstream.avail_out = s->block_size * 3;
@@ -210,7 +211,7 @@ static int flashsv_decode_block(AVCodecContext *avctx, 
AVPacket *avpkt,
 }
 
 if (s->is_keyframe) {
-s->blocks[blk_idx].pos  = s->keyframedata + (get_bits_count(gb) / 8);
+s->blocks[blk_idx].pos  = s->keyframedata + (bitstream_tell(bc) / 8);
 s->blocks[blk_idx].size = block_size;
 }
 
@@ -233,7 +234,7 @@ static int flashsv_decode_block(AVCodecContext *avctx, 
AVPacket *avpkt,
   x_pos, s->diff_height, width,
   s->frame->linesize[0], s->pal);
 }
-skip_bits_long(gb, 8 * block_size); /* skip the consumed bits */
+bitstream_skip(bc, 8 * block_size); /* skip the consumed bits */
 return 0;
 }
 
@@ -259,7 +260,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void 
*data,
 int buf_size = avpkt->size;
 FlashSVContext *s = avctx->priv_data;
 int h_blocks, v_blocks, h_part, v_part, i, j, ret;
-GetBitContext gb;
+BitstreamContext bc;
 
 /* no supplementary picture */
 if (buf_size == 0)
@@ -267,21 +268,21 @@ static int flashsv_decode_frame(AVCodecContext *avctx, 
void *data,
 if (buf_size < 4)
 return -1;
 
-init_get_bits(, avpkt->data, buf_size * 8);
+bitstream_init(, avpkt->data, buf_size * 8);
 
 /* start to parse the bitstream */
-s->block_width  = 16 * (get_bits(, 4) + 1);
-s->image_width  = get_bits(, 12);
-s->block_height = 16 * (get_bits(, 4) + 1);
-s->image_height = get_bits(, 12);
+s->block_width  = 16 * (bitstream_read(, 4) + 1);
+s->image_width  = bitstream_read(, 12);
+s->block_height = 16 * (bitstream_read(, 4) + 1);
+s->image_height = bitstream_read(, 12);
 
 if (s->ver == 2) {
-skip_bits(, 6);
-if (get_bits1()) {
+bitstream_skip(, 6);
+if (bitstream_read_bit()) {
 avpriv_request_sample(avctx, "iframe");
 return AVERROR_PATCHWELCOME;
 }
-if (get_bits1()) {
+if (bitstream_read_bit()) {
 avpriv_request_sample(avctx, "Custom palette");
 return AVERROR_PATCHWELCOME;
 }
@@ -371,7 +372,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void 
*data,
 int has_diff = 0;
 
 /* get the size of the compressed zlib chunk */
-int size = get_bits(, 16);
+int size = bitstream_read(, 16);
 
 s->color_depth= 0;
 s->zlibprime_curr = 0;
@@ -379,17 +380,17 @@ static int flashsv_decode_frame(AVCodecContext *avctx, 
void *data,
 s->diff_start = 0;
 s->diff_height= cur_blk_height;
 
-if (8 * size > get_bits_left()) {
+if (8 * size > bitstream_bits_left()) {
 av_frame_unref(s->frame);
 return AVERROR_INVALIDDATA;
 }
 
 if (s->ver == 2 && size) {
-skip_bits(, 3);
-s->color_depth= get_bits(, 2);
-has_diff  = get_bits1();
-s->zlibprime_curr = get_bits1();
-s->zlibprime_prev = get_bits1();
+bitstream_skip(, 3);
+s->color_depth= bitstream_read(, 2);
+has_diff  = bitstream_read_bit();
+s->zlibprime_curr = bitstream_read_bit();
+s->zlibprime_prev = bitstream_read_bit();
 
 if (s->color_depth != 0 && s->color_depth != 2) {
 av_log(avctx, AV_LOG_ERROR,
@@ -404,8 +405,8 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void 
*data,
   

[libav-devel] [PATCH 22/35] faxcompr: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/faxcompr.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index 4cbda3f..8a9010d 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -25,7 +25,7 @@
  * @author Konstantin Shishkov
  */
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "put_bits.h"
 #include "faxcompr.h"
 
@@ -123,7 +123,7 @@ av_cold void ff_ccitt_unpack_init(void)
 }
 
 
-static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
+static int decode_group3_1d_line(AVCodecContext *avctx, BitstreamContext *bc,
  unsigned int pix_left, int *runs,
  const int *runend)
 {
@@ -131,7 +131,7 @@ static int decode_group3_1d_line(AVCodecContext *avctx, 
GetBitContext *gb,
 unsigned int run = 0;
 unsigned int t;
 for (;;) {
-t= get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
+t= bitstream_read_vlc(bc, ccitt_vlc[mode].table, 9, 2);
 run += t;
 if (t < 64) {
 *runs++ = run;
@@ -157,7 +157,7 @@ static int decode_group3_1d_line(AVCodecContext *avctx, 
GetBitContext *gb,
 return 0;
 }
 
-static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
+static int decode_group3_2d_line(AVCodecContext *avctx, BitstreamContext *bc,
  unsigned int width, int *runs,
  const int *runend, const int *ref)
 {
@@ -168,7 +168,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, 
GetBitContext *gb,
 runend--; // for the last written 0
 
 while (offs < width) {
-int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1);
+int cmode = bitstream_read_vlc(bc, ccitt_group3_2d_vlc.table, 9, 1);
 if (cmode == -1) {
 av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n");
 return AVERROR_INVALIDDATA;
@@ -188,7 +188,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, 
GetBitContext *gb,
 for (k = 0; k < 2; k++) {
 run = 0;
 for (;;) {
-t = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
+t = bitstream_read_vlc(bc, ccitt_vlc[mode].table, 9, 2);
 if (t == -1) {
 av_log(avctx, AV_LOG_ERROR, "Incorrect code\n");
 return AVERROR_INVALIDDATA;
@@ -258,12 +258,12 @@ static void put_line(uint8_t *dst, int size, int width, 
const int *runs)
 flush_put_bits();
 }
 
-static int find_group3_syncmarker(GetBitContext *gb, int srcsize)
+static int find_group3_syncmarker(BitstreamContext *bc, int srcsize)
 {
 unsigned int state = -1;
-srcsize -= get_bits_count(gb);
+srcsize -= bitstream_tell(bc);
 while (srcsize-- > 0) {
-state += state + get_bits1(gb);
+state += state + bitstream_read_bit(bc);
 if ((state & 0xFFF) == 1)
 return 0;
 }
@@ -275,7 +275,7 @@ int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t 
*src, int srcsize,
 enum TiffCompr compr, int opts)
 {
 int j;
-GetBitContext gb;
+BitstreamContext bc;
 int *runs, *ref = NULL, *runend;
 int ret;
 int runsize = avctx->width + 2;
@@ -289,27 +289,27 @@ int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t 
*src, int srcsize,
 ref[0] = avctx->width;
 ref[1] = 0;
 ref[2] = 0;
-init_get_bits(, src, srcsize * 8);
+bitstream_init(, src, srcsize * 8);
 for (j = 0; j < height; j++) {
 runend = runs + runsize;
 if (compr == TIFF_G4) {
-ret = decode_group3_2d_line(avctx, , avctx->width, runs, runend,
+ret = decode_group3_2d_line(avctx, , avctx->width, runs, runend,
 ref);
 if (ret < 0)
 goto fail;
 } else {
 int g3d1 = (compr == TIFF_G3) && !(opts & 1);
 if (compr != TIFF_CCITT_RLE &&
-find_group3_syncmarker(, srcsize * 8) < 0)
+find_group3_syncmarker(, srcsize * 8) < 0)
 break;
-if (compr == TIFF_CCITT_RLE || g3d1 || get_bits1())
-ret = decode_group3_1d_line(avctx, , avctx->width, runs,
+if (compr == TIFF_CCITT_RLE || g3d1 || bitstream_read_bit())
+ret = decode_group3_1d_line(avctx, , avctx->width, runs,
 runend);
 else
-ret = decode_group3_2d_line(avctx, , avctx->width, runs,
+ret = decode_group3_2d_line(avctx, , avctx->width, runs,
 runend, ref);
 if (compr == TIFF_CCITT_RLE)
-align_get_bits();
+bitstream_align();
 }
 if (avctx->err_recognition & 

[libav-devel] [PATCH 20/35] escape130: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/escape130.c | 46 +++---
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/libavcodec/escape130.c b/libavcodec/escape130.c
index bfc1f3f..544f36d 100644
--- a/libavcodec/escape130.c
+++ b/libavcodec/escape130.c
@@ -24,7 +24,7 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 typedef struct Escape130Context {
@@ -163,23 +163,23 @@ static av_cold int escape130_decode_close(AVCodecContext 
*avctx)
 return 0;
 }
 
-static int decode_skip_count(GetBitContext* gb)
+static int decode_skip_count(BitstreamContext *bc)
 {
 int value;
 
-value = get_bits1(gb);
+value = bitstream_read_bit(bc);
 if (value)
 return 0;
 
-value = get_bits(gb, 3);
+value = bitstream_read(bc, 3);
 if (value)
 return value;
 
-value = get_bits(gb, 8);
+value = bitstream_read(bc, 8);
 if (value)
 return value + 7;
 
-value = get_bits(gb, 15);
+value = bitstream_read(bc, 15);
 if (value)
 return value + 262;
 
@@ -193,7 +193,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, 
void *data,
 int buf_size= avpkt->size;
 Escape130Context *s = avctx->priv_data;
 AVFrame *pic= data;
-GetBitContext gb;
+BitstreamContext bc;
 int ret;
 
 uint8_t *old_y, *old_cb, *old_cr,
@@ -216,7 +216,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, 
void *data,
 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
 return ret;
 
-init_get_bits(, buf + 16, (buf_size - 16) * 8);
+bitstream_init(, buf + 16, (buf_size - 16) * 8);
 
 new_y  = s->new_y;
 new_cb = s->new_u;
@@ -235,7 +235,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, 
void *data,
 // Note that this call will make us skip the rest of the blocks
 // if the frame ends prematurely.
 if (skip == -1)
-skip = decode_skip_count();
+skip = decode_skip_count();
 if (skip == -1) {
 av_log(avctx, AV_LOG_ERROR, "Error decoding skip value\n");
 return AVERROR_INVALIDDATA;
@@ -250,31 +250,31 @@ static int escape130_decode_frame(AVCodecContext *avctx, 
void *data,
 cb = old_cb[0];
 cr = old_cr[0];
 } else {
-if (get_bits1()) {
-unsigned sign_selector   = get_bits(, 6);
-unsigned difference_selector = get_bits(, 2);
-y_avg = 2 * get_bits(, 5);
+if (bitstream_read_bit()) {
+unsigned sign_selector   = bitstream_read(, 6);
+unsigned difference_selector = bitstream_read(, 2);
+y_avg = 2 * bitstream_read(, 5);
 for (i = 0; i < 4; i++) {
 y[i] = av_clip(y_avg + offset_table[difference_selector] *
sign_table[sign_selector][i], 0, 63);
 }
-} else if (get_bits1()) {
-if (get_bits1()) {
-y_avg = get_bits(, 6);
+} else if (bitstream_read_bit()) {
+if (bitstream_read_bit()) {
+y_avg = bitstream_read(, 6);
 } else {
-unsigned adjust_index = get_bits(, 3);
+unsigned adjust_index = bitstream_read(, 3);
 y_avg = (y_avg + luma_adjust[adjust_index]) & 63;
 }
 for (i = 0; i < 4; i++)
 y[i] = y_avg;
 }
 
-if (get_bits1()) {
-if (get_bits1()) {
-cb = get_bits(, 5);
-cr = get_bits(, 5);
+if (bitstream_read_bit()) {
+if (bitstream_read_bit()) {
+cb = bitstream_read(, 5);
+cr = bitstream_read(, 5);
 } else {
-unsigned adjust_index = get_bits(, 3);
+unsigned adjust_index = bitstream_read(, 3);
 cb = (cb + chroma_adjust[0][adjust_index]) & 31;
 cr = (cr + chroma_adjust[1][adjust_index]) & 31;
 }
@@ -333,7 +333,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, 
void *data,
 }
 
 ff_dlog(avctx, "Frame data: provided %d bytes, used %d bytes\n",
-buf_size, get_bits_count() >> 3);
+buf_size, bitstream_tell() >> 3);
 
 FFSWAP(uint8_t*, s->old_y, s->new_y);
 FFSWAP(uint8_t*, s->old_u, s->new_u);
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 09/35] atrac: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/atrac1.c | 34 ++-
 libavcodec/atrac3.c | 97 +++--
 2 files changed, 67 insertions(+), 64 deletions(-)

diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index e938976..60be853 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -33,8 +33,9 @@
 #include 
 
 #include "libavutil/float_dsp.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "fft.h"
 #include "internal.h"
 #include "sinewin.h"
@@ -164,30 +165,31 @@ static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q)
  * Parse the block size mode byte
  */
 
-static int at1_parse_bsm(GetBitContext* gb, int log2_block_cnt[AT1_QMF_BANDS])
+static int at1_parse_bsm(BitstreamContext *bc,
+ int log2_block_cnt[AT1_QMF_BANDS])
 {
 int log2_block_count_tmp, i;
 
 for (i = 0; i < 2; i++) {
 /* low and mid band */
-log2_block_count_tmp = get_bits(gb, 2);
+log2_block_count_tmp = bitstream_read(bc, 2);
 if (log2_block_count_tmp & 1)
 return AVERROR_INVALIDDATA;
 log2_block_cnt[i] = 2 - log2_block_count_tmp;
 }
 
 /* high band */
-log2_block_count_tmp = get_bits(gb, 2);
+log2_block_count_tmp = bitstream_read(bc, 2);
 if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3)
 return AVERROR_INVALIDDATA;
 log2_block_cnt[IDX_HIGH_BAND] = 3 - log2_block_count_tmp;
 
-skip_bits(gb, 2);
+bitstream_skip(bc, 2);
 return 0;
 }
 
 
-static int at1_unpack_dequant(GetBitContext* gb, AT1SUCtx* su,
+static int at1_unpack_dequant(BitstreamContext *bc, AT1SUCtx *su,
   float spec[AT1_SU_SAMPLES])
 {
 int bits_used, band_num, bfu_num, i;
@@ -195,22 +197,22 @@ static int at1_unpack_dequant(GetBitContext* gb, 
AT1SUCtx* su,
 uint8_t idsfs[AT1_MAX_BFU]; ///< the scalefactor indexes 
for each BFU
 
 /* parse the info byte (2nd byte) telling how much BFUs were coded */
-su->num_bfus = bfu_amount_tab1[get_bits(gb, 3)];
+su->num_bfus = bfu_amount_tab1[bitstream_read(bc, 3)];
 
 /* calc number of consumed bits:
 num_BFUs * (idwl(4bits) + idsf(6bits)) + log2_block_count(8bits) + 
info_byte(8bits)
 + info_byte_copy(8bits) + log2_block_count_copy(8bits) */
 bits_used = su->num_bfus * 10 + 32 +
-bfu_amount_tab2[get_bits(gb, 2)] +
-(bfu_amount_tab3[get_bits(gb, 3)] << 1);
+bfu_amount_tab2[bitstream_read(bc, 2)] +
+(bfu_amount_tab3[bitstream_read(bc, 3)] << 1);
 
 /* get word length index (idwl) for each BFU */
 for (i = 0; i < su->num_bfus; i++)
-idwls[i] = get_bits(gb, 4);
+idwls[i] = bitstream_read(bc, 4);
 
 /* get scalefactor index (idsf) for each BFU */
 for (i = 0; i < su->num_bfus; i++)
-idsfs[i] = get_bits(gb, 6);
+idsfs[i] = bitstream_read(bc, 6);
 
 /* zero idwl/idsf for empty BFUs */
 for (i = su->num_bfus; i < AT1_MAX_BFU; i++)
@@ -240,7 +242,7 @@ static int at1_unpack_dequant(GetBitContext* gb, AT1SUCtx* 
su,
 /* read in a quantized spec and convert it to
  * signed int and then inverse quantization
  */
-spec[pos+i] = get_sbits(gb, word_len) * scale_factor * 
max_quant;
+spec[pos+i] = bitstream_read_signed(bc, word_len) * 
scale_factor * max_quant;
 }
 } else { /* word_len = 0 -> empty BFU, zero all specs in the emty 
BFU */
 memset([pos], 0, num_specs * sizeof(float));
@@ -277,7 +279,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void 
*data,
 int buf_size   = avpkt->size;
 AT1Ctx *q  = avctx->priv_data;
 int ch, ret;
-GetBitContext gb;
+BitstreamContext bc;
 
 
 if (buf_size < 212 * avctx->channels) {
@@ -295,14 +297,14 @@ static int atrac1_decode_frame(AVCodecContext *avctx, 
void *data,
 for (ch = 0; ch < avctx->channels; ch++) {
 AT1SUCtx* su = >SUs[ch];
 
-init_get_bits(, [212 * ch], 212 * 8);
+bitstream_init(, [212 * ch], 212 * 8);
 
 /* parse block_size_mode, 1st byte */
-ret = at1_parse_bsm(, su->log2_block_count);
+ret = at1_parse_bsm(, su->log2_block_count);
 if (ret < 0)
 return ret;
 
-ret = at1_unpack_dequant(, su, q->spec);
+ret = at1_unpack_dequant(, su, q->spec);
 if (ret < 0)
 return ret;
 
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 2e1fd3c..be32a0e 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -38,10 +38,11 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/float_dsp.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "fft.h"
-#include "get_bits.h"
 #include "internal.h"
 
 #include "atrac.h"
@@ 

[libav-devel] [PATCH 14/35] cdxl: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/cdxl.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cdxl.c b/libavcodec/cdxl.c
index 99e96eb..4c0410d 100644
--- a/libavcodec/cdxl.c
+++ b/libavcodec/cdxl.c
@@ -21,8 +21,9 @@
 
 #include "libavutil/intreadwrite.h"
 #include "libavutil/imgutils.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 #define BIT_PLANAR   0x00
@@ -69,30 +70,30 @@ static void import_palette(CDXLVideoContext *c, uint32_t 
*new_palette)
 
 static void bitplanar2chunky(CDXLVideoContext *c, int linesize, uint8_t *out)
 {
-GetBitContext gb;
+BitstreamContext bc;
 int x, y, plane;
 
-init_get_bits(, c->video, c->video_size * 8);
+bitstream_init(, c->video, c->video_size * 8);
 for (plane = 0; plane < c->bpp; plane++) {
 for (y = 0; y < c->avctx->height; y++) {
 for (x = 0; x < c->avctx->width; x++)
-out[linesize * y + x] |= get_bits1() << plane;
-skip_bits(, c->padded_bits);
+out[linesize * y + x] |= bitstream_read_bit() << plane;
+bitstream_skip(, c->padded_bits);
 }
 }
 }
 
 static void bitline2chunky(CDXLVideoContext *c, int linesize, uint8_t *out)
 {
-GetBitContext  gb;
+BitstreamContext bc;
 int x, y, plane;
 
-init_get_bits(, c->video, c->video_size * 8);
+bitstream_init(, c->video, c->video_size * 8);
 for (y = 0; y < c->avctx->height; y++) {
 for (plane = 0; plane < c->bpp; plane++) {
 for (x = 0; x < c->avctx->width; x++)
-out[linesize * y + x] |= get_bits1() << plane;
-skip_bits(, c->padded_bits);
+out[linesize * y + x] |= bitstream_read_bit() << plane;
+bitstream_skip(, c->padded_bits);
 }
 }
 }
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 06/35] 4xm: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/4xm.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index b2d4db2..ee9d020 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -29,11 +29,12 @@
 #include "libavutil/frame.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "blockdsp.h"
 #include "bswapdsp.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "internal.h"
 
 #define BLOCK_TYPE_VLC_BITS 5
@@ -136,8 +137,8 @@ typedef struct FourXContext {
 BswapDSPContext bbdsp;
 uint16_t *frame_buffer;
 uint16_t *last_frame_buffer;
-GetBitContext pre_gb;  ///< ac/dc prefix
-GetBitContext gb;
+BitstreamContext pre_bc;// ac/dc prefix
+BitstreamContext bc;
 GetByteContext g;
 GetByteContext g2;
 int mv[256];
@@ -352,8 +353,8 @@ static int decode_p_block(FourXContext *f, uint16_t *dst, 
uint16_t *src,
 return AVERROR_INVALIDDATA;
 
 h = 1 << log2h;
-code  = get_vlc2(>gb, block_type_vlc[1 - (f->version > 1)][index].table,
- BLOCK_TYPE_VLC_BITS, 1);
+code  = bitstream_read_vlc(>bc, block_type_vlc[1 - (f->version > 
1)][index].table,
+   BLOCK_TYPE_VLC_BITS, 1);
 if (code < 0 || code > 6)
 return AVERROR_INVALIDDATA;
 
@@ -453,7 +454,7 @@ static int decode_p_frame(FourXContext *f, const uint8_t 
*buf, int length)
bitstream_size / 4);
 memset((uint8_t*)f->bitstream_buffer + bitstream_size,
0, AV_INPUT_BUFFER_PADDING_SIZE);
-init_get_bits(>gb, f->bitstream_buffer, 8 * bitstream_size);
+bitstream_init(>bc, f->bitstream_buffer, 8 * bitstream_size);
 
 wordstream_offset = extra + bitstream_size;
 bytestream_offset = extra + bitstream_size + wordstream_size;
@@ -484,19 +485,19 @@ static int decode_i_block(FourXContext *f, int16_t *block)
 int code, i, j, level, val;
 
 /* DC coef */
-val = get_vlc2(>pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
+val = bitstream_read_vlc(>pre_bc, f->pre_vlc.table, ACDC_VLC_BITS, 3);
 if (val >> 4)
 av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n");
 
 if (val)
-val = get_xbits(>gb, val);
+val = bitstream_read_xbits(>bc, val);
 
 val= val * dequant_table[0] + f->last_dc;
 f->last_dc = block[0] = val;
 /* AC coefs */
 i = 1;
 for (;;) {
-code = get_vlc2(>pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
+code = bitstream_read_vlc(>pre_bc, f->pre_vlc.table, ACDC_VLC_BITS, 
3);
 
 /* EOB */
 if (code == 0)
@@ -504,7 +505,7 @@ static int decode_i_block(FourXContext *f, int16_t *block)
 if (code == 0xf0) {
 i += 16;
 } else {
-level = get_xbits(>gb, code & 0xf);
+level = bitstream_read_xbits(>bc, code & 0xf);
 i+= code >> 4;
 if (i >= 64) {
 av_log(f->avctx, AV_LOG_ERROR, "run %d oveflow\n", i);
@@ -764,7 +765,7 @@ static int decode_i_frame(FourXContext *f, const uint8_t 
*buf, int length)
 return AVERROR_INVALIDDATA;
 }
 
-init_get_bits(>gb, buf + 4, 8 * bitstream_size);
+bitstream_init(>bc, buf + 4, 8 * bitstream_size);
 
 prestream_size = length + buf - prestream;
 
@@ -776,7 +777,7 @@ static int decode_i_frame(FourXContext *f, const uint8_t 
*buf, int length)
prestream_size / 4);
 memset((uint8_t*)f->bitstream_buffer + prestream_size,
0, AV_INPUT_BUFFER_PADDING_SIZE);
-init_get_bits(>pre_gb, f->bitstream_buffer, 8 * prestream_size);
+bitstream_init(>pre_bc, f->bitstream_buffer, 8 * prestream_size);
 
 f->last_dc = 0 * 128 * 8 * 8;
 
@@ -789,7 +790,7 @@ static int decode_i_frame(FourXContext *f, const uint8_t 
*buf, int length)
 }
 }
 
-if (get_vlc2(>pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256)
+if (bitstream_read_vlc(>pre_bc, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 
256)
 av_log(f->avctx, AV_LOG_ERROR, "end mismatch\n");
 
 return 0;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 03/35] eamad: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/eamad.c | 42 +++---
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 070cfdb..7509c2d 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -29,16 +29,17 @@
  */
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "blockdsp.h"
 #include "bytestream.h"
 #include "bswapdsp.h"
-#include "get_bits.h"
 #include "aandcttab.h"
 #include "eaidct.h"
 #include "idctdsp.h"
 #include "internal.h"
 #include "mpeg12data.h"
 #include "mpeg12vlc.h"
+#include "vlc.h"
 
 #define EA_PREAMBLE_SIZE8
 #define MADk_TAG MKTAG('M', 'A', 'D', 'k')/* MAD I-frame */
@@ -51,7 +52,7 @@ typedef struct MadContext {
 BswapDSPContext bbdsp;
 IDCTDSPContext idsp;
 AVFrame *last_frame;
-GetBitContext gb;
+BitstreamContext bc;
 void *bitstream_buf;
 unsigned int bitstream_buf_size;
 DECLARE_ALIGNED(16, int16_t, block)[64];
@@ -129,17 +130,15 @@ static inline void decode_block_intra(MadContext *s, 
int16_t * block)
 const uint8_t *scantable = s->scantable.permutated;
 int16_t *quant_matrix = s->quant_matrix;
 
-block[0] = (128 + get_sbits(>gb, 8)) * quant_matrix[0];
+block[0] = (128 + bitstream_read_signed(>bc, 8)) * quant_matrix[0];
 
 /* The RL decoder is derived from mpeg1_decode_block_intra;
Escaped level and run values a decoded differently */
 i = 0;
 {
-OPEN_READER(re, >gb);
 /* now quantify & encode AC coefficients */
 for (;;) {
-UPDATE_CACHE(re, >gb);
-GET_RL_VLC(level, run, re, >gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 
0);
+BITSTREAM_RL_VLC(level, run, >bc, rl->rl_vlc[0], TEX_VLC_BITS, 
2);
 
 if (level == 127) {
 break;
@@ -153,15 +152,12 @@ static inline void decode_block_intra(MadContext *s, 
int16_t * block)
 j = scantable[i];
 level = (level*quant_matrix[j]) >> 4;
 level = (level-1)|1;
-level = (level ^ SHOW_SBITS(re, >gb, 1)) - SHOW_SBITS(re, 
>gb, 1);
-LAST_SKIP_BITS(re, >gb, 1);
+level = bitstream_apply_sign(>bc, level);
 } else {
 /* escape */
-UPDATE_CACHE(re, >gb);
-level = SHOW_SBITS(re, >gb, 10); SKIP_BITS(re, >gb, 10);
+level = bitstream_read_signed(>bc, 10);
 
-UPDATE_CACHE(re, >gb);
-run = SHOW_UBITS(re, >gb, 6)+1; LAST_SKIP_BITS(re, >gb, 
6);
+run = bitstream_read(>bc, 6) + 1;
 
 i += run;
 if (i > 63) {
@@ -183,17 +179,17 @@ static inline void decode_block_intra(MadContext *s, 
int16_t * block)
 
 block[j] = level;
 }
-CLOSE_READER(re, >gb);
 }
 }
 
-static int decode_motion(GetBitContext *gb)
+static int decode_motion(BitstreamContext *bc)
 {
 int value = 0;
-if (get_bits1(gb)) {
-if (get_bits1(gb))
+
+if (bitstream_read_bit(bc)) {
+if (bitstream_read_bit(bc))
 value = -17;
-value += get_bits(gb, 4) + 1;
+value += bitstream_read(bc, 4) + 1;
 }
 return value;
 }
@@ -205,11 +201,11 @@ static void decode_mb(MadContext *s, AVFrame *frame, int 
inter)
 int j;
 
 if (inter) {
-int v = decode210(>gb);
+int v = bitstream_decode210(>bc);
 if (v < 2) {
-mv_map = v ? get_bits(>gb, 6) : 63;
-mv_x = decode_motion(>gb);
-mv_y = decode_motion(>gb);
+mv_map = v ? bitstream_read(>bc, 6) : 63;
+mv_x = decode_motion(>bc);
+mv_y = decode_motion(>bc);
 } else {
 mv_map = 0;
 }
@@ -217,7 +213,7 @@ static void decode_mb(MadContext *s, AVFrame *frame, int 
inter)
 
 for (j=0; j<6; j++) {
 if (mv_map & (1<gb);
+int add = 2 * decode_motion(>bc);
 comp_block(s, frame, s->mb_x, s->mb_y, j, mv_x, mv_y, add);
 } else {
 s->bdsp.clear_block(s->block);
@@ -299,7 +295,7 @@ static int decode_frame(AVCodecContext *avctx,
 return AVERROR(ENOMEM);
 s->bbdsp.bswap16_buf(s->bitstream_buf, (const uint16_t *)(buf + 
bytestream2_tell()),
  bytestream2_get_bytes_left() / 2);
-init_get_bits(>gb, s->bitstream_buf, 
8*(bytestream2_get_bytes_left()));
+bitstream_init8(>bc, s->bitstream_buf, bytestream2_get_bytes_left());
 
 for (s->mb_y=0; s->mb_y < (avctx->height+15)/16; s->mb_y++)
 for (s->mb_x=0; s->mb_x < (avctx->width +15)/16; s->mb_x++)
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 18/35] dvdsubdec: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/dvdsubdec.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 86c2873..b02bb6b 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -20,7 +20,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 #include "libavutil/attributes.h"
@@ -50,13 +50,13 @@ static void yuv_a_to_rgba(const uint8_t *ycbcr, const 
uint8_t *alpha, uint32_t *
 }
 }
 
-static int decode_run_2bit(GetBitContext *gb, int *color)
+static int decode_run_2bit(BitstreamContext *bc, int *color)
 {
 unsigned int v, t;
 
 v = 0;
 for (t = 1; v < t && t <= 0x40; t <<= 2)
-v = (v << 4) | get_bits(gb, 4);
+v = (v << 4) | bitstream_read(bc, 4);
 *color = v & 3;
 if (v < 4) { /* Code for fill rest of line */
 return INT_MAX;
@@ -64,23 +64,23 @@ static int decode_run_2bit(GetBitContext *gb, int *color)
 return v >> 2;
 }
 
-static int decode_run_8bit(GetBitContext *gb, int *color)
+static int decode_run_8bit(BitstreamContext *bc, int *color)
 {
 int len;
-int has_run = get_bits1(gb);
-if (get_bits1(gb))
-*color = get_bits(gb, 8);
+int has_run = bitstream_read_bit(bc);
+if (bitstream_read_bit(bc))
+*color = bitstream_read(bc, 8);
 else
-*color = get_bits(gb, 2);
+*color = bitstream_read(bc, 2);
 if (has_run) {
-if (get_bits1(gb)) {
-len = get_bits(gb, 7);
+if (bitstream_read_bit(bc)) {
+len = bitstream_read(bc, 7);
 if (len == 0)
 len = INT_MAX;
 else
 len += 9;
 } else
-len = get_bits(gb, 3) + 2;
+len = bitstream_read(bc, 3) + 2;
 } else
 len = 1;
 return len;
@@ -89,24 +89,24 @@ static int decode_run_8bit(GetBitContext *gb, int *color)
 static int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
   const uint8_t *buf, int start, int buf_size, int is_8bit)
 {
-GetBitContext gb;
+BitstreamContext bc;
 int bit_len;
 int x, y, len, color;
 uint8_t *d;
 
 bit_len = (buf_size - start) * 8;
-init_get_bits(, buf + start, bit_len);
+bitstream_init(, buf + start, bit_len);
 
 x = 0;
 y = 0;
 d = bitmap;
 for(;;) {
-if (get_bits_count() > bit_len)
+if (bitstream_tell() > bit_len)
 return -1;
 if (is_8bit)
-len = decode_run_8bit(, );
+len = decode_run_8bit(, );
 else
-len = decode_run_2bit(, );
+len = decode_run_2bit(, );
 len = FFMIN(len, w - x);
 memset(d + x, color, len);
 x += len;
@@ -117,7 +117,7 @@ static int decode_rle(uint8_t *bitmap, int linesize, int w, 
int h,
 d += linesize;
 x = 0;
 /* byte align */
-align_get_bits();
+bitstream_align();
 }
 }
 return 0;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 05/35] on2avc: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/on2avc.c | 64 +++--
 1 file changed, 33 insertions(+), 31 deletions(-)

diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index 2a528c6..1b81980 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -22,11 +22,13 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "fft.h"
-#include "get_bits.h"
 #include "internal.h"
+#include "vlc.h"
 
 #include "on2avcdata.h"
 
@@ -84,11 +86,11 @@ typedef struct On2AVCContext {
 DECLARE_ALIGNED(32, float, short_win)[ON2AVC_SUBFRAME_SIZE / 8];
 } On2AVCContext;
 
-static void on2avc_read_ms_info(On2AVCContext *c, GetBitContext *gb)
+static void on2avc_read_ms_info(On2AVCContext *c, BitstreamContext *bc)
 {
 int w, b, band_off = 0;
 
-c->ms_present = get_bits1(gb);
+c->ms_present = bitstream_read_bit(bc);
 if (!c->ms_present)
 return;
 for (w = 0; w < c->num_windows; w++) {
@@ -100,12 +102,12 @@ static void on2avc_read_ms_info(On2AVCContext *c, 
GetBitContext *gb)
 continue;
 }
 for (b = 0; b < c->num_bands; b++)
-c->ms_info[band_off++] = get_bits1(gb);
+c->ms_info[band_off++] = bitstream_read_bit(bc);
 }
 }
 
 // do not see Table 17 in ISO/IEC 13818-7
-static int on2avc_decode_band_types(On2AVCContext *c, GetBitContext *gb)
+static int on2avc_decode_band_types(On2AVCContext *c, BitstreamContext *bc)
 {
 int bits_per_sect = c->is_long ? 5 : 3;
 int esc_val = (1 << bits_per_sect) - 1;
@@ -113,10 +115,10 @@ static int on2avc_decode_band_types(On2AVCContext *c, 
GetBitContext *gb)
 int band = 0, i, band_type, run_len, run;
 
 while (band < num_bands) {
-band_type = get_bits(gb, 4);
+band_type = bitstream_read(bc, 4);
 run_len   = 1;
 do {
-run = get_bits(gb, bits_per_sect);
+run = bitstream_read(bc, bits_per_sect);
 run_len += run;
 } while (run == esc_val);
 if (band + run_len > num_bands) {
@@ -135,7 +137,7 @@ static int on2avc_decode_band_types(On2AVCContext *c, 
GetBitContext *gb)
 
 // completely not like Table 18 in ISO/IEC 13818-7
 // (no intensity stereo, different coding for the first coefficient)
-static int on2avc_decode_band_scales(On2AVCContext *c, GetBitContext *gb)
+static int on2avc_decode_band_scales(On2AVCContext *c, BitstreamContext *bc)
 {
 int w, w2, b, scale, first = 1;
 int band_off = 0;
@@ -165,10 +167,10 @@ static int on2avc_decode_band_scales(On2AVCContext *c, 
GetBitContext *gb)
 }
 }
 if (first) {
-scale = get_bits(gb, 7);
+scale = bitstream_read(bc, 7);
 first = 0;
 } else {
-scale += get_vlc2(gb, c->scale_diff.table, 9, 3) - 60;
+scale += bitstream_read_vlc(bc, c->scale_diff.table, 9, 3) - 
60;
 }
 if (scale < 0 || scale > 127) {
 av_log(c->avctx, AV_LOG_ERROR, "Invalid scale value %d\n",
@@ -188,13 +190,13 @@ static inline float on2avc_scale(int v, float scale)
 }
 
 // spectral data is coded completely differently - there are no unsigned 
codebooks
-static int on2avc_decode_quads(On2AVCContext *c, GetBitContext *gb, float *dst,
+static int on2avc_decode_quads(On2AVCContext *c, BitstreamContext *bc, float 
*dst,
int dst_size, int type, float band_scale)
 {
 int i, j, val, val1;
 
 for (i = 0; i < dst_size; i += 4) {
-val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
+val = bitstream_read_vlc(bc, c->cb_vlc[type].table, 9, 3);
 
 for (j = 0; j < 4; j++) {
 val1 = sign_extend((val >> (12 - j * 4)) & 0xF, 4);
@@ -205,11 +207,11 @@ static int on2avc_decode_quads(On2AVCContext *c, 
GetBitContext *gb, float *dst,
 return 0;
 }
 
-static inline int get_egolomb(GetBitContext *gb)
+static inline int get_egolomb(BitstreamContext *bc)
 {
 int v = 4;
 
-while (get_bits1(gb)) {
+while (bitstream_read_bit(bc)) {
 v++;
 if (v > 30) {
 av_log(NULL, AV_LOG_WARNING, "Too large golomb code in 
get_egolomb.\n");
@@ -218,27 +220,27 @@ static inline int get_egolomb(GetBitContext *gb)
 }
 }
 
-return (1 << v) + get_bits_long(gb, v);
+return (1 << v) + bitstream_read(bc, v);
 }
 
-static int on2avc_decode_pairs(On2AVCContext *c, GetBitContext *gb, float *dst,
+static int on2avc_decode_pairs(On2AVCContext *c, BitstreamContext *bc, float 
*dst,
int dst_size, int type, float band_scale)
 {
 int i, val, val1, val2, sign;
 
 for (i = 0; i < dst_size; i += 2) {
-val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
+val = bitstream_read_vlc(bc, c->cb_vlc[type].table, 9, 3);
 
 val1 = 

[libav-devel] [PATCH 12/35] bink: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/bink.c | 264 ++
 1 file changed, 128 insertions(+), 136 deletions(-)

diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index 7433697..74db80a 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -28,8 +28,8 @@
 #include "avcodec.h"
 #include "binkdata.h"
 #include "binkdsp.h"
+#include "bitstream.h"
 #include "blockdsp.h"
-#include "get_bits.h"
 #include "hpeldsp.h"
 #include "internal.h"
 #include "mathops.h"
@@ -93,8 +93,9 @@ typedef struct Tree {
 uint8_t syms[16]; ///< leaf value to symbol mapping
 } Tree;
 
-#define GET_HUFF(gb, tree)  (tree).syms[get_vlc2(gb, 
bink_trees[(tree).vlc_num].table,\
- 
bink_trees[(tree).vlc_num].bits, 1)]
+#define GET_HUFF(bc, tree)\
+(tree).syms[bitstream_read_vlc(bc, bink_trees[(tree).vlc_num].table,  \
+   bink_trees[(tree).vlc_num].bits, 1)]
 
 /**
  * data structure used for decoding single Bink data type
@@ -204,18 +205,18 @@ static av_cold void free_bundles(BinkContext *c)
 /**
  * Merge two consequent lists of equal size depending on bits read.
  *
- * @param gb   context for reading bits
+ * @param bc   context for reading bits
  * @param dst  buffer where merged list will be written to
  * @param src  pointer to the head of the first list (the second lists starts 
at src+size)
  * @param size input lists size
  */
-static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
+static void merge(BitstreamContext *bc, uint8_t *dst, uint8_t *src, int size)
 {
 uint8_t *src2 = src + size;
 int size2 = size;
 
 do {
-if (!get_bits1(gb)) {
+if (!bitstream_read_bit(bc)) {
 *dst++ = *src++;
 size--;
 } else {
@@ -233,37 +234,37 @@ static void merge(GetBitContext *gb, uint8_t *dst, 
uint8_t *src, int size)
 /**
  * Read information about Huffman tree used to decode data.
  *
- * @param gb   context for reading bits
+ * @param bc   context for reading bits
  * @param tree pointer for storing tree data
  */
-static void read_tree(GetBitContext *gb, Tree *tree)
+static void read_tree(BitstreamContext *bc, Tree *tree)
 {
 uint8_t tmp1[16] = { 0 }, tmp2[16], *in = tmp1, *out = tmp2;
 int i, t, len;
 
-tree->vlc_num = get_bits(gb, 4);
+tree->vlc_num = bitstream_read(bc, 4);
 if (!tree->vlc_num) {
 for (i = 0; i < 16; i++)
 tree->syms[i] = i;
 return;
 }
-if (get_bits1(gb)) {
-len = get_bits(gb, 3);
+if (bitstream_read_bit(bc)) {
+len = bitstream_read(bc, 3);
 for (i = 0; i <= len; i++) {
-tree->syms[i] = get_bits(gb, 4);
+tree->syms[i] = bitstream_read(bc, 4);
 tmp1[tree->syms[i]] = 1;
 }
 for (i = 0; i < 16 && len < 16 - 1; i++)
 if (!tmp1[i])
 tree->syms[++len] = i;
 } else {
-len = get_bits(gb, 2);
+len = bitstream_read(bc, 2);
 for (i = 0; i < 16; i++)
 in[i] = i;
 for (i = 0; i <= len; i++) {
 int size = 1 << i;
 for (t = 0; t < 16; t += size << 1)
-merge(gb, out + t, in + t, size);
+merge(bc, out + t, in + t, size);
 FFSWAP(uint8_t*, in, out);
 }
 memcpy(tree->syms, in, 16);
@@ -273,21 +274,21 @@ static void read_tree(GetBitContext *gb, Tree *tree)
 /**
  * Prepare bundle for decoding data.
  *
- * @param gb  context for reading bits
+ * @param bc  context for reading bits
  * @param c   decoder context
  * @param bundle_num  number of the bundle to initialize
  */
-static void read_bundle(GetBitContext *gb, BinkContext *c, int bundle_num)
+static void read_bundle(BitstreamContext *bc, BinkContext *c, int bundle_num)
 {
 int i;
 
 if (bundle_num == BINK_SRC_COLORS) {
 for (i = 0; i < 16; i++)
-read_tree(gb, >col_high[i]);
+read_tree(bc, >col_high[i]);
 c->col_lastval = 0;
 }
 if (bundle_num != BINK_SRC_INTRA_DC && bundle_num != BINK_SRC_INTER_DC)
-read_tree(gb, >bundle[bundle_num].tree);
+read_tree(bc, >bundle[bundle_num].tree);
 c->bundle[bundle_num].cur_dec =
 c->bundle[bundle_num].cur_ptr = c->bundle[bundle_num].data;
 }
@@ -295,66 +296,64 @@ static void read_bundle(GetBitContext *gb, BinkContext 
*c, int bundle_num)
 /**
  * common check before starting decoding bundle data
  *
- * @param gb context for reading bits
+ * @param bc context for reading bits
  * @param b  bundle
  * @param t  variable where number of elements to decode will be stored
  */
-#define CHECK_READ_VAL(gb, b, t) \
+#define CHECK_READ_VAL(bc, b, t) \
 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
 return 0; \
-t = get_bits(gb, b->len); \
+t = 

[libav-devel] [PATCH 17/35] dss_sp: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/dss_sp.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dss_sp.c b/libavcodec/dss_sp.c
index 20b0528..44d98d8 100644
--- a/libavcodec/dss_sp.c
+++ b/libavcodec/dss_sp.c
@@ -25,7 +25,7 @@
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 #define SUBFRAMES 4
@@ -302,7 +302,7 @@ static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
 
 static void dss_sp_unpack_coeffs(DssSpContext *p, const uint8_t *src)
 {
-GetBitContext gb;
+BitstreamContext bc;
 DssSpFrame *fparam = >fparam;
 int i;
 int subframe_idx;
@@ -315,24 +315,24 @@ static void dss_sp_unpack_coeffs(DssSpContext *p, const 
uint8_t *src)
 p->bits[i + 1] = src[i];
 }
 
-init_get_bits(, p->bits, DSS_SP_FRAME_SIZE * 8);
+bitstream_init(, p->bits, DSS_SP_FRAME_SIZE * 8);
 
 for (i = 0; i < 2; i++)
-fparam->filter_idx[i] = get_bits(, 5);
+fparam->filter_idx[i] = bitstream_read(, 5);
 for (; i < 8; i++)
-fparam->filter_idx[i] = get_bits(, 4);
+fparam->filter_idx[i] = bitstream_read(, 4);
 for (; i < 14; i++)
-fparam->filter_idx[i] = get_bits(, 3);
+fparam->filter_idx[i] = bitstream_read(, 3);
 
 for (subframe_idx = 0; subframe_idx < 4; subframe_idx++) {
-fparam->sf_adaptive_gain[subframe_idx] = get_bits(, 5);
+fparam->sf_adaptive_gain[subframe_idx] = bitstream_read(, 5);
 
-fparam->sf[subframe_idx].combined_pulse_pos = get_bits_long(, 31);
+fparam->sf[subframe_idx].combined_pulse_pos = bitstream_read(, 31);
 
-fparam->sf[subframe_idx].gain = get_bits(, 6);
+fparam->sf[subframe_idx].gain = bitstream_read(, 6);
 
 for (i = 0; i < 7; i++)
-fparam->sf[subframe_idx].pulse_val[i] = get_bits(, 3);
+fparam->sf[subframe_idx].pulse_val[i] = bitstream_read(, 3);
 }
 
 for (subframe_idx = 0; subframe_idx < 4; subframe_idx++) {
@@ -394,7 +394,7 @@ static void dss_sp_unpack_coeffs(DssSpContext *p, const 
uint8_t *src)
 }
 }
 
-combined_pitch = get_bits(, 24);
+combined_pitch = bitstream_read(, 24);
 
 fparam->pitch_lag[0] = (combined_pitch % 151) + 36;
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 15/35] cljrdec: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/cljrdec.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cljrdec.c b/libavcodec/cljrdec.c
index 33d8023..833707b 100644
--- a/libavcodec/cljrdec.c
+++ b/libavcodec/cljrdec.c
@@ -25,7 +25,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 static int decode_frame(AVCodecContext *avctx,
@@ -34,7 +34,7 @@ static int decode_frame(AVCodecContext *avctx,
 {
 const uint8_t *buf = avpkt->data;
 int buf_size   = avpkt->size;
-GetBitContext gb;
+BitstreamContext bc;
 AVFrame * const p = data;
 int x, y, ret;
 
@@ -56,20 +56,20 @@ static int decode_frame(AVCodecContext *avctx,
 p->pict_type = AV_PICTURE_TYPE_I;
 p->key_frame = 1;
 
-init_get_bits(, buf, buf_size * 8);
+bitstream_init(, buf, buf_size * 8);
 
 for (y = 0; y < avctx->height; y++) {
 uint8_t *luma = >data[0][y * p->linesize[0]];
 uint8_t *cb   = >data[1][y * p->linesize[1]];
 uint8_t *cr   = >data[2][y * p->linesize[2]];
 for (x = 0; x < avctx->width; x += 4) {
-luma[3] = get_bits(, 5) << 3;
-luma[2] = get_bits(, 5) << 3;
-luma[1] = get_bits(, 5) << 3;
-luma[0] = get_bits(, 5) << 3;
+luma[3] = bitstream_read(, 5) << 3;
+luma[2] = bitstream_read(, 5) << 3;
+luma[1] = bitstream_read(, 5) << 3;
+luma[0] = bitstream_read(, 5) << 3;
 luma += 4;
-*(cb++) = get_bits(, 6) << 2;
-*(cr++) = get_bits(, 6) << 2;
+*(cb++) = bitstream_read(, 6) << 2;
+*(cr++) = bitstream_read(, 6) << 2;
 }
 }
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 10/35] atrac3plus: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/atrac3plus.c| 525 +++--
 libavcodec/atrac3plus.h|   7 +-
 libavcodec/atrac3plusdec.c |  15 +-
 3 files changed, 275 insertions(+), 272 deletions(-)

diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index 076fb84..2731a80 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -26,8 +26,9 @@
  */
 
 #include "libavutil/avassert.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "atrac3plus.h"
 #include "atrac3plus_data.h"
 
@@ -212,20 +213,20 @@ av_cold void ff_atrac3p_init_vlcs(AVCodec *codec)
 /**
  * Decode number of coded quantization units.
  *
- * @param[in] gbthe GetBit context
+ * @param[in] bcthe Bitstream context
  * @param[in,out] chan  ptr to the channel parameters
  * @param[in,out] ctx   ptr to the channel unit context
  * @param[in] avctx ptr to the AVCodecContext
  * @return result code: 0 = OK, otherwise - error code
  */
-static int num_coded_units(GetBitContext *gb, Atrac3pChanParams *chan,
+static int num_coded_units(BitstreamContext *bc, Atrac3pChanParams *chan,
Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx)
 {
-chan->fill_mode = get_bits(gb, 2);
+chan->fill_mode = bitstream_read(bc, 2);
 if (!chan->fill_mode) {
 chan->num_coded_vals = ctx->num_quant_units;
 } else {
-chan->num_coded_vals = get_bits(gb, 5);
+chan->num_coded_vals = bitstream_read(bc, 5);
 if (chan->num_coded_vals > ctx->num_quant_units) {
 av_log(avctx, AV_LOG_ERROR,
"Invalid number of transmitted units!\n");
@@ -233,7 +234,7 @@ static int num_coded_units(GetBitContext *gb, 
Atrac3pChanParams *chan,
 }
 
 if (chan->fill_mode == 3)
-chan->split_point = get_bits(gb, 2) + (chan->ch_num << 1) + 1;
+chan->split_point = bitstream_read(bc, 2) + (chan->ch_num << 1) + 
1;
 }
 
 return 0;
@@ -318,21 +319,21 @@ static inline void unpack_vq_shape(int start_val, const 
int8_t *shape_vec,
 }
 }
 
-#define UNPACK_SF_VQ_SHAPE(gb, dst, num_vals)\
-start_val = get_bits((gb), 6);   \
-unpack_vq_shape(start_val, _sf_shapes[get_bits((gb), 6)][0], \
+#define UNPACK_SF_VQ_SHAPE(bc, dst, num_vals)  
\
+start_val = bitstream_read((bc), 6);   
\
+unpack_vq_shape(start_val, _sf_shapes[bitstream_read((bc), 6)][0], 
\
 (dst), (num_vals))
 
 /**
  * Decode word length for each quantization unit of a channel.
  *
- * @param[in] gbthe GetBit context
+ * @param[in] bcthe Bitstream context
  * @param[in,out] ctx   ptr to the channel unit context
  * @param[in] ch_numchannel to process
  * @param[in] avctx ptr to the AVCodecContext
  * @return result code: 0 = OK, otherwise - error code
  */
-static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
+static int decode_channel_wordlen(BitstreamContext *bc, Atrac3pChanUnitCtx 
*ctx,
   int ch_num, AVCodecContext *avctx)
 {
 int i, weight_idx = 0, delta, diff, pos, delta_bits, min_val, flag,
@@ -343,107 +344,107 @@ static int decode_channel_wordlen(GetBitContext *gb, 
Atrac3pChanUnitCtx *ctx,
 
 chan->fill_mode = 0;
 
-switch (get_bits(gb, 2)) { /* switch according to coding mode */
+switch (bitstream_read(bc, 2)) { /* switch according to coding mode */
 case 0: /* coded using constant number of bits */
 for (i = 0; i < ctx->num_quant_units; i++)
-chan->qu_wordlen[i] = get_bits(gb, 3);
+chan->qu_wordlen[i] = bitstream_read(bc, 3);
 break;
 case 1:
 if (ch_num) {
-if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
+if ((ret = num_coded_units(bc, chan, ctx, avctx)) < 0)
 return ret;
 
 if (chan->num_coded_vals) {
-vlc_tab = _vlc_tabs[get_bits(gb, 2)];
+vlc_tab = _vlc_tabs[bitstream_read(bc, 2)];
 
 for (i = 0; i < chan->num_coded_vals; i++) {
-delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
+delta = bitstream_read_vlc(bc, vlc_tab->table, 
vlc_tab->bits, 1);
 chan->qu_wordlen[i] = (ref_chan->qu_wordlen[i] + delta) & 
7;
 }
 }
 } else {
-weight_idx = get_bits(gb, 2);
-if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
+weight_idx = bitstream_read(bc, 2);
+if ((ret = num_coded_units(bc, chan, ctx, avctx)) < 0)
 return ret;
 
 if (chan->num_coded_vals) {
-pos = get_bits(gb, 5);

[libav-devel] [PATCH 02/35] cllc: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/cllc.c | 88 +++
 1 file changed, 36 insertions(+), 52 deletions(-)

diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c
index cdbed74..bac2b73 100644
--- a/libavcodec/cllc.c
+++ b/libavcodec/cllc.c
@@ -23,11 +23,13 @@
 #include 
 
 #include "libavutil/intreadwrite.h"
+
+#include "bitstream.h"
 #include "bswapdsp.h"
 #include "canopus.h"
-#include "get_bits.h"
 #include "avcodec.h"
 #include "internal.h"
+#include "vlc.h"
 
 typedef struct CLLCContext {
 AVCodecContext *avctx;
@@ -37,7 +39,7 @@ typedef struct CLLCContext {
 int  swapped_buf_size;
 } CLLCContext;
 
-static int read_code_table(CLLCContext *ctx, GetBitContext *gb, VLC *vlc)
+static int read_code_table(CLLCContext *ctx, BitstreamContext *bc, VLC *vlc)
 {
 uint8_t symbols[256];
 uint8_t bits[256];
@@ -49,10 +51,10 @@ static int read_code_table(CLLCContext *ctx, GetBitContext 
*gb, VLC *vlc)
 count = 0;
 num_codes_sum = 0;
 
-num_lens = get_bits(gb, 5);
+num_lens = bitstream_read(bc, 5);
 
 for (i = 0; i < num_lens; i++) {
-num_codes  = get_bits(gb, 9);
+num_codes  = bitstream_read(bc, 9);
 num_codes_sum += num_codes;
 
 if (num_codes_sum > 256) {
@@ -64,7 +66,7 @@ static int read_code_table(CLLCContext *ctx, GetBitContext 
*gb, VLC *vlc)
 }
 
 for (j = 0; j < num_codes; j++) {
-symbols[count] = get_bits(gb, 8);
+symbols[count] = bitstream_read(bc, 8);
 bits[count]= i + 1;
 codes[count]   = prefix++;
 
@@ -82,7 +84,7 @@ static int read_code_table(CLLCContext *ctx, GetBitContext 
*gb, VLC *vlc)
  * Unlike the RGB24 read/restore, which reads in a component at a time,
  * ARGB read/restore reads in ARGB quads.
  */
-static int read_argb_line(CLLCContext *ctx, GetBitContext *gb, int *top_left,
+static int read_argb_line(CLLCContext *ctx, BitstreamContext *bc, int 
*top_left,
   VLC *vlc, uint8_t *outbuf)
 {
 uint8_t *dst;
@@ -90,8 +92,6 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext 
*gb, int *top_left,
 int code;
 int i;
 
-OPEN_READER(bits, gb);
-
 dst = outbuf;
 pred[0] = top_left[0];
 pred[1] = top_left[1];
@@ -100,8 +100,7 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext 
*gb, int *top_left,
 
 for (i = 0; i < ctx->avctx->width; i++) {
 /* Always get the alpha component */
-UPDATE_CACHE(bits, gb);
-GET_VLC(code, bits, gb, vlc[0].table, 7, 2);
+code = bitstream_read_vlc(bc, vlc[0].table, 7, 2);
 
 pred[0] += code;
 dst[0]   = pred[0];
@@ -109,22 +108,19 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext 
*gb, int *top_left,
 /* Skip the components if they are  entirely transparent */
 if (dst[0]) {
 /* Red */
-UPDATE_CACHE(bits, gb);
-GET_VLC(code, bits, gb, vlc[1].table, 7, 2);
+code = bitstream_read_vlc(bc, vlc[1].table, 7, 2);
 
 pred[1] += code;
 dst[1]   = pred[1];
 
 /* Green */
-UPDATE_CACHE(bits, gb);
-GET_VLC(code, bits, gb, vlc[2].table, 7, 2);
+code = bitstream_read_vlc(bc, vlc[2].table, 7, 2);
 
 pred[2] += code;
 dst[2]   = pred[2];
 
 /* Blue */
-UPDATE_CACHE(bits, gb);
-GET_VLC(code, bits, gb, vlc[3].table, 7, 2);
+code = bitstream_read_vlc(bc, vlc[3].table, 7, 2);
 
 pred[3] += code;
 dst[3]   = pred[3];
@@ -137,8 +133,6 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext 
*gb, int *top_left,
 dst += 4;
 }
 
-CLOSE_READER(bits, gb);
-
 top_left[0]  = outbuf[0];
 
 /* Only stash components if they are not transparent */
@@ -151,65 +145,55 @@ static int read_argb_line(CLLCContext *ctx, GetBitContext 
*gb, int *top_left,
 return 0;
 }
 
-static int read_rgb24_component_line(CLLCContext *ctx, GetBitContext *gb,
+static int read_rgb24_component_line(CLLCContext *ctx, BitstreamContext *bc,
  int *top_left, VLC *vlc, uint8_t *outbuf)
 {
 uint8_t *dst;
 int pred, code;
 int i;
 
-OPEN_READER(bits, gb);
-
 dst  = outbuf;
 pred = *top_left;
 
 /* Simultaneously read and restore the line */
 for (i = 0; i < ctx->avctx->width; i++) {
-UPDATE_CACHE(bits, gb);
-GET_VLC(code, bits, gb, vlc->table, 7, 2);
+code = bitstream_read_vlc(bc, vlc->table, 7, 2);
 
 pred  += code;
 dst[0] = pred;
 dst   += 3;
 }
 
-CLOSE_READER(bits, gb);
-
 /* Stash the first pixel */
 *top_left = outbuf[0];
 
 return 0;
 }
 
-static int read_yuv_component_line(CLLCContext *ctx, GetBitContext *gb,
+static int read_yuv_component_line(CLLCContext *ctx, 

[libav-devel] [PATCH 07/35] adpcm: Convert to the new bitstream header

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/adpcm.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 3ab16dd..fe51c0d 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -29,8 +29,9 @@
  * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "put_bits.h"
 #include "bytestream.h"
 #include "adpcm.h"
@@ -366,32 +367,33 @@ static int xa_decode(AVCodecContext *avctx, int16_t 
*out0, int16_t *out1,
 static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int 
buf_size, int16_t *samples)
 {
 ADPCMDecodeContext *c = avctx->priv_data;
-GetBitContext gb;
+BitstreamContext bc;
 const int *table;
 int k0, signmask, nb_bits, count;
 int size = buf_size*8;
 int i;
 
-init_get_bits(, buf, size);
+bitstream_init(, buf, size);
 
 //read bits & initial values
-nb_bits = get_bits(, 2)+2;
+nb_bits = bitstream_read(, 2)+2;
 table = swf_index_tables[nb_bits-2];
 k0 = 1 << (nb_bits-2);
 signmask = 1 << (nb_bits-1);
 
-while (get_bits_count() <= size - 22*avctx->channels) {
+while (bitstream_tell() <= size - 22 * avctx->channels) {
 for (i = 0; i < avctx->channels; i++) {
-*samples++ = c->status[i].predictor = get_sbits(, 16);
-c->status[i].step_index = get_bits(, 6);
+*samples++  =
+c->status[i].predictor  = bitstream_read_signed(, 16);
+c->status[i].step_index = bitstream_read(, 6);
 }
 
-for (count = 0; get_bits_count() <= size - nb_bits*avctx->channels 
&& count < 4095; count++) {
+for (count = 0; bitstream_tell() <= size - nb_bits * 
avctx->channels && count < 4095; count++) {
 int i;
 
 for (i = 0; i < avctx->channels; i++) {
 // similar to IMA adpcm
-int delta = get_bits(, nb_bits);
+int delta = bitstream_read(, nb_bits);
 int step = ff_adpcm_step_table[c->status[i].step_index];
 long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
 int k = k0;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 08/35] asvdec: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/asv.h|  4 ++--
 libavcodec/asvdec.c | 54 ++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/libavcodec/asv.h b/libavcodec/asv.h
index 18f7a95..7c4e4fd 100644
--- a/libavcodec/asv.h
+++ b/libavcodec/asv.h
@@ -31,11 +31,11 @@
 #include "libavutil/mem.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "blockdsp.h"
 #include "bswapdsp.h"
 #include "fdctdsp.h"
 #include "idctdsp.h"
-#include "get_bits.h"
 #include "pixblockdsp.h"
 #include "put_bits.h"
 
@@ -47,7 +47,7 @@ typedef struct ASV1Context {
 IDCTDSPContext idsp;
 PixblockDSPContext pdsp;
 PutBitContext pb;
-GetBitContext gb;
+BitstreamContext bc;
 ScanTable scantable;
 int inv_qscale;
 int mb_width;
diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index f17f064..cbda63d 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -70,27 +70,27 @@ static av_cold void init_vlcs(ASV1Context *a)
 }
 
 // FIXME write a reversed bitstream reader to avoid the double reverse
-static inline int asv2_get_bits(GetBitContext *gb, int n)
+static inline int asv2_get_bits(BitstreamContext *bc, int n)
 {
-return ff_reverse[get_bits(gb, n) << (8 - n)];
+return ff_reverse[bitstream_read(bc, n) << (8 - n)];
 }
 
-static inline int asv1_get_level(GetBitContext *gb)
+static inline int asv1_get_level(BitstreamContext *bc)
 {
-int code = get_vlc2(gb, level_vlc.table, VLC_BITS, 1);
+int code = bitstream_read_vlc(bc, level_vlc.table, VLC_BITS, 1);
 
 if (code == 3)
-return get_sbits(gb, 8);
+return bitstream_read_signed(bc, 8);
 else
 return code - 3;
 }
 
-static inline int asv2_get_level(GetBitContext *gb)
+static inline int asv2_get_level(BitstreamContext *bc)
 {
-int code = get_vlc2(gb, asv2_level_vlc.table, ASV2_LEVEL_VLC_BITS, 1);
+int code = bitstream_read_vlc(bc, asv2_level_vlc.table, 
ASV2_LEVEL_VLC_BITS, 1);
 
 if (code == 31)
-return (int8_t) asv2_get_bits(gb, 8);
+return (int8_t) asv2_get_bits(bc, 8);
 else
 return code - 31;
 }
@@ -99,10 +99,10 @@ static inline int asv1_decode_block(ASV1Context *a, int16_t 
block[64])
 {
 int i;
 
-block[0] = 8 * get_bits(>gb, 8);
+block[0] = 8 * bitstream_read(>bc, 8);
 
 for (i = 0; i < 11; i++) {
-const int ccp = get_vlc2(>gb, ccp_vlc.table, VLC_BITS, 1);
+const int ccp = bitstream_read_vlc(>bc, ccp_vlc.table, VLC_BITS, 1);
 
 if (ccp) {
 if (ccp == 16)
@@ -113,13 +113,13 @@ static inline int asv1_decode_block(ASV1Context *a, 
int16_t block[64])
 }
 
 if (ccp & 8)
-block[a->scantable.permutated[4 * i + 0]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 0]) >> 4;
+block[a->scantable.permutated[4 * i + 0]] = 
(asv1_get_level(>bc) * a->intra_matrix[4 * i + 0]) >> 4;
 if (ccp & 4)
-block[a->scantable.permutated[4 * i + 1]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 1]) >> 4;
+block[a->scantable.permutated[4 * i + 1]] = 
(asv1_get_level(>bc) * a->intra_matrix[4 * i + 1]) >> 4;
 if (ccp & 2)
-block[a->scantable.permutated[4 * i + 2]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 2]) >> 4;
+block[a->scantable.permutated[4 * i + 2]] = 
(asv1_get_level(>bc) * a->intra_matrix[4 * i + 2]) >> 4;
 if (ccp & 1)
-block[a->scantable.permutated[4 * i + 3]] = 
(asv1_get_level(>gb) * a->intra_matrix[4 * i + 3]) >> 4;
+block[a->scantable.permutated[4 * i + 3]] = 
(asv1_get_level(>bc) * a->intra_matrix[4 * i + 3]) >> 4;
 }
 }
 
@@ -130,32 +130,32 @@ static inline int asv2_decode_block(ASV1Context *a, 
int16_t block[64])
 {
 int i, count, ccp;
 
-count = asv2_get_bits(>gb, 4);
+count = asv2_get_bits(>bc, 4);
 
-block[0] = 8 * asv2_get_bits(>gb, 8);
+block[0] = 8 * asv2_get_bits(>bc, 8);
 
-ccp = get_vlc2(>gb, dc_ccp_vlc.table, VLC_BITS, 1);
+ccp = bitstream_read_vlc(>bc, dc_ccp_vlc.table, VLC_BITS, 1);
 if (ccp) {
 if (ccp & 4)
-block[a->scantable.permutated[1]] = (asv2_get_level(>gb) * 
a->intra_matrix[1]) >> 4;
+block[a->scantable.permutated[1]] = (asv2_get_level(>bc) * 
a->intra_matrix[1]) >> 4;
 if (ccp & 2)
-block[a->scantable.permutated[2]] = (asv2_get_level(>gb) * 
a->intra_matrix[2]) >> 4;
+block[a->scantable.permutated[2]] = (asv2_get_level(>bc) * 
a->intra_matrix[2]) >> 4;
 if (ccp & 1)
-block[a->scantable.permutated[3]] = (asv2_get_level(>gb) * 
a->intra_matrix[3]) >> 4;
+block[a->scantable.permutated[3]] = (asv2_get_level(>bc) * 
a->intra_matrix[3]) >> 4;
 }
 
 for (i = 1; i < count + 1; i++) {
-const int ccp = get_vlc2(>gb, ac_ccp_vlc.table, VLC_BITS, 1);
+   

[libav-devel] [PATCH 11/35] avs: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/avs.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index 0d127f8..bea01a2 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -20,7 +20,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 typedef struct AvsContext {
@@ -57,7 +57,7 @@ avs_decode_frame(AVCodecContext * avctx,
 int i, j, x, y, stride, ret, vect_w = 3, vect_h = 3;
 AvsVideoSubType sub_type;
 AvsBlockType type;
-GetBitContext change_map;
+BitstreamContext change_map;
 
 if ((ret = ff_reget_buffer(avctx, p)) < 0) {
 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
@@ -125,13 +125,13 @@ avs_decode_frame(AVCodecContext * avctx,
 int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h);
 if (buf_end - table < map_size)
 return AVERROR_INVALIDDATA;
-init_get_bits(_map, table, map_size * 8);
+bitstream_init(_map, table, map_size * 8);
 table += map_size;
 }
 
 for (y=0; y<198; y+=vect_h) {
 for (x=0; x<318; x+=vect_w) {
-if (sub_type == AVS_I_FRAME || get_bits1(_map)) {
+if (sub_type == AVS_I_FRAME || bitstream_read_bit(_map)) {
 if (buf_end - table < 1)
 return AVERROR_INVALIDDATA;
 vect = [*table++ * (vect_w * vect_h)];
@@ -145,7 +145,7 @@ avs_decode_frame(AVCodecContext * avctx,
 }
 }
 if (sub_type != AVS_I_FRAME)
-align_get_bits(_map);
+bitstream_align(_map);
 }
 
 if ((ret = av_frame_ref(picture, p)) < 0)
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 13/35] binkaudio: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/binkaudio.c | 59 +-
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index 2638eb2..cf61135 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -33,8 +33,8 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
+#include "bitstream.h"
 #include "dct.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "rdft.h"
 #include "wma_freqs.h"
@@ -45,7 +45,7 @@ static float quant_table[96];
 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
 
 typedef struct BinkAudioContext {
-GetBitContext gb;
+BitstreamContext bc;
 int version_b;  ///< Bink version 'b'
 int first;
 int channels;
@@ -143,11 +143,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
 return 0;
 }
 
-static float get_float(GetBitContext *gb)
+static float get_float(BitstreamContext *bc)
 {
-int power = get_bits(gb, 5);
-float f = ldexpf(get_bits_long(gb, 23), power - 23);
-if (get_bits1(gb))
+int power = bitstream_read(bc, 5);
+float f = ldexpf(bitstream_read(bc, 23), power - 23);
+if (bitstream_read_bit(bc))
 f = -f;
 return f;
 }
@@ -166,30 +166,30 @@ static int decode_block(BinkAudioContext *s, float **out, 
int use_dct)
 int ch, i, j, k;
 float q, quant[25];
 int width, coeff;
-GetBitContext *gb = >gb;
+BitstreamContext *bc = >bc;
 
 if (use_dct)
-skip_bits(gb, 2);
+bitstream_skip(bc, 2);
 
 for (ch = 0; ch < s->channels; ch++) {
 FFTSample *coeffs = out[ch];
 
 if (s->version_b) {
-if (get_bits_left(gb) < 64)
+if (bitstream_bits_left(bc) < 64)
 return AVERROR_INVALIDDATA;
-coeffs[0] = av_int2float(get_bits_long(gb, 32)) * s->root;
-coeffs[1] = av_int2float(get_bits_long(gb, 32)) * s->root;
+coeffs[0] = av_int2float(bitstream_read(bc, 32)) * s->root;
+coeffs[1] = av_int2float(bitstream_read(bc, 32)) * s->root;
 } else {
-if (get_bits_left(gb) < 58)
+if (bitstream_bits_left(bc) < 58)
 return AVERROR_INVALIDDATA;
-coeffs[0] = get_float(gb) * s->root;
-coeffs[1] = get_float(gb) * s->root;
+coeffs[0] = get_float(bc) * s->root;
+coeffs[1] = get_float(bc) * s->root;
 }
 
-if (get_bits_left(gb) < s->num_bands * 8)
+if (bitstream_bits_left(bc) < s->num_bands * 8)
 return AVERROR_INVALIDDATA;
 for (i = 0; i < s->num_bands; i++) {
-int value = get_bits(gb, 8);
+int value = bitstream_read(bc, 8);
 quant[i]  = quant_table[FFMIN(value, 95)];
 }
 
@@ -202,9 +202,9 @@ static int decode_block(BinkAudioContext *s, float **out, 
int use_dct)
 if (s->version_b) {
 j = i + 16;
 } else {
-int v = get_bits1(gb);
+int v = bitstream_read_bit(bc);
 if (v) {
-v = get_bits(gb, 4);
+v = bitstream_read(bc, 4);
 j = i + rle_length_tab[v] * 8;
 } else {
 j = i + 8;
@@ -213,7 +213,7 @@ static int decode_block(BinkAudioContext *s, float **out, 
int use_dct)
 
 j = FFMIN(j, s->frame_len);
 
-width = get_bits(gb, 4);
+width = bitstream_read(bc, 4);
 if (width == 0) {
 memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
 i = j;
@@ -223,10 +223,10 @@ static int decode_block(BinkAudioContext *s, float **out, 
int use_dct)
 while (i < j) {
 if (s->bands[k] == i)
 q = quant[k++];
-coeff = get_bits(gb, width);
+coeff = bitstream_read(bc, width);
 if (coeff) {
 int v;
-v = get_bits1(gb);
+v = bitstream_read_bit(bc);
 if (v)
 coeffs[i] = -q * coeff;
 else
@@ -278,10 +278,11 @@ static av_cold int decode_end(AVCodecContext *avctx)
 return 0;
 }
 
-static void get_bits_align32(GetBitContext *s)
+static void get_bits_align32(BitstreamContext *s)
 {
-int n = (-get_bits_count(s)) & 31;
-if (n) skip_bits(s, n);
+int n = (-bitstream_tell(s)) & 31;
+if (n)
+bitstream_skip(s, n);
 }
 
 static int decode_frame(AVCodecContext *avctx, void *data,
@@ -289,10 +290,10 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 {
 BinkAudioContext *s = avctx->priv_data;
 AVFrame *frame  = data;
-GetBitContext *gb = >gb;
+BitstreamContext *bc = >bc;
 int ret, consumed = 0;
 
-if (!get_bits_left(gb)) {
+if 

[libav-devel] [PATCH 01/35] lavc: add a new bitstream reader to replace get_bits

2016-11-14 Thread Alexandra Hájková
The new bit reader features a simpler API and an implementation without
stacks of nested macros.
---
 libavcodec/bitstream.h | 387 +
 1 file changed, 387 insertions(+)
 create mode 100644 libavcodec/bitstream.h

diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h
new file mode 100644
index 000..996e32e
--- /dev/null
+++ b/libavcodec/bitstream.h
@@ -0,0 +1,387 @@
+/*
+ * Copyright (c) 2016 Alexandra Hájková
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * functions for reading bits from a buffer
+ */
+
+#ifndef AVCODEC_BITSTREAM_H
+#define AVCODEC_BITSTREAM_H
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+
+#include "mathops.h"
+#include "vlc.h"
+
+typedef struct BitstreamContext {
+uint64_t bits;  // stores bits read from the buffer
+const uint8_t *buffer, *buffer_end;
+const uint8_t *ptr; // position inside a buffer
+unsigned bits_left; // number of bits left in bits field
+unsigned size_in_bits;
+} BitstreamContext;
+
+static inline void refill_64(BitstreamContext *bc)
+{
+if (bc->ptr >= bc->buffer_end)
+return;
+
+#ifdef BITSTREAM_READER_LE
+bc->bits   = AV_RL64(bc->ptr);
+#else
+bc->bits   = AV_RB64(bc->ptr);
+#endif
+bc->ptr   += 8;
+bc->bits_left  = 64;
+}
+
+static inline void refill_32(BitstreamContext *bc)
+{
+if (bc->ptr >= bc->buffer_end)
+return;
+
+#ifdef BITSTREAM_READER_LE
+bc->bits   = (uint64_t)AV_RL32(bc->ptr) << bc->bits_left | bc->bits;
+#else
+bc->bits   = bc->bits | (uint64_t)AV_RB32(bc->ptr) << (32 - 
bc->bits_left);
+#endif
+bc->ptr   += 4;
+bc->bits_left += 32;
+}
+
+/* Initialize BitstreamContext. Input buffer must have an additional zero
+ * padding of AV_INPUT_BUFFER_PADDING_SIZE bytes at the end. */
+static inline int bitstream_init(BitstreamContext *bc, const uint8_t *buffer,
+ unsigned bit_size)
+{
+unsigned buffer_size;
+
+if (bit_size > INT_MAX - 7 || !buffer) {
+buffer=
+bc->buffer=
+bc->ptr   = NULL;
+bc->bits_left = 0;
+return AVERROR_INVALIDDATA;
+}
+
+buffer_size = (bit_size + 7) >> 3;
+
+bc->buffer   = buffer;
+bc->buffer_end   = buffer + buffer_size;
+bc->ptr  = bc->buffer;
+bc->size_in_bits = bit_size;
+bc->bits_left= 0;
+bc->bits = 0;
+
+refill_64(bc);
+
+return 0;
+}
+
+/* Initialize BitstreamContext with buffer size in bytes instead of bits. */
+static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,
+  unsigned byte_size)
+{
+if (byte_size > INT_MAX / 8)
+return AVERROR_INVALIDDATA;
+return bitstream_init(bc, buffer, byte_size * 8);
+}
+
+/* Return number of bits already read. */
+static inline int bitstream_tell(const BitstreamContext *bc)
+{
+return (bc->ptr - bc->buffer) * 8 - bc->bits_left;
+}
+
+/* Return buffer size in bits. */
+static inline int bitstream_tell_size(const BitstreamContext *bc)
+{
+return bc->size_in_bits;
+}
+
+/* Return the number of the bits left in a buffer. */
+static inline int bitstream_bits_left(const BitstreamContext *bc)
+{
+return (bc->buffer - bc->ptr) * 8 + bc->size_in_bits + bc->bits_left;
+}
+
+static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
+{
+#ifdef BITSTREAM_READER_LE
+uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
+bc->bits >>= n;
+#else
+uint64_t ret = bc->bits >> (64 - n);
+bc->bits <<= n;
+#endif
+bc->bits_left -= n;
+
+return ret;
+}
+
+/* Return one bit from the buffer. */
+static inline unsigned bitstream_read_bit(BitstreamContext *bc)
+{
+if (!bc->bits_left)
+refill_64(bc);
+
+return get_val(bc, 1);
+}
+
+/* Return n bits from the buffer. n has to be in the 0-63 range. */
+static inline uint64_t bitstream_read_63(BitstreamContext *bc, unsigned n)
+{
+uint64_t ret = 0;
+#ifdef BITSTREAM_READER_LE
+uint64_t left = 0;
+#endif
+
+if (!n)
+return 0;
+
+if (n > bc->bits_left) {
+n -= bc->bits_left;
+#ifdef BITSTREAM_READER_LE
+   

[libav-devel] [PATCH 04/35] ea: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/eatgq.c | 34 +-
 libavcodec/eatgv.c | 22 +++---
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index 8355471..9abedcc 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -31,9 +31,9 @@
 #define BITSTREAM_READER_LE
 #include "aandcttab.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "eaidct.h"
-#include "get_bits.h"
 #include "idctdsp.h"
 #include "internal.h"
 
@@ -58,44 +58,44 @@ static av_cold int tgq_decode_init(AVCodecContext *avctx)
 return 0;
 }
 
-static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext 
*gb)
+static void tgq_decode_block(TgqContext *s, int16_t block[64], 
BitstreamContext *bc)
 {
 uint8_t *perm = s->scantable.permutated;
 int i, j, value;
-block[0] = get_sbits(gb, 8) * s->qtable[0];
+block[0] = bitstream_read_signed(bc, 8) * s->qtable[0];
 for (i = 1; i < 64;) {
-switch (show_bits(gb, 3)) {
+switch (bitstream_peek(bc, 3)) {
 case 4:
 block[perm[i++]] = 0;
 case 0:
 block[perm[i++]] = 0;
-skip_bits(gb, 3);
+bitstream_skip(bc, 3);
 break;
 case 5:
 case 1:
-skip_bits(gb, 2);
-value = get_bits(gb, 6);
+bitstream_skip(bc, 2);
+value = bitstream_read(bc, 6);
 for (j = 0; j < value; j++)
 block[perm[i++]] = 0;
 break;
 case 6:
-skip_bits(gb, 3);
+bitstream_skip(bc, 3);
 block[perm[i]] = -s->qtable[perm[i]];
 i++;
 break;
 case 2:
-skip_bits(gb, 3);
+bitstream_skip(bc, 3);
 block[perm[i]] = s->qtable[perm[i]];
 i++;
 break;
 case 7: // 111b
 case 3: // 011b
-skip_bits(gb, 2);
-if (show_bits(gb, 6) == 0x3F) {
-skip_bits(gb, 6);
-block[perm[i]] = get_sbits(gb, 8) * s->qtable[perm[i]];
+bitstream_skip(bc, 2);
+if (bitstream_peek(bc, 6) == 0x3F) {
+bitstream_skip(bc, 6);
+block[perm[i]] = bitstream_read_signed(bc, 8) * 
s->qtable[perm[i]];
 } else {
-block[perm[i]] = get_sbits(gb, 6) * s->qtable[perm[i]];
+block[perm[i]] = bitstream_read_signed(bc, 6) * 
s->qtable[perm[i]];
 }
 i++;
 break;
@@ -156,10 +156,10 @@ static void tgq_decode_mb(TgqContext *s, AVFrame *frame, 
int mb_y, int mb_x)
 
 mode = bytestream2_get_byte(>gb);
 if (mode > 12) {
-GetBitContext gb;
-init_get_bits(, s->gb.buffer, FFMIN(s->gb.buffer_end - 
s->gb.buffer, mode) * 8);
+BitstreamContext bc;
+bitstream_init(, s->gb.buffer, FFMIN(s->gb.buffer_end - 
s->gb.buffer, mode) * 8);
 for (i = 0; i < 6; i++)
-tgq_decode_block(s, s->block[i], );
+tgq_decode_block(s, s->block[i], );
 tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
 bytestream2_skip(>gb, mode);
 } else {
diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c
index 7a50d01..549b5b6 100644
--- a/libavcodec/eatgv.c
+++ b/libavcodec/eatgv.c
@@ -33,7 +33,7 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 
 #define EA_PREAMBLE_SIZE8
@@ -153,7 +153,7 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame,
 int num_blocks_packed;
 int vector_bits;
 int i,j,x,y;
-GetBitContext gb;
+BitstreamContext bc;
 int mvbits;
 const uint8_t *blocks_raw;
 
@@ -166,7 +166,7 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame,
 vector_bits   = AV_RL16([6]);
 buf += 12;
 
-if (vector_bits > MIN_CACHE_BITS || !vector_bits) {
+if (vector_bits > 32 || !vector_bits) {
 av_log(s->avctx, AV_LOG_ERROR,
"Invalid value for motion vector bits: %d\n", vector_bits);
 return AVERROR_INVALIDDATA;
@@ -195,10 +195,10 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame,
 if (buf + (mvbits >> 3) + 16 * num_blocks_raw + 8 * num_blocks_packed > 
buf_end)
 return AVERROR_INVALIDDATA;
 
-init_get_bits(, buf, mvbits);
+bitstream_init(, buf, mvbits);
 for (i = 0; i < num_mvs; i++) {
-s->mv_codebook[i][0] = get_sbits(, 10);
-s->mv_codebook[i][1] = get_sbits(, 10);
+s->mv_codebook[i][0] = bitstream_read_signed(, 10);
+s->mv_codebook[i][1] = bitstream_read_signed(, 10);
 }
 buf += mvbits >> 3;
 
@@ -207,23 +207,23 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame,
 buf   += num_blocks_raw * 16;
 
 /* read compressed blocks */
-init_get_bits(, buf, (buf_end - buf) << 3);

[libav-devel] [PATCH 16/35] cook: Convert to the new bitstream reader

2016-11-14 Thread Alexandra Hájková
Signed-off-by: Anton Khirnov 
---
 libavcodec/cook.c | 53 +++--
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index c990333..c3304ea 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -47,7 +47,7 @@
 
 #include "audiodsp.h"
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "fft.h"
 #include "internal.h"
@@ -124,7 +124,7 @@ typedef struct cook {
 
 AVCodecContext* avctx;
 AudioDSPContext adsp;
-GetBitContext   gb;
+BitstreamContextbc;
 /* stream data */
 int num_vectors;
 int samples_per_channel;
@@ -325,23 +325,23 @@ static av_cold int cook_decode_close(AVCodecContext 
*avctx)
 /**
  * Fill the gain array for the timedomain quantization.
  *
- * @param gb  pointer to the GetBitContext
+ * @param bc  pointer to the BitstreamContext
  * @param gaininfoarray[9] of gain indexes
  */
-static void decode_gain_info(GetBitContext *gb, int *gaininfo)
+static void decode_gain_info(BitstreamContext *bc, int *gaininfo)
 {
 int i, n;
 
-while (get_bits1(gb)) {
+while (bitstream_read_bit(bc)) {
 /* NOTHING */
 }
 
-n = get_bits_count(gb) - 1; // amount of elements*2 to update
+n = bitstream_tell(bc) - 1; // amount of elements * 2 to update
 
 i = 0;
 while (n--) {
-int index = get_bits(gb, 3);
-int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1;
+int index = bitstream_read(bc, 3);
+int gain = bitstream_read_bit(bc) ? bitstream_read(bc, 4) - 7 : -1;
 
 while (i <= index)
 gaininfo[i++] = gain;
@@ -361,7 +361,7 @@ static int decode_envelope(COOKContext *q, COOKSubpacket *p,
 {
 int i, j, vlc_index;
 
-quant_index_table[0] = get_bits(>gb, 6) - 6; // This is used later in 
categorize
+quant_index_table[0] = bitstream_read(>bc, 6) - 6; // This is used 
later in categorize
 
 for (i = 1; i < p->total_subbands; i++) {
 vlc_index = i;
@@ -375,8 +375,8 @@ static int decode_envelope(COOKContext *q, COOKSubpacket *p,
 if (vlc_index > 13)
 vlc_index = 13; // the VLC tables >13 are identical to No. 13
 
-j = get_vlc2(>gb, q->envelope_quant_index[vlc_index - 1].table,
- q->envelope_quant_index[vlc_index - 1].bits, 2);
+j = bitstream_read_vlc(>bc, q->envelope_quant_index[vlc_index - 
1].table,
+   q->envelope_quant_index[vlc_index - 1].bits, 2);
 quant_index_table[i] = quant_index_table[i - 1] + j - 12; // 
differential encoding
 if (quant_index_table[i] > 63 || quant_index_table[i] < -63) {
 av_log(q->avctx, AV_LOG_ERROR,
@@ -408,7 +408,7 @@ static void categorize(COOKContext *q, COOKSubpacket *p, 
int *quant_index_table,
 int tmp_categorize_array1_idx = p->numvector_size;
 int tmp_categorize_array2_idx = p->numvector_size;
 
-bits_left = p->bits_per_subpacket - get_bits_count(>gb);
+bits_left = p->bits_per_subpacket - bitstream_tell(>bc);
 
 if (bits_left > q->samples_per_channel)
 bits_left = q->samples_per_channel +
@@ -554,8 +554,8 @@ static int unpack_SQVH(COOKContext *q, COOKSubpacket *p, 
int category,
 vd = vd_tab[category];
 result = 0;
 for (i = 0; i < vpr_tab[category]; i++) {
-vlc = get_vlc2(>gb, q->sqvh[category].table, 
q->sqvh[category].bits, 3);
-if (p->bits_per_subpacket < get_bits_count(>gb)) {
+vlc = bitstream_read_vlc(>bc, q->sqvh[category].table, 
q->sqvh[category].bits, 3);
+if (p->bits_per_subpacket < bitstream_tell(>bc)) {
 vlc = 0;
 result = 1;
 }
@@ -566,8 +566,8 @@ static int unpack_SQVH(COOKContext *q, COOKSubpacket *p, 
int category,
 }
 for (j = 0; j < vd; j++) {
 if (subband_coef_index[i * vd + j]) {
-if (get_bits_count(>gb) < p->bits_per_subpacket) {
-subband_coef_sign[i * vd + j] = get_bits1(>gb);
+if (bitstream_tell(>bc) < p->bits_per_subpacket) {
+subband_coef_sign[i * vd + j] = bitstream_read_bit(>bc);
 } else {
 result = 1;
 subband_coef_sign[i * vd + j] = 0;
@@ -634,7 +634,7 @@ static int mono_decode(COOKContext *q, COOKSubpacket *p, 
float *mlt_buffer)
 
 if ((res = decode_envelope(q, p, quant_index_table)) < 0)
 return res;
-q->num_vectors = get_bits(>gb, p->log2_numvector_size);
+q->num_vectors = bitstream_read(>bc, p->log2_numvector_size);
 categorize(q, p, quant_index_table, category, category_index);
 expand_category(q, category, category_index);
 decode_vectors(q, p, category, quant_index_table, mlt_buffer);
@@ -739,7 +739,7 @@ static void imlt_gain(COOKContext *q, float *inbuffer,
 static void 

Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Anton Khirnov
Quoting Diego Biurrun (2016-11-14 11:58:34)
> On Mon, Nov 14, 2016 at 11:40:22AM +0100, Anton Khirnov wrote:
> > Quoting Diego Biurrun (2016-11-14 10:27:32)
> > > On Mon, Nov 14, 2016 at 10:12:02AM +0100, Anton Khirnov wrote:
> > > > Quoting Diego Biurrun (2016-11-14 10:03:43)
> > > > > On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> > > > > > Quoting Diego Biurrun (2016-11-14 09:05:33)
> > > > > > > Fixes a number of warnings of the type
> > > > > > > libavutil/hmac.c:61:21: warning: assignment from incompatible 
> > > > > > > pointer type
> > > > > > 
> > > > > > No, this does not "fix" anything. It hides real warnings caused by 
> > > > > > real
> > > > > > problems. I really wish you stopped fixing warnings and perhaps 
> > > > > > fixed
> > > > > > the bugs that cause those warnings instead.
> > > > > 
> > > > > Interestingly, this patch is from Kostya. I'm open to your suggestion
> > > > > of the "real fix".
> > > > 
> > > > What does it matter who is it from? It is wrong. The compiler prints a
> > > > warning because you're calling a function using a wrong signature
> > > > (signed int vs unsigned). Strictly speaking, this is UB. The only thing
> > > > this patch does is shut up the warning, but the problem is still there -
> > > > you are still calling a function using a wrong signature.
> > > 
> > > No, the signed vs. unsigned thing is not the issue and does not affect the
> > > warning(s).
> > 
> > It may not be the _only_ reason for the warnings, but it is certainly
> > one of the reasons.
> 
> You always need a cast to assign non-identical function pointers.
> 
> What is it that you suggest should be done? Change the API for sha and
> md5 take unsigned or size_t as type for the length parameter? We use
> nt as type for sizes in 99% of all cases throughout the codebase.

MD5 already takes int, it's just SHA that's unsigned. Ideally all of
those should be size_t, so breaking API is one possibility.
Another, non-breaking one, would be to add wrappers to hmac.c, similarly
to what it already does for sha init.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Diego Biurrun
On Mon, Nov 14, 2016 at 11:40:22AM +0100, Anton Khirnov wrote:
> Quoting Diego Biurrun (2016-11-14 10:27:32)
> > On Mon, Nov 14, 2016 at 10:12:02AM +0100, Anton Khirnov wrote:
> > > Quoting Diego Biurrun (2016-11-14 10:03:43)
> > > > On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> > > > > Quoting Diego Biurrun (2016-11-14 09:05:33)
> > > > > > Fixes a number of warnings of the type
> > > > > > libavutil/hmac.c:61:21: warning: assignment from incompatible 
> > > > > > pointer type
> > > > > 
> > > > > No, this does not "fix" anything. It hides real warnings caused by 
> > > > > real
> > > > > problems. I really wish you stopped fixing warnings and perhaps fixed
> > > > > the bugs that cause those warnings instead.
> > > > 
> > > > Interestingly, this patch is from Kostya. I'm open to your suggestion
> > > > of the "real fix".
> > > 
> > > What does it matter who is it from? It is wrong. The compiler prints a
> > > warning because you're calling a function using a wrong signature
> > > (signed int vs unsigned). Strictly speaking, this is UB. The only thing
> > > this patch does is shut up the warning, but the problem is still there -
> > > you are still calling a function using a wrong signature.
> > 
> > No, the signed vs. unsigned thing is not the issue and does not affect the
> > warning(s).
> 
> It may not be the _only_ reason for the warnings, but it is certainly
> one of the reasons.

You always need a cast to assign non-identical function pointers.

What is it that you suggest should be done? Change the API for sha and
md5 take unsigned or size_t as type for the length parameter? We use
nt as type for sizes in 99% of all cases throughout the codebase.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Anton Khirnov
Quoting Diego Biurrun (2016-11-14 10:27:32)
> On Mon, Nov 14, 2016 at 10:12:02AM +0100, Anton Khirnov wrote:
> > Quoting Diego Biurrun (2016-11-14 10:03:43)
> > > On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> > > > Quoting Diego Biurrun (2016-11-14 09:05:33)
> > > > > Fixes a number of warnings of the type
> > > > > libavutil/hmac.c:61:21: warning: assignment from incompatible pointer 
> > > > > type
> > > > 
> > > > No, this does not "fix" anything. It hides real warnings caused by real
> > > > problems. I really wish you stopped fixing warnings and perhaps fixed
> > > > the bugs that cause those warnings instead.
> > > 
> > > Interestingly, this patch is from Kostya. I'm open to your suggestion
> > > of the "real fix".
> > 
> > What does it matter who is it from? It is wrong. The compiler prints a
> > warning because you're calling a function using a wrong signature
> > (signed int vs unsigned). Strictly speaking, this is UB. The only thing
> > this patch does is shut up the warning, but the problem is still there -
> > you are still calling a function using a wrong signature.
> 
> No, the signed vs. unsigned thing is not the issue and does not affect the
> warning(s).

It may not be the _only_ reason for the warnings, but it is certainly
one of the reasons.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] aarch64: vp9: use alternative returns in the core loop filter function

2016-11-14 Thread Martin Storsjö

On Mon, 14 Nov 2016, Janne Grunau wrote:


Since aarch64 has enough free general purpose registers use them to
branch to the appropiate storage code. 1-2 cycles faster for the
functions using loop_filter 8/16, ... on a cortex-a53. Mixed results
(up to 2 cycles faster/slower) on a cortex-a57.
---
libavcodec/aarch64/vp9lpf_neon.S | 48 +++-
1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/libavcodec/aarch64/vp9lpf_neon.S b/libavcodec/aarch64/vp9lpf_neon.S
index 995a97d..3a82bd4 100644
--- a/libavcodec/aarch64/vp9lpf_neon.S
+++ b/libavcodec/aarch64/vp9lpf_neon.S
@@ -410,15 +410,19 @@
.endif
// If no pixels needed flat8in nor flat8out, jump to a
// writeout of the inner 4 pixels
-cbz x5,  7f
+cbnzx5,  1f
+br  x14
+1:
mov x5,  v7.d[0]
.ifc \sz, .16b
mov x6,  v2.d[1]
orr x5,  x5,  x6
.endif
// If no pixels need flat8out, jump to a writeout of the inner 6 pixels
-cbz x5,  8f
+cbnzx5,  1f
+br  x15

+1:
// flat8out
// This writes all outputs into v2-v17 (skipping v6 and v16).
// If this part is skipped, the output is read from v21-v26 (which is 
the input
@@ -549,35 +553,24 @@ endfunc

function vp9_loop_filter_8
loop_filter 8,  .8b,  0,v16, v17, v18, v19, v28, v29, v30, v31
-mov x5,  #0
ret
6:
-mov x5,  #6
-ret
+br  x13
9:
br  x10
endfunc


Looks really neat, thanks!

Couldn't you get rid of the 6: label here as well, with something like 
this?


@@ -352,7 +352,13 @@
 .endif
 // If no pixels need flat8in, jump to flat8out
 // (or to a writeout of the inner 4 pixels, for wd=8)
+.if \wd == 16
 cbz x5,  6f
+.else
+cbnzx5,  6f
+br  x13
+6:
+.endif

And similarly for the 9: label for all cases except \wd == 16 (where we 
need it for the clobbered registers).


// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Diego Biurrun
On Mon, Nov 14, 2016 at 10:12:02AM +0100, Anton Khirnov wrote:
> Quoting Diego Biurrun (2016-11-14 10:03:43)
> > On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> > > Quoting Diego Biurrun (2016-11-14 09:05:33)
> > > > Fixes a number of warnings of the type
> > > > libavutil/hmac.c:61:21: warning: assignment from incompatible pointer 
> > > > type
> > > 
> > > No, this does not "fix" anything. It hides real warnings caused by real
> > > problems. I really wish you stopped fixing warnings and perhaps fixed
> > > the bugs that cause those warnings instead.
> > 
> > Interestingly, this patch is from Kostya. I'm open to your suggestion
> > of the "real fix".
> 
> What does it matter who is it from? It is wrong. The compiler prints a
> warning because you're calling a function using a wrong signature
> (signed int vs unsigned). Strictly speaking, this is UB. The only thing
> this patch does is shut up the warning, but the problem is still there -
> you are still calling a function using a wrong signature.

No, the signed vs. unsigned thing is not the issue and does not affect the
warning(s).

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Anton Khirnov
Quoting Diego Biurrun (2016-11-14 10:03:43)
> On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> > Quoting Diego Biurrun (2016-11-14 09:05:33)
> > > Fixes a number of warnings of the type
> > > libavutil/hmac.c:61:21: warning: assignment from incompatible pointer type
> > 
> > No, this does not "fix" anything. It hides real warnings caused by real
> > problems. I really wish you stopped fixing warnings and perhaps fixed
> > the bugs that cause those warnings instead.
> 
> Interestingly, this patch is from Kostya. I'm open to your suggestion
> of the "real fix".

What does it matter who is it from? It is wrong. The compiler prints a
warning because you're calling a function using a wrong signature
(signed int vs unsigned). Strictly speaking, this is UB. The only thing
this patch does is shut up the warning, but the problem is still there -
you are still calling a function using a wrong signature.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Diego Biurrun
On Mon, Nov 14, 2016 at 09:20:12AM +0100, Anton Khirnov wrote:
> Quoting Diego Biurrun (2016-11-14 09:05:33)
> > Fixes a number of warnings of the type
> > libavutil/hmac.c:61:21: warning: assignment from incompatible pointer type
> 
> No, this does not "fix" anything. It hides real warnings caused by real
> problems. I really wish you stopped fixing warnings and perhaps fixed
> the bugs that cause those warnings instead.

Interestingly, this patch is from Kostya. I'm open to your suggestion
of the "real fix".

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 7/8] qsv: Add VP8 decoder

2016-11-14 Thread Anton Khirnov
Quoting Mark Thompson (2016-10-27 22:00:05)
> ---
> The VP8 hwaccel (that is, output to opaque memory) doesn't actually work for 
> me, though the MSS 2017 release notes suggest this was something fixed in 
> that version.  Can anyone else try it?  (And is it worth keeping anyway even 
> if it currently works nowhere?)
> 
>  configure |  3 +++
>  libavcodec/Makefile   |  1 +
>  libavcodec/allcodecs.c|  2 ++
>  libavcodec/qsv.c  |  8 
>  libavcodec/qsvdec_other.c | 48 
> ++-
>  5 files changed, 61 insertions(+), 1 deletion(-)
> 

Tested that this works on Windows. So patch ok.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Anton Khirnov
Quoting Diego Biurrun (2016-11-14 09:05:33)
> Fixes a number of warnings of the type
> libavutil/hmac.c:61:21: warning: assignment from incompatible pointer type

No, this does not "fix" anything. It hides real warnings caused by real
problems. I really wish you stopped fixing warnings and perhaps fixed
the bugs that cause those warnings instead.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] golomb: Replace __PRETTY_FUNCTION__ with __func__ for tracing

2016-11-14 Thread Diego Biurrun
On Mon, Nov 14, 2016 at 09:05:04AM +0100, Diego Biurrun wrote:
> The former is a GNU extension while the latter is C99.
> ---
>  libavcodec/golomb.h | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

This was already approved by Janne; I resent it by mistake.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] hmac: Explicitly convert types at function pointer assignment

2016-11-14 Thread Diego Biurrun
Fixes a number of warnings of the type
libavutil/hmac.c:61:21: warning: assignment from incompatible pointer type
---
 libavutil/hmac.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index 378be62..62516be 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -29,12 +29,16 @@
 #define MAX_HASHLEN 32
 #define MAX_BLOCKLEN 64
 
+typedef void (*hmac_final)(void *, uint8_t *);
+typedef void (*hmac_update)(void *, const uint8_t *, int len);
+typedef void (*hmac_init)(void *);
+
 struct AVHMAC {
 void *hash;
 int blocklen, hashlen;
-void (*final)(void*, uint8_t*);
-void (*update)(void*, const uint8_t*, int len);
-void (*init)(void*);
+hmac_final  final;
+hmac_update update;
+hmac_init   init;
 uint8_t key[MAX_BLOCKLEN];
 int keylen;
 };
@@ -58,33 +62,33 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type)
 case AV_HMAC_MD5:
 c->blocklen = 64;
 c->hashlen  = 16;
-c->init = av_md5_init;
-c->update   = av_md5_update;
-c->final= av_md5_final;
+c->init = (hmac_init) av_md5_init;
+c->update   = (hmac_update) av_md5_update;
+c->final= (hmac_final) av_md5_final;
 c->hash = av_md5_alloc();
 break;
 case AV_HMAC_SHA1:
 c->blocklen = 64;
 c->hashlen  = 20;
 c->init = sha160_init;
-c->update   = av_sha_update;
-c->final= av_sha_final;
+c->update   = (hmac_update) av_sha_update;
+c->final= (hmac_final) av_sha_final;
 c->hash = av_sha_alloc();
 break;
 case AV_HMAC_SHA224:
 c->blocklen = 64;
 c->hashlen  = 28;
 c->init = sha224_init;
-c->update   = av_sha_update;
-c->final= av_sha_final;
+c->update   = (hmac_update) av_sha_update;
+c->final= (hmac_final) av_sha_final;
 c->hash = av_sha_alloc();
 break;
 case AV_HMAC_SHA256:
 c->blocklen = 64;
 c->hashlen  = 32;
 c->init = sha256_init;
-c->update   = av_sha_update;
-c->final= av_sha_final;
+c->update   = (hmac_update) av_sha_update;
+c->final= (hmac_final) av_sha_final;
 c->hash = av_sha_alloc();
 break;
 default:
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/2] examples/transcode_aac: Drop pointless return value const qualifier

2016-11-14 Thread Diego Biurrun
doc/examples/transcode_aac.c:52:20: warning: type qualifiers ignored on 
function return type [-Wignored-qualifiers]
---
 doc/examples/transcode_aac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index be86fe5..5c640d9 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -49,7 +49,7 @@
  * @param error Error code to be converted
  * @return Corresponding error text (not thread-safe)
  */
-static char *const get_error_text(const int error)
+static char *get_error_text(const int error)
 {
 static char error_buffer[255];
 av_strerror(error, error_buffer, sizeof(error_buffer));
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/2] golomb: Replace __PRETTY_FUNCTION__ with __func__ for tracing

2016-11-14 Thread Diego Biurrun
The former is a GNU extension while the latter is C99.
---
 libavcodec/golomb.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index bf80fae..9fafbcd 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -449,10 +449,10 @@ static inline int get_te(GetBitContext *s, int r, char 
*file, const char *func,
 return i;
 }
 
-#define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_te_golomb(a, r)  get_te(a, r, __FILE__, __PRETTY_FUNCTION__, 
__LINE__)
-#define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, 
__LINE__)
+#define get_ue_golomb(a) get_ue(a, __FILE__, __func__, __LINE__)
+#define get_se_golomb(a) get_se(a, __FILE__, __func__, __LINE__)
+#define get_te_golomb(a, r)  get_te(a, r, __FILE__, __func__, __LINE__)
+#define get_te0_golomb(a, r) get_te(a, r, __FILE__, __func__, __LINE__)
 
 #endif /* TRACE */
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel