Re: [FFmpeg-devel] [PATCH v3] avcodec: implement a native VC-2 HQ profile encoder

2016-02-08 Thread Kieran Kunhya
On 7 February 2016 at 22:21, Rostislav Pehlivanov  wrote:
> Changes from last version:
> -use ptrdiff_t for strides
>
> Signed-off-by: Rostislav Pehlivanov 
> ---
>  libavcodec/Makefile |1 +
>  libavcodec/allcodecs.c  |1 +
>  libavcodec/vc2enc.c | 1194 
> +++
>  libavcodec/vc2enc_dwt.c |  234 ++
>  libavcodec/vc2enc_dwt.h |   54 +++
>  5 files changed, 1484 insertions(+)
>  create mode 100644 libavcodec/vc2enc.c
>  create mode 100644 libavcodec/vc2enc_dwt.c
>  create mode 100644 libavcodec/vc2enc_dwt.h
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 941057b..f6a4fbb 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -543,6 +543,7 @@ OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o 
> vc1_block.o vc1_loopfilter.o
>wmv2dsp.o
>  OBJS-$(CONFIG_VC1_MMAL_DECODER)+= mmaldec.o
>  OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec_vc1.o
> +OBJS-$(CONFIG_VC2_ENCODER) += vc2enc.o vc2enc_dwt.o diractab.o
>  OBJS-$(CONFIG_VCR1_DECODER)+= vcr1.o
>  OBJS-$(CONFIG_VMDAUDIO_DECODER)+= vmdaudio.o
>  OBJS-$(CONFIG_VMDVIDEO_DECODER)+= vmdvideo.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index c7c1af5..2097db0 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -336,6 +336,7 @@ void avcodec_register_all(void)
>  REGISTER_DECODER(VC1IMAGE,  vc1image);
>  REGISTER_DECODER(VC1_MMAL,  vc1_mmal);
>  REGISTER_DECODER(VC1_QSV,   vc1_qsv);
> +REGISTER_ENCODER(VC2,   vc2);
>  REGISTER_DECODER(VCR1,  vcr1);
>  REGISTER_DECODER(VMDVIDEO,  vmdvideo);
>  REGISTER_DECODER(VMNC,  vmnc);
> diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
> new file mode 100644
> index 000..dbcde0f
> --- /dev/null
> +++ b/libavcodec/vc2enc.c
> @@ -0,0 +1,1194 @@
> +/*
> + * Copyright (C) 2016 Open Broadcast Systems Ltd.
> + * Author(C) 2016 Rostislav Pehlivanov 
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg 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.
> + *
> + * FFmpeg 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 FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "libavutil/ffversion.h"
> +#include "libavutil/pixdesc.h"
> +#include "libavutil/opt.h"
> +#include "dirac.h"
> +#include "put_bits.h"
> +#include "internal.h"
> +
> +#include "vc2enc_dwt.h"
> +#include "diractab.h"
> +
> +/* Quantizations above this usually zero coefficients and lower the quality 
> */
> +#define MAX_QUANT_INDEX 49
> +
> +#define COEF_LUT_TAB 2048
> +
> +enum VC2_QM {
> +VC2_QM_DEF = 0,
> +VC2_QM_COL,
> +VC2_QM_FLAT,
> +
> +VC2_QM_NB
> +};
> +
> +typedef struct SubBand {
> +dwtcoef *buf;
> +ptrdiff_t stride;
> +int width;
> +int height;
> +} SubBand;
> +
> +typedef struct Plane {
> +SubBand band[MAX_DWT_LEVELS][4];
> +dwtcoef *coef_buf;
> +int width;
> +int height;
> +int dwt_width;
> +int dwt_height;
> +ptrdiff_t coef_stride;
> +} Plane;
> +
> +typedef struct SliceArgs {
> +PutBitContext pb;
> +void *ctx;
> +int x;
> +int y;
> +int quant_idx;
> +int bits_ceil;
> +int bytes;
> +} SliceArgs;
> +
> +typedef struct TransformArgs {
> +void *ctx;
> +Plane *plane;
> +void *idata;
> +ptrdiff_t istride;
> +int field;
> +VC2TransformContext t;
> +} TransformArgs;
> +
> +typedef struct VC2EncContext {
> +AVClass *av_class;
> +PutBitContext pb;
> +Plane plane[3];
> +AVCodecContext *avctx;
> +DiracVersionInfo ver;
> +
> +SliceArgs *slice_args;
> +TransformArgs transform_args[3];
> +
> +/* For conversion from unsigned pixel values to signed */
> +int diff_offset;
> +int bpp;
> +
> +/* Picture number */
> +uint32_t picture_number;
> +
> +/* Base video format */
> +int base_vf;
> +int level;
> +int profile;
> +
> +/* Quantization matrix */
> +uint8_t quant[MAX_DWT_LEVELS][4];
> +
> +/* Coefficient LUT */
> +uint32_t *coef_lut_val;
> +uint8_t  *coef_lut_len;
> +
> +int num_x; /* #slices horizontally */
> +int num_y; /* #slices vertically */

pointles comment imo

> +

[FFmpeg-devel] [PATCH v3] avcodec: implement a native VC-2 HQ profile encoder

2016-02-07 Thread Rostislav Pehlivanov
Changes from last version:
-use ptrdiff_t for strides

Signed-off-by: Rostislav Pehlivanov 
---
 libavcodec/Makefile |1 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/vc2enc.c | 1194 +++
 libavcodec/vc2enc_dwt.c |  234 ++
 libavcodec/vc2enc_dwt.h |   54 +++
 5 files changed, 1484 insertions(+)
 create mode 100644 libavcodec/vc2enc.c
 create mode 100644 libavcodec/vc2enc_dwt.c
 create mode 100644 libavcodec/vc2enc_dwt.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 941057b..f6a4fbb 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -543,6 +543,7 @@ OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o 
vc1_block.o vc1_loopfilter.o
   wmv2dsp.o
 OBJS-$(CONFIG_VC1_MMAL_DECODER)+= mmaldec.o
 OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec_vc1.o
+OBJS-$(CONFIG_VC2_ENCODER) += vc2enc.o vc2enc_dwt.o diractab.o
 OBJS-$(CONFIG_VCR1_DECODER)+= vcr1.o
 OBJS-$(CONFIG_VMDAUDIO_DECODER)+= vmdaudio.o
 OBJS-$(CONFIG_VMDVIDEO_DECODER)+= vmdvideo.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index c7c1af5..2097db0 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -336,6 +336,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(VC1IMAGE,  vc1image);
 REGISTER_DECODER(VC1_MMAL,  vc1_mmal);
 REGISTER_DECODER(VC1_QSV,   vc1_qsv);
+REGISTER_ENCODER(VC2,   vc2);
 REGISTER_DECODER(VCR1,  vcr1);
 REGISTER_DECODER(VMDVIDEO,  vmdvideo);
 REGISTER_DECODER(VMNC,  vmnc);
diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
new file mode 100644
index 000..dbcde0f
--- /dev/null
+++ b/libavcodec/vc2enc.c
@@ -0,0 +1,1194 @@
+/*
+ * Copyright (C) 2016 Open Broadcast Systems Ltd.
+ * Author(C) 2016 Rostislav Pehlivanov 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/ffversion.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "dirac.h"
+#include "put_bits.h"
+#include "internal.h"
+
+#include "vc2enc_dwt.h"
+#include "diractab.h"
+
+/* Quantizations above this usually zero coefficients and lower the quality */
+#define MAX_QUANT_INDEX 49
+
+#define COEF_LUT_TAB 2048
+
+enum VC2_QM {
+VC2_QM_DEF = 0,
+VC2_QM_COL,
+VC2_QM_FLAT,
+
+VC2_QM_NB
+};
+
+typedef struct SubBand {
+dwtcoef *buf;
+ptrdiff_t stride;
+int width;
+int height;
+} SubBand;
+
+typedef struct Plane {
+SubBand band[MAX_DWT_LEVELS][4];
+dwtcoef *coef_buf;
+int width;
+int height;
+int dwt_width;
+int dwt_height;
+ptrdiff_t coef_stride;
+} Plane;
+
+typedef struct SliceArgs {
+PutBitContext pb;
+void *ctx;
+int x;
+int y;
+int quant_idx;
+int bits_ceil;
+int bytes;
+} SliceArgs;
+
+typedef struct TransformArgs {
+void *ctx;
+Plane *plane;
+void *idata;
+ptrdiff_t istride;
+int field;
+VC2TransformContext t;
+} TransformArgs;
+
+typedef struct VC2EncContext {
+AVClass *av_class;
+PutBitContext pb;
+Plane plane[3];
+AVCodecContext *avctx;
+DiracVersionInfo ver;
+
+SliceArgs *slice_args;
+TransformArgs transform_args[3];
+
+/* For conversion from unsigned pixel values to signed */
+int diff_offset;
+int bpp;
+
+/* Picture number */
+uint32_t picture_number;
+
+/* Base video format */
+int base_vf;
+int level;
+int profile;
+
+/* Quantization matrix */
+uint8_t quant[MAX_DWT_LEVELS][4];
+
+/* Coefficient LUT */
+uint32_t *coef_lut_val;
+uint8_t  *coef_lut_len;
+
+int num_x; /* #slices horizontally */
+int num_y; /* #slices vertically */
+int prefix_bytes;
+int size_scaler;
+int chroma_x_shift;
+int chroma_y_shift;
+
+/* Rate control stuff */
+int slice_max_bytes;
+int q_ceil;
+int q_start;
+
+/* Options */
+double tolerance;
+int wavelet_idx;
+int wavelet_depth;
+int strict_compliance;
+int slice_height;
+int slice_width;
+int interlaced;
+enum VC2_QM quant_matrix;
+
+/* Parse code state */