[FFmpeg-devel] 回复: [PATCH 1/2] avcodec/d3d12va_mpeg2: remove unused variables

2024-01-01 Thread Wu Jianhua
James Almer:
> [FFmpeg-devel] [PATCH 1/2] avcodec/d3d12va_mpeg2: remove unused variables
>
> Signed-off-by: James Almer 
> ---
> is_field worries me. Was it a copy-paste left over, or is it meant to
> be checked?
>
> libavcodec/d3d12va_mpeg2.c | 8 
> 1 file changed, 8 deletions(-)

> diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
> index 91bf3f8b75..a2ae8bf948 100644
> --- a/libavcodec/d3d12va_mpeg2.c
> +++ b/libavcodec/d3d12va_mpeg2.c
> @@ -49,7 +49,6 @@ static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, 
> av_unused const uint
> const MpegEncContext  *s   = avctx->priv_data;
> D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
> D3D12DecodePictureContext *ctx_pic = 
> s->current_picture_ptr->hwaccel_picture_private;
>-DXVA_QmatrixData  *qm  = &ctx_pic->qm;
>
> if (!ctx)
> return -1;
>@@ -76,8 +75,6 @@ static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, 
>const uint8_t *buff
> const MpegEncContext  *s   = avctx->priv_data;
> D3D12DecodePictureContext *ctx_pic = 
> s->current_picture_ptr->hwaccel_picture_private;
>
> -int is_field = s->picture_structure != PICT_FRAME;
> -
> 

This patch set LGTM. It's something added for debugging but forgot to remove. 
Thanks for your fix.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] configure: correct lensfun header function check

2024-01-01 Thread Gyan Doshi




On 2024-01-01 09:33 am, Gyan Doshi wrote:



On 2023-12-31 01:03 pm, Gyan Doshi wrote:

The function lf_db_new was deprecated in lensfun 09dcd3e7ad in 2017
in favour of lf_db_create. The AVfilter was adjusted in 8b78eb312d
but the configure check wasn't changed.

lensfun removed lf_db_new declaration in lf 35c0017593 so configure
fails to find lensfun.
---

This unbreaks use of the lib so plan to push in a few hours.


Pushed as e1c1dc8347f13104bc21e4100fcf4d4dddf5e5d8

Regards,
Gyan

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v9 00/13] Add vvc decoder

2024-01-01 Thread Nuo Mi
Changes since v8:
  Fixed 'make clean'
  Used Frank's full name, as Martin suggested
  Added Co-authors, as jb suggested
  Included thanks to reviewers and issue reporters

Nuo Mi (13):
  vvcdec: add vvc_data
  vvcdec: add parameter parser for sps, pps, ph, sh
  vvcdec: add cabac decoder
  vvcdec: add reference management
  vvcdec: add motion vector decoder
  vvcdec: add inter prediction
  vvcdec: add inv transform 1d
  vvcdec: add intra prediction
  vvcdec: add LMCS, Deblocking, SAO, and ALF filters
  vvcdec: add dsp init and inv transform
  vvcdec: add CTU parser
  vvcdec: add CTU thread logical
  vvcdec: add vvc decoder

 Changelog|1 +
 configure|1 +
 libavcodec/Makefile  |1 +
 libavcodec/allcodecs.c   |1 +
 libavcodec/version.h |2 +-
 libavcodec/vvc/Makefile  |   16 +
 libavcodec/vvc/vvc_cabac.c   | 2478 ++
 libavcodec/vvc/vvc_cabac.h   |  126 +
 libavcodec/vvc/vvc_ctu.c | 2491 ++
 libavcodec/vvc/vvc_ctu.h |  480 
 libavcodec/vvc/vvc_data.c| 3486 ++
 libavcodec/vvc/vvc_data.h|   80 +
 libavcodec/vvc/vvc_filter.c  | 1332 ++
 libavcodec/vvc/vvc_filter.h  |   71 +
 libavcodec/vvc/vvc_filter_template.c | 1135 +
 libavcodec/vvc/vvc_inter.c   |  923 +++
 libavcodec/vvc/vvc_inter.h   |   42 +
 libavcodec/vvc/vvc_inter_template.c  | 1023 
 libavcodec/vvc/vvc_intra.c   |  797 ++
 libavcodec/vvc/vvc_intra.h   |   49 +
 libavcodec/vvc/vvc_intra_template.c  | 1015 
 libavcodec/vvc/vvc_itx_1d.c  |  708 ++
 libavcodec/vvc/vvc_itx_1d.h  |   52 +
 libavcodec/vvc/vvc_mvs.c | 1798 +
 libavcodec/vvc/vvc_mvs.h |   46 +
 libavcodec/vvc/vvc_ps.c  | 1150 +
 libavcodec/vvc/vvc_ps.h  |  263 ++
 libavcodec/vvc/vvc_refs.c|  559 +
 libavcodec/vvc/vvc_refs.h|   57 +
 libavcodec/vvc/vvc_thread.c  |  828 ++
 libavcodec/vvc/vvc_thread.h  |   36 +
 libavcodec/vvc/vvcdec.c  | 1017 
 libavcodec/vvc/vvcdec.h  |  226 ++
 libavcodec/vvc/vvcdsp.c  |  141 ++
 libavcodec/vvc/vvcdsp.h  |  170 ++
 libavcodec/vvc/vvcdsp_template.c |  120 +
 36 files changed, 22720 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/Makefile
 create mode 100644 libavcodec/vvc/vvc_cabac.c
 create mode 100644 libavcodec/vvc/vvc_cabac.h
 create mode 100644 libavcodec/vvc/vvc_ctu.c
 create mode 100644 libavcodec/vvc/vvc_ctu.h
 create mode 100644 libavcodec/vvc/vvc_data.c
 create mode 100644 libavcodec/vvc/vvc_data.h
 create mode 100644 libavcodec/vvc/vvc_filter.c
 create mode 100644 libavcodec/vvc/vvc_filter.h
 create mode 100644 libavcodec/vvc/vvc_filter_template.c
 create mode 100644 libavcodec/vvc/vvc_inter.c
 create mode 100644 libavcodec/vvc/vvc_inter.h
 create mode 100644 libavcodec/vvc/vvc_inter_template.c
 create mode 100644 libavcodec/vvc/vvc_intra.c
 create mode 100644 libavcodec/vvc/vvc_intra.h
 create mode 100644 libavcodec/vvc/vvc_intra_template.c
 create mode 100644 libavcodec/vvc/vvc_itx_1d.c
 create mode 100644 libavcodec/vvc/vvc_itx_1d.h
 create mode 100644 libavcodec/vvc/vvc_mvs.c
 create mode 100644 libavcodec/vvc/vvc_mvs.h
 create mode 100644 libavcodec/vvc/vvc_ps.c
 create mode 100644 libavcodec/vvc/vvc_ps.h
 create mode 100644 libavcodec/vvc/vvc_refs.c
 create mode 100644 libavcodec/vvc/vvc_refs.h
 create mode 100644 libavcodec/vvc/vvc_thread.c
 create mode 100644 libavcodec/vvc/vvc_thread.h
 create mode 100644 libavcodec/vvc/vvcdec.c
 create mode 100644 libavcodec/vvc/vvcdec.h
 create mode 100644 libavcodec/vvc/vvcdsp.c
 create mode 100644 libavcodec/vvc/vvcdsp.h
 create mode 100644 libavcodec/vvc/vvcdsp_template.c

--
2.25.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v9 02/13] vvcdec: add parameter parser for sps, pps, ph, sh

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile |1 +
 libavcodec/vvc/vvc_ps.c | 1150 +++
 libavcodec/vvc/vvc_ps.h |  263 +
 libavcodec/vvc/vvcdec.h |  214 
 4 files changed, 1628 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_ps.c
 create mode 100644 libavcodec/vvc/vvc_ps.h
 create mode 100644 libavcodec/vvc/vvcdec.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 172b1133b1..0e9816581d 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -2,3 +2,4 @@ clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
 OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_data.o  \
+vvc/vvc_ps.o\
diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
new file mode 100644
index 00..ac96ed9f43
--- /dev/null
+++ b/libavcodec/vvc/vvc_ps.c
@@ -0,0 +1,1150 @@
+/*
+ * VVC parameter set parser
+ *
+ * Copyright (C) 2023 Nuo Mi
+ * Copyright (C) 2022 Xu Mu
+ *
+ * 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 "libavcodec/cbs_h266.h"
+#include "libavutil/imgutils.h"
+#include "libavcodec/refstruct.h"
+#include "vvc_data.h"
+#include "vvc_ps.h"
+#include "vvcdec.h"
+
+static int sps_map_pixel_format(VVCSPS *sps, void *log_ctx)
+{
+const H266RawSPS *r = sps->r;
+const AVPixFmtDescriptor *desc;
+
+switch (sps->bit_depth) {
+case 8:
+if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
+if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
+if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
+if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
+   break;
+case 10:
+if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10;
+if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
+if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
+if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
+break;
+case 12:
+if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12;
+if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
+if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
+if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
+break;
+default:
+av_log(log_ctx, AV_LOG_ERROR,
+   "The following bit-depths are currently specified: 8, 10, 12 
bits, "
+   "chroma_format_idc is %d, depth is %d\n",
+   r->sps_chroma_format_idc, sps->bit_depth);
+return AVERROR_INVALIDDATA;
+}
+
+desc = av_pix_fmt_desc_get(sps->pix_fmt);
+if (!desc)
+return AVERROR(EINVAL);
+
+sps->hshift[0] = sps->vshift[0] = 0;
+sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
+sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
+
+sps->pixel_shift = sps->bit_depth > 8;
+
+return 0;
+}
+
+static int sps_bit_depth(VVCSPS *sps, void *log_ctx)
+{
+const H266RawSPS *r = sps->r;
+
+sps->bit_depth = r->sps_bitdepth_minus8 + 8;
+sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
+sps->log2_transform_range =
+r->sps_extended_precision_flag ? FFMAX(15, FFMIN(20, sps->bit_depth + 
6)) : 15;
+return sps_map_pixel_format(sps, log_ctx);
+}
+
+static int sps_chroma_qp_table(VVCSPS *sps)
+{
+const H266RawSPS *r = sps->r;
+const int num_qp_tables = r->sps_same_qp_table_for_chroma_flag ?
+1 : (r->sps_joint_cbcr_enabled_flag ? 3 : 2);
+
+for (int i = 0; i < num_qp_tables; i++) {
+int num_points_in_qp_table;
+int8_t qp_in[VVC_MAX_POINTS_IN_QP_TABLE], 
qp_out[VVC_MAX_POINTS_IN_QP_TABLE];
+unsigned int delta_qp_in[VVC_MAX_POINTS_IN_QP_TABLE];
+int off = sps->qp_bd_offset;
+
+num_points_in_qp_table = r->sps_num_points_in_qp_table_minus1[i] + 1;
+
+qp_out[0] = qp_in[0] = r->sps_qp_table_start_minus26[i] + 26;
+for (int j = 0; j < num_points_in_qp_table; j++ ) {
+delta_qp_in[

[FFmpeg-devel] [PATCH v9 03/13] vvcdec: add cabac decoder

2024-01-01 Thread Nuo Mi
add Context-based Adaptive Binary Arithmetic Coding (CABAC) decoder

Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile|4 +-
 libavcodec/vvc/vvc_cabac.c | 2478 
 libavcodec/vvc/vvc_cabac.h |  126 ++
 libavcodec/vvc/vvc_ctu.c   |   32 +
 libavcodec/vvc/vvc_ctu.h   |  464 +++
 libavcodec/vvc/vvcdec.h|7 +
 6 files changed, 3110 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_cabac.c
 create mode 100644 libavcodec/vvc/vvc_cabac.h
 create mode 100644 libavcodec/vvc/vvc_ctu.c
 create mode 100644 libavcodec/vvc/vvc_ctu.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 0e9816581d..a2f3cc1883 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -1,5 +1,7 @@
 clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
-OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_data.o  \
+OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o \
+vvc/vvc_ctu.o   \
+vvc/vvc_data.o  \
 vvc/vvc_ps.o\
diff --git a/libavcodec/vvc/vvc_cabac.c b/libavcodec/vvc/vvc_cabac.c
new file mode 100644
index 00..4342dfc342
--- /dev/null
+++ b/libavcodec/vvc/vvc_cabac.c
@@ -0,0 +1,2478 @@
+/*
+ * VVC CABAC decoder
+ *
+ * Copyright (C) 2021 Nuo Mi
+ *
+ * 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 "libavcodec/cabac_functions.h"
+
+#include "vvc_cabac.h"
+#include "vvc_ctu.h"
+#include "vvc_data.h"
+
+#define CABAC_MAX_BIN 31
+
+#define CNU 35
+
+enum SyntaxElement {
+ALF_CTB_FLAG= 0,
+ALF_USE_APS_FLAG= ALF_CTB_FLAG  + 9,
+ALF_CTB_CC_CB_IDC,
+ALF_CTB_CC_CR_IDC   = ALF_CTB_CC_CB_IDC + 3,
+ALF_CTB_FILTER_ALT_IDX  = ALF_CTB_CC_CR_IDC + 3,
+SAO_MERGE_FLAG  = ALF_CTB_FILTER_ALT_IDX+ 2,
+SAO_TYPE_IDX,
+SPLIT_CU_FLAG,
+SPLIT_QT_FLAG   = SPLIT_CU_FLAG + 9,
+MTT_SPLIT_CU_VERTICAL_FLAG  = SPLIT_QT_FLAG + 6,
+MTT_SPLIT_CU_BINARY_FLAG= MTT_SPLIT_CU_VERTICAL_FLAG+ 5,
+NON_INTER_FLAG  = MTT_SPLIT_CU_BINARY_FLAG  + 4,
+CU_SKIP_FLAG= NON_INTER_FLAG+ 2,
+PRED_MODE_IBC_FLAG  = CU_SKIP_FLAG  + 3,
+PRED_MODE_FLAG  = PRED_MODE_IBC_FLAG+ 3,
+PRED_MODE_PLT_FLAG  = PRED_MODE_FLAG+ 2,
+CU_ACT_ENABLED_FLAG,
+INTRA_BDPCM_LUMA_FLAG,
+INTRA_BDPCM_LUMA_DIR_FLAG,
+INTRA_MIP_FLAG,
+INTRA_LUMA_REF_IDX  = INTRA_MIP_FLAG+ 4,
+INTRA_SUBPARTITIONS_MODE_FLAG   = INTRA_LUMA_REF_IDX+ 2,
+INTRA_SUBPARTITIONS_SPLIT_FLAG,
+INTRA_LUMA_MPM_FLAG,
+INTRA_LUMA_NOT_PLANAR_FLAG,
+INTRA_BDPCM_CHROMA_FLAG = INTRA_LUMA_NOT_PLANAR_FLAG+ 2,
+INTRA_BDPCM_CHROMA_DIR_FLAG,
+CCLM_MODE_FLAG,
+CCLM_MODE_IDX,
+INTRA_CHROMA_PRED_MODE,
+GENERAL_MERGE_FLAG,
+INTER_PRED_IDC,
+INTER_AFFINE_FLAG   = INTER_PRED_IDC+ 6,
+CU_AFFINE_TYPE_FLAG = INTER_AFFINE_FLAG + 3,
+SYM_MVD_FLAG,
+REF_IDX_LX,
+MVP_LX_FLAG = REF_IDX_LX+ 2,
+AMVR_FLAG,
+AMVR_PRECISION_IDX  = AMVR_FLAG + 2,
+BCW_IDX = AMVR_PRECISION_IDX+ 3,
+CU_CODED_FLAG,
+CU_SBT_FLAG,
+CU_SBT_QUAD_FLAG= CU_SBT_FLAG   + 2,
+CU_SBT_HORIZONTAL_FLAG,
+CU_SBT_POS_FLAG = CU_SBT_HORIZONTAL_FLAG+ 3,
+LFNST_IDX,
+MTS_IDX = LFNST_IDX + 3,
+COPY_ABOVE_PALETTE_INDICES_FLAG = MTS_IDX   + 4,
+PALETTE_TRANSPOSE_FLAG,
+RUN_COPY_FLAG,
+REGULAR_MERGE_FLAG  = RUN_COPY_FLAG + 8,
+MMVD_MER

[FFmpeg-devel] [PATCH v9 05/13] vvcdec: add motion vector decoder

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile  |1 +
 libavcodec/vvc/vvc_ctu.c |   18 +
 libavcodec/vvc/vvc_ctu.h |2 +
 libavcodec/vvc/vvc_mvs.c | 1798 ++
 libavcodec/vvc/vvc_mvs.h |   46 +
 5 files changed, 1865 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_mvs.c
 create mode 100644 libavcodec/vvc/vvc_mvs.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 0c8e942ba4..261866691f 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -4,5 +4,6 @@ clean::
 OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
+vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
 vvc/vvc_refs.o  \
diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index 78b13ffb00..3d31b862ae 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -20,7 +20,25 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "vvc_cabac.h"
 #include "vvc_ctu.h"
+#include "vvc_mvs.h"
+
+void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
+const int x0, const int y0, const int w, const int h)
+{
+const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
+const int x0b = av_mod_uintp2(x0, log2_ctb_size);
+const int y0b = av_mod_uintp2(y0, log2_ctb_size);
+
+lc->na.cand_up   = (lc->ctb_up_flag   || y0b);
+lc->na.cand_left = (lc->ctb_left_flag || x0b);
+lc->na.cand_up_left  = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : 
lc->ctb_up_left_flag;
+lc->na.cand_up_right_sap =
+(x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : 
lc->na.cand_up;
+lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < 
lc->end_of_tiles_x;
+}
+
 
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
diff --git a/libavcodec/vvc/vvc_ctu.h b/libavcodec/vvc/vvc_ctu.h
index 7cf9d9f045..d35b680aff 100644
--- a/libavcodec/vvc/vvc_ctu.h
+++ b/libavcodec/vvc/vvc_ctu.h
@@ -459,6 +459,8 @@ typedef struct ALFParams {
 uint8_t applied[3];
 } ALFParams;
 
+//utils
+void ff_vvc_set_neighbour_available(VVCLocalContext *lc, int x0, int y0, int 
w, int h);
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, int bit_depth, int 
persistent_rice_adaptation_enabled_flag);
 
 #endif // AVCODEC_VVC_VVC_CTU_H
diff --git a/libavcodec/vvc/vvc_mvs.c b/libavcodec/vvc/vvc_mvs.c
new file mode 100644
index 00..81e73fe746
--- /dev/null
+++ b/libavcodec/vvc/vvc_mvs.c
@@ -0,0 +1,1798 @@
+/*
+ * VVC motion vector decoder
+ *
+ * Copyright (C) 2023 Nuo Mi
+ * Copyright (C) 2022 Xu Mu
+ * 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 "vvc_ctu.h"
+#include "vvc_data.h"
+#include "vvc_refs.h"
+#include "vvc_mvs.h"
+
+#define IS_SAME_MV(a, b) (AV_RN64A(a) == AV_RN64A(b))
+
+//check if the two luma locations belong to the same motion estimation region
+static av_always_inline int is_same_mer(const VVCFrameContext *fc, const int 
xN, const int yN, const int xP, const int yP)
+{
+const uint8_t plevel = fc->ps.sps->log2_parallel_merge_level;
+
+return xN >> plevel == xP >> plevel &&
+   yN >> plevel == yP >> plevel;
+}
+
+//return true if we have same mvs and ref_idxs
+static av_always_inline int compare_mv_ref_idx(const MvField *n, const MvField 
*o)
+{
+if (!o || n->pred_flag != o->pred_flag)
+return 0;
+for (int i = 0; i < 2; i++) {
+PredFlag mask = i + 1;
+if (n->pred_flag & mask) {
+const int same_ref_idx = n->ref_idx[i] == o->ref_idx[i];
+const int same_mv = IS_SAME_MV(n->mv + i, o->mv + i);
+if (!same_ref_idx || !same_mv)
+return 0;
+}
+}
+return 1;
+}
+
+// 8.5.2.15 Temporal motion buffer compression process for collocated motion 
vectors
+static av_always_inline void mv_compression(Mv *motion)
+

[FFmpeg-devel] [PATCH v9 06/13] vvcdec: add inter prediction

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile |1 +
 libavcodec/vvc/vvc_inter.c  |  923 
 libavcodec/vvc/vvc_inter.h  |   42 ++
 libavcodec/vvc/vvc_inter_template.c | 1023 +++
 libavcodec/vvc/vvcdec.h |5 +
 libavcodec/vvc/vvcdsp.h |  170 +
 6 files changed, 2164 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_inter.c
 create mode 100644 libavcodec/vvc/vvc_inter.h
 create mode 100644 libavcodec/vvc/vvc_inter_template.c
 create mode 100644 libavcodec/vvc/vvcdsp.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 261866691f..21e31cb14a 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -4,6 +4,7 @@ clean::
 OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
+vvc/vvc_inter.o \
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
 vvc/vvc_refs.o  \
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
new file mode 100644
index 00..9b2925f60c
--- /dev/null
+++ b/libavcodec/vvc/vvc_inter.c
@@ -0,0 +1,923 @@
+/*
+ * VVC inter prediction
+ *
+ * Copyright (C) 2022 Nuo Mi
+ *
+ * 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/frame.h"
+
+#include "vvc_data.h"
+#include "vvc_inter.h"
+#include "vvc_mvs.h"
+#include "vvc_refs.h"
+
+// +1 is enough, + 32 for asm alignment
+#define PROF_TEMP_OFFSET (MAX_PB_SIZE + 32)
+static const int bcw_w_lut[] = {4, 5, 3, 10, -2};
+
+static int emulated_edge(const VVCFrameContext *fc, uint8_t *dst, const 
uint8_t **src, ptrdiff_t *src_stride,
+const int x_off, const int y_off, const int block_w, const int block_h, 
const int is_luma)
+{
+const int extra_before = is_luma ? LUMA_EXTRA_BEFORE : CHROMA_EXTRA_BEFORE;
+const int extra_after  = is_luma ? LUMA_EXTRA_AFTER : CHROMA_EXTRA_AFTER;
+const int extra= is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
+const int pic_width= is_luma ? fc->ps.pps->width  : (fc->ps.pps->width 
>> fc->ps.sps->hshift[1]);
+const int pic_height   = is_luma ? fc->ps.pps->height : 
(fc->ps.pps->height >> fc->ps.sps->vshift[1]);
+
+if (x_off < extra_before || y_off < extra_before ||
+x_off >= pic_width - block_w - extra_after ||
+y_off >= pic_height - block_h - extra_after) {
+const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << 
fc->ps.sps->pixel_shift;
+int offset = extra_before * *src_stride  + (extra_before << 
fc->ps.sps->pixel_shift);
+int buf_offset = extra_before * edge_emu_stride + (extra_before << 
fc->ps.sps->pixel_shift);
+
+fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, 
*src_stride,
+block_w + extra, block_h + extra, x_off - extra_before, y_off - 
extra_before,
+pic_width, pic_height);
+
+*src = dst + buf_offset;
+*src_stride = edge_emu_stride;
+return 1;
+}
+return 0;
+}
+
+static void emulated_edge_dmvr(const VVCFrameContext *fc, uint8_t *dst, const 
uint8_t **src, ptrdiff_t *src_stride,
+const int x_sb, const int y_sb, const int x_off, const int y_off, const 
int block_w, const int block_h, const int is_luma)
+{
+const int extra_before = is_luma ? LUMA_EXTRA_BEFORE : CHROMA_EXTRA_BEFORE;
+const int extra_after  = is_luma ? LUMA_EXTRA_AFTER : CHROMA_EXTRA_AFTER;
+const int extra= is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
+const int pic_width= is_luma ? fc->ps.pps->width  : (fc->ps.pps->width 
>> fc->ps.sps->hshift[1]);
+const int pic_height   = is_luma ? fc->ps.pps->height : 
(fc->ps.pps->height >> fc->ps.sps->vshift[1]);
+
+if (x_off < extra_before || y_off < extra_before ||
+x_off >= pic_width - block_w - extra_after ||
+y_off >= pic_height - block_h - extra_after||
+(x_off != x_sb || y_off !=  y_sb)) {
+   

[FFmpeg-devel] [PATCH v9 04/13] vvcdec: add reference management

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile   |   1 +
 libavcodec/vvc/vvc_refs.c | 559 ++
 libavcodec/vvc/vvc_refs.h |  57 
 3 files changed, 617 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_refs.c
 create mode 100644 libavcodec/vvc/vvc_refs.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index a2f3cc1883..0c8e942ba4 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -5,3 +5,4 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o 
\
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_ps.o\
+vvc/vvc_refs.o  \
diff --git a/libavcodec/vvc/vvc_refs.c b/libavcodec/vvc/vvc_refs.c
new file mode 100644
index 00..bf503e429e
--- /dev/null
+++ b/libavcodec/vvc/vvc_refs.c
@@ -0,0 +1,559 @@
+/*
+ * VVC reference management
+ *
+ * Copyright (C) 2023 Nuo Mi
+ *
+ * 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 
+
+#include "libavutil/thread.h"
+#include "libavcodec/refstruct.h"
+#include "libavcodec/thread.h"
+
+#include "vvc_refs.h"
+
+#define VVC_FRAME_FLAG_OUTPUT(1 << 0)
+#define VVC_FRAME_FLAG_SHORT_REF (1 << 1)
+#define VVC_FRAME_FLAG_LONG_REF  (1 << 2)
+#define VVC_FRAME_FLAG_BUMPING   (1 << 3)
+
+typedef struct FrameProgress {
+atomic_int progress[VVC_PROGRESS_LAST];
+VVCProgressListener *listener[VVC_PROGRESS_LAST];
+AVMutex lock;
+AVCond  cond;
+uint8_t has_lock;
+uint8_t has_cond;
+} FrameProgress;
+
+void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame *frame, int flags)
+{
+/* frame->frame can be NULL if context init failed */
+if (!frame->frame || !frame->frame->buf[0])
+return;
+
+frame->flags &= ~flags;
+if (!frame->flags) {
+av_frame_unref(frame->frame);
+ff_refstruct_unref(&frame->progress);
+
+ff_refstruct_unref(&frame->tab_dmvr_mvf);
+
+ff_refstruct_unref(&frame->rpl);
+frame->nb_rpl_elems = 0;
+ff_refstruct_unref(&frame->rpl_tab);
+
+frame->collocated_ref = NULL;
+}
+}
+
+const RefPicList *ff_vvc_get_ref_list(const VVCFrameContext *fc, const 
VVCFrame *ref, int x0, int y0)
+{
+const int x_cb = x0 >> fc->ps.sps->ctb_log2_size_y;
+const int y_cb = y0 >> fc->ps.sps->ctb_log2_size_y;
+const int pic_width_cb = fc->ps.pps->ctb_width;
+const int ctb_addr_rs  = y_cb * pic_width_cb + x_cb;
+
+return (const RefPicList *)ref->rpl_tab[ctb_addr_rs];
+}
+
+void ff_vvc_clear_refs(VVCFrameContext *fc)
+{
+for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++)
+ff_vvc_unref_frame(fc, &fc->DPB[i],
+VVC_FRAME_FLAG_SHORT_REF | VVC_FRAME_FLAG_LONG_REF);
+}
+
+static void free_progress(FFRefStructOpaque unused, void *obj)
+{
+FrameProgress *p = (FrameProgress *)obj;
+
+if (p->has_cond)
+ff_cond_destroy(&p->cond);
+if (p->has_lock)
+ff_mutex_destroy(&p->lock);
+}
+
+static FrameProgress *alloc_progress(void)
+{
+FrameProgress *p = ff_refstruct_alloc_ext(sizeof(*p), 0, NULL, 
free_progress);
+
+if (p) {
+p->has_lock = !ff_mutex_init(&p->lock, NULL);
+p->has_cond = !ff_cond_init(&p->cond, NULL);
+if (!p->has_lock || !p->has_cond)
+ff_refstruct_unref(&p);
+}
+return p;
+}
+
+static VVCFrame *alloc_frame(VVCContext *s, VVCFrameContext *fc)
+{
+const VVCPPS *pps = fc->ps.pps;
+for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
+int ret;
+VVCFrame *frame = &fc->DPB[i];
+if (frame->frame->buf[0])
+continue;
+
+ret = ff_thread_get_buffer(s->avctx, frame->frame, 
AV_GET_BUFFER_FLAG_REF);
+if (ret < 0)
+return NULL;
+
+frame->rpl = ff_refstruct_allocz(s->current_frame.nb_units * 
sizeof(RefPicListTab));
+if (!frame->rpl)
+goto fail;
+frame->nb_rpl_elems = s->current_frame.nb_units;
+
+frame->tab_dmvr_mvf = ff_refstruct_pool_get(fc->tab_dmvr_mvf_pool);
+if (!fr

[FFmpeg-devel] [PATCH v9 08/13] vvcdec: add intra prediction

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile |1 +
 libavcodec/vvc/vvc_ctu.c|   50 ++
 libavcodec/vvc/vvc_ctu.h|2 +
 libavcodec/vvc/vvc_intra.c  |  797 +
 libavcodec/vvc/vvc_intra.h  |   49 ++
 libavcodec/vvc/vvc_intra_template.c | 1015 +++
 6 files changed, 1914 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_intra.c
 create mode 100644 libavcodec/vvc/vvc_intra.h
 create mode 100644 libavcodec/vvc/vvc_intra_template.c

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index f28a47b0ee..35bb565680 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -5,6 +5,7 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o 
\
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_inter.o \
+vvc/vvc_intra.o \
 vvc/vvc_itx_1d.o\
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index 3d31b862ae..6138d2fc9f 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -20,10 +20,41 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcodec/refstruct.h"
+
 #include "vvc_cabac.h"
 #include "vvc_ctu.h"
 #include "vvc_mvs.h"
 
+void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int 
y_ctb,
+const int rx, const int ry, const int rs)
+{
+VVCFrameContext *fc = lc->fc;
+const int ctb_size = fc->ps.sps->ctb_size_y;
+
+lc->end_of_tiles_x = fc->ps.sps->width;
+lc->end_of_tiles_y = fc->ps.sps->height;
+if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
+lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
+if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
+lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
+
+lc->boundary_flags = 0;
+if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != 
fc->ps.pps->ctb_to_col_bd[rx - 1])
+lc->boundary_flags |= BOUNDARY_LEFT_TILE;
+if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
+lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
+if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != 
fc->ps.pps->ctb_to_row_bd[ry - 1])
+lc->boundary_flags |= BOUNDARY_UPPER_TILE;
+if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 
fc->ps.pps->ctb_width])
+lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
+lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
+lc->ctb_up_flag   = ry > 0 && !(lc->boundary_flags & BOUNDARY_UPPER_TILE) 
&& !(lc->boundary_flags & BOUNDARY_UPPER_SLICE);
+lc->ctb_up_right_flag = lc->ctb_up_flag && (fc->ps.pps->ctb_to_col_bd[rx] 
== fc->ps.pps->ctb_to_col_bd[rx + 1]) &&
+(fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
+lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
+}
+
 void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
 const int x0, const int y0, const int w, const int h)
 {
@@ -39,6 +70,25 @@ void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
 lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < 
lc->end_of_tiles_x;
 }
 
+void ff_vvc_ctu_free_cus(CTU *ctu)
+{
+CodingUnit **cus  = &ctu->cus;
+while (*cus) {
+CodingUnit *cu  = *cus;
+TransformUnit **head= &cu->tus.head;
+
+*cus = cu->next;
+
+while (*head) {
+TransformUnit *tu = *head;
+*head = tu->next;
+ff_refstruct_unref(&tu);
+}
+cu->tus.tail = NULL;
+
+ff_refstruct_unref(&cu);
+}
+}
 
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
diff --git a/libavcodec/vvc/vvc_ctu.h b/libavcodec/vvc/vvc_ctu.h
index d35b680aff..47c9f181bb 100644
--- a/libavcodec/vvc/vvc_ctu.h
+++ b/libavcodec/vvc/vvc_ctu.h
@@ -461,6 +461,8 @@ typedef struct ALFParams {
 
 //utils
 void ff_vvc_set_neighbour_available(VVCLocalContext *lc, int x0, int y0, int 
w, int h);
+void ff_vvc_decode_neighbour(VVCLocalContext *lc, int x_ctb, int y_ctb, int 
rx, int ry, int rs);
+void ff_vvc_ctu_free_cus(CTU *ctu);
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, int bit_depth, int 
persistent_rice_adaptation_enabled_flag);
 
 #endif // AVCODEC_VVC_VVC_CTU_H
diff --git a/libavcodec/vvc/vvc_intra.c b/libavcodec/vvc/vvc_intra.c
new file mode 100644
index 00..43de312a71
--- /dev/null
+++ b/libavcodec/vvc/

[FFmpeg-devel] [PATCH v9 10/13] vvcdec: add dsp init and inv transform

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile  |   3 +-
 libavcodec/vvc/vvcdsp.c  | 141 +++
 libavcodec/vvc/vvcdsp_template.c | 120 ++
 3 files changed, 263 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvcdsp.c
 create mode 100644 libavcodec/vvc/vvcdsp_template.c

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 57e2a2af75..10ba5f35be 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -1,7 +1,8 @@
 clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
-OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o \
+OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdsp.o\
+vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_filter.o\
diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c
new file mode 100644
index 00..c82ea7be30
--- /dev/null
+++ b/libavcodec/vvc/vvcdsp.c
@@ -0,0 +1,141 @@
+/*
+ * VVC DSP
+ *
+ * Copyright (C) 2021 Nuo Mi
+ *
+ * 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 "vvcdsp.h"
+#include "vvc_ctu.h"
+#include "vvc_itx_1d.h"
+
+#define VVC_SIGN(v) (v < 0 ? -1 : !!v)
+
+static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t 
dst_stride, const int width, const int height)
+{
+const int padded_width = width + 2;
+int16_t *dst;
+for (int y = 0; y < height; y++) {
+dst = _dst + y * dst_stride;
+for (int x = 0; x < width; x++) {
+dst[-1] = dst[0];
+dst[width] = dst[width - 1];
+}
+}
+
+_dst--;
+//top
+memcpy(_dst - dst_stride, _dst, padded_width * sizeof(int16_t));
+//bottom
+_dst += dst_stride * height;
+memcpy(_dst, _dst - dst_stride, padded_width * sizeof(int16_t));
+}
+
+static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy,
+const int block_w, const int block_h)
+{
+int sad = 0;
+dx -= 2;
+dy -= 2;
+src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx;
+src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx;
+for (int y = 0; y < block_h; y += 2) {
+for (int x = 0; x < block_w; x++) {
+sad += FFABS(src0[x] - src1[x]);
+}
+src0 += 2 * MAX_PB_SIZE;
+src1 += 2 * MAX_PB_SIZE;
+}
+return sad;
+}
+
+#define itx_fn(type, s)
 \
+static void itx_##type##_##s(int *coeffs, ptrdiff_t step, size_t nz)   
 \
+{  
 \
+  ff_vvc_inv_##type##_##s(coeffs, step, nz);   
 \
+}
+
+#define itx_fn_common(type) \
+itx_fn(type, 4);\
+itx_fn(type, 8);\
+itx_fn(type, 16);   \
+itx_fn(type, 32);   \
+
+itx_fn_common(dct2);
+itx_fn_common(dst7);
+itx_fn_common(dct8);
+itx_fn(dct2, 2);
+itx_fn(dct2, 64);
+
+typedef struct IntraEdgeParams {
+uint8_t* top;
+uint8_t* left;
+int filter_flag;
+
+uint16_t left_array[3 * MAX_TB_SIZE + 3];
+uint16_t filtered_left_array[3 * MAX_TB_SIZE + 3];
+uint16_t top_array[3 * MAX_TB_SIZE + 3];
+uint16_t filtered_top_array[3 * MAX_TB_SIZE + 3];
+} IntraEdgeParams;
+
+#define PROF_BORDER_EXT 1
+#define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2)
+#define BDOF_BORDER_EXT 1
+
+#define BDOF_PADDED_SIZE(16 + BDOF_BORDER_EXT * 2)
+#define BDOF_BLOCK_SIZE 4
+#define BDOF_GRADIENT_SIZE  (BDOF_BLOCK_SIZE + BDOF_BORDER_EXT * 2)
+
+#define BIT_DEPTH 8
+#include "vvcdsp_template.c"
+#undef BIT_DEPTH
+
+#define BIT_DEPTH 10
+#include "vvcdsp_template.c"
+#undef BIT_DEPTH
+
+#define BIT_DEPTH 12
+#include "vvcdsp_template.c"
+#undef BIT_DEPTH
+
+void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
+{
+#undef FUNC
+#define FUNC(a, depth) a ## _ ## depth
+
+#define VVC_DSP(depth) 
 \
+FUNC(ff_vvc

[FFmpeg-devel] [PATCH v9 11/13] vvcdec: add CTU parser

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/vvc_ctu.c | 2393 +-
 libavcodec/vvc/vvc_ctu.h |   11 +
 2 files changed, 2403 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index 6138d2fc9f..dd3c8884cb 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -24,8 +24,2391 @@
 
 #include "vvc_cabac.h"
 #include "vvc_ctu.h"
+#include "vvc_inter.h"
 #include "vvc_mvs.h"
 
+#define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
+
+#define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * 
fc->ps.pps->width32 + ((x) >> 5)]
+#define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + 
((x) >> 6)]
+
+typedef enum VVCModeType {
+MODE_TYPE_ALL,
+MODE_TYPE_INTER,
+MODE_TYPE_INTRA,
+} VVCModeType;
+
+static void set_tb_pos(const VVCFrameContext *fc, const TransformBlock *tb)
+{
+const int x_tb  = tb->x0 >> MIN_TU_LOG2;
+const int y_tb  = tb->y0 >> MIN_TU_LOG2;
+const int hs= fc->ps.sps->hshift[tb->c_idx];
+const int vs= fc->ps.sps->vshift[tb->c_idx];
+const int is_chroma = tb->c_idx != 0;
+const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
+const int end   = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
+
+for (int y = y_tb; y < end; y++) {
+const int off = y * fc->ps.pps->min_tu_width + x_tb;
+for (int i = 0; i < width; i++) {
+fc->tab.tb_pos_x0[is_chroma][off + i] = tb->x0;
+fc->tab.tb_pos_y0[is_chroma][off + i] = tb->y0;
+}
+memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width,  width);
+memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
+}
+}
+
+static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
+const TransformBlock *tb)
+{
+const int width  = tb->tb_width  << fc->ps.sps->hshift[tb->c_idx];
+const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
+
+for (int h = 0; h < height; h += MIN_TU_SIZE) {
+const int y = (tb->y0 + h) >> MIN_TU_LOG2;
+const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
+const int w = FFMAX(1, width >> MIN_TU_LOG2);
+memset(tab + off, v, w);
+}
+}
+
+// 8.7.1 Derivation process for quantization parameters
+static int get_qp_y_pred(const VVCLocalContext *lc)
+{
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps   = fc->ps.sps;
+const VVCPPS *pps   = fc->ps.pps;
+const CodingUnit *cu= lc->cu;
+const int ctb_log2_size = sps->ctb_log2_size_y;
+const int ctb_size_mask = (1 << ctb_log2_size) - 1;
+const int xQg   = lc->parse.cu_qg_top_left_x;
+const int yQg   = lc->parse.cu_qg_top_left_y;
+const int min_cb_width  = fc->ps.pps->min_cb_width;
+const int x_cb  = cu->x0 >> sps->min_cb_log2_size_y;
+const int y_cb  = cu->y0 >> sps->min_cb_log2_size_y;
+const int x_ctb = cu->x0 >> ctb_log2_size;
+const int y_ctb = cu->y0 >> ctb_log2_size;
+const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == x_ctb && (yQg >> 
ctb_log2_size) == y_ctb;
+const int in_same_ctb_b = (xQg >> ctb_log2_size) == x_ctb && ((yQg - 1) >> 
ctb_log2_size) == y_ctb;
+int qPy_pred, qPy_a, qPy_b;
+
+if (lc->na.cand_up) {
+const int first_qg_in_ctu = !(xQg & ctb_size_mask) &&  !(yQg & 
ctb_size_mask);
+const int qPy_up  = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * 
min_cb_width];
+if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg)
+return qPy_up;
+}
+
+// qPy_pred
+qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
+
+// qPy_b
+if (!lc->na.cand_up || !in_same_ctb_b)
+qPy_b = qPy_pred;
+else
+qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
+
+// qPy_a
+if (!lc->na.cand_left || !in_same_ctb_a)
+qPy_a = qPy_pred;
+else
+qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
+
+av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a < 63);
+av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b < 63);
+
+return (qPy_a + qPy_b + 1) >> 1;
+}
+
+static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t 
v)
+{
+const VVCFrameContext *fc   = lc->fc;
+const VVCPPS *pps   = fc->ps.pps;
+const CodingUnit *cu= lc->cu;
+const int log2_min_cb_size  = fc->ps.sps->min_cb_log2_size_y;
+const int x_cb  = cu->x0 >> log2_min_cb_size;
+const int y_cb  = cu->y0 >> log2_min_cb_size;
+const int cb_width  = cu->cb_width;
+const int cb_height = cu->cb_height;
+int x   = y_cb * pps->min_cb_width + x_cb;
+
+for (int y = 0; y < (cb

[FFmpeg-devel] [PATCH v9 07/13] vvcdec: add inv transform 1d

2024-01-01 Thread Nuo Mi
Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile |   1 +
 libavcodec/vvc/vvc_itx_1d.c | 708 
 libavcodec/vvc/vvc_itx_1d.h |  52 +++
 3 files changed, 761 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_itx_1d.c
 create mode 100644 libavcodec/vvc/vvc_itx_1d.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 21e31cb14a..f28a47b0ee 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -5,6 +5,7 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvc_cabac.o 
\
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_inter.o \
+vvc/vvc_itx_1d.o\
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
 vvc/vvc_refs.o  \
diff --git a/libavcodec/vvc/vvc_itx_1d.c b/libavcodec/vvc/vvc_itx_1d.c
new file mode 100644
index 00..01a50aad25
--- /dev/null
+++ b/libavcodec/vvc/vvc_itx_1d.c
@@ -0,0 +1,708 @@
+/*
+ * VVC 1D transform
+ *
+ * Copyright (C) 2023 Nuo Mi
+ *
+ * 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
+ */
+
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2021, ITU/ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *this list of conditions and the following disclaimer in the documentation
+ *and/or other materials provided with the distribution.
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
+ *be used to endorse or promote products derived from this software without
+ *specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* optimizaed with partial butterfly, see Hung C-Y, Landman P (1997)
+   Compact inverse discrete cosine transform circuit for MPEG video decoding.
+ */
+
+#include "vvc_data.h"
+#include "vvc_itx_1d.h"
+#include "libavutil/avutil.h"
+
+#define G2(m)  ((nz >  2) ? (m) : 0)
+#define G4(m)  ((nz >  4) ? (m) : 0)
+#define G8(m)  ((nz >  8) ? (m) : 0)
+#define G16(m) ((nz > 16) ? (m) : 0)
+
+/*
+transmatrix[2][2] = {
+{ a,  a },
+{ a, -a },
+}
+ */
+void ff_vvc_inv_dct2_2(int *coeffs, const ptrdiff_t stride, const size_t nz)
+{
+const int a = 64;
+const int x0 = coeffs[0 * stride], x1 = coeffs[1 * stride];
+
+coeffs[0 * stride] = a * (x0 + x1);
+coeffs[1 * stride] = a * (x0 - x1);
+}
+
+/*
+transmatrix[4][4] = {
+{ a,  a,  a,  a},
+{ b,  c, -c, -b},
+{ a, -a, -a,  a},
+{ c, -b,  b, -c},
+}
+ */
+void ff_vvc_inv_dct2_4(int *coeffs, const ptrdiff_t stride, const size_t nz)
+{
+const int a = 64, b = 83, c = 36;
+const int x0 = coeffs[0 * strid

[FFmpeg-devel] [PATCH v9 13/13] vvcdec: add vvc decoder

2024-01-01 Thread Nuo Mi
vvc decoder plug-in to avcodec.
split frames into slices/tiles and send them to vvc_thread for further decoding
reorder and wait for the frame decoding to be done and output the frame

Features:
+ Support I, P, B frames
+ Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range extension
+ Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF, 
LMCS, ALF
+ 295 conformace clips passed
- Not support RPR, IBC, PALETTE, and other minor features yet

Performance:
C code FPS on an i7-12700K (x86):
BQTerrace_1920x1080_60_10_420_22_RA.vvc  93.0
Chimera_8bit_1080P_1000_frames.vvc  184.3
NovosobornayaSquare_1920x1080.bin   191.3
RitualDance_1920x1080_60_10_420_32_LD.266   150.7
RitualDance_1920x1080_60_10_420_37_RA.266   170.0
Tango2_3840x2160_60_10_420_27_LD.266 33.7

C code FPS on a M1 Mac Pro (ARM):
BQTerrace_1920x1080_60_10_420_22_RA.vvc 58.7
Chimera_8bit_1080P_1000_frames.vvc  153.3
NovosobornayaSquare_1920x1080.bin   150.3
RitualDance_1920x1080_60_10_420_32_LD.266   105.0
RitualDance_1920x1080_60_10_420_37_RA.266   133.0
Tango2_3840x2160_60_10_420_27_LD.26621.7

Asm optimizations still working in progress. please check
https://github.com/ffvvc/FFmpeg/wiki#performance-data for the latest

Thank you for reporting issues and providing performance reports:
Łukasz Czech 
Xu Fulong <839789...@qq.com>

Thank you for providing review comments:
Ronald S. Bultje 
James Almer 
Andreas Rheinhardt 

Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 Changelog   |1 +
 configure   |1 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/version.h|2 +-
 libavcodec/vvc/Makefile |3 +-
 libavcodec/vvc/vvcdec.c | 1017 +++
 6 files changed, 1023 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/vvc/vvcdec.c

diff --git a/Changelog b/Changelog
index a638c03250..0451f265bc 100644
--- a/Changelog
+++ b/Changelog
@@ -13,6 +13,7 @@ version :
 - IAMF raw demuxer and muxer
 - D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 - tiltandshift filter
+- VVC decoder
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index 037c08afff..c2343f3987 100755
--- a/configure
+++ b/configure
@@ -3025,6 +3025,7 @@ vp6f_decoder_select="vp6_decoder"
 vp7_decoder_select="h264pred videodsp vp8dsp"
 vp8_decoder_select="h264pred videodsp vp8dsp"
 vp9_decoder_select="videodsp vp9_parser vp9_superframe_split_bsf"
+vvc_decoder_select="cabac golomb videodsp"
 wcmv_decoder_select="inflate_wrapper"
 webp_decoder_select="vp8_decoder exif"
 wmalossless_decoder_select="llauddsp"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b0f004e15c..93ce8e3224 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -389,6 +389,7 @@ extern const FFCodec ff_vp9_rkmpp_decoder;
 extern const FFCodec ff_vp9_v4l2m2m_decoder;
 extern const FFCodec ff_vqa_decoder;
 extern const FFCodec ff_vqc_decoder;
+extern const FFCodec ff_vvc_decoder;
 extern const FFCodec ff_wbmp_decoder;
 extern const FFCodec ff_wbmp_encoder;
 extern const FFCodec ff_webp_decoder;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 34b059a8a9..376388c5bb 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  36
+#define LIBAVCODEC_VERSION_MINOR  37
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 2f95cf7c63..dc484e5fb9 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -1,7 +1,8 @@
 clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
-OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdsp.o\
+OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o\
+vvc/vvcdsp.o\
 vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
new file mode 100644
index 00..608d497cb7
--- /dev/null
+++ b/libavcodec/vvc/vvcdec.c
@@ -0,0 +1,1017 @@
+/*
+ * VVC video decoder
+ *
+ * Copyright (C) 2021 Nuo Mi
+ * Copyright (C) 2022 Xu Mu
+ *
+ * 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 distr

[FFmpeg-devel] [PATCH v9 12/13] vvcdec: add CTU thread logical

2024-01-01 Thread Nuo Mi
This is the main entry point for the CTU (Coding Tree Unit) decoder.
The code will divide the CTU decoder into several stages.
It will check the stage dependencies and run the stage decoder.

Co-authored-by: Xu Mu 
Co-authored-by: Frank Plowman 
Co-authored-by: Shaun Loo 
Co-authored-by: Wu Jianhua 
---
 libavcodec/vvc/Makefile |   1 +
 libavcodec/vvc/vvc_thread.c | 828 
 libavcodec/vvc/vvc_thread.h |  36 ++
 3 files changed, 865 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_thread.c
 create mode 100644 libavcodec/vvc/vvc_thread.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 10ba5f35be..2f95cf7c63 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -12,3 +12,4 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdsp.o  
  \
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
 vvc/vvc_refs.o  \
+vvc/vvc_thread.o\
diff --git a/libavcodec/vvc/vvc_thread.c b/libavcodec/vvc/vvc_thread.c
new file mode 100644
index 00..db901585a4
--- /dev/null
+++ b/libavcodec/vvc/vvc_thread.c
@@ -0,0 +1,828 @@
+/*
+ * VVC thread logic
+ *
+ * Copyright (C) 2023 Nuo Mi
+ *
+ * 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 
+
+#include "libavutil/executor.h"
+#include "libavutil/thread.h"
+
+#include "vvc_thread.h"
+#include "vvc_ctu.h"
+#include "vvc_filter.h"
+#include "vvc_inter.h"
+#include "vvc_intra.h"
+#include "vvc_refs.h"
+
+typedef struct ProgressListener {
+VVCProgressListener l;
+struct VVCTask *task;
+VVCContext *s;
+} ProgressListener;
+
+typedef enum VVCTaskStage {
+VVC_TASK_STAGE_PARSE,
+VVC_TASK_STAGE_INTER,
+VVC_TASK_STAGE_RECON,
+VVC_TASK_STAGE_LMCS,
+VVC_TASK_STAGE_DEBLOCK_V,
+VVC_TASK_STAGE_DEBLOCK_H,
+VVC_TASK_STAGE_SAO,
+VVC_TASK_STAGE_ALF,
+VVC_TASK_STAGE_LAST
+} VVCTaskStage;
+
+typedef struct VVCTask {
+union {
+struct VVCTask *next;//for executor debug only
+AVTask task;
+};
+
+VVCTaskStage stage;
+
+// ctu x, y, and raster scan order
+int rx, ry, rs;
+VVCFrameContext *fc;
+
+ProgressListener col_listener;
+ProgressListener listener[2][VVC_MAX_REF_ENTRIES];
+
+// for parse task only
+SliceContext *sc;
+EntryPoint *ep;
+int ctu_idx;//ctu idx in the current slice
+
+// tasks with target scores met are ready for scheduling
+atomic_uchar score[VVC_TASK_STAGE_LAST];
+atomic_uchar target_inter_score;
+} VVCTask;
+
+typedef struct VVCRowThread {
+atomic_int col_progress[VVC_PROGRESS_LAST];
+} VVCRowThread;
+
+typedef struct VVCFrameThread {
+// error return for tasks
+atomic_int ret;
+
+VVCRowThread *rows;
+VVCTask *tasks;
+
+int ctu_size;
+int ctu_width;
+int ctu_height;
+int ctu_count;
+
+//protected by lock
+atomic_int nb_scheduled_tasks;
+atomic_int nb_scheduled_listeners;
+
+int row_progress[VVC_PROGRESS_LAST];
+
+AVMutex lock;
+AVCond  cond;
+} VVCFrameThread;
+
+static void add_task(VVCContext *s, VVCTask *t)
+{
+VVCFrameThread *ft = t->fc->ft;
+
+atomic_fetch_add(&ft->nb_scheduled_tasks, 1);
+
+av_executor_execute(s->executor, &t->task);
+}
+
+static void task_init(VVCTask *t, VVCTaskStage stage, VVCFrameContext *fc, 
const int rx, const int ry)
+{
+memset(t, 0, sizeof(*t));
+t->stage = stage;
+t->fc= fc;
+t->rx= rx;
+t->ry= ry;
+t->rs= ry * fc->ft->ctu_width + rx;
+for (int i = 0; i < FF_ARRAY_ELEMS(t->score); i++)
+atomic_store(t->score + i, 0);
+atomic_store(&t->target_inter_score, 0);
+}
+
+static void task_init_parse(VVCTask *t, SliceContext *sc, EntryPoint *ep, 
const int ctu_idx)
+{
+t->sc  = sc;
+t->ep  = ep;
+t->ctu_idx = ctu_idx;
+}
+
+static uint8_t task_add_score(VVCTask *t, const VVCTaskStage stage)
+{
+return atomic_fetch_add(&t->score[stage], 1) + 1;
+}
+
+static uint8_t task_get_score(VVCTask *t, const VVCTaskStage stage)
+{
+return atomic_load(&t->score[stage]);
+}
+
+//first r

[FFmpeg-devel] [PATCH] libavdevice/avfoundation.m Add missing type AVMediaType for macOS < 10.13.

2024-01-01 Thread David Bohman
This is a build failure in the master branch as a result of commit
e37b15e26fbc7bc31a86a4a2c7c798e20d4f4c2c:

There is no type AVMediaType prior to macOS 10.13.
---
 libavdevice/avfoundation.m | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index 6a57163eb7..5fc5cb61c5 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -761,6 +761,10 @@ static int get_audio_config(AVFormatContext *s)
 return 0;
 }

+#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+typedef NSString *AVMediaType;
+#endif
+
 static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
 #if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 10)
|| (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500))
 NSMutableArray *deviceTypes = nil;
-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 07/13] vvcdec: add inv transform 1d

2024-01-01 Thread Lynne
Jan 1, 2024, 15:16 by nuomi2...@gmail.com:

> + */
> +void ff_vvc_inv_dct2_4(int *coeffs, const ptrdiff_t stride, const size_t nz)
> +{
> +const int a = 64, b = 83, c = 36;
> +const int x0 = coeffs[0 * stride], x1 = coeffs[1 * stride];
> +const int x2 = coeffs[2 * stride], x3 = coeffs[3 * stride];
> +const int E[2] = {
> +a * (x0 + G2(+x2)),
> +a * (x0 + G2(-x2)),
> +};
> +const int O[2] = {
> +b * x1 + G2(+c * x3),
> +c * x1 + G2(-b * x3),
> +};
> +
> +coeffs[0 * stride] = E[0] + O[0];
> +coeffs[1 * stride] = E[1] + O[1];
> +coeffs[2 * stride] = E[1] - O[1];
> +coeffs[3 * stride] = E[0] - O[0];
> +}
>

Is that how the transforms are specified (matrices)?
Also, why are you not adding the transformed residual *directly* to the input.
This is how all our other decoders do this, because it skips a copy. This isn't
something you can quite optimize later on.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 13/13] vvcdec: add vvc decoder

2024-01-01 Thread Lynne
Jan 1, 2024, 15:16 by nuomi2...@gmail.com:

> vvc decoder plug-in to avcodec.
> split frames into slices/tiles and send them to vvc_thread for further 
> decoding
> reorder and wait for the frame decoding to be done and output the frame
>
> Features:
>  + Support I, P, B frames
>  + Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range extension
>  + Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF, LMCS, 
> ALF
>  + 295 conformace clips passed
>  - Not support RPR, IBC, PALETTE, and other minor features yet
>

IBC == Intra-block copy?
Palette == palette (screen content) coding?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 06/13] vvcdec: add inter prediction

2024-01-01 Thread Lynne
Jan 1, 2024, 15:15 by nuomi2...@gmail.com:

> +
> +
> +//
> +
>

What's with these markers?


> +static void FUNC(put_pixels)(int16_t *dst,
> +const uint8_t *_src, const ptrdiff_t _src_stride,
> +const int height, const int8_t *hf, const int8_t *vf, const int width)
> +{
> +const pixel *src= (const pixel *)_src;
> +const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
> +
> +for (int y = 0; y < height; y++) {
> +for (int x = 0; x < width; x++)
> +dst[x] = src[x] << (14 - BIT_DEPTH);
> +src += src_stride;
> +dst += MAX_PB_SIZE;
> +}
> +}
>

av_image_copy(AV_PIX_FMT_GRAY14, input_format)?

Also, why is the decoder using 14-bits internally rather than expanding
it to 16-bits? Headroom to avoid overflows?


> +
> +static void FUNC(put_uni_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
> +const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
> + const int8_t *hf, const int8_t *vf, const int width)
> +{
> +const pixel *src= (const pixel *)_src;
> +pixel *dst  = (pixel *)_dst;
> +const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
> +const ptrdiff_t dst_stride  = _dst_stride / sizeof(pixel);
> +
> +for (int y = 0; y < height; y++) {
> +memcpy(dst, src, width * sizeof(pixel));
> +src += src_stride;
> +dst += dst_stride;
> +}
> +}
>

av_image_copy()?
Also, this function is identical for all bit depths.


> +
> +enum TxType {
> +DCT2,
> +DST7,
> +DCT8,
> +N_TX_TYPE,
> +};
> +
> +enum TxSize {
> +TX_SIZE_2,
> +TX_SIZE_4,
> +TX_SIZE_8,
> +TX_SIZE_16,
> +TX_SIZE_32,
> +TX_SIZE_64,
> +N_TX_SIZE,
> +};
>

Could you prefix these enums with VVC_?

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] fix rounding errors in .ass subtitles format timings

2024-01-01 Thread Muhammed

Would appreciate it if someone could look at this.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 03/13] vvcdec: add cabac decoder

2024-01-01 Thread Lynne



Jan 1, 2024, 15:14 by nuomi2...@gmail.com:

> +
> +//fixme
> +static void vvc_refill2(CABACContext* c) {
>

Fix what?
Also, wrong coding style.


> +int i;
> +unsigned x;
> +#if !HAVE_FAST_CLZ
> +x = c->low ^ (c->low - 1);
> +i = 7 - ff_h264_norm_shift[x >> (CABAC_BITS - 1)];
> +#else
> +i = ff_ctz(c->low) - CABAC_BITS;
> +#endif
> +
> +x = -CABAC_MASK;
> +
> +#if CABAC_BITS == 16
> +x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1);
> +#else
> +x += c->bytestream[0] << 1;
> +#endif
>

CABAC_BITS?


> +
> +c->low += x << i;
> +#if !UNCHECKED_BITSTREAM_READER
> +if (c->bytestream < c->bytestream_end)
> +#endif
> +c->bytestream += CABAC_BITS / 8;
> +}
> +
> +static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const 
> int ctx)
> +{
> +VVCCabacState *s = base + ctx;
> +const int qRangeIdx = c->range >> 5;
> +const int pState = s->state[1] + (s->state[0] << 4);
> +const int valMps = pState >> 14;
> +const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 
> 9 ) >> 1) + 4;
> +int bit, lps_mask;
> +
> +c->range -= RangeLPS;
> +lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
> +
> +c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
> +c->range += (RangeLPS - c->range) & lps_mask;
> +
> +bit = valMps ^ (lps_mask & 1);
> +
> +lps_mask = ff_h264_norm_shift[c->range];
> +c->range <<= lps_mask;
> +c->low  <<= lps_mask;
> +
> +if (!(c->low & CABAC_MASK))
> +vvc_refill2(c);
> +s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit 
> >> s->shift[0]);
> +s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit 
> >> s->shift[1]);
> +return bit;
> +}
> +
> +#define GET_CABAC(ctx) vvc_get_cabac(&lc->ep->cc, lc->ep->cabac_state, ctx)
> +
> +//9.3.3.4 Truncated binary (TB) binarization process
> +static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
> +{
> +const int n = c_max + 1;
> +const int k = av_log2(n);
> +const int u = (1 << (k+1)) - n;
> +int v = 0;
> +for (int i = 0; i < k; i++)
> +v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
> +if (v >= u) {
> +v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
> +v -= u;
> +}
> +return v;
> +}
> +
> +// 9.3.3.6 Limited k-th order Exp-Golomb binarization process
> +static int limited_kth_order_egk_decode(CABACContext *c, const int k, const 
> int max_pre_ext_len, const int trunc_suffix_len)
> +{
> +int pre_ext_len = 0;
> +int escape_length;
> +int val = 0;
> +while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c))
> +pre_ext_len++;
> +if (pre_ext_len == max_pre_ext_len)
> +escape_length = trunc_suffix_len;
> +else
> +escape_length = pre_ext_len + k;
> +while (escape_length-- > 0) {
> +val = (val << 1) + get_cabac_bypass(c);
> +}
> +val += ((1 << pre_ext_len) - 1) << k;
> +return val;
> +}
> +
> +static av_always_inline
> +void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top,
> +const int x0, const int y0, const uint8_t *left_ctx, const uint8_t 
> *top_ctx)
> +{
> +const VVCFrameContext *fc = lc->fc;
> +const VVCSPS *sps = fc->ps.sps;
> +const int min_cb_width= fc->ps.pps->min_cb_width;
> +const int x0b = av_mod_uintp2(x0, sps->ctb_log2_size_y);
> +const int y0b = av_mod_uintp2(y0, sps->ctb_log2_size_y);
> +const int x_cb = x0 >> sps->min_cb_log2_size_y;
> +const int y_cb = y0 >> sps->min_cb_log2_size_y;
> +
> +if (lc->ctb_left_flag || x0b)
> +*left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb);
> +if (lc->ctb_up_flag || y0b)
> +*top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1);
> +}
> +
> +static av_always_inline
> +uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx)
> +{
> +uint8_t left = 0, top = 0;
> +get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
> +return left + top;
> +}
> +
> +int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
> +{
> +return GET_CABAC(SAO_MERGE_FLAG);
> +}
> +
> +int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
> +{
> +if (!GET_CABAC(SAO_TYPE_IDX))
> +return SAO_NOT_APPLIED;
> +
> +if (!get_cabac_bypass(&lc->ep->cc))
> +return SAO_BAND;
> +return SAO_EDGE;
> +}
> +
> +int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
> +{
> +int value = get_cabac_bypass(&lc->ep->cc);
> +
> +for (int i = 0; i < 4; i++)
> +value = (value << 1) | get_cabac_bypass(&lc->ep->cc);
> +return value;
> +}
> +
> +int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
> +{
> +int i = 0;
> +const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1;
> +
> +while (i < length && get_cabac_bypass(&lc->ep->cc))
> +i++;
> +return i;
> +}
> +
> +int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
> +{
> +return get_cabac_bypass(&

Re: [FFmpeg-devel] [PATCH v9 13/13] vvcdec: add vvc decoder

2024-01-01 Thread Hendrik Leppkes
On Mon, Jan 1, 2024 at 3:54 PM Lynne  wrote:
>
> Jan 1, 2024, 15:16 by nuomi2...@gmail.com:
>
> > vvc decoder plug-in to avcodec.
> > split frames into slices/tiles and send them to vvc_thread for further 
> > decoding
> > reorder and wait for the frame decoding to be done and output the frame
> >
> > Features:
> >  + Support I, P, B frames
> >  + Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range extension
> >  + Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF, 
> > LMCS, ALF
> >  + 295 conformace clips passed
> >  - Not support RPR, IBC, PALETTE, and other minor features yet
> >
>
> IBC == Intra-block copy?
> Palette == palette (screen content) coding?

Yes; Both IBC and PALETTE modes are alternate block coding modes, with
these two primarily optimized for screen content.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 00/13] Add vvc decoder

2024-01-01 Thread Lynne
Jan 1, 2024, 15:13 by nuomi2...@gmail.com:

>  libavcodec/vvc/Makefile  |   16 +
>  libavcodec/vvc/vvc_cabac.c   | 2478 ++
>  libavcodec/vvc/vvc_cabac.h   |  126 +
>  libavcodec/vvc/vvc_ctu.c | 2491 ++
>  libavcodec/vvc/vvc_ctu.h |  480 
>  libavcodec/vvc/vvc_data.c| 3486 ++
>  libavcodec/vvc/vvc_data.h|   80 +
>  libavcodec/vvc/vvc_filter.c  | 1332 ++
>  libavcodec/vvc/vvc_filter.h  |   71 +
>  libavcodec/vvc/vvc_filter_template.c | 1135 +
>  libavcodec/vvc/vvc_inter.c   |  923 +++
>  libavcodec/vvc/vvc_inter.h   |   42 +
>  libavcodec/vvc/vvc_inter_template.c  | 1023 
>  libavcodec/vvc/vvc_intra.c   |  797 ++
>  libavcodec/vvc/vvc_intra.h   |   49 +
>  libavcodec/vvc/vvc_intra_template.c  | 1015 
>  libavcodec/vvc/vvc_itx_1d.c  |  708 ++
>  libavcodec/vvc/vvc_itx_1d.h  |   52 +
>  libavcodec/vvc/vvc_mvs.c | 1798 +
>  libavcodec/vvc/vvc_mvs.h |   46 +
>  libavcodec/vvc/vvc_ps.c  | 1150 +
>  libavcodec/vvc/vvc_ps.h  |  263 ++
>  libavcodec/vvc/vvc_refs.c|  559 +
>  libavcodec/vvc/vvc_refs.h|   57 +
>  libavcodec/vvc/vvc_thread.c  |  828 ++
>  libavcodec/vvc/vvc_thread.h  |   36 +
>  libavcodec/vvc/vvcdec.c  | 1017 
>  libavcodec/vvc/vvcdec.h  |  226 ++
>  libavcodec/vvc/vvcdsp.c  |  141 ++
>  libavcodec/vvc/vvcdsp.h  |  170 ++
>  libavcodec/vvc/vvcdsp_template.c |  120 +
>

We have larger decoders than this, could you just put all files in libavodec/?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 09/13] vvcdec: add LMCS, Deblocking, SAO, and ALF filters

2024-01-01 Thread Lynne
Jan 1, 2024, 15:15 by nuomi2...@gmail.com:

> Co-authored-by: Xu Mu 
> Co-authored-by: Frank Plowman 
> Co-authored-by: Shaun Loo 
> Co-authored-by: Wu Jianhua 
> ---
>  libavcodec/vvc/Makefile  |1 +
>  libavcodec/vvc/vvc_ctu.h |1 +
>  libavcodec/vvc/vvc_filter.c  | 1332 ++
>  libavcodec/vvc/vvc_filter.h  |   71 ++
>  libavcodec/vvc/vvc_filter_template.c | 1135 ++
>  5 files changed, 2540 insertions(+)
>  create mode 100644 libavcodec/vvc/vvc_filter.c
>  create mode 100644 libavcodec/vvc/vvc_filter.h
>  create mode 100644 libavcodec/vvc/vvc_filter_template.c
>

Is there really absolutely nothing you can reuse from the HEVC decoder?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 13/13] vvcdec: add vvc decoder

2024-01-01 Thread Lynne
Jan 1, 2024, 16:14 by h.lepp...@gmail.com:

> On Mon, Jan 1, 2024 at 3:54 PM Lynne  wrote:
>
>>
>> Jan 1, 2024, 15:16 by nuomi2...@gmail.com:
>>
>> > vvc decoder plug-in to avcodec.
>> > split frames into slices/tiles and send them to vvc_thread for further 
>> > decoding
>> > reorder and wait for the frame decoding to be done and output the frame
>> >
>> > Features:
>> >  + Support I, P, B frames
>> >  + Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range extension
>> >  + Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF, 
>> > LMCS, ALF
>> >  + 295 conformace clips passed
>> >  - Not support RPR, IBC, PALETTE, and other minor features yet
>> >
>>
>> IBC == Intra-block copy?
>> Palette == palette (screen content) coding?
>>
>
> Yes; Both IBC and PALETTE modes are alternate block coding modes, with
> these two primarily optimized for screen content.
>

IBC is more general purpose in AV1 afaik.
They are rather important these days, is there a chance they could be
implemented before merging? We don't have a wrapper decoder for
VVC so it's fine if they're not implemented before being merged.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] fix rounding errors in .ass subtitles format timings

2024-01-01 Thread Muhammed

Would appreciate it if someone could look at this.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 00/13] Add vvc decoder

2024-01-01 Thread James Almer

On 1/1/2024 12:16 PM, Lynne wrote:

Jan 1, 2024, 15:13 by nuomi2...@gmail.com:


  libavcodec/vvc/Makefile  |   16 +
  libavcodec/vvc/vvc_cabac.c   | 2478 ++
  libavcodec/vvc/vvc_cabac.h   |  126 +
  libavcodec/vvc/vvc_ctu.c | 2491 ++
  libavcodec/vvc/vvc_ctu.h |  480 
  libavcodec/vvc/vvc_data.c| 3486 ++
  libavcodec/vvc/vvc_data.h|   80 +
  libavcodec/vvc/vvc_filter.c  | 1332 ++
  libavcodec/vvc/vvc_filter.h  |   71 +
  libavcodec/vvc/vvc_filter_template.c | 1135 +
  libavcodec/vvc/vvc_inter.c   |  923 +++
  libavcodec/vvc/vvc_inter.h   |   42 +
  libavcodec/vvc/vvc_inter_template.c  | 1023 
  libavcodec/vvc/vvc_intra.c   |  797 ++
  libavcodec/vvc/vvc_intra.h   |   49 +
  libavcodec/vvc/vvc_intra_template.c  | 1015 
  libavcodec/vvc/vvc_itx_1d.c  |  708 ++
  libavcodec/vvc/vvc_itx_1d.h  |   52 +
  libavcodec/vvc/vvc_mvs.c | 1798 +
  libavcodec/vvc/vvc_mvs.h |   46 +
  libavcodec/vvc/vvc_ps.c  | 1150 +
  libavcodec/vvc/vvc_ps.h  |  263 ++
  libavcodec/vvc/vvc_refs.c|  559 +
  libavcodec/vvc/vvc_refs.h|   57 +
  libavcodec/vvc/vvc_thread.c  |  828 ++
  libavcodec/vvc/vvc_thread.h  |   36 +
  libavcodec/vvc/vvcdec.c  | 1017 
  libavcodec/vvc/vvcdec.h  |  226 ++
  libavcodec/vvc/vvcdsp.c  |  141 ++
  libavcodec/vvc/vvcdsp.h  |  170 ++
  libavcodec/vvc/vvcdsp_template.c |  120 +



We have larger decoders than this, could you just put all files in libavodec/?


Was asked him to do it this way. Ideally, other codecs would follow 
after it, too.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] fix rounding errors in .ass subtitles format timings

2024-01-01 Thread Muhammed
for some reason the reply mailto link didn't work properly. sorry for 
spamming.
here's the patch: 
https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-November/317250.html

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 00/13] Add vvc decoder

2024-01-01 Thread Lynne
Jan 1, 2024, 16:26 by jamr...@gmail.com:

> On 1/1/2024 12:16 PM, Lynne wrote:
>
>> Jan 1, 2024, 15:13 by nuomi2...@gmail.com:
>>
>>> libavcodec/vvc/Makefile  |   16 +
>>>  libavcodec/vvc/vvc_cabac.c   | 2478 ++
>>>  libavcodec/vvc/vvc_cabac.h   |  126 +
>>>  libavcodec/vvc/vvc_ctu.c | 2491 ++
>>>  libavcodec/vvc/vvc_ctu.h |  480 
>>>  libavcodec/vvc/vvc_data.c| 3486 ++
>>>  libavcodec/vvc/vvc_data.h|   80 +
>>>  libavcodec/vvc/vvc_filter.c  | 1332 ++
>>>  libavcodec/vvc/vvc_filter.h  |   71 +
>>>  libavcodec/vvc/vvc_filter_template.c | 1135 +
>>>  libavcodec/vvc/vvc_inter.c   |  923 +++
>>>  libavcodec/vvc/vvc_inter.h   |   42 +
>>>  libavcodec/vvc/vvc_inter_template.c  | 1023 
>>>  libavcodec/vvc/vvc_intra.c   |  797 ++
>>>  libavcodec/vvc/vvc_intra.h   |   49 +
>>>  libavcodec/vvc/vvc_intra_template.c  | 1015 
>>>  libavcodec/vvc/vvc_itx_1d.c  |  708 ++
>>>  libavcodec/vvc/vvc_itx_1d.h  |   52 +
>>>  libavcodec/vvc/vvc_mvs.c | 1798 +
>>>  libavcodec/vvc/vvc_mvs.h |   46 +
>>>  libavcodec/vvc/vvc_ps.c  | 1150 +
>>>  libavcodec/vvc/vvc_ps.h  |  263 ++
>>>  libavcodec/vvc/vvc_refs.c|  559 +
>>>  libavcodec/vvc/vvc_refs.h|   57 +
>>>  libavcodec/vvc/vvc_thread.c  |  828 ++
>>>  libavcodec/vvc/vvc_thread.h  |   36 +
>>>  libavcodec/vvc/vvcdec.c  | 1017 
>>>  libavcodec/vvc/vvcdec.h  |  226 ++
>>>  libavcodec/vvc/vvcdsp.c  |  141 ++
>>>  libavcodec/vvc/vvcdsp.h  |  170 ++
>>>  libavcodec/vvc/vvcdsp_template.c |  120 +
>>>
>>
>> We have larger decoders than this, could you just put all files in 
>> libavodec/?
>>
>
> Was asked him to do it this way. Ideally, other codecs would follow after it, 
> too.
>

Sure.
Future asm files should probably go into libavcodec//vvc to avoid
duplicating shared asm stuff and makefiles. Makes it disjointed, which
is why I wanted to avoid it, but I don't mind it.

We could switch to meson too, which would let us define generators and
include directives that any component could use :)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] libavformat/hlsenc.c: Populate OTI using AAC profile in write_codec_attr.

2024-01-01 Thread Romain Beauxis
This patch populates the third entry for HLS codec attribute using the
AAC profile.

The HLS specifications[1] require this value to be the Object Type ID as
referred to in table 1.3 of ISO/IEC 14496-3:2009[2].

The numerical constants in the code refer to these OTIs minus one, as
documented in commit 372597e[3], confirmed by comparing the values in the
code with the values in the table mentioned above.

Links:
1: https://datatracker.ietf.org/doc/html/rfc6381#section-3.3
2: https://csclub.uwaterloo.ca/~ehashman/ISO14496-3-2009.pdf
3: 
https://github.com/FFmpeg/FFmpeg/commit/372597e5381c097455a7b73849254d56083eb056

Changes in this version:
- Default value set to "mp4a.40.2" when profile is unknown for backward
  compatibility.

---
 libavformat/hlsenc.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7049956dd7..55123d2297 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -418,8 +418,11 @@ static void write_codec_attr(AVStream *st, VariantStream 
*vs)
 } else if (st->codecpar->codec_id == AV_CODEC_ID_MP3) {
 snprintf(attr, sizeof(attr), "mp4a.40.34");
 } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
-/* TODO : For HE-AAC, HE-AACv2, the last digit needs to be set to 5 
and 29 respectively */
-snprintf(attr, sizeof(attr), "mp4a.40.2");
+if (st->codecpar->profile != AV_PROFILE_UNKNOWN)
+snprintf(attr, sizeof(attr), "mp4a.40.%d", 
st->codecpar->profile+1);
+else
+// This is for backward compatibility with the previous 
implementation.
+snprintf(attr, sizeof(attr), "mp4a.40.2");
 } else if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
 snprintf(attr, sizeof(attr), "ac-3");
 } else if (st->codecpar->codec_id == AV_CODEC_ID_EAC3) {
-- 
2.39.3 (Apple Git-145)

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavformat/hlsenc.c: Populate OTI using AAC profile in write_codec_attr.

2024-01-01 Thread Romain Beauxis
Le sam. 30 déc. 2023 à 16:25, David Johansen  a écrit :
>
> On Sat, Dec 30, 2023 at 8:23 AM Romain Beauxis  wrote:
>>
>> Le jeu. 28 déc. 2023 à 17:26, David Johansen  a 
>> écrit :
>> >>
>> >> I love this change, but it appears that st->codecpar->profile is always 
>> >> AV_PROFILE_UNKNOWN when using libfdk_aac as the encoder. Any indications 
>> >> where I should look for fix that so this can be used with that encoder?
>> >
>> >
>> > It appears that the issue is that profile doesn't default to what's being 
>> > used so `--profile:a` has to be set explicitly with libfdk_aac and then it 
>> > works. Not sure if that's an issue worth fixing, but if someone points me 
>> > to where it needs to be done, then I'd be glad to take a look at fixing it
>>
>> This feels like a second, separate issue to me?
>>
>> Maybe we could get these changes in first and then tackle it?
>
>
> But this is technically a breaking change, because it takes commands/uses 
> that currently work and changes them to no longer include CODECS since the 
> profile value is unknown by default

Ha gotcha.

Yes, in this case we do need to send the previous value as fallback
when the profile is unknown.

Just sent an updated patch!

-- Romain
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavdevice/avfoundation.m Add missing type AVMediaType for macOS < 10.13.

2024-01-01 Thread Michael Niedermayer
On Mon, Jan 01, 2024 at 06:38:00AM -0800, David Bohman wrote:
> This is a build failure in the master branch as a result of commit
> e37b15e26fbc7bc31a86a4a2c7c798e20d4f4c2c:
> 
> There is no type AVMediaType prior to macOS 10.13.
> ---
>  libavdevice/avfoundation.m | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> index 6a57163eb7..5fc5cb61c5 100644
> --- a/libavdevice/avfoundation.m
> +++ b/libavdevice/avfoundation.m
> @@ -761,6 +761,10 @@ static int get_audio_config(AVFormatContext *s)
>  return 0;
>  }
> 
> +#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
> +typedef NSString *AVMediaType;
> +#endif
> +
>  static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
>  #if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 10)
> || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500))
>  NSMutableArray *deviceTypes = nil;

error: corrupt patch at line 19

[...]

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavdevice/avfoundation.m Add missing type AVMediaType for macOS < 10.13.

2024-01-01 Thread epirat07



On 1 Jan 2024, at 15:38, David Bohman wrote:

> This is a build failure in the master branch as a result of commit
> e37b15e26fbc7bc31a86a4a2c7c798e20d4f4c2c:
>
> There is no type AVMediaType prior to macOS 10.13.
> ---
>  libavdevice/avfoundation.m | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> index 6a57163eb7..5fc5cb61c5 100644
> --- a/libavdevice/avfoundation.m
> +++ b/libavdevice/avfoundation.m
> @@ -761,6 +761,10 @@ static int get_audio_config(AVFormatContext *s)
>  return 0;
>  }
>
> +#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
> +typedef NSString *AVMediaType;
> +#endif

AFAICT this is lacking the similar check for iOS

> +
>  static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
>  #if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 10)
> || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500))
>  NSMutableArray *deviceTypes = nil;
> -- 
> 2.43.0
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v9 03/13] vvcdec: add cabac decoder

2024-01-01 Thread Michael Niedermayer
On Mon, Jan 01, 2024 at 10:12:29PM +0800, Nuo Mi wrote:
> add Context-based Adaptive Binary Arithmetic Coding (CABAC) decoder
> 
> Co-authored-by: Xu Mu 
> Co-authored-by: Frank Plowman 
> Co-authored-by: Shaun Loo 
> Co-authored-by: Wu Jianhua 
> ---
>  libavcodec/vvc/Makefile|4 +-
>  libavcodec/vvc/vvc_cabac.c | 2478 
>  libavcodec/vvc/vvc_cabac.h |  126 ++
>  libavcodec/vvc/vvc_ctu.c   |   32 +
>  libavcodec/vvc/vvc_ctu.h   |  464 +++
>  libavcodec/vvc/vvcdec.h|7 +
>  6 files changed, 3110 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/vvc/vvc_cabac.c
>  create mode 100644 libavcodec/vvc/vvc_cabac.h
>  create mode 100644 libavcodec/vvc/vvc_ctu.c
>  create mode 100644 libavcodec/vvc/vvc_ctu.h

[...]

> +static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding* 
> rc, const int i)
> +{
> +const CodingUnit *cu   = lc->cu;
> +TransformBlock *tb = rc->tb;
> +const int bdpcm_flag   = cu->bdpcm_flag[tb->c_idx];
> +const int xs   = rc->sb_scan_x_off[i];
> +const int ys   = rc->sb_scan_y_off[i];
> +uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
> +int infer_sb_sig_coeff_flag = 1;
> +int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
> +int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
> +int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];   ///< 
> AbsLevelPass2
> +
> +if (i != rc->last_sub_block || !rc->infer_sb_cbf)
> +*sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
> +else
> +*sb_coded_flag = 1;
> +if (*sb_coded_flag && i < rc->last_sub_block)
> +rc->infer_sb_cbf = 0;
> +
> +//first scan pass
> +for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
> +const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
> +const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
> +const int off = yc * tb->tb_width + xc;
> +int *sig_coeff_flag   = rc->sig_coeff_flag + off;
> +int *abs_level_pass1  = rc->abs_level_pass1 + off;
> +int *coeff_sign_level = rc->coeff_sign_level + off;
> +int par_level_flag= 0;
> +
> +abs_level_gtx_flag[n] = 0;
> +last_scan_pos_pass1 = n;
> +if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || 
> !infer_sb_sig_coeff_flag)) {
> +*sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
> +rc->rem_bins_pass1--;
> +if (*sig_coeff_flag)
> +infer_sb_sig_coeff_flag = 0;
> +} else {
> +*sig_coeff_flag = (n == rc->num_sb_coeff - 1) && 
> infer_sb_sig_coeff_flag && *sb_coded_flag;
> +}
> +*coeff_sign_level = 0;
> +if (*sig_coeff_flag) {
> +*coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, 
> rc, xc, yc);
> +abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, 
> xc, yc);
> +rc->rem_bins_pass1 -= 2;
> +if (abs_level_gtx_flag[n]) {
> +par_level_flag = par_level_flag_ts_decode(lc);
> +rc->rem_bins_pass1--;
> +}
> +}
> +*abs_level_pass1 = *sig_coeff_flag + par_level_flag + 
> abs_level_gtx_flag[n];
> +}
> +
> +//greater than x scan pass
> +for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
> +const int xc  = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
> +const int yc  = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
> +const int off = yc * tb->tb_width + xc;
> +
> +abs_level_pass2[n] = rc->abs_level_pass1[off];
> +for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
> +abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j);
> +abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
> +rc->rem_bins_pass1--;
> +}
> +last_scan_pos_pass2 = n;
> +}
> +
> +/* remainder scan pass */
> +for (n = 0; n < rc->num_sb_coeff; n++) {
> +const int xc  = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
> +const int yc  = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
> +const int off = yc * tb->tb_width + xc;
> +const int *abs_level_pass1 = rc->abs_level_pass1 + off;
> +int *abs_level = rc->abs_level + off;
> +int *coeff_sign_level  = rc->coeff_sign_level + off;
> +int abs_remainder  = 0;
> +
> +if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
> +(n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
> +*abs_level_pass1 >= 2) ||
> +(n > last_scan_pos_pass1 &&  *sb_coded_flag))
> +abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc);
> +if (n <= last_scan_pos_pass2) {
> +*abs_level = abs_level_pass2[n] + 2 * abs_remainder;
> +} else if (n

[FFmpeg-devel] [PATCH 2/2] doc/utils/eval: clarify meaning of random* seed value

2024-01-01 Thread Stefano Sabatini
Possible address trac issue:
http://trac.ffmpeg.org/ticket/10763
---
 doc/utils.texi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/doc/utils.texi b/doc/utils.texi
index ac9b63826e..554a07f057 100644
--- a/doc/utils.texi
+++ b/doc/utils.texi
@@ -944,11 +944,17 @@ Return a pseudo random value between 0.0 and 1.0. 
@var{idx} is the
 index of the internal variable which will be used to save the
 seed/state.
 
+The seed is represented as 64-bit unsigned integer. You can use a
+fraction of @code{UINT64_MAX} to initialize it.
+
 @item randomi(idx, min, max)
 Return a pseudo random value in the interval between @var{min} and
 @var{max}. @var{idx} is the index of the internal variable which will
 be used to save the seed/state.
 
+The seed is represented as 64-bit unsigned integer. You can use a
+fraction of @code{UINT64_MAX} to initialize it.
+
 @item root(expr, max)
 Find an input value for which the function represented by @var{expr}
 with argument @var{ld(0)} is 0 in the interval 0..@var{max}.
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] libavutil/eval: introduce UINT64_MAX constant

2024-01-01 Thread Stefano Sabatini
This might be useful, e.g. when setting the random seed expressed as a
uint64_t.
---
 doc/utils.texi   | 3 +++
 libavutil/eval.c | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/utils.texi b/doc/utils.texi
index 0c4f146f4f..ac9b63826e 100644
--- a/doc/utils.texi
+++ b/doc/utils.texi
@@ -1030,6 +1030,9 @@ area of the unit disc, approximately 3.14
 exp(1) (Euler's number), approximately 2.718
 @item PHI
 golden ratio (1+sqrt(5))/2, approximately 1.618
+@item UINT64_MAX
+maximum value expressed as an unsigned integer, corresponds to
+18446744073709551616 ((2^64)-1)
 @end table
 
 Assuming that an expression is considered "true" if it has a non-zero
diff --git a/libavutil/eval.c b/libavutil/eval.c
index dc6b3697bc..93048bff91 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -100,6 +100,7 @@ static const struct {
 { "PI",  M_PI  },
 { "PHI", M_PHI },
 { "QP2LAMBDA", FF_QP2LAMBDA },
+{ "UINT64_MAX", UINT64_MAX }
 };
 
 double av_strtod(const char *numstr, char **tail)
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavdevice/avfoundation.m Add missing type AVMediaType for macOS < 10.13.

2024-01-01 Thread Martin Storsjö

On Mon, 1 Jan 2024, David Bohman wrote:


This is a build failure in the master branch as a result of commit
e37b15e26fbc7bc31a86a4a2c7c798e20d4f4c2c:

There is no type AVMediaType prior to macOS 10.13.
---
libavdevice/avfoundation.m | 4 
1 file changed, 4 insertions(+)

diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index 6a57163eb7..5fc5cb61c5 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -761,6 +761,10 @@ static int get_audio_config(AVFormatContext *s)
return 0;
}

+#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+typedef NSString *AVMediaType;
+#endif
+


Checking the min required version of the SDK is the wrong check here.

If you use a recent macOS SDK but target an older version of macOS, this 
typedef is still available; check the AVMediaFormat.h header - there's no 
ifdef around the AVMediaType typedef.


Therefore, the availability of this type is connected to the SDK version, 
not the runtime target version. Therefore, use 
MAC_OS_X_VERSION_MAX_ALLOWED or something similar to check the actual SDK 
version, not the target version (as set by e.g. -mmacosx-version-min).


// Martin

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavdevice/avfoundation.m Add missing type AVMediaType for macOS < 10.13.

2024-01-01 Thread David Bohman
On Mon, Jan 1, 2024 at 9:08 AM Michael Niedermayer
 wrote:
>
> error: corrupt patch at line 19
>

Sorry, I have also attached the patch file to this message.
---
 libavdevice/avfoundation.m | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index 6a57163eb7..5fc5cb61c5 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -761,6 +761,10 @@ static int get_audio_config(AVFormatContext *s)
 return 0;
 }

+#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+typedef NSString *AVMediaType;
+#endif
+
 static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
 #if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 10)
|| (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500))
 NSMutableArray *deviceTypes = nil;
--
2.43.0


0001-Add-missing-type-AVMediaType-for-macOS-10.13.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavdevice/avfoundation.m Add missing type AVMediaType for macOS < 10.13.

2024-01-01 Thread David Bohman
On Mon, Jan 1, 2024 at 9:26 AM  wrote:
>
>
>
> On 1 Jan 2024, at 15:38, David Bohman wrote:
>
> > This is a build failure in the master branch as a result of commit
> > e37b15e26fbc7bc31a86a4a2c7c798e20d4f4c2c:
> >
> > There is no type AVMediaType prior to macOS 10.13.
> > ---
> >  libavdevice/avfoundation.m | 4 
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> > index 6a57163eb7..5fc5cb61c5 100644
> > --- a/libavdevice/avfoundation.m
> > +++ b/libavdevice/avfoundation.m
> > @@ -761,6 +761,10 @@ static int get_audio_config(AVFormatContext *s)
> >  return 0;
> >  }
> >
> > +#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
> > +typedef NSString *AVMediaType;
> > +#endif
>
> AFAICT this is lacking the similar check for iOS
>

Correct. I have built and tested it for / on my system, which is
running macOS 10.12.X.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] libavutil/eval: introduce UINT64_MAX constant

2024-01-01 Thread Michael Niedermayer
On Mon, Jan 01, 2024 at 08:38:58PM +0100, Stefano Sabatini wrote:
> This might be useful, e.g. when setting the random seed expressed as a
> uint64_t.
> ---
>  doc/utils.texi   | 3 +++
>  libavutil/eval.c | 1 +
>  2 files changed, 4 insertions(+)
> 
> diff --git a/doc/utils.texi b/doc/utils.texi
> index 0c4f146f4f..ac9b63826e 100644
> --- a/doc/utils.texi
> +++ b/doc/utils.texi
> @@ -1030,6 +1030,9 @@ area of the unit disc, approximately 3.14
>  exp(1) (Euler's number), approximately 2.718
>  @item PHI
>  golden ratio (1+sqrt(5))/2, approximately 1.618
> +@item UINT64_MAX
> +maximum value expressed as an unsigned integer, corresponds to

> +18446744073709551616 ((2^64)-1)

this doesnt look right
2^x is even
even -1 is odd
18446744073709551616 should be a odd number
18446744073709551615 looks more likely

double precission also doesnt like exactly ((2^64)-1) because the mantisse has 
too few bits

(U)INT64_MIN should work though exactly in double

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavutil/ppc/cpu.c: check that AT_HWCAP2 is defined

2024-01-01 Thread Sean McGovern
Hi,


On Thu, Oct 19, 2023, 07:44 Michael Niedermayer 
wrote:

> On Wed, Oct 18, 2023 at 01:18:54PM -0400, Sean McGovern wrote:
> > On Sat, Oct 14, 2023, 23:27 Sean McGovern  wrote:
> >
> > > It was not introduced until glibc 2.18.
> > > ---
> > > This should fix the ppc32 FATE node.
> > > ---
> > >  libavutil/ppc/cpu.c | 5 -
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavutil/ppc/cpu.c b/libavutil/ppc/cpu.c
> > > index 96b491c716..bc8bb5f47c 100644
> > > --- a/libavutil/ppc/cpu.c
> > > +++ b/libavutil/ppc/cpu.c
> > > @@ -95,12 +95,15 @@ int ff_get_cpu_flags_ppc(void)
> > >  #endif
> > >  if (ret & AV_CPU_FLAG_VSX)
> > >  av_assert0(ret & AV_CPU_FLAG_ALTIVEC);
> > > -} else if (buf[i] == AT_HWCAP2) {
> > > +}
> > > +#ifdef AT_HWCAP2 /* not introduced until glibc 2.18 */
> > > +else if (buf[i] == AT_HWCAP2) {
> > >  #ifdef PPC_FEATURE2_ARCH_2_07
> > >  if (buf[i + 1] & PPC_FEATURE2_ARCH_2_07)
> > >  ret |= AV_CPU_FLAG_POWER8;
> > >  #endif
> > >  }
> > > +#endif /* AT_HWCAP2 */
> > >  }
> > >  }
> > >
> > > --
> > > 2.39.2
> > >
> >
> > Ping review.
>
> will apply with my next push to master
>
>
> >
> > Alternatively, can the ppc32 FATE nodes be upgraded to a distribution
> > release with glibc 2.18 or higher?
>
> > Can I assist with that somehow?
>
> If you want, you can run a fate client to replace or augment the old one.
> for this sent the public ssh key the cleint will use to fate-admin (email
> addr
> should be in the docs)
>
> thx
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
>
Just a quick update: I have not forgot about this. I'm still in the middle
of converting my workstation to running Linux natively instead of as a VM.
Stay tuned!

-- Sean McGovern
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] avcodec/cbs_vp8: Apply clang-format and fix typos.

2024-01-01 Thread Dai, Jianhui J
This commit applies clang-format to the source and fixes typos.

TETS: ffmpeg -i fate-suite/vp8-test-vectors-r1/* -vcodec copy -bsf:v
trace_headers -f null -

Signed-off-by: Jianhui Dai 
---
 libavcodec/cbs_vp8.c | 52 ++--
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/libavcodec/cbs_vp8.c b/libavcodec/cbs_vp8.c
index 065156c248..5e6468d1b4 100644
--- a/libavcodec/cbs_vp8.c
+++ b/libavcodec/cbs_vp8.c
@@ -33,22 +33,22 @@ extern const uint8_t ff_vp8_token_update_probs[4][8][3][11];
 typedef struct CBSVP8BoolDecoder {
 GetBitContext *gbc;
 
-uint8_t value;
 uint8_t range;
 
-uint8_t count; // Store the number of bits in the `value` buffer.
-
+uint8_t value;
+// Store the number of bits in the `value` buffer.
+uint8_t count;
 } CBSVP8BoolDecoder;
 
-static int cbs_vp8_bool_decoder_init(CBSVP8BoolDecoder *decoder, GetBitContext 
*gbc)
+static int cbs_vp8_bool_decoder_init(CBSVP8BoolDecoder *decoder,
+ GetBitContext *gbc)
 {
 av_assert0(decoder);
 av_assert0(gbc);
 
 decoder->gbc = gbc;
-decoder->value = 0;
 decoder->range = 255;
-
+decoder->value = 0;
 decoder->count = 0;
 
 return 0;
@@ -60,7 +60,7 @@ static bool cbs_vp8_bool_decoder_fill_value(CBSVP8BoolDecoder 
*decoder)
 
 av_assert0(decoder->count <= 8);
 if (decoder->count == 8) {
-  return true;
+return true;
 }
 
 if (get_bits_left(decoder->gbc) >= bits) {
@@ -141,7 +141,7 @@ static int cbs_vp8_bool_decoder_read_unsigned(
 }
 
 if (trace_enable) {
-  CBS_TRACE_READ_END();
+CBS_TRACE_READ_END();
 }
 
 *write_to = value;
@@ -181,9 +181,11 @@ static int cbs_vp8_bool_decoder_read_signed(
 return 0;
 }
 
-static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext 
*gbc,
- int width, const char *name,
- const int *subscripts, uint32_t *write_to)
+static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx,
+GetBitContext *gbc, int width,
+const char *name, const int *subscripts,
+uint32_t *write_to, uint32_t range_min,
+uint32_t range_max)
 {
 int32_t value;
 
@@ -200,6 +202,14 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext 
*ctx, GetBitContext *g
 
 CBS_TRACE_READ_END();
 
+if (value < range_min || value > range_max) {
+av_log(ctx->log_ctx, AV_LOG_ERROR,
+   "%s out of range: "
+   "%" PRIu32 ", but must be in [%" PRIu32 ",%" PRIu32 "].\n",
+   name, value, range_min, range_max);
+return AVERROR_INVALIDDATA;
+}
+
 *write_to = value;
 return 0;
 }
@@ -246,15 +256,16 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext 
*ctx, GetBitContext *g
 do { \
 uint32_t value; \
 CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, \
-SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
+   SUBSCRIPTS(subs, __VA_ARGS__), &value, \
+   0, MAX_UINT_BITS(width))); \
 current->name = value; \
 } while (0)
 
 #define fixed(width, name, value) \
 do { \
 uint32_t fixed_value; \
-CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &fixed_value, \
-   value, value)); \
+CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, 0, &fixed_value, 
\
+   value, value)); \
 } while (0)
 
 #define bc_unsigned_subs(width, prob, enable_trace, name, subs, ...) \
@@ -277,6 +288,15 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext 
*ctx, GetBitContext *g
 
 #include "cbs_vp8_syntax_template.c"
 
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef CBSVP8BoolCodingRW
+#undef xf
+#undef fixed
+#undef bc_unsigned_subs
+#undef bc_signed_subs
+
 static int cbs_vp8_split_fragment(CodedBitstreamContext *ctx,
   CodedBitstreamFragment *frag, int header)
 {
@@ -328,8 +348,7 @@ static int cbs_vp8_read_unit(CodedBitstreamContext *ctx,
 return err;
 
 pos = get_bits_count(&gbc);
-pos /= 8;
-av_assert0(pos <= unit->data_size);
+av_assert0(pos <= unit->data_size * 8);
 
 frame->data_ref = av_buffer_ref(unit->data_ref);
 if (!frame->data_ref)
@@ -363,6 +382,7 @@ static const CodedBitstreamUnitTypeDescriptor 
cbs_vp8_unit_types[] = {
 CBS_UNIT_TYPE_END_OF_LIST,
 };
 
+// clang-format off
 const CodedBitstreamType ff_cbs_type_vp8 = {
 .codec_id  = AV_CODEC_ID_VP8,
 
-- 
2.25.1

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

To unsubscribe, visit link above, 

[FFmpeg-devel] [PATCH] avutil/eval: Use integer for random() state

2024-01-01 Thread Michael Niedermayer
rounding the 64bit integer state to double between each iteration
causes a reduction in quality of the random number generator.
For example its period drops from 2^64 to around 200 million

Signed-off-by: Michael Niedermayer 
---
 libavutil/eval.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/libavutil/eval.c b/libavutil/eval.c
index bad9e4ecb8d..89c61ba4bf5 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -55,6 +55,7 @@ typedef struct Parser {
 void *log_ctx;
 #define VARS 10
 double *var;
+uint64_t *var_uint64;
 } Parser;
 
 static const AVClass eval_class = {
@@ -173,6 +174,7 @@ struct AVExpr {
 } a;
 struct AVExpr *param[3];
 double *var;
+uint64_t *var_uint64;
 };
 
 static double etime(double v)
@@ -230,9 +232,10 @@ static double eval_expr(Parser *p, AVExpr *e)
 }
 case e_random:{
 int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
-uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
+uint64_t r= p->var_uint64[idx] ? p->var_uint64[idx] : 
(isnan(p->var[idx]) ? 0 : p->var[idx]);
 r= r*1664525+1013904223;
 p->var[idx]= r;
+p->var_uint64[idx]= r;
 return e->value * (r * (1.0/UINT64_MAX));
 }
 case e_while: {
@@ -319,7 +322,11 @@ static double eval_expr(Parser *p, AVExpr *e)
 case e_div: return e->value * (d2 ? (d / d2) : d * INFINITY);
 case e_add: return e->value * (d + d2);
 case e_last:return e->value * d2;
-case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= 
d2);
+case e_st :  {
+int index = av_clip(d, 0, VARS-1);
+p->var_uint64[index] = 0;
+return e->value * (p->var[index]= d2);
+}
 case e_hypot:return e->value * hypot(d, d2);
 case e_atan2:return e->value * atan2(d, d2);
 case e_bitand: return isnan(d) || isnan(d2) ? NAN : e->value * 
((long int)d & (long int)d2);
@@ -339,6 +346,7 @@ void av_expr_free(AVExpr *e)
 av_expr_free(e->param[1]);
 av_expr_free(e->param[2]);
 av_freep(&e->var);
+av_freep(&e->var_uint64);
 av_freep(&e);
 }
 
@@ -724,7 +732,8 @@ int av_expr_parse(AVExpr **expr, const char *s,
 goto end;
 }
 e->var= av_mallocz(sizeof(double) *VARS);
-if (!e->var) {
+e->var_uint64= av_mallocz(sizeof(uint64_t) *VARS);
+if (!e->var || !e->var_uint64) {
 ret = AVERROR(ENOMEM);
 goto end;
 }
@@ -766,6 +775,7 @@ double av_expr_eval(AVExpr *e, const double *const_values, 
void *opaque)
 {
 Parser p = { 0 };
 p.var= e->var;
+p.var_uint64= e->var_uint64;
 
 p.const_values = const_values;
 p.opaque = opaque;
-- 
2.17.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/4] avcodec/mdec: DC reading for STRv1 is like STRv2

2024-01-01 Thread aybe aybe
Hi,

As I understand, support for .STR files is broken for almost 10 years now 
(since 161442ff2c4b0dd8a5072c6bbe6bf55303fffccf it seems).

Currently, ffmpeg fails with tons of errors like this on version 1 STRs, e.g. 
Wipeout 1:
[mdec @ 027c72c0] ac-tex damaged at 1 9

What happens is that only the audio is present in the video file.

Anyway, that one character patch fixes the problem, video is now rendered.

Signed-off-by: aybe 
---
  libavcodec/mdec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 44b12471a9..c4904216b8 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -68,7 +68,7 @@ static inline int mdec_decode_block_intra(MDECContext *a, 
int16_t *block, int n)
  const int qscale = a->qscale;

  /* DC coefficient */
-if (a->version == 2) {
+if (a->version <= 2) {
  block[0] = 2 * get_sbits(&a->gb, 10) + 1024;
  } else {
  component = (n <= 3 ? 0 : n - 4 + 1);
--
2.41.0.windows.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/4] avformat/psxstr: fix demuxing I/O error at EOF

2024-01-01 Thread aybe aybe
This second patch fixes the following error at the end of a .STR stream 
conversion:

[in#0/psxstr @ 00681e80] Error during demuxing: I/O error

It's been a bit of trial and error as I've never used ffmpeg, but returning 
AVERROR_EOF appears to be the way to go (doesn't complain anymore).

Signed-off-by: aybe 
---
  libavformat/psxstr.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index bb56b05688..72d14b9792 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -165,8 +165,12 @@ static int str_read_packet(AVFormatContext *s,
  AVStream *st;

  while (1) {
+int read = avio_read(pb, sector, RAW_CD_SECTOR_SIZE);

-if (avio_read(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
+if (read == AVERROR_EOF)
+return AVERROR_EOF;
+
+if (read != RAW_CD_SECTOR_SIZE)
  return AVERROR(EIO);

  channel = sector[0x11];
--
2.41.0.windows.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/4] avformat/psxstr: fix unknown sector type 00/80

2024-01-01 Thread aybe aybe
This third patch fixes warnings that are false positives (still on STRv1).

That's because these sectors are simply empty ones as can be read in "System 
Description CD-ROM XA, May 1991,
4.3.2.3".

Haven't attempted significant refactoring as it just works, left a comment 
instead about the situation.

The result is that there are no more false warnings when converting.

Signed-off-by: aybe 
---
  libavformat/psxstr.c | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index 72d14b9792..306a690f52 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -48,6 +48,7 @@
  #define CDXA_TYPE_DATA 0x08
  #define CDXA_TYPE_AUDIO0x04
  #define CDXA_TYPE_VIDEO0x02
+#define CDXA_TYPE_EMPTY0x00

  #define STR_MAGIC (0x80010160)

@@ -274,6 +275,12 @@ static int str_read_packet(AVFormatContext *s,
  str->channels[channel].audio_stream_index;
  pkt->duration = 1;
  return 0;
+case CDXA_TYPE_EMPTY: /* CD-ROM XA, May 1991, 4.3.2.3 */
+{
+/* NOTE this also catches 0x80 (EOF bit) because of 
CDXA_TYPE_MASK */
+/* TODO consider refactoring so as to explicitly handle each 
case? */
+break;
+}
  default:
  av_log(s, AV_LOG_WARNING, "Unknown sector type %02X\n", 
sector[0x12]);
  /* drop the sector and move on */
--
2.41.0.windows.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/4] avformat/psxstr: basic FPS detection instead of fixed value

2024-01-01 Thread aybe aybe
This fourth and last patch is an attempt at removing the hard-coded value of 15 
FPS.

In patch 1/4, although it would render video, the audio and video were not 
synchronized at all, now there are.

In this approach I kept it simple, grab min/max possible rates, pick min, clamp 
to 15/30 just in case.

It appears to work quite well, the right frame rate is picked up and both 
streams are in sync.

(tested against Wipeout introduction for both PAL and NTSC versions).


Besides, there have been significant findings over the years regarding that 
format, specifically:
https://problemkaputt.de/psxspx-macroblock-decoder-mdec.htm
https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt

Maybe someone versed in this topic (I'm not) could further improve support of 
this format according these docs...



Signed-off-by: aybe 
---
  libavformat/psxstr.c | 27 +--
  1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index 306a690f52..98897acde3 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -52,6 +52,9 @@

  #define STR_MAGIC (0x80010160)

+#define MDEC_STR_FPS_MIN 15
+#define MDEC_STR_FPS_MAX 30
+
  typedef struct StrChannel {
  /* video parameters */
  int video_stream_index;
@@ -65,6 +68,10 @@ typedef struct StrDemuxContext {

  /* a STR file can contain up to 32 channels of data */
  StrChannel channels[32];
+/* trivial FPS detection based on sectors per frame */
+int fps_min; /* slowest FPS found */
+int fps_max; /* fastest FPS found */
+int fps_val; /* nominal FPS value */
  } StrDemuxContext;

  static const uint8_t sync_header[12] = 
{0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00};
@@ -150,6 +157,10 @@ static int str_read_header(AVFormatContext *s)
  str->channels[i].audio_stream_index= -1;
  }

+str->fps_min = INT_MAX;
+str->fps_max = INT_MIN;
+str->fps_val = 0;
+
  s->ctx_flags |= AVFMTCTX_NOHEADER;

  return 0;
@@ -161,7 +172,7 @@ static int str_read_packet(AVFormatContext *s,
  AVIOContext *pb = s->pb;
  StrDemuxContext *str = s->priv_data;
  unsigned char sector[RAW_CD_SECTOR_SIZE];
-int channel, ret;
+int channel, ret, sub_mode, idx_sect, num_sect;
  AVPacket *pkt;
  AVStream *st;

@@ -178,6 +189,18 @@ static int str_read_packet(AVFormatContext *s,
  if (channel >= 32)
  return AVERROR_INVALIDDATA;

+sub_mode = sector[0x12];
+idx_sect = AV_RL16(§or[0x1C]);
+num_sect = AV_RL16(§or[0x1E]);
+
+/* compute FPS from sector count @ each new video frame */
+if (sub_mode & 0x02 && idx_sect == 0x00) {
+int fps = 150 / num_sect;
+str->fps_min = FFMIN(str->fps_min, fps);
+str->fps_max = FFMAX(str->fps_max, fps);
+str->fps_val = FFMIN(MDEC_STR_FPS_MAX, FFMAX(MDEC_STR_FPS_MIN, 
str->fps_min));
+}
+
  switch (sector[0x12] & CDXA_TYPE_MASK) {

  case CDXA_TYPE_DATA:
@@ -200,7 +223,7 @@ static int str_read_packet(AVFormatContext *s,
  st = avformat_new_stream(s, NULL);
  if (!st)
  return AVERROR(ENOMEM);
-avpriv_set_pts_info(st, 64, 1, 15);
+avpriv_set_pts_info(st, 64, 1, str->fps_val);

  str->channels[channel].video_stream_index = st->index;

--
2.41.0.windows.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2] libavformat/hlsenc.c: Populate OTI using AAC profile in write_codec_attr.

2024-01-01 Thread Steven Liu
Romain Beauxis  于2024年1月1日周一 23:53写道:
>
> This patch populates the third entry for HLS codec attribute using the
> AAC profile.
>
> The HLS specifications[1] require this value to be the Object Type ID as
> referred to in table 1.3 of ISO/IEC 14496-3:2009[2].
>
> The numerical constants in the code refer to these OTIs minus one, as
> documented in commit 372597e[3], confirmed by comparing the values in the
> code with the values in the table mentioned above.
>
> Links:
> 1: https://datatracker.ietf.org/doc/html/rfc6381#section-3.3
> 2: https://csclub.uwaterloo.ca/~ehashman/ISO14496-3-2009.pdf
> 3: 
> https://github.com/FFmpeg/FFmpeg/commit/372597e5381c097455a7b73849254d56083eb056
>
> Changes in this version:
> - Default value set to "mp4a.40.2" when profile is unknown for backward
>   compatibility.
>
> ---
>  libavformat/hlsenc.c | 7 +--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 7049956dd7..55123d2297 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -418,8 +418,11 @@ static void write_codec_attr(AVStream *st, VariantStream 
> *vs)
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_MP3) {
>  snprintf(attr, sizeof(attr), "mp4a.40.34");
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
> -/* TODO : For HE-AAC, HE-AACv2, the last digit needs to be set to 5 
> and 29 respectively */
> -snprintf(attr, sizeof(attr), "mp4a.40.2");
> +if (st->codecpar->profile != AV_PROFILE_UNKNOWN)
> +snprintf(attr, sizeof(attr), "mp4a.40.%d", 
> st->codecpar->profile+1);
> +else
> +// This is for backward compatibility with the previous 
> implementation.
> +snprintf(attr, sizeof(attr), "mp4a.40.2");
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
>  snprintf(attr, sizeof(attr), "ac-3");
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_EAC3) {
> --
> 2.39.3 (Apple Git-145)
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

LGTM, will apply after 24 hours if there have no objections.

Thanks
Steven
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/5] avcodec/d3d12va_vp9: fix vp9 max_num_refs value

2024-01-01 Thread Xiang, Haihao
On Do, 2023-12-28 at 11:10 +0800, Tong Wu wrote:
> Previous max_num_refs was based on pp.frame_refs plus 1 and it could possibly
> reaches the size limit. Actually it should be the size of pp.ref_frame_map
> plus 1.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/d3d12va_vp9.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
> index bb94e18781..d6dfc905d9 100644
> --- a/libavcodec/d3d12va_vp9.c
> +++ b/libavcodec/d3d12va_vp9.c
> @@ -148,7 +148,7 @@ static int d3d12va_vp9_decode_init(AVCodecContext *avctx)
>  break;
>  };
>  
> -    ctx->max_num_ref = FF_ARRAY_ELEMS(pp.frame_refs) + 1;
> +    ctx->max_num_ref = FF_ARRAY_ELEMS(pp.ref_frame_map) + 1;
>  
>  return ff_d3d12va_decode_init(avctx);
>  }

LGTM, will apply if there are no objections

Thanks
Haihao


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] doc/ffmpeg: update the documentation about qsv device creation

2024-01-01 Thread Xiang, Haihao
On Vr, 2023-12-29 at 12:23 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Signed-off-by: Haihao Xiang 
> ---
>  doc/ffmpeg.texi | 21 +++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index ab17d1d687..c6c0606e8a 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -1406,16 +1406,33 @@ If not specified, @samp{auto_any} is used.
>  platform-appropriate subdevice (@samp{dxva2} or @samp{d3d11va} or
> @samp{vaapi}) and then deriving a
>  QSV device from that.)
>  
> -Alternatively, @samp{child_device_type} helps to choose platform-appropriate
> subdevice type.
> -On Windows @samp{d3d11va} is used as default subdevice type.
> +The following options are recognized:
> +@table @option
> +@item child_device
> +Specify a DRM render node on Linux or DirectX adapter on Windows
> +@item child_device_type
> +Choose platform-appropriate subdevice type. On Windows @samp{d3d11va} is used
> +as default subdevice type.
> +@end table
>  
>  Examples:
>  @table @emph
> +@item -init_hw_device qsv:hw,child_device=/dev/dri/renderD129
> +Create a QSV device with @samp{MFX_IMPL_HARDWARE} on DRM render node
> /dev/dri/renderD129
> +
> +@item -init_hw_device qsv:hw,child_device=1
> +Create a QSV device with @samp{MFX_IMPL_HARDWARE} on DirectX adapter 1. The
> subdevice
> +type is @samp{d3d11va} if @code{--enable-libvpl} is specified at
> configuration time, the
> +subdevice type is @samp{dxva2} if @code{--enable-libmfx} is specified at
> configuration time.
> +
>  @item -init_hw_device qsv:hw,child_device_type=d3d11va
>  Choose the GPU subdevice with type @samp{d3d11va} and create QSV device with
> @samp{MFX_IMPL_HARDWARE}.
>  
>  @item -init_hw_device qsv:hw,child_device_type=dxva2
>  Choose the GPU subdevice with type @samp{dxva2} and create QSV device with
> @samp{MFX_IMPL_HARDWARE}.
> +
> +@item -init_hw_device qsv:hw,child_device=1,child_device_type=d3d11va
> +Create a QSV device with @samp{MFX_IMPL_HARDWARE} on DirectX adapter 1 with
> subdevice type @samp{d3d11va}
>  @end table
>  
>  @item opencl

Will apply the patchset

- Haihao

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools

2024-01-01 Thread Xiang, Haihao
On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Add AVQSVFramesContext.info and update the description
> 
> Signed-off-by: Haihao Xiang 
> ---
> Rebased https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=9639
> against the latest master with a few changes.
> 
>  doc/APIchanges    |  3 +++
>  libavutil/hwcontext_qsv.c |  4 ++--
>  libavutil/hwcontext_qsv.h | 31 +++
>  libavutil/version.h   |  2 +-
>  4 files changed, 33 insertions(+), 7 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index a3e4ebbccd..b68156ee94 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>  
>  API changes, most recent first:
>  
> +2023-12-xx - xx  - lavu 58.36.100 - hwcontext_qsv.h
> +  Add AVQSVFramesContext.info
> +
>  2023-12-18 - 74279227dd2 - lavc 60.36.100 - packet.h
>    Add AV_PKT_DATA_IAMF_MIX_GAIN_PARAM, AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
>    and AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM.
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index a67552b5ac..071489f070 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -613,7 +613,7 @@ static mfxStatus frame_alloc(mfxHDL pthis,
> mfxFrameAllocRequest *req,
>  QSVFramesContext   *s = ctx->internal->priv;
>  AVQSVFramesContext *hwctx = ctx->hwctx;
>  mfxFrameInfo *i  = &req->Info;
> -    mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
> +    mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : hwctx-
> >info;
>  
>  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
>  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
> @@ -1173,7 +1173,7 @@ static int qsv_init_internal_session(AVHWFramesContext
> *ctx,
>    MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
>  par.AsyncDepth = 1;
>  
> -    par.vpp.In = frames_hwctx->surfaces[0].Info;
> +    par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info :
> *frames_hwctx->info;
>  
>  /* Apparently VPP requires the frame rate to be set to some value,
> otherwise
>   * init will fail (probably for the framerate conversion filter). Since
> we
> diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
> index e2dba8ad83..5950e38500 100644
> --- a/libavutil/hwcontext_qsv.h
> +++ b/libavutil/hwcontext_qsv.h
> @@ -25,8 +25,8 @@
>   * @file
>   * An API-specific header for AV_HWDEVICE_TYPE_QSV.
>   *
> - * This API does not support dynamic frame pools. AVHWFramesContext.pool must
> - * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1
> struct.
> + * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
> + * to a mfxFrameSurface1 struct.
>   */
>  
>  /**
> @@ -51,11 +51,34 @@ typedef struct AVQSVDeviceContext {
>   * This struct is allocated as AVHWFramesContext.hwctx
>   */
>  typedef struct AVQSVFramesContext {
> -    mfxFrameSurface1 *surfaces;
> +    /**
> + * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
> + *
> + * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
> + * struct.
> + *
> + * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
> + * buffers allocated from the pool have the same mfxFrameInfo.
> + */
> +    union {
> +    mfxFrameSurface1 *surfaces;
> +    mfxFrameInfo *info;
> +    };
> +
> +    /**
> + * Number of frames in the pool
> + *
> + * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
> + * for fixed frame pools.
> + *
> + * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
> + * on d3d11va or vaapi
> + */
>  int    nb_surfaces;
>  
>  /**
> - * A combination of MFX_MEMTYPE_* describing the frame pool.
> + * Set by user. It is a combination of MFX_MEMTYPE_* describing the frame
> + * pool.
>   */
>  int frame_type;
>  } AVQSVFramesContext;
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 7664cd97bd..3b4c50e9a9 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  58
> -#define LIBAVUTIL_VERSION_MINOR  35
> +#define LIBAVUTIL_VERSION_MINOR  36
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Hi,

Any comment for this patchset ?

Thanks
Haihao

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".