Re: [libav-devel] [PATCH 09/14] svq3: Change type of array stride parameters to ptrdiff_t

2016-09-22 Thread Luca Barbato
On 22/09/16 19:24, Diego Biurrun wrote:
> On Tue, Sep 20, 2016 at 10:21:40PM +0100, Mark Thompson wrote:
>> On 20/09/16 22:07, Diego Biurrun wrote:
>>> On Tue, Sep 20, 2016 at 09:22:06PM +0100, Mark Thompson wrote:
 On 20/09/16 19:36, Diego Biurrun wrote:
> ptrdiff_t is the correct type for array strides and similar.
> --- a/libavcodec/svq3.c
> +++ b/libavcodec/svq3.c
> @@ -118,8 +118,8 @@ typedef struct SVQ3Context {
>  int mb_x, mb_y;
>  int mb_xy;
>  int mb_width, mb_height;
> -int mb_stride, mb_num;
> -int b_stride;
> +int mb_num;
> +ptrdiff_t mb_stride, b_stride;

 mb_stride should stay an int.
>>>
>>> Why?
>>
>> It's used as:
>>
>> (a) an offset against the current macroblock for prediction modes.
>>
>> (b) a multiplier for y offsets to macroblock lines.
>>
>> (c) a size for macroblock lines.
>>
>> All of the other things there are ints (well, last one could be size_t), and 
>> have nothing to do with pointers.
> 
> All of the above sounds stride-ish to me and we seem to use ptrdiff_t
> for such variables elsewhere.  Ame I wrong?

Probably, I think Mark is the second person finding wrong using ptrdiff
there.

lu

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


Re: [libav-devel] [PATCH 09/14] svq3: Change type of array stride parameters to ptrdiff_t

2016-09-22 Thread Diego Biurrun
On Tue, Sep 20, 2016 at 10:21:40PM +0100, Mark Thompson wrote:
> On 20/09/16 22:07, Diego Biurrun wrote:
> > On Tue, Sep 20, 2016 at 09:22:06PM +0100, Mark Thompson wrote:
> >> On 20/09/16 19:36, Diego Biurrun wrote:
> >>> ptrdiff_t is the correct type for array strides and similar.
> >>> --- a/libavcodec/svq3.c
> >>> +++ b/libavcodec/svq3.c
> >>> @@ -118,8 +118,8 @@ typedef struct SVQ3Context {
> >>>  int mb_x, mb_y;
> >>>  int mb_xy;
> >>>  int mb_width, mb_height;
> >>> -int mb_stride, mb_num;
> >>> -int b_stride;
> >>> +int mb_num;
> >>> +ptrdiff_t mb_stride, b_stride;
> >>
> >> mb_stride should stay an int.
> > 
> > Why?
> 
> It's used as:
> 
> (a) an offset against the current macroblock for prediction modes.
> 
> (b) a multiplier for y offsets to macroblock lines.
> 
> (c) a size for macroblock lines.
> 
> All of the other things there are ints (well, last one could be size_t), and 
> have nothing to do with pointers.

All of the above sounds stride-ish to me and we seem to use ptrdiff_t
for such variables elsewhere.  Ame I wrong?

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


[libav-devel] hwupload_cuda - Add P010 and YUV444P16 pixel format

2016-09-22 Thread Yogender Gupta


>>Are you going to add support for those to scale_npp as well?
yes, will submit a patch shortly

thx
yogender





---
This email message is for the sole use of the intended recipient(s) and may 
contain
confidential information.  Any unauthorized review, use, disclosure or 
distribution
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
---
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 5/6] lavc: add a bitstream filter for extracting extradata from packets

2016-09-22 Thread Diego Biurrun
I think this needs a version bump.

On Thu, Sep 22, 2016 at 04:29:10PM +0200, Anton Khirnov wrote:
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -21,6 +21,24 @@ Below is a description of the currently available 
> bitstream filters.
> +@table @option
> +@item remove
> +When this option is enabled, the long-term headers are additionally removed 
> from
> +the bitstream.

This sounds somehow awkward to me.  I suggest

  When this option is enabled, the long-term headers are removed from
  the bitstream after extraction.

> --- /dev/null
> +++ b/libavcodec/extract_extradata_bsf.c
> @@ -0,0 +1,300 @@
> +
> +typedef struct ExtractExtradataContext {
> +const AVClass *class;
> +
> +int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
> +   uint8_t **data, int *size);

IMO we could use more size_t for sizes.

> +static int extract_extradata_mpeg124(AVBSFContext *ctx, AVPacket *pkt,
> + uint8_t **data, int *size)
> +{
> +for (i = 0; i < pkt->size; i++) {
> +state = (state << 8) | pkt->data[i];
> +if ((is_mpeg12 && state != 0x1B3 && state != 0x1B5 && state < 0x200 
> && state >= 0x100) ||
> +(!is_mpeg12 && (state == 0x1B3 || state == 0x1B6))) {

magic

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


Re: [libav-devel] [PATCH 6/6] lavf: use the new bitstream filter for extracting extradata

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 04:29:11PM +0200, Anton Khirnov wrote:
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -113,6 +113,15 @@ struct AVStreamInternal {
>  
> +/* the context for extracting extradata in find_stream_info()
> + * inited=1/bsf=NULL signals that extracting is not possible (codec not
> + * supported) */
> +struct {
> +AVBSFContext *bsf;
> +AVPacket *pkt;
> +int inited;

"initialized"? "inited" is Engrish.

> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2089,6 +2089,104 @@ static int get_std_framerate(int i)
>  
> +static int extract_extradata_init(AVStream *st)
> +{
> +/* if init fails here, we assume extracting extradata is just not
> + * supported for this codec, so we return success */
> +ret = av_bsf_init(i->extract_extradata.bsf);
> +if (ret < 0) {
> +av_bsf_free(>extract_extradata.bsf);
> +ret = 0;
> +}
> +
> +finish:
> +i->extract_extradata.inited = 1;
> +
> +return 0;

Setting ret to 0 is pointless.

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


Re: [libav-devel] [PATCH 4/6] hevcdec: move parameter set parsing into a separate header

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 04:29:09PM +0200, Anton Khirnov wrote:
> This code is independent from the decoder, so it makes more sense for it
> to to have its own header.
> ---
>  libavcodec/hevc.h|   5 +
>  libavcodec/hevc_data.h   |  29 +
>  libavcodec/hevc_ps.c |  15 +--
>  libavcodec/hevc_ps.h | 320 
> +++
>  libavcodec/hevc_ps_enc.c |   2 +-
>  libavcodec/hevc_refs.c   |   2 +-
>  libavcodec/hevcdec.c |   3 +-
>  libavcodec/hevcdec.h | 301 +---
>  8 files changed, 370 insertions(+), 307 deletions(-)
>  create mode 100644 libavcodec/hevc_data.h
>  create mode 100644 libavcodec/hevc_ps.h
> 
> --- /dev/null
> +++ b/libavcodec/hevc_data.h
> @@ -0,0 +1,29 @@
> +
> +#ifndef AVCODEC_HEVC_DATA_H
> +#define AVCODEC_HEVC_DATA_H
> +
> +extern const uint8_t ff_hevc_diag_scan4x4_x[16];
> +extern const uint8_t ff_hevc_diag_scan4x4_y[16];
> +extern const uint8_t ff_hevc_diag_scan8x8_x[64];
> +extern const uint8_t ff_hevc_diag_scan8x8_y[64];
> +
> +#endif /* AVCODEC_HEVC_DATA_H */

This should be a separate patch IMO. Also, this header will not compile
standalone. Plus, hevc_data.c was not updated to #include it.

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


Re: [libav-devel] [PATCH 1/6] hevc: rename hevc.[ch] to hevcdec.[ch]

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 04:29:06PM +0200, Anton Khirnov wrote:
> This is more consistent with the rest of libav and frees up the hevc.h
> name for decoder-independent shared declarations.
> ---
>  libavcodec/Makefile   | 2 +-
>  libavcodec/dxva2_hevc.c   | 2 +-
>  libavcodec/hevc_cabac.c   | 2 +-
>  libavcodec/hevc_data.c| 2 +-
>  libavcodec/hevc_filter.c  | 2 +-
>  libavcodec/hevc_mp4toannexb_bsf.c | 2 +-
>  libavcodec/hevc_mvs.c | 2 +-
>  libavcodec/hevc_parser.c  | 2 +-
>  libavcodec/hevc_ps.c  | 2 +-
>  libavcodec/hevc_ps_enc.c  | 2 +-
>  libavcodec/hevc_refs.c| 2 +-
>  libavcodec/hevc_sei.c | 2 +-
>  libavcodec/{hevc.c => hevcdec.c}  | 2 +-
>  libavcodec/{hevc.h => hevcdec.h}  | 6 +++---
>  libavcodec/hevcdsp_template.c | 2 +-
>  libavcodec/hevcpred.c | 2 +-
>  libavcodec/hevcpred_template.c| 2 +-
>  libavcodec/qsvenc_hevc.c  | 2 +-
>  libavcodec/vaapi_encode_h265.c| 2 +-
>  libavcodec/vdpau_hevc.c   | 2 +-
>  libavformat/hevc.c| 2 +-
>  libavformat/hevcdec.c | 2 +-
>  22 files changed, 24 insertions(+), 24 deletions(-)
>  rename libavcodec/{hevc.c => hevcdec.c} (99%)
>  rename libavcodec/{hevc.h => hevcdec.h} (99%)

Hmm...

~/src/libav $ git grep -l hevc\\.h | cat
configure
libavcodec/dxva2_hevc.c
libavcodec/hevc.c
libavcodec/hevc_cabac.c
libavcodec/hevc_data.c
libavcodec/hevc_filter.c
libavcodec/hevc_mp4toannexb_bsf.c
libavcodec/hevc_mvs.c
libavcodec/hevc_parser.c
libavcodec/hevc_ps.c
libavcodec/hevc_ps_enc.c
libavcodec/hevc_refs.c
libavcodec/hevc_sei.c
libavcodec/hevcdsp_template.c
libavcodec/hevcpred.c
libavcodec/hevcpred_template.c
libavcodec/qsvenc_hevc.c
libavcodec/vaapi_encode_h265.c
libavcodec/vdpau_hevc.c
libavformat/hevc.c
libavformat/hevcdec.c
libavformat/matroskaenc.c
libavformat/movenc.c
libavformat/sdp.c

You don't change the last three. Did you forget to test compilation of
intermediate revisions?

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


Re: [libav-devel] [PATCH 2/6] hevcdec: move decoder-independent declarations into a separate header

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 04:29:07PM +0200, Anton Khirnov wrote:
> This way they can be reused by other code without including the whole
> decoder-specific hevcdec.h
> Also, add the HEVC_ prefix to them, since similarly named values exist
> for H.264 as well and are sometimes used in the same code.
> ---
>  libavcodec/hevc.h | 65 +
>  libavcodec/hevc_mp4toannexb_bsf.c |  6 +--
>  libavcodec/hevc_parser.c  | 51 +-
>  libavcodec/hevc_ps.c  | 16 
>  libavcodec/hevc_refs.c|  7 ++--
>  libavcodec/hevc_sei.c |  2 +-
>  libavcodec/hevcdec.c  | 77 
> ---
>  libavcodec/hevcdec.h  | 74 +
>  libavcodec/qsvenc_hevc.c  | 11 +++---
>  libavcodec/vaapi_encode_h265.c| 22 +--
>  libavformat/hevc.c| 59 +++---
>  libavformat/hevcdec.c | 20 +-
>  12 files changed, 220 insertions(+), 190 deletions(-)
>  create mode 100644 libavcodec/hevc.h

LGTM

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


Re: [libav-devel] [PATCH 3/9] blockdsp/x86: yasmify

2016-09-22 Thread Henrik Gramner
On Thu, Sep 22, 2016 at 9:39 AM, Anton Khirnov  wrote:
> Quoting Henrik Gramner (2016-09-21 17:13:31)
>> Why not use xorps like the original code then? INIT_XMM sse will also
>> make mova assemble to movaps instead of movdqa, so no problem there.
>
> mmx only has pxor, so I'd need yet more ifdefs then.

If you really care about optimizing for Pentium II, yes. Alternatively
just drop the MMX implementation.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/6] hevcdec: drop the prototype of a non-existing function

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 04:29:08PM +0200, Anton Khirnov wrote:
> ---
>  libavcodec/hevcdec.h | 2 --
>  1 file changed, 2 deletions(-)

OK

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


[libav-devel] [PATCH 4/6] hevcdec: move parameter set parsing into a separate header

2016-09-22 Thread Anton Khirnov
This code is independent from the decoder, so it makes more sense for it
to to have its own header.
---
 libavcodec/hevc.h|   5 +
 libavcodec/hevc_data.h   |  29 +
 libavcodec/hevc_ps.c |  15 +--
 libavcodec/hevc_ps.h | 320 +++
 libavcodec/hevc_ps_enc.c |   2 +-
 libavcodec/hevc_refs.c   |   2 +-
 libavcodec/hevcdec.c |   3 +-
 libavcodec/hevcdec.h | 301 +---
 8 files changed, 370 insertions(+), 307 deletions(-)
 create mode 100644 libavcodec/hevc_data.h
 create mode 100644 libavcodec/hevc_ps.h

diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 66816b8..9536608 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -62,4 +62,9 @@ enum HEVCNALUnitType {
 #define HEVC_MAX_SHORT_TERM_RPS_COUNT 64
 #define HEVC_MAX_CU_SIZE 128
 
+#define HEVC_MAX_REFS 16
+#define HEVC_MAX_DPB_SIZE 16 // A.4.1
+
+#define HEVC_MAX_LOG2_CTB_SIZE 6
+
 #endif /* AVCODEC_HEVC_H */
diff --git a/libavcodec/hevc_data.h b/libavcodec/hevc_data.h
new file mode 100644
index 000..abd4dc7
--- /dev/null
+++ b/libavcodec/hevc_data.h
@@ -0,0 +1,29 @@
+/*
+ * HEVC shared data tables
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_HEVC_DATA_H
+#define AVCODEC_HEVC_DATA_H
+
+extern const uint8_t ff_hevc_diag_scan4x4_x[16];
+extern const uint8_t ff_hevc_diag_scan4x4_y[16];
+extern const uint8_t ff_hevc_diag_scan8x8_x[64];
+extern const uint8_t ff_hevc_diag_scan8x8_y[64];
+
+#endif /* AVCODEC_HEVC_DATA_H */
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 520017b..6a8cfeb 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -26,7 +26,8 @@
 #include "libavutil/imgutils.h"
 
 #include "golomb.h"
-#include "hevcdec.h"
+#include "hevc_data.h"
+#include "hevc_ps.h"
 
 static const uint8_t default_scaling_list_intra[] = {
 16, 16, 16, 16, 17, 18, 21, 24,
@@ -199,8 +200,8 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 rps->num_negative_pics = get_ue_golomb_long(gb);
 nb_positive_pics   = get_ue_golomb_long(gb);
 
-if (rps->num_negative_pics >= MAX_REFS ||
-nb_positive_pics >= MAX_REFS) {
+if (rps->num_negative_pics >= HEVC_MAX_REFS ||
+nb_positive_pics >= HEVC_MAX_REFS) {
 av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term 
RPS.\n");
 return AVERROR_INVALIDDATA;
 }
@@ -405,7 +406,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, 
AVCodecContext *avctx,
 vps->vps_num_reorder_pics[i]  = get_ue_golomb_long(gb);
 vps->vps_max_latency_increase[i]  = get_ue_golomb_long(gb) - 1;
 
-if (vps->vps_max_dec_pic_buffering[i] > MAX_DPB_SIZE) {
+if (vps->vps_max_dec_pic_buffering[i] > HEVC_MAX_DPB_SIZE) {
 av_log(avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out 
of range: %d\n",
vps->vps_max_dec_pic_buffering[i] - 1);
 goto err;
@@ -793,7 +794,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 sps->temporal_layer[i].max_dec_pic_buffering = get_ue_golomb_long(gb) 
+ 1;
 sps->temporal_layer[i].num_reorder_pics  = get_ue_golomb_long(gb);
 sps->temporal_layer[i].max_latency_increase  = get_ue_golomb_long(gb) 
- 1;
-if (sps->temporal_layer[i].max_dec_pic_buffering > MAX_DPB_SIZE) {
+if (sps->temporal_layer[i].max_dec_pic_buffering > HEVC_MAX_DPB_SIZE) {
 av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out 
of range: %d\n",
sps->temporal_layer[i].max_dec_pic_buffering - 1);
 ret = AVERROR_INVALIDDATA;
@@ -803,7 +804,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of 
range: %d\n",
sps->temporal_layer[i].num_reorder_pics);
 if (avctx->err_recognition & AV_EF_EXPLODE ||
-sps->temporal_layer[i].num_reorder_pics > MAX_DPB_SIZE - 1) {
+sps->temporal_layer[i].num_reorder_pics > HEVC_MAX_DPB_SIZE - 
1) {
 ret = AVERROR_INVALIDDATA;
 goto err;
   

[libav-devel] [PATCH 5/6] lavc: add a bitstream filter for extracting extradata from packets

2016-09-22 Thread Anton Khirnov
This is intended as a replacement for the 'split' function exported by
some parsers.
---
 doc/bitstream_filters.texi |  18 +++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/extract_extradata_bsf.c | 300 +
 4 files changed, 320 insertions(+)
 create mode 100644 libavcodec/extract_extradata_bsf.c

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 6e7f878..e063491 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -21,6 +21,24 @@ Below is a description of the currently available bitstream 
filters.
 
 @section dump_extradata
 
+@section extract_extradata
+
+Extract the in-band extradata.
+
+Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
+or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
+of the bitstream containing the coded frames) or "out of band" (e.g. on the
+container level). This latter form is called "extradata" in Libav terminology.
+
+This bitstream filter detects the in-band headers and makes them available as
+extradata.
+
+@table @option
+@item remove
+When this option is enabled, the long-term headers are additionally removed 
from
+the bitstream.
+@end table
+
 @section h264_mp4toannexb
 
 @section imx_dump_header
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d4579f9..66a6c66 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -748,6 +748,7 @@ OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)  += 
aac_adtstoasc_bsf.o aacadtsdec.o \
  mpeg4audio.o
 OBJS-$(CONFIG_CHOMP_BSF)  += chomp_bsf.o
 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
+OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 3b4026c..8a5379e 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -27,6 +27,7 @@
 extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
 extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
+extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
diff --git a/libavcodec/extract_extradata_bsf.c 
b/libavcodec/extract_extradata_bsf.c
new file mode 100644
index 000..20b3080
--- /dev/null
+++ b/libavcodec/extract_extradata_bsf.c
@@ -0,0 +1,300 @@
+/*
+ * 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
+ */
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+
+#include "avcodec.h"
+#include "bsf.h"
+#include "h2645_parse.h"
+#include "h264.h"
+#include "hevc.h"
+#include "vc1_common.h"
+
+typedef struct ExtractExtradataContext {
+const AVClass *class;
+
+int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
+   uint8_t **data, int *size);
+
+/* AVOptions */
+int remove;
+} ExtractExtradataContext;
+
+static int val_in_array(const int *arr, int len, int val)
+{
+int i;
+for (i = 0; i < len; i++)
+if (arr[i] == val)
+return 1;
+return 0;
+}
+
+static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
+   uint8_t **data, int *size)
+{
+static const int extradata_nal_types_hevc[] = {
+HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,
+};
+static const int extradata_nal_types_h264[] = {
+H264_NAL_SPS, H264_NAL_PPS,
+};
+
+ExtractExtradataContext *s = ctx->priv_data;
+
+H2645Packet h2645_pkt = { 0 };
+int extradata_size = 0;
+const int *extradata_nal_types;
+int nb_extradata_nal_types;
+int i, ret = 0;
+
+if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
+extradata_nal_types= extradata_nal_types_hevc;
+

[libav-devel] [PATCH 6/6] lavf: use the new bitstream filter for extracting extradata

2016-09-22 Thread Anton Khirnov
This also fixes a minor bug introduced in the codecpar conversion, where
the termination condition for extracting the extradata does not match
the actual extradata setting code. As a result, the packet durations
made up by lavf go back to their values before the codecpar conversion.
That is of little consequence since that code should eventually be
dropped completely.
---
 libavformat/internal.h   |   9 
 libavformat/utils.c  | 122 ++-
 tests/ref/fate/iv8-demux |  10 ++--
 tests/ref/fate/wtv-demux |  68 +-
 4 files changed, 157 insertions(+), 52 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index de55af5..52cd29b 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -113,6 +113,15 @@ struct AVStreamInternal {
 
 enum AVCodecID orig_codec_id;
 
+/* the context for extracting extradata in find_stream_info()
+ * inited=1/bsf=NULL signals that extracting is not possible (codec not
+ * supported) */
+struct {
+AVBSFContext *bsf;
+AVPacket *pkt;
+int inited;
+} extract_extradata;
+
 #if FF_API_LAVF_AVCTX
 // whether the deprecated stream codec context needs
 // to be filled from the codec parameters
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 6df1a32..d5ed38d 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2089,6 +2089,104 @@ static int get_std_framerate(int i)
 return ((const int[]) { 24, 30, 60, 12, 15 })[i - 60 * 12] * 1000 * 12;
 }
 
+static int extract_extradata_init(AVStream *st)
+{
+AVStreamInternal *i = st->internal;
+const AVBitStreamFilter *f;
+int ret;
+
+f = av_bsf_get_by_name("extract_extradata");
+if (!f)
+goto finish;
+
+i->extract_extradata.pkt = av_packet_alloc();
+if (!i->extract_extradata.pkt)
+return AVERROR(ENOMEM);
+
+ret = av_bsf_alloc(f, >extract_extradata.bsf);
+if (ret < 0)
+goto fail;
+
+ret = avcodec_parameters_copy(i->extract_extradata.bsf->par_in,
+  st->codecpar);
+if (ret < 0)
+goto fail;
+
+i->extract_extradata.bsf->time_base_in = st->time_base;
+
+/* if init fails here, we assume extracting extradata is just not
+ * supported for this codec, so we return success */
+ret = av_bsf_init(i->extract_extradata.bsf);
+if (ret < 0) {
+av_bsf_free(>extract_extradata.bsf);
+ret = 0;
+}
+
+finish:
+i->extract_extradata.inited = 1;
+
+return 0;
+fail:
+av_bsf_free(>extract_extradata.bsf);
+av_packet_free(>extract_extradata.pkt);
+return ret;
+}
+
+static int extract_extradata(AVStream *st, AVPacket *pkt)
+{
+AVStreamInternal *i = st->internal;
+AVPacket *pkt_ref;
+int ret;
+
+if (!i->extract_extradata.inited) {
+ret = extract_extradata_init(st);
+if (ret < 0)
+return ret;
+}
+
+if (i->extract_extradata.inited && !i->extract_extradata.bsf)
+return 0;
+
+pkt_ref = i->extract_extradata.pkt;
+ret = av_packet_ref(pkt_ref, pkt);
+if (ret < 0)
+return ret;
+
+ret = av_bsf_send_packet(i->extract_extradata.bsf, pkt_ref);
+if (ret < 0) {
+av_packet_unref(pkt_ref);
+return ret;
+}
+
+while (ret >= 0 && !st->codecpar->extradata) {
+int extradata_size;
+uint8_t *extradata;
+
+ret = av_bsf_receive_packet(i->extract_extradata.bsf, pkt_ref);
+if (ret < 0) {
+if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
+return ret;
+continue;
+}
+
+extradata = av_packet_get_side_data(pkt_ref, AV_PKT_DATA_NEW_EXTRADATA,
+_size);
+
+if (extradata) {
+st->codecpar->extradata = av_mallocz(extradata_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
+if (!st->codecpar->extradata) {
+av_packet_unref(pkt_ref);
+return AVERROR(ENOMEM);
+}
+memcpy(st->codecpar->extradata, extradata, extradata_size);
+st->codecpar->extradata_size = extradata_size;
+}
+av_packet_unref(pkt_ref);
+}
+
+return 0;
+}
+
 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 {
 int i, count, ret, read_size, j;
@@ -2194,8 +2292,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 st->codec_info_nb_frames < fps_analyze_framecount &&
 st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 break;
-if (st->parser && st->parser->parser->split &&
-!st->codecpar->extradata)
+if (!st->codecpar->extradata &&
+(!st->internal->extract_extradata.inited ||
+ st->internal->extract_extradata.bsf))
 break;
 if (st->first_dts == AV_NOPTS_VALUE &&
 st->codec_info_nb_frames < 

[libav-devel] [PATCH 3/6] hevcdec: drop the prototype of a non-existing function

2016-09-22 Thread Anton Khirnov
---
 libavcodec/hevcdec.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index df81e55..9566223 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -957,8 +957,6 @@ int ff_hevc_cu_qp_delta_abs(HEVCContext *s);
 void ff_hevc_hls_filter(HEVCContext *s, int x, int y);
 void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size);
 
-void ff_hevc_pps_free(HEVCPPS **ppps);
-
 void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth);
 
 int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id,
-- 
2.0.0

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


[libav-devel] [PATCH 1/6] hevc: rename hevc.[ch] to hevcdec.[ch]

2016-09-22 Thread Anton Khirnov
This is more consistent with the rest of libav and frees up the hevc.h
name for decoder-independent shared declarations.
---
 libavcodec/Makefile   | 2 +-
 libavcodec/dxva2_hevc.c   | 2 +-
 libavcodec/hevc_cabac.c   | 2 +-
 libavcodec/hevc_data.c| 2 +-
 libavcodec/hevc_filter.c  | 2 +-
 libavcodec/hevc_mp4toannexb_bsf.c | 2 +-
 libavcodec/hevc_mvs.c | 2 +-
 libavcodec/hevc_parser.c  | 2 +-
 libavcodec/hevc_ps.c  | 2 +-
 libavcodec/hevc_ps_enc.c  | 2 +-
 libavcodec/hevc_refs.c| 2 +-
 libavcodec/hevc_sei.c | 2 +-
 libavcodec/{hevc.c => hevcdec.c}  | 2 +-
 libavcodec/{hevc.h => hevcdec.h}  | 6 +++---
 libavcodec/hevcdsp_template.c | 2 +-
 libavcodec/hevcpred.c | 2 +-
 libavcodec/hevcpred_template.c| 2 +-
 libavcodec/qsvenc_hevc.c  | 2 +-
 libavcodec/vaapi_encode_h265.c| 2 +-
 libavcodec/vdpau_hevc.c   | 2 +-
 libavformat/hevc.c| 2 +-
 libavformat/hevcdec.c | 2 +-
 22 files changed, 24 insertions(+), 24 deletions(-)
 rename libavcodec/{hevc.c => hevcdec.c} (99%)
 rename libavcodec/{hevc.h => hevcdec.h} (99%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bec461b..d4579f9 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -264,7 +264,7 @@ OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
 OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o 
vaapi_encode_h26x.o
 OBJS-$(CONFIG_HAP_DECODER) += hapdec.o hap.o
 OBJS-$(CONFIG_HAP_ENCODER) += hapenc.o hap.o
-OBJS-$(CONFIG_HEVC_DECODER)+= hevc.o hevc_mvs.o hevc_ps.o 
hevc_sei.o \
+OBJS-$(CONFIG_HEVC_DECODER)+= hevcdec.o hevc_mvs.o hevc_ps.o 
hevc_sei.o \
   hevc_cabac.o hevc_refs.o hevcpred.o  
  \
   hevcdsp.o hevc_filter.o 
h2645_parse.o hevc_data.o
 OBJS-$(CONFIG_HEVC_NVENC_ENCODER)  += nvenc_hevc.o
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 5bb10d6..53fd638 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -22,7 +22,7 @@
 
 #include "libavutil/avassert.h"
 
-#include "hevc.h"
+#include "hevcdec.h"
 
 // The headers above may include w32threads.h, which uses the original
 // _WIN32_WINNT define, while dxva2_internal.h redefines it to target a
diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index b01808f..eb16f57 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -25,7 +25,7 @@
 #include "libavutil/common.h"
 
 #include "cabac_functions.h"
-#include "hevc.h"
+#include "hevcdec.h"
 
 #define CABAC_MAX_BIN 31
 
diff --git a/libavcodec/hevc_data.c b/libavcodec/hevc_data.c
index f4b6096..7976c34 100644
--- a/libavcodec/hevc_data.c
+++ b/libavcodec/hevc_data.c
@@ -20,7 +20,7 @@
 
 #include 
 
-#include "hevc.h"
+#include "hevcdec.h"
 
 const uint8_t ff_hevc_diag_scan4x4_x[16] = {
 0, 0, 1, 0,
diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c
index 39ac4ee..a7a9c04 100644
--- a/libavcodec/hevc_filter.c
+++ b/libavcodec/hevc_filter.c
@@ -26,7 +26,7 @@
 #include "libavutil/internal.h"
 
 #include "cabac_functions.h"
-#include "hevc.h"
+#include "hevcdec.h"
 
 #define LUMA 0
 #define CB 1
diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 8d7ac58..f364fbd 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -27,7 +27,7 @@
 #include "avcodec.h"
 #include "bsf.h"
 #include "bytestream.h"
-#include "hevc.h"
+#include "hevcdec.h"
 
 #define MIN_HEVCC_LENGTH 23
 
diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c
index 446b83a..90aff97 100644
--- a/libavcodec/hevc_mvs.c
+++ b/libavcodec/hevc_mvs.c
@@ -21,7 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "hevc.h"
+#include "hevcdec.h"
 
 static const uint8_t l0_l1_cand_idx[12][2] = {
 { 0, 1, },
diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index dc5fffc..b68ceb9 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -23,7 +23,7 @@
 #include "libavutil/common.h"
 
 #include "golomb.h"
-#include "hevc.h"
+#include "hevcdec.h"
 #include "h2645_parse.h"
 #include "parser.h"
 
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 5c249d8..b7b2ea9 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -26,7 +26,7 @@
 #include "libavutil/imgutils.h"
 
 #include "golomb.h"
-#include "hevc.h"
+#include "hevcdec.h"
 
 static const uint8_t default_scaling_list_intra[] = {
 16, 16, 16, 16, 17, 18, 21, 24,
diff --git a/libavcodec/hevc_ps_enc.c b/libavcodec/hevc_ps_enc.c
index 007a132..fdf9fb7 100644
--- a/libavcodec/hevc_ps_enc.c
+++ b/libavcodec/hevc_ps_enc.c
@@ -19,7 +19,7 @@
  */
 
 #include "golomb.h"
-#include "hevc.h"
+#include "hevcdec.h"
 #include "put_bits.h"
 
 static void 

Re: [libav-devel] [PATCH 6/6] examples/output: switch to the new encoding API

2016-09-22 Thread Vittorio Giovara
On Thu, Sep 22, 2016 at 3:35 AM, Anton Khirnov  wrote:
> ---
>  doc/examples/output.c | 71 
> +++
>  1 file changed, 44 insertions(+), 27 deletions(-)
>
> diff --git a/doc/examples/output.c b/doc/examples/output.c
> index 44a55f5..bb0da30 100644
> --- a/doc/examples/output.c
> +++ b/doc/examples/output.c
> @@ -233,25 +233,37 @@ static AVFrame *get_audio_frame(OutputStream *ost)
>  static int encode_audio_frame(AVFormatContext *oc, OutputStream *ost,
>AVFrame *frame)
>  {
> -AVPacket pkt = { 0 }; // data and size must be 0;
> -int got_packet;
> +int ret;
>
> -av_init_packet();
> -avcodec_encode_audio2(ost->enc, , frame, _packet);
> +ret = avcodec_send_frame(ost->enc, frame);
> +if (ret < 0) {
> +fprintf(stderr, "Error submitting a frame for encoding\n");
> +exit(1);
> +}
>
> -if (got_packet) {
> -pkt.stream_index = ost->st->index;
> +while (ret >= 0) {
> +AVPacket pkt = { 0 }; // data and size must be 0;
>
> -av_packet_rescale_ts(, ost->enc->time_base, ost->st->time_base);
> +av_init_packet();
>
> -/* Write the compressed frame to the media file. */
> -if (av_interleaved_write_frame(oc, ) != 0) {
> -fprintf(stderr, "Error while writing audio frame\n");
> +ret = avcodec_receive_packet(ost->enc, );
> +if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
> +fprintf(stderr, "Error encoding a video frame\n");
>  exit(1);
> +} else if (ret >= 0) {
> +av_packet_rescale_ts(, ost->enc->time_base, 
> ost->st->time_base);
> +pkt.stream_index = ost->st->index;
> +
> +/* Write the compressed frame to the media file. */
> +ret = av_interleaved_write_frame(oc, );
> +if (ret < 0) {
> +fprintf(stderr, "Error while writing video frame\n");
> +exit(1);
> +}
>  }
>  }
>
> -return (frame || got_packet) ? 0 : 1;
> +return ret == AVERROR_EOF;
>  }
>
>  /*
> @@ -517,36 +529,41 @@ static int write_video_frame(AVFormatContext *oc, 
> OutputStream *ost)
>  int ret;
>  AVCodecContext *c;
>  AVFrame *frame;
> -AVPacket pkt   = { 0 };
> -int got_packet = 0;
>
>  c = ost->enc;
>
>  frame = get_video_frame(ost);
>
> -av_init_packet();
> -
>  /* encode the image */
> -ret = avcodec_encode_video2(c, , frame, _packet);
> +ret = avcodec_send_frame(c, frame);
>  if (ret < 0) {
> -fprintf(stderr, "Error encoding a video frame\n");
> +fprintf(stderr, "Error submitting a frame for encoding\n");
>  exit(1);
>  }
>
> -if (got_packet) {
> -av_packet_rescale_ts(, c->time_base, ost->st->time_base);
> -pkt.stream_index = ost->st->index;
> +while (ret >= 0) {
> +AVPacket pkt = { 0 };
>
> -/* Write the compressed frame to the media file. */
> -ret = av_interleaved_write_frame(oc, );
> -}
> +av_init_packet();
>
> -if (ret != 0) {
> -fprintf(stderr, "Error while writing video frame\n");
> -exit(1);
> +ret = avcodec_receive_packet(c, );
> +if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
> +fprintf(stderr, "Error encoding a video frame\n");
> +exit(1);
> +} else if (ret >= 0) {
> +av_packet_rescale_ts(, c->time_base, ost->st->time_base);
> +pkt.stream_index = ost->st->index;
> +
> +/* Write the compressed frame to the media file. */
> +ret = av_interleaved_write_frame(oc, );
> +if (ret < 0) {
> +fprintf(stderr, "Error while writing video frame\n");
> +exit(1);
> +}
> +}
>  }
>
> -return (frame || got_packet) ? 0 : 1;
> +return ret == AVERROR_EOF;
>  }
>
>  static void close_stream(AVFormatContext *oc, OutputStream *ost)
> --

ok i think

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


Re: [libav-devel] [PATCH 5/6] tdsc: use the new decoding API

2016-09-22 Thread Vittorio Giovara
On Thu, Sep 22, 2016 at 3:35 AM, Anton Khirnov  wrote:
> ---
>  libavcodec/tdsc.c | 15 +--
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c
> index c70c77f..5b952b3 100644
> --- a/libavcodec/tdsc.c
> +++ b/libavcodec/tdsc.c
> @@ -343,7 +343,6 @@ static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, 
> int tile_size,
>  {
>  TDSCContext *ctx = avctx->priv_data;
>  AVPacket jpkt;
> -int got_frame = 0;
>  int ret;
>
>  /* Prepare a packet and send to the MJPEG decoder */
> @@ -351,12 +350,16 @@ static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, 
> int tile_size,
>  jpkt.data = ctx->tilebuffer;
>  jpkt.size = tile_size;
>
> -ret = avcodec_decode_video2(ctx->jpeg_avctx, ctx->jpgframe,
> -_frame, );
> -if (ret < 0 || !got_frame || ctx->jpgframe->format != 
> AV_PIX_FMT_YUVJ420P) {
> +ret = avcodec_send_packet(ctx->jpeg_avctx, );
> +if (ret < 0) {
> +av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for 
> decoding\n");
> +return ret;
> +}
> +
> +ret = avcodec_receive_frame(ctx->jpeg_avctx, ctx->jpgframe);
> +if (ret < 0 || ctx->jpgframe->format != AV_PIX_FMT_YUVJ420P) {
>  av_log(avctx, AV_LOG_ERROR,
> -   "JPEG decoding error (%d) for (%d) frame.\n",
> -   ret, got_frame);
> +   "JPEG decoding error (%d).\n", ret);
>
>  /* Normally skip, error if explode */
>  if (avctx->err_recognition & AV_EF_EXPLODE)
> --

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


Re: [libav-devel] [PATCH 4/6] lavc: add clobber tests for the new encoding/decoding API

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 09:35:30AM +0200, Anton Khirnov wrote:
> ---
>  configure |  8 
>  libavcodec/aarch64/neontest.c | 20 
>  libavcodec/arm/neontest.c | 20 
>  libavcodec/x86/w64xmmtest.c   | 20 
>  4 files changed, 68 insertions(+)

probably OK

What is the criterion for adding functions to the list of clobber tests?

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


Re: [libav-devel] [PATCH 3/6] mpegvideo_enc: use the new encoding API for b_strategy=2

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 09:35:29AM +0200, Anton Khirnov wrote:
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -1313,27 +1306,46 @@ static int estimate_best_b_count(MpegEncContext *s)
>  for (j = 0; j < s->max_b_frames + 1; j++) {
> +AVCodecContext *c = avcodec_alloc_context3(NULL);
>  int64_t rd = 0;
>  
> -c->error[0] = c->error[1] = c->error[2] = 0;
> +c = avcodec_alloc_context3(NULL);

Double allocation?

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


Re: [libav-devel] [PATCH 2/6] mpegvideo_enc: handle encoding errors with b_strategy=2

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 09:35:28AM +0200, Anton Khirnov wrote:
> ---
>  libavcodec/mpegvideo_enc.c | 18 ++
>  1 file changed, 18 insertions(+)

LGTM

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


Re: [libav-devel] [PATCH 02/14] intrax8: Change type of array stride parameters to ptrdiff_t

2016-09-22 Thread Diego Biurrun
On Tue, Sep 20, 2016 at 11:09:51PM +0100, Mark Thompson wrote:
> On 20/09/16 19:36, Diego Biurrun wrote:
> Aside:
> 
> Seeing a lot of little functions like (picking a random one):
> 
> > -static void spatial_compensation_3(uint8_t *src, uint8_t *dst, int 
> > linesize)
> > +static void spatial_compensation_3(uint8_t *src, uint8_t *dst, ptrdiff_t 
> > stride)
> >  {
> >  int x, y;
> >  
> >  for (y = 0; y < 8; y++) {
> >  for (x = 0; x < 8; x++)
> >  dst[x] = src[area4 + ((y + 1) >> 1) + x];
> > -dst += linesize;
> > +dst += stride;
> >  }
> >  }
> 
> makes me wonder how much faster the C code would be if we just added the 
> right type qualifiers to all the pointers.

Are you trying to troll me into my next refactoring project? :)

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


Re: [libav-devel] [PATCH 1/6] mpegvideo_enc: add const to the AVCodec instance

2016-09-22 Thread Diego Biurrun
On Thu, Sep 22, 2016 at 09:35:27AM +0200, Anton Khirnov wrote:
> ---
>  libavcodec/mpegvideo_enc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

LGTM

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


Re: [libav-devel] [PATCH 3/9] blockdsp/x86: yasmify

2016-09-22 Thread Anton Khirnov
Quoting Henrik Gramner (2016-09-21 17:13:31)
> On Wed, Sep 21, 2016 at 9:01 AM, Anton Khirnov  wrote:
> > Yes they are, because pxor does not exist in SSE.
> 
> Why not use xorps like the original code then? INIT_XMM sse will also
> make mova assemble to movaps instead of movdqa, so no problem there.

mmx only has pxor, so I'd need yet more ifdefs then.

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


[libav-devel] [PATCH 3/6] mpegvideo_enc: use the new encoding API for b_strategy=2

2016-09-22 Thread Anton Khirnov
---
 libavcodec/mpegvideo_enc.c | 88 ++
 1 file changed, 49 insertions(+), 39 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6ab9ba5..cd7bca03 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1245,30 +1245,38 @@ static int skip_check(MpegEncContext *s, Picture *p, 
Picture *ref)
 static int encode_frame(AVCodecContext *c, AVFrame *frame)
 {
 AVPacket pkt = { 0 };
-int ret, got_output;
+int ret;
+int size = 0;
 
 av_init_packet();
-ret = avcodec_encode_video2(c, , frame, _output);
+
+ret = avcodec_send_frame(c, frame);
 if (ret < 0)
 return ret;
 
-ret = pkt.size;
-av_packet_unref();
-return ret;
+do {
+ret = avcodec_receive_packet(c, );
+if (ret >= 0) {
+size += pkt.size;
+av_packet_unref();
+} else if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
+return ret;
+} while (ret >= 0);
+
+return size;
 }
 
 static int estimate_best_b_count(MpegEncContext *s)
 {
 const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
-AVCodecContext *c = avcodec_alloc_context3(NULL);
 const int scale = s->brd_scale;
+int width  = s->width  >> scale;
+int height = s->height >> scale;
 int i, j, out_size, p_lambda, b_lambda, lambda2;
 int64_t best_rd  = INT64_MAX;
 int best_b_count = -1;
 int ret = 0;
 
-if (!c)
-return AVERROR(ENOMEM);
 assert(scale >= 0 && scale <= 3);
 
 //emms_c();
@@ -1281,21 +1289,6 @@ static int estimate_best_b_count(MpegEncContext *s)
 lambda2  = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>
FF_LAMBDA_SHIFT;
 
-c->width= s->width  >> scale;
-c->height   = s->height >> scale;
-c->flags= AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_PSNR;
-c->flags   |= s->avctx->flags & AV_CODEC_FLAG_QPEL;
-c->mb_decision  = s->avctx->mb_decision;
-c->me_cmp   = s->avctx->me_cmp;
-c->mb_cmp   = s->avctx->mb_cmp;
-c->me_sub_cmp   = s->avctx->me_sub_cmp;
-c->pix_fmt  = AV_PIX_FMT_YUV420P;
-c->time_base= s->avctx->time_base;
-c->max_b_frames = s->max_b_frames;
-
-if (avcodec_open2(c, codec, NULL) < 0)
-return -1;
-
 for (i = 0; i < s->max_b_frames + 2; i++) {
 Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
 s->next_picture_ptr;
@@ -1313,27 +1306,46 @@ static int estimate_best_b_count(MpegEncContext *s)
s->tmp_frames[i]->linesize[0],
pre_input.f->data[0],
pre_input.f->linesize[0],
-   c->width, c->height);
+   width, height);
 s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1],
s->tmp_frames[i]->linesize[1],
pre_input.f->data[1],
pre_input.f->linesize[1],
-   c->width >> 1, c->height >> 1);
+   width >> 1, height >> 1);
 s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2],
s->tmp_frames[i]->linesize[2],
pre_input.f->data[2],
pre_input.f->linesize[2],
-   c->width >> 1, c->height >> 1);
+   width >> 1, height >> 1);
 }
 }
 
 for (j = 0; j < s->max_b_frames + 1; j++) {
+AVCodecContext *c = avcodec_alloc_context3(NULL);
 int64_t rd = 0;
 
 if (!s->input_picture[j])
 break;
 
-c->error[0] = c->error[1] = c->error[2] = 0;
+c = avcodec_alloc_context3(NULL);
+if (!c)
+return AVERROR(ENOMEM);
+
+c->width= width;
+c->height   = height;
+c->flags= AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_PSNR;
+c->flags   |= s->avctx->flags & AV_CODEC_FLAG_QPEL;
+c->mb_decision  = s->avctx->mb_decision;
+c->me_cmp   = s->avctx->me_cmp;
+c->mb_cmp   = s->avctx->mb_cmp;
+c->me_sub_cmp   = s->avctx->me_sub_cmp;
+c->pix_fmt  = AV_PIX_FMT_YUV420P;
+c->time_base= s->avctx->time_base;
+c->max_b_frames = s->max_b_frames;
+
+ret = avcodec_open2(c, codec, NULL);
+if (ret < 0)
+goto fail;
 
 s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I;
 s->tmp_frames[0]->quality   = 1 * FF_QP2LAMBDA;
@@ -1363,14 +1375,12 @@ static int estimate_best_b_count(MpegEncContext *s)
 }
 
 /* get the delayed frames */
-

[libav-devel] [PATCH 6/6] examples/output: switch to the new encoding API

2016-09-22 Thread Anton Khirnov
---
 doc/examples/output.c | 71 +++
 1 file changed, 44 insertions(+), 27 deletions(-)

diff --git a/doc/examples/output.c b/doc/examples/output.c
index 44a55f5..bb0da30 100644
--- a/doc/examples/output.c
+++ b/doc/examples/output.c
@@ -233,25 +233,37 @@ static AVFrame *get_audio_frame(OutputStream *ost)
 static int encode_audio_frame(AVFormatContext *oc, OutputStream *ost,
   AVFrame *frame)
 {
-AVPacket pkt = { 0 }; // data and size must be 0;
-int got_packet;
+int ret;
 
-av_init_packet();
-avcodec_encode_audio2(ost->enc, , frame, _packet);
+ret = avcodec_send_frame(ost->enc, frame);
+if (ret < 0) {
+fprintf(stderr, "Error submitting a frame for encoding\n");
+exit(1);
+}
 
-if (got_packet) {
-pkt.stream_index = ost->st->index;
+while (ret >= 0) {
+AVPacket pkt = { 0 }; // data and size must be 0;
 
-av_packet_rescale_ts(, ost->enc->time_base, ost->st->time_base);
+av_init_packet();
 
-/* Write the compressed frame to the media file. */
-if (av_interleaved_write_frame(oc, ) != 0) {
-fprintf(stderr, "Error while writing audio frame\n");
+ret = avcodec_receive_packet(ost->enc, );
+if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
+fprintf(stderr, "Error encoding a video frame\n");
 exit(1);
+} else if (ret >= 0) {
+av_packet_rescale_ts(, ost->enc->time_base, 
ost->st->time_base);
+pkt.stream_index = ost->st->index;
+
+/* Write the compressed frame to the media file. */
+ret = av_interleaved_write_frame(oc, );
+if (ret < 0) {
+fprintf(stderr, "Error while writing video frame\n");
+exit(1);
+}
 }
 }
 
-return (frame || got_packet) ? 0 : 1;
+return ret == AVERROR_EOF;
 }
 
 /*
@@ -517,36 +529,41 @@ static int write_video_frame(AVFormatContext *oc, 
OutputStream *ost)
 int ret;
 AVCodecContext *c;
 AVFrame *frame;
-AVPacket pkt   = { 0 };
-int got_packet = 0;
 
 c = ost->enc;
 
 frame = get_video_frame(ost);
 
-av_init_packet();
-
 /* encode the image */
-ret = avcodec_encode_video2(c, , frame, _packet);
+ret = avcodec_send_frame(c, frame);
 if (ret < 0) {
-fprintf(stderr, "Error encoding a video frame\n");
+fprintf(stderr, "Error submitting a frame for encoding\n");
 exit(1);
 }
 
-if (got_packet) {
-av_packet_rescale_ts(, c->time_base, ost->st->time_base);
-pkt.stream_index = ost->st->index;
+while (ret >= 0) {
+AVPacket pkt = { 0 };
 
-/* Write the compressed frame to the media file. */
-ret = av_interleaved_write_frame(oc, );
-}
+av_init_packet();
 
-if (ret != 0) {
-fprintf(stderr, "Error while writing video frame\n");
-exit(1);
+ret = avcodec_receive_packet(c, );
+if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
+fprintf(stderr, "Error encoding a video frame\n");
+exit(1);
+} else if (ret >= 0) {
+av_packet_rescale_ts(, c->time_base, ost->st->time_base);
+pkt.stream_index = ost->st->index;
+
+/* Write the compressed frame to the media file. */
+ret = av_interleaved_write_frame(oc, );
+if (ret < 0) {
+fprintf(stderr, "Error while writing video frame\n");
+exit(1);
+}
+}
 }
 
-return (frame || got_packet) ? 0 : 1;
+return ret == AVERROR_EOF;
 }
 
 static void close_stream(AVFormatContext *oc, OutputStream *ost)
-- 
2.0.0

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


[libav-devel] [PATCH 1/6] mpegvideo_enc: add const to the AVCodec instance

2016-09-22 Thread Anton Khirnov
---
 libavcodec/mpegvideo_enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d738d06..46e2e2c 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1259,7 +1259,7 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame)
 
 static int estimate_best_b_count(MpegEncContext *s)
 {
-AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);
+const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
 AVCodecContext *c = avcodec_alloc_context3(NULL);
 const int scale = s->brd_scale;
 int i, j, out_size, p_lambda, b_lambda, lambda2;
-- 
2.0.0

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


[libav-devel] [PATCH 5/6] tdsc: use the new decoding API

2016-09-22 Thread Anton Khirnov
---
 libavcodec/tdsc.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c
index c70c77f..5b952b3 100644
--- a/libavcodec/tdsc.c
+++ b/libavcodec/tdsc.c
@@ -343,7 +343,6 @@ static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, int 
tile_size,
 {
 TDSCContext *ctx = avctx->priv_data;
 AVPacket jpkt;
-int got_frame = 0;
 int ret;
 
 /* Prepare a packet and send to the MJPEG decoder */
@@ -351,12 +350,16 @@ static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, 
int tile_size,
 jpkt.data = ctx->tilebuffer;
 jpkt.size = tile_size;
 
-ret = avcodec_decode_video2(ctx->jpeg_avctx, ctx->jpgframe,
-_frame, );
-if (ret < 0 || !got_frame || ctx->jpgframe->format != AV_PIX_FMT_YUVJ420P) 
{
+ret = avcodec_send_packet(ctx->jpeg_avctx, );
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for 
decoding\n");
+return ret;
+}
+
+ret = avcodec_receive_frame(ctx->jpeg_avctx, ctx->jpgframe);
+if (ret < 0 || ctx->jpgframe->format != AV_PIX_FMT_YUVJ420P) {
 av_log(avctx, AV_LOG_ERROR,
-   "JPEG decoding error (%d) for (%d) frame.\n",
-   ret, got_frame);
+   "JPEG decoding error (%d).\n", ret);
 
 /* Normally skip, error if explode */
 if (avctx->err_recognition & AV_EF_EXPLODE)
-- 
2.0.0

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


[libav-devel] [PATCH 4/6] lavc: add clobber tests for the new encoding/decoding API

2016-09-22 Thread Anton Khirnov
---
 configure |  8 
 libavcodec/aarch64/neontest.c | 20 
 libavcodec/arm/neontest.c | 20 
 libavcodec/x86/w64xmmtest.c   | 20 
 4 files changed, 68 insertions(+)

diff --git a/configure b/configure
index 1f5fb8a..3c416da 100755
--- a/configure
+++ b/configure
@@ -4831,6 +4831,10 @@ enabled neon_clobber_test &&
   -Wl,--wrap,avcodec_encode_audio2  \
   -Wl,--wrap,avcodec_encode_video2  \
   -Wl,--wrap,avcodec_encode_subtitle\
+  -Wl,--wrap,avcodec_send_packet\
+  -Wl,--wrap,avcodec_receive_packet \
+  -Wl,--wrap,avcodec_send_frame \
+  -Wl,--wrap,avcodec_receive_frame  \
   -Wl,--wrap,avresample_convert ||
 disable neon_clobber_test
 
@@ -4842,6 +4846,10 @@ enabled xmm_clobber_test &&
   -Wl,--wrap,avcodec_encode_audio2  \
   -Wl,--wrap,avcodec_encode_video2  \
   -Wl,--wrap,avcodec_encode_subtitle\
+  -Wl,--wrap,avcodec_send_packet\
+  -Wl,--wrap,avcodec_receive_packet \
+  -Wl,--wrap,avcodec_send_frame \
+  -Wl,--wrap,avcodec_receive_frame  \
   -Wl,--wrap,avresample_convert \
   -Wl,--wrap,sws_scale ||
 disable xmm_clobber_test
diff --git a/libavcodec/aarch64/neontest.c b/libavcodec/aarch64/neontest.c
index 137c8e6..201bfb1 100644
--- a/libavcodec/aarch64/neontest.c
+++ b/libavcodec/aarch64/neontest.c
@@ -77,3 +77,23 @@ wrap(avcodec_encode_video2(AVCodecContext *avctx, AVPacket 
*avpkt,
 {
 testneonclobbers(avcodec_encode_video2, avctx, avpkt, frame, 
got_packet_ptr);
 }
+
+wrap(avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt))
+{
+testneonclobbers(avcodec_send_packet, avctx, avpkt);
+}
+
+wrap(avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt))
+{
+testneonclobbers(avcodec_receive_packet, avctx, avpkt);
+}
+
+wrap(avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame))
+{
+testneonclobbers(avcodec_send_frame, avctx, frame);
+}
+
+wrap(avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame))
+{
+testneonclobbers(avcodec_receive_frame, avctx, frame);
+}
diff --git a/libavcodec/arm/neontest.c b/libavcodec/arm/neontest.c
index 692576e..67d7747 100644
--- a/libavcodec/arm/neontest.c
+++ b/libavcodec/arm/neontest.c
@@ -77,3 +77,23 @@ wrap(avcodec_encode_video2(AVCodecContext *avctx, AVPacket 
*avpkt,
 {
 testneonclobbers(avcodec_encode_video2, avctx, avpkt, frame, 
got_packet_ptr);
 }
+
+wrap(avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt))
+{
+testneonclobbers(avcodec_send_packet, avctx, avpkt);
+}
+
+wrap(avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt))
+{
+testneonclobbers(avcodec_receive_packet, avctx, avpkt);
+}
+
+wrap(avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame))
+{
+testneonclobbers(avcodec_send_frame, avctx, frame);
+}
+
+wrap(avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame))
+{
+testneonclobbers(avcodec_receive_frame, avctx, frame);
+}
diff --git a/libavcodec/x86/w64xmmtest.c b/libavcodec/x86/w64xmmtest.c
index 400dc4d..8925573 100644
--- a/libavcodec/x86/w64xmmtest.c
+++ b/libavcodec/x86/w64xmmtest.c
@@ -77,3 +77,23 @@ wrap(avcodec_encode_video2(AVCodecContext *avctx, AVPacket 
*avpkt,
 {
 testxmmclobbers(avcodec_encode_video2, avctx, avpkt, frame, 
got_packet_ptr);
 }
+
+wrap(avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt))
+{
+testxmmclobbers(avcodec_send_packet, avctx, avpkt);
+}
+
+wrap(avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt))
+{
+testxmmclobbers(avcodec_receive_packet, avctx, avpkt);
+}
+
+wrap(avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame))
+{
+testxmmclobbers(avcodec_send_frame, avctx, frame);
+}
+
+wrap(avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame))
+{
+testxmmclobbers(avcodec_receive_frame, avctx, frame);
+}
-- 
2.0.0

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


[libav-devel] [PATCH 2/6] mpegvideo_enc: handle encoding errors with b_strategy=2

2016-09-22 Thread Anton Khirnov
---
 libavcodec/mpegvideo_enc.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 46e2e2c..6ab9ba5 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1265,6 +1265,7 @@ static int estimate_best_b_count(MpegEncContext *s)
 int i, j, out_size, p_lambda, b_lambda, lambda2;
 int64_t best_rd  = INT64_MAX;
 int best_b_count = -1;
+int ret = 0;
 
 if (!c)
 return AVERROR(ENOMEM);
@@ -1338,6 +1339,10 @@ static int estimate_best_b_count(MpegEncContext *s)
 s->tmp_frames[0]->quality   = 1 * FF_QP2LAMBDA;
 
 out_size = encode_frame(c, s->tmp_frames[0]);
+if (out_size < 0) {
+ret = out_size;
+goto fail;
+}
 
 //rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;
 
@@ -1349,6 +1354,10 @@ static int estimate_best_b_count(MpegEncContext *s)
 s->tmp_frames[i + 1]->quality   = is_p ? p_lambda : b_lambda;
 
 out_size = encode_frame(c, s->tmp_frames[i + 1]);
+if (out_size < 0) {
+ret = out_size;
+goto fail;
+}
 
 rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
 }
@@ -1356,6 +1365,10 @@ static int estimate_best_b_count(MpegEncContext *s)
 /* get the delayed frames */
 while (out_size) {
 out_size = encode_frame(c, NULL);
+if (out_size < 0) {
+ret = out_size;
+goto fail;
+}
 rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
 }
 
@@ -1370,6 +1383,9 @@ static int estimate_best_b_count(MpegEncContext *s)
 avcodec_free_context();
 
 return best_b_count;
+fail:
+avcodec_free_context();
+return ret;
 }
 
 static int select_input_picture(MpegEncContext *s)
@@ -1450,6 +1466,8 @@ static int select_input_picture(MpegEncContext *s)
 }
 } else if (s->b_frame_strategy == 2) {
 b_frames = estimate_best_b_count(s);
+if (b_frames < 0)
+return b_frames;
 }
 
 emms_c();
-- 
2.0.0

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