[FFmpeg-devel] [PATCH V4 3/4] libavcodec/qsvenc: Add low latency P-pyramid support to qsv

2022-01-12 Thread Wenbin Chen
Add low latency P-pyramid support to qsv. This feature relates to
command line option "-p_strategy". To enable this flag, user also
need to set "-bf" to 0. P-strategy has two modes "1-simple" and
"2-pyramid". The details of the two models refer to
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#preftype

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi   |  6 ++
 libavcodec/qsvenc.c | 36 
 libavcodec/qsvenc.h |  3 +++
 3 files changed, 45 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6fc94daa11..3d7c944fba 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3296,6 +3296,9 @@ to allow changing of frame type from P and B to I.
 @item @var{adaptive_b}
 This flag controls changing of frame type from B to P.
 
+@item @var{p_strategy}
+Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
+
 @item @var{b_strategy}
 This option controls usage of B frames as reference.
 
@@ -3394,6 +3397,9 @@ Enable rate distortion optimization.
 @item @var{max_frame_size}
 Maximum encoded frame size in bytes.
 
+@item @var{p_strategy}
+Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
+
 @item @var{dblk_idc}
 This option disable deblocking. It has value in range 0~2.
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index e87b69369a..f2ba0241c6 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -315,6 +315,14 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid");   break;
 default:av_log(avctx, AV_LOG_VERBOSE, "auto");  break;
 }
+
+av_log(avctx, AV_LOG_VERBOSE, "; PRefType: ");
+switch (co3->PRefType) {
+case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE, "default");   break;
+case MFX_P_REF_SIMPLE:  av_log(avctx, AV_LOG_VERBOSE, "simple");break;
+case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid");   break;
+default:av_log(avctx, AV_LOG_VERBOSE, "unknown");   break;
+}
 av_log(avctx, AV_LOG_VERBOSE, "\n");
 #endif
 
@@ -934,6 +942,34 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 #if QSV_HAVE_CO3
 q->extco3.Header.BufferId  = MFX_EXTBUFF_CODING_OPTION3;
 q->extco3.Header.BufferSz  = sizeof(q->extco3);
+
+if (avctx->codec_id == AV_CODEC_ID_HEVC ||
+avctx->codec_id == AV_CODEC_ID_H264) {
+#if QSV_HAVE_PREF
+switch (q->p_strategy) {
+case 0:
+q->extco3.PRefType = MFX_P_REF_DEFAULT;
+break;
+case 1:
+q->extco3.PRefType = MFX_P_REF_SIMPLE;
+break;
+case 2:
+q->extco3.PRefType = MFX_P_REF_PYRAMID;
+break;
+default:
+q->extco3.PRefType = MFX_P_REF_DEFAULT;
+av_log(avctx, AV_LOG_WARNING,
+   "invalid p_strategy, set to default\n");
+break;
+}
+if (q->extco3.PRefType == MFX_P_REF_PYRAMID &&
+avctx->max_b_frames != 0) {
+av_log(avctx, AV_LOG_WARNING,
+   "Please set max_b_frames(-bf) to 0 to enable 
P-pyramid\n");
+}
+#endif
+}
+
 #if QSV_HAVE_GPB
 if (avctx->codec_id == AV_CODEC_ID_HEVC)
 q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index aa49b35f07..960604cb9a 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -51,6 +51,7 @@
 #define QSV_HAVE_LA_DS  QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
 #define QSV_HAVE_VDENC  QSV_VERSION_ATLEAST(1, 15)
+#define QSV_HAVE_PREF   QSV_VERSION_ATLEAST(1, 16)
 
 #define QSV_HAVE_GPBQSV_VERSION_ATLEAST(1, 18)
 
@@ -95,6 +96,7 @@
 { "extbrc", "Extended bitrate control",   
OFFSET(qsv.extbrc), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "adaptive_i", "Adaptive I-frame placement", 
OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "adaptive_b", "Adaptive B-frame placement", 
OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
+{ "p_strategy", "Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to 
be set to 0).",OFFSET(qsv.p_strategy), AV_OPT_TYPE_INT,{ .i64 = 0}, 0,  
  2, VE }, \
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 

[FFmpeg-devel] [PATCH V4 2/4] libavcodec/qsvenc: Add DisableDeblockingIdc support to qsv

2022-01-12 Thread Wenbin Chen
Add dblk_idc option to 264_qsv and hevc_qsv. Turining on this opion can
disable deblocking.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi   | 6 ++
 libavcodec/qsvenc.c | 8 
 libavcodec/qsvenc.h | 3 +++
 3 files changed, 17 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 68921fbd40..6fc94daa11 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3299,6 +3299,9 @@ This flag controls changing of frame type from B to P.
 @item @var{b_strategy}
 This option controls usage of B frames as reference.
 
+@item @var{dblk_idc}
+This option disable deblocking. It has value in range 0~2.
+
 @item @var{cavlc}
 If set, CAVLC is used; if unset, CABAC is used for encoding.
 
@@ -3391,6 +3394,9 @@ Enable rate distortion optimization.
 @item @var{max_frame_size}
 Maximum encoded frame size in bytes.
 
+@item @var{dblk_idc}
+This option disable deblocking. It has value in range 0~2.
+
 @item @var{idr_interval}
 Distance (in I-frames) between IDR frames.
 @table @samp
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index b3728d28d5..e87b69369a 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -346,6 +346,10 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: 
%"PRIu32" \n",
info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
 
+#if QSV_HAVE_DISABLEDEBLOCKIDC
+av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", 
co2->DisableDeblockingIdc);
+#endif
+
 }
 
 static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
@@ -889,6 +893,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 if (q->max_frame_size >= 0)
 q->extco2.MaxFrameSize = q->max_frame_size;
+#if QSV_HAVE_DISABLEDEBLOCKIDC
+if(q->dblk_idc >= 0)
+q->extco2.DisableDeblockingIdc = q->dblk_idc;
+#endif
 
 #if QSV_VERSION_ATLEAST(1, 9)
 if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
avctx->qmax) {
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 31516b8e55..aa49b35f07 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -44,6 +44,7 @@
 
 #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
+#define QSV_HAVE_DISABLEDEBLOCKIDC QSV_VERSION_ATLEAST(1, 9)
 #define QSV_HAVE_BREF_TYPE  QSV_VERSION_ATLEAST(1, 8)
 
 #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
@@ -97,6 +98,7 @@
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0  },  0,  1, VE 
}, \
 { "low_power", "enable low power mode(experimental: many limitations by mfx 
version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 = 
-1}, -1, 1, VE},\
+{ "dblk_idc", "This option disable deblocking. It has value in range 0~2.",   
OFFSET(qsv.dblk_idc),   AV_OPT_TYPE_INT,{ .i64 = -1 },   -1,  2,  VE},\
 
 extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
 
@@ -169,6 +171,7 @@ typedef struct QSVEncContext {
 int rdo;
 int max_frame_size;
 int max_slice_size;
+int dblk_idc;
 
 int tile_cols;
 int tile_rows;
-- 
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 V4 1/4] libavcodec/qsvenc: Add max_frame_size support to hevc_qsv

2022-01-12 Thread Wenbin Chen
Add max_frame_size support to hevc_qsv as well.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi   | 3 +++
 libavcodec/qsvenc.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7cc8be1209..68921fbd40 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3388,6 +3388,9 @@ intra refresh cycle.
 @item @var{rdo}
 Enable rate distortion optimization.
 
+@item @var{max_frame_size}
+Maximum encoded frame size in bytes.
+
 @item @var{idr_interval}
 Distance (in I-frames) between IDR frames.
 @table @samp
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 4e7a15f060..b3728d28d5 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -859,8 +859,6 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (q->mbbrc >= 0)
 q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 
-if (q->max_frame_size >= 0)
-q->extco2.MaxFrameSize = q->max_frame_size;
 #if QSV_HAVE_MAX_SLICE_SIZE
 if (q->max_slice_size >= 0)
 q->extco2.MaxSliceSize = q->max_slice_size;
@@ -889,6 +887,8 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == 
AV_CODEC_ID_HEVC) {
 if (q->extbrc >= 0)
 q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
+if (q->max_frame_size >= 0)
+q->extco2.MaxFrameSize = q->max_frame_size;
 
 #if QSV_VERSION_ATLEAST(1, 9)
 if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
avctx->qmax) {
-- 
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 V4 4/4] libavcodec/qsvenc: Add transform skip to hevc_qsv

2022-01-12 Thread Wenbin Chen
Add transform_skip option to hevc_qsv. By enabling this option,
the transform_skip_enabled_flag in PPS will be set to 1.
This option is supported on the platform equal or newer than ICL.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi|  4 
 libavcodec/qsvenc.c  | 10 +-
 libavcodec/qsvenc.h  |  1 +
 libavcodec/qsvenc_hevc.c |  3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 3d7c944fba..66e4753c2a 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3447,6 +3447,10 @@ Number of rows for tiled encoding.
 
 @item @var{aud}
 Insert the Access Unit Delimiter NAL.
+
+@item @var{transform_skip}
+Turn this option ON to enable transformskip. It is supported on platform equal
+or newer than ICL.
 @end table
 
 @subsection MPEG2 Options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f2ba0241c6..4e5997c9ed 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -358,6 +358,9 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", 
co2->DisableDeblockingIdc);
 #endif
 
+#if QSV_VERSION_ATLEAST(1, 26)
+av_log(avctx, AV_LOG_VERBOSE, "TransformSkip: %s \n", 
print_threestate(co3->TransformSkip));
+#endif
 }
 
 static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
@@ -970,10 +973,15 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 #endif
 }
 
+if (avctx->codec_id == AV_CODEC_ID_HEVC) {
+#if QSV_VERSION_ATLEAST(1, 26)
+q->extco3.TransformSkip = q->transform_skip ? MFX_CODINGOPTION_ON :
+  MFX_CODINGOPTION_OFF;
+#endif
 #if QSV_HAVE_GPB
-if (avctx->codec_id == AV_CODEC_ID_HEVC)
 q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 #endif
+}
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco3;
 #endif
 }
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 960604cb9a..5a574ada30 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -200,6 +200,7 @@ typedef struct QSVEncContext {
 int repeat_pps;
 int low_power;
 int gpb;
+int transform_skip;
 
 int a53_cc;
 
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 08aba3011d..679c09c858 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -251,6 +251,9 @@ static const AVOption options[] = {
 { "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE },
 { "recovery_point_sei", "Insert recovery point SEI messages",   
OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT, { .i64 = -1 },
   -1,  1, VE },
 { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
+#if QSV_VERSION_ATLEAST(1, 26)
+{ "transform_skip", "Turn this option ON to enable transformskip",   
OFFSET(qsv.transform_skip),  AV_OPT_TYPE_INT,{ .i64 = -1},   -1, 1, 
 VE},
+#endif
 
 { NULL },
 };
-- 
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".


Re: [FFmpeg-devel] [PATCH V3 4/4] libavcodec/qsvenc: Add transform skip to hevc_qsv

2022-01-12 Thread Xiang, Haihao
On Thu, 2022-01-13 at 13:12 +0800, Wenbin Chen wrote:
> Add transform_skip option to hevc_qsv. By enabling this option,
> the transform_skip_enabled_flag in PPS will be set to 1.
> This option is supported on the platform equal or newer than CNL.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi|  4 
>  libavcodec/qsvenc.c  | 10 +-
>  libavcodec/qsvenc.h  |  1 +
>  libavcodec/qsvenc_hevc.c |  3 +++
>  4 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 3d7c944fba..7714084864 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3447,6 +3447,10 @@ Number of rows for tiled encoding.
>  
>  @item @var{aud}
>  Insert the Access Unit Delimiter NAL.
> +
> +@item @var{transform_skip}
> +Turn this option ON to enable transformskip. It is supported on platform
> equal
> +or newer than CNL.
>  @end table
>  
>  @subsection MPEG2 Options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index f2ba0241c6..4e5997c9ed 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -358,6 +358,9 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", co2-
> >DisableDeblockingIdc);
>  #endif
>  
> +#if QSV_VERSION_ATLEAST(1, 26)
> +av_log(avctx, AV_LOG_VERBOSE, "TransformSkip: %s \n",
> print_threestate(co3->TransformSkip));
> +#endif
>  }
>  
>  static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
> @@ -970,10 +973,15 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  #endif
>  }
>  
> +if (avctx->codec_id == AV_CODEC_ID_HEVC) {
> +#if QSV_VERSION_ATLEAST(1, 26)
> +q->extco3.TransformSkip = q->transform_skip ? MFX_CODINGOPTION_ON
> :
> +  MFX_CODINGOPTION_OF
> F;

q->extco3.TransformSkip is set to MFX_CODINGOPTION_ON when q->transform_skip is
-1, right ? TransformSkip is tri-state flag, we may set it to
MFX_CODINGOPTION_UNKNOWN when q->transform_skip is -1. 

Thanks
Haihao


> +#endif
>  #if QSV_HAVE_GPB
> -if (avctx->codec_id == AV_CODEC_ID_HEVC)
>  q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  #endif
> +}
>  q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)
> >extco3;
>  #endif
>  }
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index 960604cb9a..5a574ada30 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -200,6 +200,7 @@ typedef struct QSVEncContext {
>  int repeat_pps;
>  int low_power;
>  int gpb;
> +int transform_skip;
>  
>  int a53_cc;
>  
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index 08aba3011d..679c09c858 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -251,6 +251,9 @@ static const AVOption options[] = {
>  { "tile_rows",  "Number of rows for tiled
> encoding",  OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0,
> UINT16_MAX, VE },
>  { "recovery_point_sei", "Insert recovery point SEI
> messages",   OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT, { .i64
> = -1 },   -1,  1, VE },
>  { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud),
> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
> +#if QSV_VERSION_ATLEAST(1, 26)
> +{ "transform_skip", "Turn this option ON to enable
> transformskip",   OFFSET(qsv.transform_skip),  AV_OPT_TYPE_INT,{
> .i64 = -1},   -1, 1,  VE},
> +#endif
>  
>  { NULL },
>  };
___
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 V3 3/4] libavcodec/qsvenc: Add low latency P-pyramid support to qsv

2022-01-12 Thread Xiang, Haihao
On Thu, 2022-01-13 at 13:12 +0800, Wenbin Chen wrote:
> Add low latency P-pyramid support to qsv. This feature relates to
> command line option "-p_strategy". To enable this flag, user also
> need to set "-bf" to 0. P-strategy has two modes "1-simple" and
> "2-pyramid". The details of the two models refer to
> 
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#preftype
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   |  6 ++
>  libavcodec/qsvenc.c | 36 
>  libavcodec/qsvenc.h |  3 +++
>  3 files changed, 45 insertions(+)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 6fc94daa11..3d7c944fba 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3296,6 +3296,9 @@ to allow changing of frame type from P and B to I.
>  @item @var{adaptive_b}
>  This flag controls changing of frame type from B to P.
>  
> +@item @var{p_strategy}
> +Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
> +
>  @item @var{b_strategy}
>  This option controls usage of B frames as reference.
>  
> @@ -3394,6 +3397,9 @@ Enable rate distortion optimization.
>  @item @var{max_frame_size}
>  Maximum encoded frame size in bytes.
>  
> +@item @var{p_strategy}
> +Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
> +
>  @item @var{dblk_idc}
>  This option disable deblocking. It has value in range 0~2.
>  
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index e87b69369a..f2ba0241c6 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -315,6 +315,14 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE,
> "pyramid");   break;
>  default:av_log(avctx, AV_LOG_VERBOSE,
> "auto");  break;
>  }
> +
> +av_log(avctx, AV_LOG_VERBOSE, "; PRefType: ");
> +switch (co3->PRefType) {
> +case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE,
> "default");   break;
> +case MFX_P_REF_SIMPLE:  av_log(avctx, AV_LOG_VERBOSE,
> "simple");break;
> +case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE,
> "pyramid");   break;
> +default:av_log(avctx, AV_LOG_VERBOSE,
> "unknown");   break;
> +}
>  av_log(avctx, AV_LOG_VERBOSE, "\n");
>  #endif
>  
> @@ -934,6 +942,34 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  #if QSV_HAVE_CO3
>  q->extco3.Header.BufferId  = MFX_EXTBUFF_CODING_OPTION3;
>  q->extco3.Header.BufferSz  = sizeof(q->extco3);
> +
> +if (avctx->codec_id == AV_CODEC_ID_HEVC ||
> +avctx->codec_id == AV_CODEC_ID_H264) {
> +#if QSV_HAVE_PREF
> +switch (q->p_strategy) {
> +case 0:
> +q->extco3.PRefType = MFX_P_REF_DEFAULT;
> +break;
> +case 1:
> +q->extco3.PRefType = MFX_P_REF_SIMPLE;
> +break;
> +case 2:
> +q->extco3.PRefType = MFX_P_REF_PYRAMID;
> +break;
> +default:
> +q->extco3.PRefType = MFX_P_REF_DEFAULT;
> +av_log(avctx, AV_LOG_WARNING,
> +   "invalid p_strategy, set to default\n");
> +break;
> +}
> +if (q->extco3.PRefType == MFX_P_REF_PYRAMID &&
> +avctx->max_b_frames != 0) {
> +av_log(avctx, AV_LOG_WARNING,
> +   "Please set max_b_frames(-bf) to 0 to enable P-
> pyramid\n");
> +}
> +#endif
> +}
> +
>  #if QSV_HAVE_GPB
>  if (avctx->codec_id == AV_CODEC_ID_HEVC)
>  q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index aa49b35f07..960604cb9a 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -51,6 +51,7 @@
>  #define QSV_HAVE_LA_DS  QSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
>  #define QSV_HAVE_VDENC  QSV_VERSION_ATLEAST(1, 15)
> +#define QSV_HAVE_PREF   QSV_VERSION_ATLEAST(1, 16)
>  
>  #define QSV_HAVE_GPBQSV_VERSION_ATLEAST(1, 18)
>  
> @@ -95,6 +96,7 @@
>  { "extbrc", "Extended bitrate
> control",   OFFSET(qsv.extbrc), AV_OPT_TYPE_INT, { .i64 =
> -1 }, -1,  1, VE }, \
>  { "adaptive_i", "Adaptive I-frame
> placement", OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 =
> -1 }, -1,  1, VE }, \
>  { "adaptive_b", "Adaptive B-frame
> placement", OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 =
> -1 }, -1,  1, VE }, \
> +{ "p_strategy", "Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need
> to be set to 0).",OFFSET(qsv.p_strategy), AV_OPT_TYPE_INT,{ .i64 = 0},
> 0,2, VE },   

Re: [FFmpeg-devel] [PATCH V3 1/4] libavcodec/qsvenc: Add max_frame_size support to hevc_qsv

2022-01-12 Thread Xiang, Haihao
On Thu, 2022-01-13 at 13:12 +0800, Wenbin Chen wrote:
> Add max_frame_size support to hevc_qsv as well.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   | 3 +++
>  libavcodec/qsvenc.c | 4 ++--
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 7cc8be1209..68921fbd40 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3388,6 +3388,9 @@ intra refresh cycle.
>  @item @var{rdo}
>  Enable rate distortion optimization.
>  
> +@item @var{max_frame_size}
> +Maximum encoded frame size in bytes.
> +
>  @item @var{idr_interval}
>  Distance (in I-frames) between IDR frames.
>  @table @samp
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 4e7a15f060..b3728d28d5 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -859,8 +859,6 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  if (q->mbbrc >= 0)
>  q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  
> -if (q->max_frame_size >= 0)
> -q->extco2.MaxFrameSize = q->max_frame_size;
>  #if QSV_HAVE_MAX_SLICE_SIZE
>  if (q->max_slice_size >= 0)
>  q->extco2.MaxSliceSize = q->max_slice_size;
> @@ -889,6 +887,8 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id ==
> AV_CODEC_ID_HEVC) {
>  if (q->extbrc >= 0)
>  q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
> +if (q->max_frame_size >= 0)
> +q->extco2.MaxFrameSize = q->max_frame_size;
>  
>  #if QSV_VERSION_ATLEAST(1, 9)
>  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx-
> >qmax) {

LGTM

-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 V3 2/4] libavcodec/qsvenc: Add DisableDeblockingIdc support to qsv

2022-01-12 Thread Xiang, Haihao
On Thu, 2022-01-13 at 13:12 +0800, Wenbin Chen wrote:
> Add dblk_idc option to 264_qsv and hevc_qsv. Turining on this opion can
> disable deblocking.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   | 6 ++
>  libavcodec/qsvenc.c | 8 
>  libavcodec/qsvenc.h | 3 +++
>  3 files changed, 17 insertions(+)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 68921fbd40..6fc94daa11 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3299,6 +3299,9 @@ This flag controls changing of frame type from B to P.
>  @item @var{b_strategy}
>  This option controls usage of B frames as reference.
>  
> +@item @var{dblk_idc}
> +This option disable deblocking. It has value in range 0~2.
> +
>  @item @var{cavlc}
>  If set, CAVLC is used; if unset, CABAC is used for encoding.
>  
> @@ -3391,6 +3394,9 @@ Enable rate distortion optimization.
>  @item @var{max_frame_size}
>  Maximum encoded frame size in bytes.
>  
> +@item @var{dblk_idc}
> +This option disable deblocking. It has value in range 0~2.
> +
>  @item @var{idr_interval}
>  Distance (in I-frames) between IDR frames.
>  @table @samp
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index b3728d28d5..e87b69369a 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -346,6 +346,10 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN:
> %"PRIu32" \n",
> info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
>  
> +#if QSV_HAVE_DISABLEDEBLOCKIDC
> +av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", co2-
> >DisableDeblockingIdc);
> +#endif
> +
>  }
>  
>  static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
> @@ -889,6 +893,10 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  if (q->max_frame_size >= 0)
>  q->extco2.MaxFrameSize = q->max_frame_size;
> +#if QSV_HAVE_DISABLEDEBLOCKIDC
> +if(q->dblk_idc >= 0)
> +q->extco2.DisableDeblockingIdc = q->dblk_idc;
> +#endif
>  
>  #if QSV_VERSION_ATLEAST(1, 9)
>  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx-
> >qmax) {
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index 31516b8e55..aa49b35f07 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -44,6 +44,7 @@
>  
>  #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
> +#define QSV_HAVE_DISABLEDEBLOCKIDC QSV_VERSION_ATLEAST(1, 9)
>  #define QSV_HAVE_BREF_TYPE  QSV_VERSION_ATLEAST(1, 8)
>  
>  #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
> @@ -97,6 +98,7 @@
>  { "b_strategy", "Strategy to choose between I/P/B-frames",
> OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE
> }, \
>  { "forced_idr", "Forcing I frames as IDR
> frames", OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 =
> 0  },  0,  1, VE }, \
>  { "low_power", "enable low power mode(experimental: many limitations by mfx
> version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 =
> -1}, -1, 1, VE},\
> +{ "dblk_idc", "This option disable deblocking. It has value in range
> 0~2.",   OFFSET(qsv.dblk_idc),   AV_OPT_TYPE_INT,{ .i64 = -1 },   -
> 1,  2,  VE},\


The range is 0~2 in the help string, however the minimal value is -1, which will
confuse user. We may set both the default and minimal values to 0 here. 

Thanks
Haihao

>  
>  extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
>  
> @@ -169,6 +171,7 @@ typedef struct QSVEncContext {
>  int rdo;
>  int max_frame_size;
>  int max_slice_size;
> +int dblk_idc;
>  
>  int tile_cols;
>  int tile_rows;
___
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] lavc/qsvenc: add tile encoding support for VP9

2022-01-12 Thread Haihao Xiang
Add -tile_rows and -tile_cols options to specify the number of tile
rows and columns

Signed-off-by: Haihao Xiang 
---
v2: add option descriptions in the doc

 doc/encoders.texi   |  6 ++
 libavcodec/qsvenc.c |  4 
 libavcodec/qsvenc.h |  1 +
 libavcodec/qsvenc_vp9.c | 10 ++
 4 files changed, 21 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7cc8be1209..a4176089d5 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3457,6 +3457,12 @@ These options are used by vp9_qsv
 @item profile2
 @item profile3
 @end table
+
+@item @var{tile_cols}
+Number of columns for tiled encoding (requires libmfx >= 1.29).
+
+@item @var{tile_rows}
+Number of rows for tiled encoding (requires libmfx  >= 1.29).
 @end table
 
 @section snow
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 4e7a15f060..4cbc9ff4dc 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -939,6 +939,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
 q->extvp9param.Header.BufferSz = sizeof(q->extvp9param);
 q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
+#if QSV_HAVE_EXT_VP9_TILES
+q->extvp9param.NumTileColumns  = q->tile_cols;
+q->extvp9param.NumTileRows = q->tile_rows;
+#endif
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extvp9param;
 }
 #endif
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 31516b8e55..00ee52a5d1 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -41,6 +41,7 @@
 
 #define QSV_HAVE_EXT_HEVC_TILES QSV_VERSION_ATLEAST(1, 13)
 #define QSV_HAVE_EXT_VP9_PARAM QSV_VERSION_ATLEAST(1, 26)
+#define QSV_HAVE_EXT_VP9_TILES QSV_VERSION_ATLEAST(1, 29)
 
 #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c
index 9329990d11..1168ddda0e 100644
--- a/libavcodec/qsvenc_vp9.c
+++ b/libavcodec/qsvenc_vp9.c
@@ -73,6 +73,16 @@ static const AVOption options[] = {
 { "profile2",  NULL, 0,   AV_OPT_TYPE_CONST, { .i64 = 
MFX_PROFILE_VP9_2   },  INT_MIN,  INT_MAX,  VE,  "profile" },
 { "profile3",  NULL, 0,   AV_OPT_TYPE_CONST, { .i64 = 
MFX_PROFILE_VP9_3   },  INT_MIN,  INT_MAX,  VE,  "profile" },
 
+#if QSV_HAVE_EXT_VP9_TILES
+/* The minimum tile width in luma pixels is 256, set maximum tile_cols to 
32 for 8K video */
+{ "tile_cols",  "Number of columns for tiled encoding",   
OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 32, VE },
+/* Set maximum tile_rows to 4 per VP9 spec */
+{ "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 4, VE },
+#else
+{ "tile_cols",  "(not supported)",
OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0, VE },
+{ "tile_rows",  "(not supported)",
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0, VE },
+#endif
+
 { NULL },
 };
 
-- 
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 V3 4/4] libavcodec/qsvenc: Add transform skip to hevc_qsv

2022-01-12 Thread Wenbin Chen
Add transform_skip option to hevc_qsv. By enabling this option,
the transform_skip_enabled_flag in PPS will be set to 1.
This option is supported on the platform equal or newer than CNL.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi|  4 
 libavcodec/qsvenc.c  | 10 +-
 libavcodec/qsvenc.h  |  1 +
 libavcodec/qsvenc_hevc.c |  3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 3d7c944fba..7714084864 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3447,6 +3447,10 @@ Number of rows for tiled encoding.
 
 @item @var{aud}
 Insert the Access Unit Delimiter NAL.
+
+@item @var{transform_skip}
+Turn this option ON to enable transformskip. It is supported on platform equal
+or newer than CNL.
 @end table
 
 @subsection MPEG2 Options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f2ba0241c6..4e5997c9ed 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -358,6 +358,9 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", 
co2->DisableDeblockingIdc);
 #endif
 
+#if QSV_VERSION_ATLEAST(1, 26)
+av_log(avctx, AV_LOG_VERBOSE, "TransformSkip: %s \n", 
print_threestate(co3->TransformSkip));
+#endif
 }
 
 static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
@@ -970,10 +973,15 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 #endif
 }
 
+if (avctx->codec_id == AV_CODEC_ID_HEVC) {
+#if QSV_VERSION_ATLEAST(1, 26)
+q->extco3.TransformSkip = q->transform_skip ? MFX_CODINGOPTION_ON :
+  MFX_CODINGOPTION_OFF;
+#endif
 #if QSV_HAVE_GPB
-if (avctx->codec_id == AV_CODEC_ID_HEVC)
 q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 #endif
+}
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco3;
 #endif
 }
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 960604cb9a..5a574ada30 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -200,6 +200,7 @@ typedef struct QSVEncContext {
 int repeat_pps;
 int low_power;
 int gpb;
+int transform_skip;
 
 int a53_cc;
 
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 08aba3011d..679c09c858 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -251,6 +251,9 @@ static const AVOption options[] = {
 { "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE },
 { "recovery_point_sei", "Insert recovery point SEI messages",   
OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT, { .i64 = -1 },
   -1,  1, VE },
 { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
+#if QSV_VERSION_ATLEAST(1, 26)
+{ "transform_skip", "Turn this option ON to enable transformskip",   
OFFSET(qsv.transform_skip),  AV_OPT_TYPE_INT,{ .i64 = -1},   -1, 1, 
 VE},
+#endif
 
 { NULL },
 };
-- 
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 V3 3/4] libavcodec/qsvenc: Add low latency P-pyramid support to qsv

2022-01-12 Thread Wenbin Chen
Add low latency P-pyramid support to qsv. This feature relates to
command line option "-p_strategy". To enable this flag, user also
need to set "-bf" to 0. P-strategy has two modes "1-simple" and
"2-pyramid". The details of the two models refer to
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#preftype

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi   |  6 ++
 libavcodec/qsvenc.c | 36 
 libavcodec/qsvenc.h |  3 +++
 3 files changed, 45 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6fc94daa11..3d7c944fba 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3296,6 +3296,9 @@ to allow changing of frame type from P and B to I.
 @item @var{adaptive_b}
 This flag controls changing of frame type from B to P.
 
+@item @var{p_strategy}
+Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
+
 @item @var{b_strategy}
 This option controls usage of B frames as reference.
 
@@ -3394,6 +3397,9 @@ Enable rate distortion optimization.
 @item @var{max_frame_size}
 Maximum encoded frame size in bytes.
 
+@item @var{p_strategy}
+Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
+
 @item @var{dblk_idc}
 This option disable deblocking. It has value in range 0~2.
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index e87b69369a..f2ba0241c6 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -315,6 +315,14 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid");   break;
 default:av_log(avctx, AV_LOG_VERBOSE, "auto");  break;
 }
+
+av_log(avctx, AV_LOG_VERBOSE, "; PRefType: ");
+switch (co3->PRefType) {
+case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE, "default");   break;
+case MFX_P_REF_SIMPLE:  av_log(avctx, AV_LOG_VERBOSE, "simple");break;
+case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid");   break;
+default:av_log(avctx, AV_LOG_VERBOSE, "unknown");   break;
+}
 av_log(avctx, AV_LOG_VERBOSE, "\n");
 #endif
 
@@ -934,6 +942,34 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 #if QSV_HAVE_CO3
 q->extco3.Header.BufferId  = MFX_EXTBUFF_CODING_OPTION3;
 q->extco3.Header.BufferSz  = sizeof(q->extco3);
+
+if (avctx->codec_id == AV_CODEC_ID_HEVC ||
+avctx->codec_id == AV_CODEC_ID_H264) {
+#if QSV_HAVE_PREF
+switch (q->p_strategy) {
+case 0:
+q->extco3.PRefType = MFX_P_REF_DEFAULT;
+break;
+case 1:
+q->extco3.PRefType = MFX_P_REF_SIMPLE;
+break;
+case 2:
+q->extco3.PRefType = MFX_P_REF_PYRAMID;
+break;
+default:
+q->extco3.PRefType = MFX_P_REF_DEFAULT;
+av_log(avctx, AV_LOG_WARNING,
+   "invalid p_strategy, set to default\n");
+break;
+}
+if (q->extco3.PRefType == MFX_P_REF_PYRAMID &&
+avctx->max_b_frames != 0) {
+av_log(avctx, AV_LOG_WARNING,
+   "Please set max_b_frames(-bf) to 0 to enable 
P-pyramid\n");
+}
+#endif
+}
+
 #if QSV_HAVE_GPB
 if (avctx->codec_id == AV_CODEC_ID_HEVC)
 q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index aa49b35f07..960604cb9a 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -51,6 +51,7 @@
 #define QSV_HAVE_LA_DS  QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
 #define QSV_HAVE_VDENC  QSV_VERSION_ATLEAST(1, 15)
+#define QSV_HAVE_PREF   QSV_VERSION_ATLEAST(1, 16)
 
 #define QSV_HAVE_GPBQSV_VERSION_ATLEAST(1, 18)
 
@@ -95,6 +96,7 @@
 { "extbrc", "Extended bitrate control",   
OFFSET(qsv.extbrc), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "adaptive_i", "Adaptive I-frame placement", 
OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "adaptive_b", "Adaptive B-frame placement", 
OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
+{ "p_strategy", "Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to 
be set to 0).",OFFSET(qsv.p_strategy), AV_OPT_TYPE_INT,{ .i64 = 0}, 0,  
  2, VE }, \
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 

[FFmpeg-devel] [PATCH V3 2/4] libavcodec/qsvenc: Add DisableDeblockingIdc support to qsv

2022-01-12 Thread Wenbin Chen
Add dblk_idc option to 264_qsv and hevc_qsv. Turining on this opion can
disable deblocking.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi   | 6 ++
 libavcodec/qsvenc.c | 8 
 libavcodec/qsvenc.h | 3 +++
 3 files changed, 17 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 68921fbd40..6fc94daa11 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3299,6 +3299,9 @@ This flag controls changing of frame type from B to P.
 @item @var{b_strategy}
 This option controls usage of B frames as reference.
 
+@item @var{dblk_idc}
+This option disable deblocking. It has value in range 0~2.
+
 @item @var{cavlc}
 If set, CAVLC is used; if unset, CABAC is used for encoding.
 
@@ -3391,6 +3394,9 @@ Enable rate distortion optimization.
 @item @var{max_frame_size}
 Maximum encoded frame size in bytes.
 
+@item @var{dblk_idc}
+This option disable deblocking. It has value in range 0~2.
+
 @item @var{idr_interval}
 Distance (in I-frames) between IDR frames.
 @table @samp
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index b3728d28d5..e87b69369a 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -346,6 +346,10 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: 
%"PRIu32" \n",
info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
 
+#if QSV_HAVE_DISABLEDEBLOCKIDC
+av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", 
co2->DisableDeblockingIdc);
+#endif
+
 }
 
 static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
@@ -889,6 +893,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 if (q->max_frame_size >= 0)
 q->extco2.MaxFrameSize = q->max_frame_size;
+#if QSV_HAVE_DISABLEDEBLOCKIDC
+if(q->dblk_idc >= 0)
+q->extco2.DisableDeblockingIdc = q->dblk_idc;
+#endif
 
 #if QSV_VERSION_ATLEAST(1, 9)
 if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
avctx->qmax) {
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 31516b8e55..aa49b35f07 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -44,6 +44,7 @@
 
 #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
+#define QSV_HAVE_DISABLEDEBLOCKIDC QSV_VERSION_ATLEAST(1, 9)
 #define QSV_HAVE_BREF_TYPE  QSV_VERSION_ATLEAST(1, 8)
 
 #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
@@ -97,6 +98,7 @@
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0  },  0,  1, VE 
}, \
 { "low_power", "enable low power mode(experimental: many limitations by mfx 
version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 = 
-1}, -1, 1, VE},\
+{ "dblk_idc", "This option disable deblocking. It has value in range 0~2.",   
OFFSET(qsv.dblk_idc),   AV_OPT_TYPE_INT,{ .i64 = -1 },   -1,  2,  VE},\
 
 extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
 
@@ -169,6 +171,7 @@ typedef struct QSVEncContext {
 int rdo;
 int max_frame_size;
 int max_slice_size;
+int dblk_idc;
 
 int tile_cols;
 int tile_rows;
-- 
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 V3 1/4] libavcodec/qsvenc: Add max_frame_size support to hevc_qsv

2022-01-12 Thread Wenbin Chen
Add max_frame_size support to hevc_qsv as well.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi   | 3 +++
 libavcodec/qsvenc.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7cc8be1209..68921fbd40 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3388,6 +3388,9 @@ intra refresh cycle.
 @item @var{rdo}
 Enable rate distortion optimization.
 
+@item @var{max_frame_size}
+Maximum encoded frame size in bytes.
+
 @item @var{idr_interval}
 Distance (in I-frames) between IDR frames.
 @table @samp
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 4e7a15f060..b3728d28d5 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -859,8 +859,6 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (q->mbbrc >= 0)
 q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 
-if (q->max_frame_size >= 0)
-q->extco2.MaxFrameSize = q->max_frame_size;
 #if QSV_HAVE_MAX_SLICE_SIZE
 if (q->max_slice_size >= 0)
 q->extco2.MaxSliceSize = q->max_slice_size;
@@ -889,6 +887,8 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == 
AV_CODEC_ID_HEVC) {
 if (q->extbrc >= 0)
 q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
+if (q->max_frame_size >= 0)
+q->extco2.MaxFrameSize = q->max_frame_size;
 
 #if QSV_VERSION_ATLEAST(1, 9)
 if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
avctx->qmax) {
-- 
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".


Re: [FFmpeg-devel] [PATCH V2] libavcodec/qsvenc: Add DisableDeblockingIdc support to qsv

2022-01-12 Thread Chen, Wenbin
> On Wed, 2022-01-12 at 13:28 +0800, Wenbin Chen wrote:
> > Add dblk_idc option to 264_qsv and hevc_qsv. Turining on this opion can
> > disable deblocking.
> >
> > Signed-off-by: Wenbin Chen 
> > ---
> >  doc/encoders.texi   | 6 ++
> >  libavcodec/qsvenc.c | 8 
> >  libavcodec/qsvenc.h | 3 +++
> >  3 files changed, 17 insertions(+)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 68921fbd40..6fc94daa11 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -3299,6 +3299,9 @@ This flag controls changing of frame type from B
> to P.
> >  @item @var{b_strategy}
> >  This option controls usage of B frames as reference.
> >
> > +@item @var{dblk_idc}
> > +This option disable deblocking. It has value in range 0~2.
> > +
> >  @item @var{cavlc}
> >  If set, CAVLC is used; if unset, CABAC is used for encoding.
> >
> > @@ -3391,6 +3394,9 @@ Enable rate distortion optimization.
> >  @item @var{max_frame_size}
> >  Maximum encoded frame size in bytes.
> >
> > +@item @var{dblk_idc}
> > +This option disable deblocking. It has value in range 0~2.
> > +
> >  @item @var{idr_interval}
> >  Distance (in I-frames) between IDR frames.
> >  @table @samp
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index a13718652e..3a51d00ca9 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -346,6 +346,10 @@ static void dump_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q,
> >  av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32";
> FrameRateExtN:
> > %"PRIu32" \n",
> > info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
> >
> > +#if QSV_HAVE_DISABLEDEBLOCKIDC
> > +av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n",
> co2-
> > >DisableDeblockingIdc);
> > +#endif
> > +
> >  }
> >
> >  static void dump_video_vp9_param(AVCodecContext *avctx,
> QSVEncContext *q,
> > @@ -885,6 +889,10 @@ static int init_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q)
> >  q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON :
> > MFX_CODINGOPTION_OFF;
> >  if (q->max_frame_size >= 0)
> >  q->extco2.MaxFrameSize = q->max_frame_size;
> > +#if QSV_HAVE_DISABLEDEBLOCKIDC
> > +if(q->dblk_idc >= 0)
> > +q->extco2.DisableDeblockingIdc = q->dblk_idc;
> > +#endif
> >
> >  #if QSV_VERSION_ATLEAST(1, 9)
> >  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
> > avctx-
> > >qmax) {
> > diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> > index 31516b8e55..aa49b35f07 100644
> > --- a/libavcodec/qsvenc.h
> > +++ b/libavcodec/qsvenc.h
> > @@ -44,6 +44,7 @@
> >
> >  #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
> >  #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
> > +#define QSV_HAVE_DISABLEDEBLOCKIDC QSV_VERSION_ATLEAST(1, 9)
> >  #define QSV_HAVE_BREF_TYPE  QSV_VERSION_ATLEAST(1, 8)
> >
> >  #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
> > @@ -97,6 +98,7 @@
> >  { "b_strategy", "Strategy to choose between I/P/B-frames",
> > OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, 
> > VE
> > }, \
> >  { "forced_idr", "Forcing I frames as IDR
> > frames", OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 =
> > 0  },  0,  1, VE }, \
> >  { "low_power", "enable low power mode(experimental: many limitations
> by mfx
> > version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL,
> { .i64 =
> > -1}, -1, 1, VE},\
> > +{ "dblk_idc", "This option disable deblocking. It has value in range
> > 0~2.",   OFFSET(qsv.dblk_idc),   AV_OPT_TYPE_INT,{ .i64 = -1 },   -
> > 1,  2,  VE},\
> >
> >  extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
> >
> > @@ -169,6 +171,7 @@ typedef struct QSVEncContext {
> >  int rdo;
> >  int max_frame_size;
> >  int max_slice_size;
> > +int dblk_idc;
> >
> >  int tile_cols;
> >  int tile_rows;
> 
> 
> patchwork failed to apply this patch, see
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220112052850.1147
> 160-1-wenbin.c...@intel.com/
> 
> Thanks
> Haihao

I see. I should submit patches in one patchset. I will resubmit them.

Thanks
Wenbin
> 
> 
> ___
> 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 V2] libavcodec/qsvenc: Add DisableDeblockingIdc support to qsv

2022-01-12 Thread Xiang, Haihao
On Wed, 2022-01-12 at 13:28 +0800, Wenbin Chen wrote:
> Add dblk_idc option to 264_qsv and hevc_qsv. Turining on this opion can
> disable deblocking.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   | 6 ++
>  libavcodec/qsvenc.c | 8 
>  libavcodec/qsvenc.h | 3 +++
>  3 files changed, 17 insertions(+)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 68921fbd40..6fc94daa11 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3299,6 +3299,9 @@ This flag controls changing of frame type from B to P.
>  @item @var{b_strategy}
>  This option controls usage of B frames as reference.
>  
> +@item @var{dblk_idc}
> +This option disable deblocking. It has value in range 0~2.
> +
>  @item @var{cavlc}
>  If set, CAVLC is used; if unset, CABAC is used for encoding.
>  
> @@ -3391,6 +3394,9 @@ Enable rate distortion optimization.
>  @item @var{max_frame_size}
>  Maximum encoded frame size in bytes.
>  
> +@item @var{dblk_idc}
> +This option disable deblocking. It has value in range 0~2.
> +
>  @item @var{idr_interval}
>  Distance (in I-frames) between IDR frames.
>  @table @samp
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index a13718652e..3a51d00ca9 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -346,6 +346,10 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN:
> %"PRIu32" \n",
> info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
>  
> +#if QSV_HAVE_DISABLEDEBLOCKIDC
> +av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", co2-
> >DisableDeblockingIdc);
> +#endif
> +
>  }
>  
>  static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
> @@ -885,6 +889,10 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  if (q->max_frame_size >= 0)
>  q->extco2.MaxFrameSize = q->max_frame_size;
> +#if QSV_HAVE_DISABLEDEBLOCKIDC
> +if(q->dblk_idc >= 0)
> +q->extco2.DisableDeblockingIdc = q->dblk_idc;
> +#endif
>  
>  #if QSV_VERSION_ATLEAST(1, 9)
>  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx-
> >qmax) {
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index 31516b8e55..aa49b35f07 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -44,6 +44,7 @@
>  
>  #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
> +#define QSV_HAVE_DISABLEDEBLOCKIDC QSV_VERSION_ATLEAST(1, 9)
>  #define QSV_HAVE_BREF_TYPE  QSV_VERSION_ATLEAST(1, 8)
>  
>  #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
> @@ -97,6 +98,7 @@
>  { "b_strategy", "Strategy to choose between I/P/B-frames",
> OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE
> }, \
>  { "forced_idr", "Forcing I frames as IDR
> frames", OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 =
> 0  },  0,  1, VE }, \
>  { "low_power", "enable low power mode(experimental: many limitations by mfx
> version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 =
> -1}, -1, 1, VE},\
> +{ "dblk_idc", "This option disable deblocking. It has value in range
> 0~2.",   OFFSET(qsv.dblk_idc),   AV_OPT_TYPE_INT,{ .i64 = -1 },   -
> 1,  2,  VE},\
>  
>  extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
>  
> @@ -169,6 +171,7 @@ typedef struct QSVEncContext {
>  int rdo;
>  int max_frame_size;
>  int max_slice_size;
> +int dblk_idc;
>  
>  int tile_cols;
>  int tile_rows;


patchwork failed to apply this patch, see 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220112052850.1147160-1-wenbin.c...@intel.com/

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] 5.0 blocking issues

2022-01-12 Thread Xiang, Haihao
On Wed, 2022-01-12 at 21:35 +, Soft Works wrote:
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of Michael
> > Niedermayer
> > Sent: Wednesday, January 12, 2022 5:31 PM
> > To: FFmpeg development discussions and patches 
> > Subject: Re: [FFmpeg-devel] 5.0 blocking issues
> > 
> > On Wed, Jan 12, 2022 at 07:37:03AM +0100, Lynne wrote:
> > > 8 Jan 2022, 17:30 by mich...@niedermayer.cc:
> > > 
> > > > Hi all
> > > > 
> > > > This is a simple go/no go call
> > > > if you know of something that still should go into 5.0 please reply here
> > > > with a list of what you are working on and a timelimit until when you
> > > > will be done with it
> > > > 
> > > > if you think everything is ready for the release, then too feel free to
> > > > reply (assuming few others said ok yet) this is not supposed to become a
> > > > 100 reply thread with oks, just maybe 2-3 people confirming that noone
> > > > is aware of things missing.
> > > > 
> > > > I intend to do the release within 2-3 days of all "no go" things being
> > > > resolved or timeouting
> > > > 
> > > > thx
> > > > 
> > > 
> > > Both of elenril and mkver's patches got merged, isn't it
> > > time to tag and make archives already?
> > 
> > something is not working efficiently here
> > There have been more replies here than from elenril and mkver
> > also there have been over the ML multiple requests for backports
> > to 5.0 today. (which may or may not be all unimportant)
> > We do need a better way to detect when a branch is ready for release
> > or master is ready to be branched.
> > Iam really bad at keeping track of everything everyone asks to be
> > included and then notice when it was included fully with nothing
> > missing and no amendmends.
> > Maybe we could put a RELEASE_BLOCKER file in release branches in the future
> > and everyone can list in it what needs to be done before the release
> > and when something is done the person pushing would also remove that
> > line from the file.
> > 
> > for 5.0 now, i guess this is a 2nd go/no go call here
> > anything else that I should wait for ?
> > if not i will make the release _probably_ in the next 2-3 days or so
> > (if nothing interferes)
> 
> 
> [PATCH v4] avfilter/vpp_qsv: fix regression on older api versions (e.g. 1.11)
> 
> Published-As: 
> https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-15%2Fsoftworkz%2Fqsv_vpp_regression-v4
>  
> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/15
> Patchwork:
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/pull.15.v4.ffstaging.ffmpeg.1641538891098.ffmpegag...@gmail.com/
> 
> => Has been merged in to master
> 

It would be better to include this fix in 5.0 release. May I cherry-pick this
patch to the release branch ? 

Thanks
Haihao


> 
> [PATCH] avcodec/dvdsubdec: fix incorrect yellow appearance of dvd subtitles
> 
> Published-As: 
> https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-16%2Fsoftworkz%2Fpatch_dvdsubdec_fix-v1
>  
> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/16 
> Patchwork:
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/pull.16.ffstaging.ffmpeg.1641262759164.ffmpegag...@gmail.com/
> 
> => not merged yet
> 
> 
> Thanks,
> softworkz
> 
> 
> 
> 
> ___
> 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".


[FFmpeg-devel] [PATCH 281/281] mov: Implement spatial audio support

2022-01-12 Thread James Almer
From: Vittorio Giovara 

As defined by Google's Spatial Audio RFC.

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavformat/mov.c | 96 +++
 1 file changed, 96 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index e307df8e3c..d6d287262d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7193,6 +7193,100 @@ cleanup:
 return ret;
 }
 
+static int mov_read_SA3D(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVStream *st;
+int i, version, type;
+int ambisonic_order, channel_order, normalization, channel_count;
+
+if (c->fc->nb_streams < 1)
+return 0;
+
+st = c->fc->streams[c->fc->nb_streams - 1];
+
+if (atom.size < 16) {
+av_log(c->fc, AV_LOG_ERROR, "SA3D audio box too small\n");
+return AVERROR_INVALIDDATA;
+}
+
+version = avio_r8(pb);
+if (version) {
+av_log(c->fc, AV_LOG_WARNING, "Unsupported SA3D box version %d\n", 
version);
+return 0;
+}
+
+type = avio_r8(pb);
+if (type) {
+av_log(c->fc, AV_LOG_WARNING,
+   "Unsupported ambisonic type %d\n", type);
+return 0;
+}
+
+ambisonic_order = avio_rb32(pb);
+
+channel_order = avio_r8(pb);
+if (channel_order) {
+av_log(c->fc, AV_LOG_WARNING,
+   "Unsupported channel_order %d\n", channel_order);
+return 0;
+}
+
+normalization = avio_r8(pb);
+if (normalization) {
+av_log(c->fc, AV_LOG_WARNING,
+   "Unsupported normalization %d\n", normalization);
+return 0;
+}
+
+channel_count = avio_rb32(pb);
+if (channel_count != (ambisonic_order + 1) * (ambisonic_order + 1)) {
+av_log(c->fc, AV_LOG_ERROR,
+   "Invalid number of channels (%d / %d)\n",
+   channel_count, ambisonic_order);
+return 0;
+}
+
+for (i = 0; i < channel_count; i++) {
+if (i != avio_rb32(pb)) {
+av_log(c->fc, AV_LOG_WARNING,
+   "Ambisonic channel reordering is not supported\n");
+return 0;
+}
+}
+
+av_channel_layout_uninit(>codecpar->ch_layout);
+st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_AMBISONIC;
+st->codecpar->ch_layout.nb_channels = channel_count;
+
+return 0;
+}
+
+static int mov_read_SAND(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVStream *st;
+int version;
+
+if (c->fc->nb_streams < 1)
+return 0;
+
+st = c->fc->streams[c->fc->nb_streams - 1];
+
+if (atom.size < 5) {
+av_log(c->fc, AV_LOG_ERROR, "Empty SAND audio box\n");
+return AVERROR_INVALIDDATA;
+}
+
+version = avio_r8(pb);
+if (version) {
+av_log(c->fc, AV_LOG_WARNING, "Unsupported SAND box version %d\n", 
version);
+return 0;
+}
+
+st->disposition |= AV_DISPOSITION_NON_DIEGETIC;
+
+return 0;
+}
+
 static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('A','C','L','R'), mov_read_aclr },
 { MKTAG('A','P','R','G'), mov_read_avid },
@@ -7292,6 +7386,8 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('d','v','v','C'), mov_read_dvcc_dvvc },
 { MKTAG('d','v','w','C'), mov_read_dvcc_dvvc },
 { MKTAG('k','i','n','d'), mov_read_kind },
+{ MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
+{ MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
 { 0, NULL }
 };
 
-- 
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 280/281] opus: export mapping family 2 (Ambisonic) as Ambisonic layout

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/opus.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index c18ff47f71..474ae427aa 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -398,8 +398,22 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+
 layout.nb_channels = channels;
+if (channels == (ambisonic_order + 1) * (ambisonic_order + 1)) {
+layout.order = AV_CHANNEL_ORDER_AMBISONIC;
+} else {
+layout.order = AV_CHANNEL_ORDER_CUSTOM;
+layout.u.map = av_mallocz_array(channels, 
sizeof(*layout.u.map));
+if (!layout.u.map) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+for (i = 0; i < channels - 2; i++)
+layout.u.map[i].id = AV_CHAN_AMBISONIC_BASE + i;
+layout.u.map[channels - 2].id = AV_CHAN_FRONT_LEFT;
+layout.u.map[channels - 1].id = AV_CHAN_FRONT_RIGHT;
+}
 } else {
 layout.order   = AV_CHANNEL_ORDER_UNSPEC;
 layout.nb_channels = channels;
@@ -450,8 +464,10 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 }
 }
 
-av_channel_layout_uninit(>ch_layout);
-avctx->ch_layout = layout;
+ret = av_channel_layout_copy(>ch_layout, );
+if (ret < 0)
+goto fail;
+
 s->nb_streams = streams;
 s->nb_stereo_streams  = stereo_streams;
 
-- 
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 279/281] channel_layout: add support for Ambisonic

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: James Almer 
---
 libavutil/channel_layout.c   | 166 ++-
 libavutil/channel_layout.h   |  52 +-
 libavutil/tests/channel_layout.c |  20 
 tests/ref/fate/channel_layout|  13 +++
 4 files changed, 247 insertions(+), 4 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index 68b40cc37c..3863e50e91 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -31,6 +31,9 @@
 #include "bprint.h"
 #include "common.h"
 
+#define CHAN_IS_AMBI(x) ((x) >= AV_CHAN_AMBISONIC_BASE &&\
+ (x) <= AV_CHAN_AMBISONIC_END)
+
 struct channel_name {
 const char *name;
 const char *description;
@@ -81,7 +84,10 @@ void av_channel_name_bprint(AVBPrint *bp, enum AVChannel 
channel_id)
 {
 av_bprint_clear(bp);
 
-if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
+if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
+channel_id <= AV_CHAN_AMBISONIC_END)
+av_bprintf(bp, "AMBI%d", channel_id - AV_CHAN_AMBISONIC_BASE);
+else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
 av_bprintf(bp, "%s", channel_names[channel_id].name);
 else
 av_bprintf(bp, "USR%d", channel_id);
@@ -104,7 +110,10 @@ void av_channel_description_bprint(AVBPrint *bp, enum 
AVChannel channel_id)
 {
 av_bprint_clear(bp);
 
-if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
+if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
+channel_id <= AV_CHAN_AMBISONIC_END)
+av_bprintf(bp, "ambisonic ACN %d", channel_id - 
AV_CHAN_AMBISONIC_BASE);
+else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
 av_bprintf(bp, "%s", channel_names[channel_id].description);
 else
 av_bprintf(bp, "user %d", channel_id);
@@ -128,6 +137,14 @@ enum AVChannel av_channel_from_string(const char *str)
 int i;
 char *endptr = (char *)str;
 enum AVChannel id = AV_CHAN_NONE;
+
+if (!strncmp(str, "AMBI", 4)) {
+i = strtol(str + 4, NULL, 0);
+if (i < 0 || i > AV_CHAN_AMBISONIC_END - AV_CHAN_AMBISONIC_BASE)
+return AV_CHAN_NONE;
+return AV_CHAN_AMBISONIC_BASE + i;
+}
+
 for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
 if (channel_names[i].name && !strcmp(str, channel_names[i].name))
 return i;
@@ -395,6 +412,60 @@ int av_channel_layout_from_string(AVChannelLayout 
*channel_layout,
 }
 }
 
+/* ambisonic */
+if (!strncmp(str, "ambisonic ", 10)) {
+const char *p = str + 10;
+char *endptr;
+AVChannelLayout extra = {0};
+int order;
+
+order = strtol(p, , 0);
+if (order < 0 || order + 1  > INT_MAX / (order + 1) ||
+(*endptr && *endptr != '+'))
+return AVERROR(EINVAL);
+
+channel_layout->order   = AV_CHANNEL_ORDER_AMBISONIC;
+channel_layout->nb_channels = (order + 1) * (order + 1);
+
+if (*endptr) {
+int ret = av_channel_layout_from_string(, endptr + 1);
+if (ret < 0)
+return ret;
+if (extra.nb_channels >= INT_MAX - channel_layout->nb_channels) {
+av_channel_layout_uninit();
+return AVERROR(EINVAL);
+}
+
+if (extra.order == AV_CHANNEL_ORDER_NATIVE) {
+channel_layout->u.mask = extra.u.mask;
+} else {
+channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
+channel_layout->u.map =
+av_calloc(channel_layout->nb_channels + extra.nb_channels,
+  sizeof(*channel_layout->u.map));
+if (!channel_layout->u.map) {
+av_channel_layout_uninit();
+return AVERROR(ENOMEM);
+}
+
+for (i = 0; i < channel_layout->nb_channels; i++)
+channel_layout->u.map[i].id = AV_CHAN_AMBISONIC_BASE + i;
+for (i = 0; i < extra.nb_channels; i++) {
+enum AVChannel ch = 
av_channel_layout_channel_from_index(, i);
+if (CHAN_IS_AMBI(ch)) {
+av_channel_layout_uninit();
+return AVERROR(EINVAL);
+}
+channel_layout->u.map[channel_layout->nb_channels + i].id 
= ch;
+}
+}
+channel_layout->nb_channels += extra.nb_channels;
+av_channel_layout_uninit();
+}
+
+return 0;
+}
+
 /* channel names */
 while (*dup) {
 char *chname = av_get_token(, "+");
@@ -526,6 +597,77 @@ int av_channel_layout_copy(AVChannelLayout *dst, const 
AVChannelLayout *src)
 return 0;
 }
 
+/**
+ * If the custom layout is n-th order standard-order ambisonic, with optional
+ * extra non-diegetic channels at the end, write its string description in bp.
+ * 

[FFmpeg-devel] [PATCH 278/281] ffprobe: convert to new channel layout-API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 fftools/ffprobe.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 20582ca7ac..aff9b880cc 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2462,12 +2462,10 @@ static void show_frame(WriterContext *w, AVFrame 
*frame, AVStream *stream,
 if (s) print_str("sample_fmt", s);
 else   print_str_opt("sample_fmt", "unknown");
 print_int("nb_samples", frame->nb_samples);
-print_int("channels", frame->channels);
-if (frame->channel_layout) {
-av_bprint_clear();
-av_bprint_channel_layout(, frame->channels,
- frame->channel_layout);
-print_str("channel_layout", pbuf.str);
+print_int("channels", frame->ch_layout.nb_channels);
+if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+av_channel_layout_describe(>ch_layout, val_str, 
sizeof(val_str));
+print_str("channel_layout", val_str);
 } else
 print_str_opt("channel_layout", "unknown");
 break;
@@ -2873,12 +2871,11 @@ static int show_stream(WriterContext *w, 
AVFormatContext *fmt_ctx, int stream_id
 if (s) print_str("sample_fmt", s);
 else   print_str_opt("sample_fmt", "unknown");
 print_val("sample_rate", par->sample_rate, unit_hertz_str);
-print_int("channels",par->channels);
+print_int("channels",par->ch_layout.nb_channels);
 
-if (par->channel_layout) {
-av_bprint_clear();
-av_bprint_channel_layout(, par->channels, 
par->channel_layout);
-print_str("channel_layout", pbuf.str);
+if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+av_channel_layout_describe(>ch_layout, val_str, 
sizeof(val_str));
+print_str("channel_layout", val_str);
 } else {
 print_str_opt("channel_layout", "unknown");
 }
-- 
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 277/281] ffmpeg: convert to new channel layout-API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 fftools/cmdutils.c| 42 +++-
 fftools/cmdutils.h|  8 -
 fftools/ffmpeg.c  | 47 --
 fftools/ffmpeg.h  |  7 ++--
 fftools/ffmpeg_filter.c   | 52 ++---
 fftools/ffmpeg_opt.c  | 62 ++-
 tests/fate/aac.mak|  2 +-
 tests/fate/lavf-container.mak |  2 +-
 8 files changed, 155 insertions(+), 67 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15eef..55cdbfb7a7 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1470,8 +1470,19 @@ static void print_codec(const AVCodec *c)
   GET_SAMPLE_RATE_NAME);
 PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample 
formats",
   AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
-PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
-  0, GET_CH_LAYOUT_DESC);
+
+if (c->ch_layouts) {
+const AVChannelLayout *p = c->ch_layouts;
+
+printf("Supported channel layouts:");
+while (p->nb_channels) {
+char name[128];
+av_channel_layout_describe(p, name, sizeof(name));
+printf(" %s", name);
+p++;
+}
+printf("\n");
+}
 
 if (c->priv_class) {
 show_help_children(c->priv_class,
@@ -1784,29 +1795,30 @@ int show_pix_fmts(void *optctx, const char *opt, const 
char *arg)
 
 int show_layouts(void *optctx, const char *opt, const char *arg)
 {
+const AVChannelLayout *ch_layout;
+void *iter = NULL;
+char buf[128], buf2[128];
 int i = 0;
-uint64_t layout, j;
-const char *name, *descr;
 
 printf("Individual channels:\n"
"NAME   DESCRIPTION\n");
 for (i = 0; i < 63; i++) {
-name = av_get_channel_name((uint64_t)1 << i);
-if (!name)
+av_channel_name(buf, sizeof(buf), i);
+if (!strcmp(buf, "?"))
 continue;
-descr = av_get_channel_description((uint64_t)1 << i);
-printf("%-14s %s\n", name, descr);
+av_channel_description(buf2, sizeof(buf2), i);
+printf("%-14s %s\n", buf, buf2);
 }
 printf("\nStandard channel layouts:\n"
"NAME   DECOMPOSITION\n");
-for (i = 0; !av_get_standard_channel_layout(i, , ); i++) {
-if (name) {
-printf("%-14s ", name);
-for (j = 1; j; j <<= 1)
-if ((layout & j))
-printf("%s%s", (layout & (j - 1)) ? "+" : "", 
av_get_channel_name(j));
+while (ch_layout = av_channel_layout_standard()) {
+av_channel_layout_describe(ch_layout, buf, sizeof(buf));
+av_channel_name(buf2, sizeof(buf2), i);
+printf("%-14s ", buf);
+for (i = 0; i < 63; i++)
+if (av_channel_layout_index_from_channel(ch_layout, i) >= 0)
+printf("%s%s", i ? "+" : "", buf2);
 printf("\n");
-}
 }
 return 0;
 }
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 50eed9b13a..274d2e5b14 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -663,14 +663,6 @@ void *allocate_array_elem(void *array, size_t elem_size, 
int *nb_elems);
 char name[16];\
 snprintf(name, sizeof(name), "%d", rate);
 
-#define GET_CH_LAYOUT_NAME(ch_layout)\
-char name[16];\
-snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
-
-#define GET_CH_LAYOUT_DESC(ch_layout)\
-char name[128];\
-av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
-
 double get_rotation(int32_t *displaymatrix);
 
 #endif /* FFTOOLS_CMDUTILS_H */
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d134b025f..22d6309f2a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -555,6 +555,7 @@ static void ffmpeg_cleanup(int ret)
 
 avfilter_inout_free(>out_tmp);
 av_freep(>name);
+av_channel_layout_uninit(>ch_layout);
 av_freep(>outputs[j]);
 }
 av_freep(>outputs);
@@ -1537,7 +1538,7 @@ static int reap_filters(int flush)
 break;
 case AVMEDIA_TYPE_AUDIO:
 if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
-enc->channels != filtered_frame->channels) {
+enc->ch_layout.nb_channels != 
filtered_frame->ch_layout.nb_channels) {
 av_log(NULL, AV_LOG_ERROR,
"Audio filter graph output is not normalized and 
encoder does not support parameter changes\n");
 break;
@@ -1883,17 +1884,22 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 print_final_stats(total_size);
 }
 
-static void ifilter_parameters_from_codecpar(InputFilter *ifilter, 
AVCodecParameters *par)
+static int 

[FFmpeg-devel] [PATCH 276/281] avdevice/lavfi: remove call to deprecated function av_buffersink_get_channel_layout()

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libavdevice/lavfi.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index fdb93b835f..db5d0b94de 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -333,11 +333,9 @@ av_cold static int lavfi_read_header(AVFormatContext 
*avctx)
 par->sample_aspect_ratio = 
av_buffersink_get_sample_aspect_ratio(sink);
 } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
 par->sample_rate = av_buffersink_get_sample_rate(sink);
-ret = av_channel_layout_from_mask(>ch_layout, 
av_buffersink_get_channel_layout(sink));
-if (ret < 0) {
-par->ch_layout.nb_channels = av_buffersink_get_channels(sink);
-par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
-}
+ret = av_buffersink_get_ch_layout(sink, >ch_layout);
+if (ret < 0)
+goto end;
 par->format  = av_buffersink_get_format(sink);
 par->codec_id= av_get_pcm_codec(par->format, -1);
 if (par->codec_id == AV_CODEC_ID_NONE)
@@ -441,7 +439,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, 
AVPacket *pkt)
 frame->format, frame->width, frame->height, 1);
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
 size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *
-   frame->channels;
+   frame->ch_layout.nb_channels;
 if ((ret = av_new_packet(pkt, size)) < 0)
 goto fail;
 memcpy(pkt->data, frame->data[0], size);
-- 
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 273/281] lavf: Add non diegetic stream disposition flag

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavformat/avformat.h | 7 +++
 libavformat/dump.c | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6ce367e854..182545e607 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -879,6 +879,13 @@ typedef struct AVIndexEntry {
  */
 #define AV_DISPOSITION_TIMED_THUMBNAILS (1 << 11)
 
+/**
+ * The stream is intended to be mixed with a spatial audio track. For example,
+ * it could be used for narration or stereo music, and may remain unchanged by
+ * listener head rotation.
+ */
+#define AV_DISPOSITION_NON_DIEGETIC (1 << 12)
+
 /**
  * The subtitle stream contains captions, providing a transcription and 
possibly
  * a translation of audio. Typically intended for hearing-impaired audiences.
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 69b838fbc7..e3f0056c20 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -618,6 +618,8 @@ static void dump_stream_format(const AVFormatContext *ic, 
int i,
 av_log(NULL, AV_LOG_INFO, " (dependent)");
 if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
 av_log(NULL, AV_LOG_INFO, " (still image)");
+if (st->disposition & AV_DISPOSITION_NON_DIEGETIC)
+av_log(NULL, AV_LOG_INFO, " (non-diegetic)");
 av_log(NULL, AV_LOG_INFO, "\n");
 
 dump_metadata(NULL, st->metadata, "");
-- 
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 272/281] lavc: drop temporary compat wrappers for channel layout API change

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/aacdec_template.c |  7 ---
 libavcodec/avcodec.c | 29 -
 libavcodec/dca_lbr.c |  7 ---
 libavcodec/dcadec.c  |  8 
 libavcodec/decode.c  | 20 
 libavcodec/encode.c  | 17 +
 6 files changed, 1 insertion(+), 87 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 387a4acfce..349ecdefb3 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -592,13 +592,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 
 av_channel_layout_copy(>ch_layout, >oc[1].ch_layout);
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-avctx->channels = avctx->ch_layout.nb_channels;
-avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-avctx->ch_layout.u.mask : 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
 ac->oc[1].status = oc_type;
 
 if (get_new_frame) {
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 0436a6d0bd..5b68e799ec 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -137,8 +137,6 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec 
*codec, AVDictionary **options)
 {
 int ret = 0;
-int orig_channels;
-uint64_t orig_channel_layout;
 AVCodecInternal *avci;
 
 if (avcodec_is_open(avctx))
@@ -275,14 +273,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
 avctx->ch_layout.nb_channels = avctx->channels;
 }
 }
-
-/* temporary compat wrapper for new-style callers and old-style codecs;
- * to be removed once all the codecs have been converted */
-if (avctx->ch_layout.nb_channels) {
-avctx->channels = avctx->ch_layout.nb_channels;
-avctx->channel_layout = avctx->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
-avctx->ch_layout.u.mask : 0;
-}
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
@@ -345,13 +335,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
 avctx->thread_count = 1;
 
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-orig_channels = avctx->channels;
-orig_channel_layout = avctx->channel_layout;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
 avci->frame_thread_encoder) {
 if (avctx->codec->init) {
@@ -372,18 +355,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
-/* decoder setting the old-style fields */
-if (avctx->channels != orig_channels ||
-avctx->channel_layout != orig_channel_layout) {
-av_channel_layout_uninit(>ch_layout);
-if (avctx->channel_layout) {
-av_channel_layout_from_mask(>ch_layout, 
avctx->channel_layout);
-} else {
-avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-avctx->ch_layout.nb_channels = avctx->channels;
-}
-}
-
 /* update the deprecated fields for old-style callers */
 avctx->channels = avctx->ch_layout.nb_channels;
 avctx->channel_layout = avctx->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index c11f2f7e18..527bc8b7c0 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -1744,13 +1744,6 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame 
*frame)
 
 av_channel_layout_uninit(>ch_layout);
 av_channel_layout_from_mask(>ch_layout, channel_mask);
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-avctx->channels = avctx->ch_layout.nb_channels;
-avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-avctx->ch_layout.u.mask : 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
 
 frame->nb_samples = 1024 << s->freq_range;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 239ed9ac91..9f40da20fc 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -78,14 +78,6 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int 
*ch_remap, int dca_mask
 av_channel_layout_from_mask(>ch_layout, wav_mask);
 }
 
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-avctx->channels = avctx->ch_layout.nb_channels;
-avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-avctx->ch_layout.u.mask : 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
 return nchannels;
 }
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6381ec68e1..a076a8884f 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1698,26 +1698,6 @@ int 

[FFmpeg-devel] [PATCH 271/281] ws-snd1: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/ws-snd1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ws-snd1.c b/libavcodec/ws-snd1.c
index aa8cd0f5f9..cd16445935 100644
--- a/libavcodec/ws-snd1.c
+++ b/libavcodec/ws-snd1.c
@@ -43,8 +43,8 @@ static const int8_t ws_adpcm_4bit[] = {
 
 static av_cold int ws_snd_decode_init(AVCodecContext *avctx)
 {
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_U8;
 
 return 0;
-- 
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 274/281] swresample: convert to new channel layout API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libswresample/options.c |  33 +++-
 libswresample/rematrix.c| 237 ++--
 libswresample/rematrix_template.c   |   7 +-
 libswresample/swresample.c  | 152 +++---
 libswresample/swresample.h  |  63 
 libswresample/swresample_frame.c|  65 +++-
 libswresample/swresample_internal.h |  10 +-
 7 files changed, 445 insertions(+), 122 deletions(-)

diff --git a/libswresample/options.c b/libswresample/options.c
index 6911709157..ffa27c590d 100644
--- a/libswresample/options.c
+++ b/libswresample/options.c
@@ -34,12 +34,19 @@
 
 #define OFFSET(x) offsetof(SwrContext,x)
 #define PARAM AV_OPT_FLAG_AUDIO_PARAM
+#define DEPREC AV_OPT_FLAG_DEPRECATED
 
 static const AVOption options[]={
-{"ich"  , "set input channel count" , 
OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM},
-{"in_channel_count" , "set input channel count" , 
OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM},
-{"och"  , "set output channel count", 
OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM},
-{"out_channel_count", "set output channel count", 
OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM},
+#if FF_API_OLD_CHANNEL_LAYOUT
+{"ich"  , "set input channel count (Deprecated, use ichl)",
+  
OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM|DEPREC},
+{"in_channel_count" , "set input channel count (Deprecated, use 
in_chlayout)",
+  
OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM|DEPREC},
+{"och"  , "set output channel count (Deprecated, use ochl)",
+  
OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM|DEPREC},
+{"out_channel_count", "set output channel count (Deprecated, use 
out_chlayout)",
+  
OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM|DEPREC},
+#endif
 {"uch"  , "set used channel count"  , 
OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM},
 {"used_channel_count"   , "set used channel count"  , 
OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0}, 0
  , SWR_CH_MAX, PARAM},
 {"isr"  , "set input sample rate"   , OFFSET( 
in_sample_rate), AV_OPT_TYPE_INT  , {.i64=0 }, 0  , 
INT_MAX   , PARAM},
@@ -52,10 +59,20 @@ static const AVOption options[]={
 {"out_sample_fmt"   , "set output sample format", 
OFFSET(out_sample_fmt ), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1 
  , INT_MAX, PARAM},
 {"tsf"  , "set internal sample format"  , 
OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , 
{.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
 {"internal_sample_fmt"  , "set internal sample format"  , 
OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , 
{.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
-{"icl"  , "set input channel layout", 
OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0   }, 
INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
-{"in_channel_layout", "set input channel layout", 
OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0   }, 
INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
-{"ocl"  , "set output channel layout"   , 
OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0   }, 
INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
-{"out_channel_layout"   , "set output channel layout"   , 
OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0   }, 
INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
+#if FF_API_OLD_CHANNEL_LAYOUT
+{"icl"  , "set input channel layout (Deprecated, use ichl)",
+  
OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0  }, 
INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
+{"in_channel_layout", "set input channel layout (Deprecated, use 
in_chlayout)",
+  
OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0  }, 
INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
+{"ocl"  , "set output channel layout (Deprecated, use ochl)",
+  

[FFmpeg-devel] [PATCH 270/281] wma: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/wma.c| 11 ++-
 libavcodec/wmadec.c | 29 +++--
 libavcodec/wmaenc.c | 27 ++-
 libavcodec/wmalosslessdec.c | 13 +++--
 libavcodec/wmaprodec.c  | 30 --
 libavcodec/wmavoice.c   |  4 ++--
 6 files changed, 64 insertions(+), 50 deletions(-)

diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index d9fda2dbfa..4cd60cc35e 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -79,6 +79,7 @@ static av_cold int init_coef_vlc(VLC *vlc, uint16_t 
**prun_table,
 av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 {
 WMACodecContext *s = avctx->priv_data;
+int channels = avctx->ch_layout.nb_channels;
 int i, ret;
 float bps1, high_freq;
 float bps;
@@ -86,7 +87,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 int coef_vlc_table;
 
 if (avctx->sample_rate <= 0 || avctx->sample_rate > 5 ||
-avctx->channels<= 0 || avctx->channels> 2 ||
+channels   <= 0 || channels> 2||
 avctx->bit_rate<= 0)
 return -1;
 
@@ -107,7 +108,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 if (s->use_variable_block_len) {
 int nb_max, nb;
 nb = ((flags2 >> 3) & 3) + 1;
-if ((avctx->bit_rate / avctx->channels) >= 32000)
+if ((avctx->bit_rate / channels) >= 32000)
 nb += 2;
 nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
 if (nb > nb_max)
@@ -136,7 +137,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 }
 
 bps = (float) avctx->bit_rate /
-  (float) (avctx->channels * avctx->sample_rate);
+  (float) (channels * avctx->sample_rate);
 s->byte_offset_bits = av_log2((int) (bps * s->frame_len / 8.0 + 0.5)) + 2;
 if (s->byte_offset_bits + 3 > MIN_CACHE_BITS) {
 av_log(avctx, AV_LOG_ERROR, "byte_offset_bits %d is too large\n", 
s->byte_offset_bits);
@@ -146,7 +147,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 /* compute high frequency value and choose if noise coding should
  * be activated */
 bps1 = bps;
-if (avctx->channels == 2)
+if (channels == 2)
 bps1 = bps * 1.6;
 if (sample_rate1 == 44100) {
 if (bps1 >= 0.61)
@@ -184,7 +185,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 }
 ff_dlog(s->avctx, "flags2=0x%x\n", flags2);
 ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%"PRId64" 
block_align=%d\n",
-s->version, avctx->channels, avctx->sample_rate, avctx->bit_rate,
+s->version, channels, avctx->sample_rate, avctx->bit_rate,
 avctx->block_align);
 ff_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
 bps, bps1, high_freq, s->byte_offset_bits);
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 9955aaa7d6..8b0893c74e 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -439,6 +439,7 @@ static void wma_window(WMACodecContext *s, float *out)
  */
 static int wma_decode_block(WMACodecContext *s)
 {
+int channels = s->avctx->ch_layout.nb_channels;
 int n, v, a, ch, bsize;
 int coef_nb_bits, total_gain;
 int nb_coefs[MAX_CHANNELS];
@@ -504,10 +505,10 @@ static int wma_decode_block(WMACodecContext *s)
 return -1;
 }
 
-if (s->avctx->channels == 2)
+if (channels == 2)
 s->ms_stereo = get_bits1(>gb);
 v = 0;
-for (ch = 0; ch < s->avctx->channels; ch++) {
+for (ch = 0; ch < channels; ch++) {
 a= get_bits1(>gb);
 s->channel_coded[ch] = a;
 v   |= a;
@@ -538,12 +539,12 @@ static int wma_decode_block(WMACodecContext *s)
 
 /* compute number of coefficients */
 n = s->coefs_end[bsize] - s->coefs_start;
-for (ch = 0; ch < s->avctx->channels; ch++)
+for (ch = 0; ch < channels; ch++)
 nb_coefs[ch] = n;
 
 /* complex coding */
 if (s->use_noise_coding) {
-for (ch = 0; ch < s->avctx->channels; ch++) {
+for (ch = 0; ch < channels; ch++) {
 if (s->channel_coded[ch]) {
 int i, n, a;
 n = s->exponent_high_sizes[bsize];
@@ -556,7 +557,7 @@ static int wma_decode_block(WMACodecContext *s)
 }
 }
 }
-for (ch = 0; ch < s->avctx->channels; ch++) {
+for (ch = 0; ch < channels; ch++) {
 if (s->channel_coded[ch]) {
 int i, n, val;
 
@@ -579,7 +580,7 @@ static int wma_decode_block(WMACodecContext *s)
 
 /* exponents can be reused in short blocks. */
 if ((s->block_len_bits == s->frame_len_bits) || get_bits1(>gb)) {
-for (ch = 0; ch < s->avctx->channels; ch++) {
+for (ch = 0; ch < channels; ch++) {
   

[FFmpeg-devel] [PATCH 269/281] wavpack: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/wavpack.c| 51 ++---
 libavcodec/wavpackenc.c | 29 ---
 2 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 6b2ec19bf1..e0350ce732 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1412,25 +1412,23 @@ static int wavpack_decode_block(AVCodecContext *avctx, 
int block_no,
 size = bytestream2_get_byte();
 chan  |= (bytestream2_get_byte() & 0xF) << 8;
 chan  += 1;
-if (avctx->channels != chan)
+if (avctx->ch_layout.nb_channels != chan)
 av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
-   " instead of %i.\n", chan, avctx->channels);
+   " instead of %i.\n", chan, 
avctx->ch_layout.nb_channels);
 chmask = bytestream2_get_le24();
 break;
 case 5:
 size = bytestream2_get_byte();
 chan  |= (bytestream2_get_byte() & 0xF) << 8;
 chan  += 1;
-if (avctx->channels != chan)
+if (avctx->ch_layout.nb_channels != chan)
 av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
-   " instead of %i.\n", chan, avctx->channels);
+   " instead of %i.\n", chan, 
avctx->ch_layout.nb_channels);
 chmask = bytestream2_get_le32();
 break;
 default:
 av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
size);
-chan   = avctx->channels;
-chmask = avctx->channel_layout;
 }
 break;
 case WP_ID_SAMPLE_RATE:
@@ -1494,8 +1492,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, 
int block_no,
 }
 
 if (!wc->ch_offset) {
-int  new_channels = avctx->channels;
-uint64_t new_chmask   = avctx->channel_layout;
+AVChannelLayout new_ch_layout = { 0 };
 int new_samplerate;
 int sr = (s->frame_flags >> 23) & 0xf;
 if (sr == 0xf) {
@@ -1512,36 +1509,32 @@ static int wavpack_decode_block(AVCodecContext *avctx, 
int block_no,
 new_samplerate *= rate_x;
 
 if (multiblock) {
-if (chan)
-new_channels = chan;
-if (chmask)
-new_chmask = chmask;
+if (chmask) {
+av_channel_layout_from_mask(_ch_layout, chmask);
+if (chan && new_ch_layout.nb_channels != chan) {
+av_log(avctx, AV_LOG_ERROR, "Channel mask does not match 
the channel count\n");
+return AVERROR_INVALIDDATA;
+}
+} else
+av_channel_layout_copy(_ch_layout, >ch_layout);
 } else {
-new_channels = s->stereo ? 2 : 1;
-new_chmask   = s->stereo ? AV_CH_LAYOUT_STEREO :
-   AV_CH_LAYOUT_MONO;
-}
-
-if (new_chmask &&
-av_get_channel_layout_nb_channels(new_chmask) != new_channels) {
-av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the 
channel count\n");
-return AVERROR_INVALIDDATA;
+av_channel_layout_default(_ch_layout, s->stereo + 1);
 }
 
 /* clear DSD state if stream properties change */
-if (new_channels   != wc->dsd_channels  ||
-new_chmask != avctx->channel_layout ||
+if (new_ch_layout.nb_channels != wc->dsd_channels ||
+av_channel_layout_compare(_ch_layout, >ch_layout) ||
 new_samplerate != avctx->sample_rate||
 !!got_dsd  != !!wc->dsdctx) {
-ret = wv_dsd_reset(wc, got_dsd ? new_channels : 0);
+ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD 
context\n");
 return ret;
 }
 ff_thread_release_buffer(avctx, >curr_frame);
 }
-avctx->channels= new_channels;
-avctx->channel_layout  = new_chmask;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_copy(>ch_layout, _ch_layout);
 avctx->sample_rate = new_samplerate;
 avctx->sample_fmt  = sample_fmt;
 avctx->bits_per_raw_sample = orig_bpp;
@@ -1558,7 +1551,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, 
int block_no,
 ff_thread_finish_setup(avctx);
 }
 
-if (wc->ch_offset + s->stereo >= avctx->channels) {
+if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a 

[FFmpeg-devel] [PATCH 268/281] vorbis: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/vorbisdec.c | 27 +--
 libavcodec/vorbisenc.c |  7 ---
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 6e07bc5a8a..d961dc37b9 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1077,12 +1077,14 @@ static av_cold int vorbis_decode_init(AVCodecContext 
*avctx)
 return ret;
 }
 
-if (vc->audio_channels > 8)
-avctx->channel_layout = 0;
-else
-avctx->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 
1];
+av_channel_layout_uninit(>ch_layout);
+if (vc->audio_channels > 8) {
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = vc->audio_channels;
+} else {
+av_channel_layout_copy(>ch_layout, 
_vorbis_ch_layouts[vc->audio_channels - 1]);
+}
 
-avctx->channels= vc->audio_channels;
 avctx->sample_rate = vc->audio_samplerate;
 
 return 0;
@@ -1788,12 +1790,14 @@ static int vorbis_decode_frame(AVCodecContext *avctx, 
void *data,
 return ret;
 }
 
-if (vc->audio_channels > 8)
-avctx->channel_layout = 0;
-else
-avctx->channel_layout = 
ff_vorbis_channel_layouts[vc->audio_channels - 1];
+av_channel_layout_uninit(>ch_layout);
+if (vc->audio_channels > 8) {
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = vc->audio_channels;
+} else {
+av_channel_layout_copy(>ch_layout, 
_vorbis_ch_layouts[vc->audio_channels - 1]);
+}
 
-avctx->channels= vc->audio_channels;
 avctx->sample_rate = vc->audio_samplerate;
 return buf_size;
 }
@@ -1892,7 +1896,10 @@ const AVCodec ff_vorbis_decoder = {
 .flush   = vorbis_decode_flush,
 .capabilities= AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
 .caps_internal   = FF_CODEC_CAP_INIT_CLEANUP,
+#if FF_API_OLD_CHANNEL_LAYOUT
 .channel_layouts = ff_vorbis_channel_layouts,
+#endif
+.ch_layouts  = ff_vorbis_ch_layouts,
 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
 };
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 858c6ac6dd..30b75ab3f6 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -276,7 +276,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
 const uint8_t *clens, *quant;
 int i, book, ret;
 
-venc->channels= avctx->channels;
+venc->channels= avctx->ch_layout.nb_channels;
 venc->sample_rate = avctx->sample_rate;
 venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
 
@@ -1038,7 +1038,8 @@ static AVFrame *spawn_empty_frame(AVCodecContext *avctx, 
int channels)
 
 f->format = avctx->sample_fmt;
 f->nb_samples = avctx->frame_size;
-f->channel_layout = avctx->channel_layout;
+f->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+f->ch_layout.nb_channels = channels;
 
 if (av_frame_get_buffer(f, 4)) {
 av_frame_free();
@@ -1267,7 +1268,7 @@ static av_cold int vorbis_encode_init(AVCodecContext 
*avctx)
 vorbis_enc_context *venc = avctx->priv_data;
 int ret;
 
-if (avctx->channels != 2) {
+if (avctx->ch_layout.nb_channels != 2) {
 av_log(avctx, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only 
supports 2 channels.\n");
 return -1;
 }
-- 
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 267/281] vmdaudio: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/vmdaudio.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vmdaudio.c b/libavcodec/vmdaudio.c
index 53aef660ef..5e04686cb1 100644
--- a/libavcodec/vmdaudio.c
+++ b/libavcodec/vmdaudio.c
@@ -71,20 +71,20 @@ static const uint16_t vmdaudio_table[128] = {
 static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
 {
 VmdAudioContext *s = avctx->priv_data;
+int channels = avctx->ch_layout.nb_channels;
 
-if (avctx->channels < 1 || avctx->channels > 2) {
+if (channels < 1 || channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
 return AVERROR(EINVAL);
 }
-if (avctx->block_align < 1 || avctx->block_align % avctx->channels ||
-avctx->block_align > INT_MAX - avctx->channels
-) {
+if (avctx->block_align < 1 || avctx->block_align % channels ||
+avctx->block_align > INT_MAX - channels) {
 av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
 return AVERROR(EINVAL);
 }
 
-avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
-   AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, channels == 1);
 
 if (avctx->bits_per_coded_sample == 16)
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
@@ -92,11 +92,11 @@ static av_cold int vmdaudio_decode_init(AVCodecContext 
*avctx)
 avctx->sample_fmt = AV_SAMPLE_FMT_U8;
 s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
 
-s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
+s->chunk_size = avctx->block_align + channels * (s->out_bps == 2);
 
 av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
"block align = %d, sample rate = %d\n",
-   avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
+   channels, avctx->bits_per_coded_sample, avctx->block_align,
avctx->sample_rate);
 
 return 0;
@@ -143,6 +143,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, 
void *data,
 int ret;
 uint8_t *output_samples_u8;
 int16_t *output_samples_s16;
+int channels = avctx->ch_layout.nb_channels;
 
 if (buf_size < 16) {
 av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
@@ -186,7 +187,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, 
void *data,
 
 /* get output buffer */
 frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
-avctx->channels;
+avctx->ch_layout.nb_channels;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 output_samples_u8  =frame->data[0];
@@ -195,7 +196,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, 
void *data,
 /* decode silent chunks */
 if (silent_chunks > 0) {
 int silent_size = avctx->block_align * silent_chunks;
-av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * 
avctx->channels);
+av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * 
avctx->ch_layout.nb_channels);
 
 if (s->out_bps == 2) {
 memset(output_samples_s16, 0x00, silent_size * 2);
@@ -209,11 +210,10 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, 
void *data,
 /* decode audio chunks */
 if (audio_chunks > 0) {
 buf_end = buf + buf_size;
-av_assert0((buf_size & (avctx->channels > 1)) == 0);
+av_assert0((buf_size & (avctx->ch_layout.nb_channels > 1)) == 0);
 while (buf_end - buf >= s->chunk_size) {
 if (s->out_bps == 2) {
-decode_audio_s16(output_samples_s16, buf, s->chunk_size,
- avctx->channels);
+decode_audio_s16(output_samples_s16, buf, s->chunk_size, 
channels);
 output_samples_s16 += avctx->block_align;
 } else {
 memcpy(output_samples_u8, buf, s->chunk_size);
-- 
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 266/281] vima: convert to new channel layout API

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/vima.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vima.c b/libavcodec/vima.c
index c9a81e4401..5053feda90 100644
--- a/libavcodec/vima.c
+++ b/libavcodec/vima.c
@@ -147,9 +147,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 channel_hint[0] = ~channel_hint[0];
 channels = 2;
 }
-avctx->channels = channels;
-avctx->channel_layout = (channels == 2) ? AV_CH_LAYOUT_STEREO
-: AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, channels);
 pcm_data[0] = get_sbits(, 16);
 if (channels > 1) {
 channel_hint[1] = get_sbits(, 8);
-- 
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 265/281] twinvq: convert to new channel layout API

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: James Almer 
---
 libavcodec/twinvq.c| 20 +++-
 libavcodec/twinvqdec.c | 18 +-
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c
index 6dfaf06b14..ba9672a41f 100644
--- a/libavcodec/twinvq.c
+++ b/libavcodec/twinvq.c
@@ -217,17 +217,18 @@ static void dec_gain(TwinVQContext *tctx,
 const TwinVQModeTab   *mtab =  tctx->mtab;
 const TwinVQFrameData *bits = >bits[tctx->cur_frame];
 int i, j;
+int channels   = tctx->avctx->ch_layout.nb_channels;
 int sub= mtab->fmode[ftype].sub;
 float step = TWINVQ_AMP_MAX / ((1 << TWINVQ_GAIN_BITS) - 1);
 float sub_step = TWINVQ_SUB_AMP_MAX / ((1 << TWINVQ_SUB_GAIN_BITS) - 1);
 
 if (ftype == TWINVQ_FT_LONG) {
-for (i = 0; i < tctx->avctx->channels; i++)
+for (i = 0; i < channels; i++)
 out[i] = (1.0 / (1 << 13)) *
  twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
  TWINVQ_AMP_MAX, TWINVQ_MULAW_MU);
 } else {
-for (i = 0; i < tctx->avctx->channels; i++) {
+for (i = 0; i < channels; i++) {
 float val = (1.0 / (1 << 23)) *
 twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
 TWINVQ_AMP_MAX, TWINVQ_MULAW_MU);
@@ -380,10 +381,11 @@ static void imdct_output(TwinVQContext *tctx, enum 
TwinVQFrameType ftype,
 {
 const TwinVQModeTab *mtab = tctx->mtab;
 float *prev_buf   = tctx->prev_frame + tctx->last_block_pos[0];
+int channels  = tctx->avctx->ch_layout.nb_channels;
 int size1, size2, i;
 float *out1, *out2;
 
-for (i = 0; i < tctx->avctx->channels; i++)
+for (i = 0; i < channels; i++)
 imdct_and_window(tctx, ftype, wtype,
  tctx->spectrum + i * mtab->size,
  prev_buf + 2 * i * mtab->size,
@@ -399,7 +401,7 @@ static void imdct_output(TwinVQContext *tctx, enum 
TwinVQFrameType ftype,
 memcpy(out1, prev_buf, size1 * sizeof(*out1));
 memcpy(out1 + size1, tctx->curr_frame, size2 * sizeof(*out1));
 
-if (tctx->avctx->channels == 2) {
+if (channels == 2) {
 out2 = [1][0] + offset;
 memcpy(out2, _buf[2 * mtab->size],
size1 * sizeof(*out2));
@@ -414,7 +416,7 @@ static void read_and_decode_spectrum(TwinVQContext *tctx, 
float *out,
 {
 const TwinVQModeTab *mtab = tctx->mtab;
 TwinVQFrameData *bits = >bits[tctx->cur_frame];
-int channels  = tctx->avctx->channels;
+int channels  = tctx->avctx->ch_layout.nb_channels;
 int sub= mtab->fmode[ftype].sub;
 int block_size = mtab->size / sub;
 float gain[TWINVQ_CHANNELS_MAX * TWINVQ_SUBBLOCKS_MAX];
@@ -536,7 +538,7 @@ static av_cold int init_mdct_win(TwinVQContext *tctx)
 const TwinVQModeTab *mtab = tctx->mtab;
 int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub;
 int size_m = mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub;
-int channels = tctx->avctx->channels;
+int channels = tctx->avctx->ch_layout.nb_channels;
 float norm = channels == 1 ? 2.0 : 1.0;
 int table_size = 2 * mtab->size * channels;
 
@@ -645,10 +647,10 @@ static av_cold void construct_perm_table(TwinVQContext 
*tctx,
 int16_t *tmp_perm = (int16_t *)tctx->tmp_buf;
 
 if (ftype == TWINVQ_FT_PPC) {
-size   = tctx->avctx->channels;
+size   = tctx->avctx->ch_layout.nb_channels;
 block_size = mtab->ppc_shape_len;
 } else {
-size   = tctx->avctx->channels * mtab->fmode[ftype].sub;
+size   = tctx->avctx->ch_layout.nb_channels * 
mtab->fmode[ftype].sub;
 block_size = mtab->size / mtab->fmode[ftype].sub;
 }
 
@@ -666,7 +668,7 @@ static av_cold void construct_perm_table(TwinVQContext 
*tctx,
 static av_cold void init_bitstream_params(TwinVQContext *tctx)
 {
 const TwinVQModeTab *mtab = tctx->mtab;
-int n_ch  = tctx->avctx->channels;
+int n_ch  = tctx->avctx->ch_layout.nb_channels;
 int total_fr_bits = tctx->avctx->bit_rate * mtab->size /
 tctx->avctx->sample_rate;
 
diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c
index 1fbe0bc32e..98702c7ef2 100644
--- a/libavcodec/twinvqdec.c
+++ b/libavcodec/twinvqdec.c
@@ -181,7 +181,7 @@ static void decode_ppc(TwinVQContext *tctx, int 
period_coef, int g_coef,
 {
 const TwinVQModeTab *mtab = tctx->mtab;
 int isampf = tctx->avctx->sample_rate /  1000;
-int ibps   = tctx->avctx->bit_rate/ (1000 * tctx->avctx->channels);
+int ibps   = tctx->avctx->bit_rate/ (1000 * 
tctx->avctx->ch_layout.nb_channels);
 int min_period   = ROUNDED_DIV(40 * 2 * mtab->size, isampf);
 int max_period   = ROUNDED_DIV(40 * 2 * mtab->size * 

[FFmpeg-devel] [PATCH 264/281] tta: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/tta.c| 18 +-
 libavcodec/ttaenc.c | 14 +++---
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index 17b4ca9032..fed18451eb 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -113,7 +113,7 @@ static int allocate_buffers(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 } else
 s->decode_buffer = NULL;
-s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx));
+s->ch_ctx = av_malloc_array(avctx->ch_layout.nb_channels, 
sizeof(*s->ch_ctx));
 if (!s->ch_ctx) {
 av_freep(>decode_buffer);
 return AVERROR(ENOMEM);
@@ -156,9 +156,17 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
 }
 AV_WL64(s->crc_pass, tta_check_crc64(s->pass));
 }
-avctx->channels = s->channels = get_bits(, 16);
-if (s->channels > 1 && s->channels < 9)
-avctx->channel_layout = tta_channel_layouts[s->channels-2];
+
+s->channels = get_bits(, 16);
+
+av_channel_layout_uninit(>ch_layout);
+if (s->channels > 1 && s->channels < 9) {
+av_channel_layout_from_mask(>ch_layout, 
tta_channel_layouts[s->channels-2]);
+} else {
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = s->channels;
+}
+
 avctx->bits_per_raw_sample = get_bits(, 16);
 s->bps = (avctx->bits_per_raw_sample + 7) / 8;
 avctx->sample_rate = get_bits_long(, 32);
@@ -199,7 +207,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
(s->last_frame_length ? 1 : 0);
 
 av_log(avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d 
block: %d\n",
-s->format, avctx->channels, avctx->bits_per_coded_sample, 
avctx->sample_rate,
+s->format, avctx->ch_layout.nb_channels, 
avctx->bits_per_coded_sample, avctx->sample_rate,
 avctx->block_align);
 av_log(avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d 
total: %d\n",
 s->data_length, s->frame_length, s->last_frame_length, 
total_frames);
diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c
index addaf30bb5..5717ec22d1 100644
--- a/libavcodec/ttaenc.c
+++ b/libavcodec/ttaenc.c
@@ -56,7 +56,7 @@ static av_cold int tta_encode_init(AVCodecContext *avctx)
 s->bps = avctx->bits_per_raw_sample >> 3;
 avctx->frame_size = 256 * avctx->sample_rate / 245;
 
-s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx));
+s->ch_ctx = av_malloc_array(avctx->ch_layout.nb_channels, 
sizeof(*s->ch_ctx));
 if (!s->ch_ctx)
 return AVERROR(ENOMEM);
 
@@ -89,7 +89,7 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 TTAEncContext *s = avctx->priv_data;
 PutBitContext pb;
 int ret, i, out_bytes, cur_chan, res, samples;
-int64_t pkt_size =  frame->nb_samples * 2LL * avctx->channels * s->bps;
+int64_t pkt_size =  frame->nb_samples * 2LL * avctx->ch_layout.nb_channels 
* s->bps;
 
 pkt_alloc:
 cur_chan = 0, res = 0, samples = 0;
@@ -98,13 +98,13 @@ pkt_alloc:
 init_put_bits(, avpkt->data, avpkt->size);
 
 // init per channel states
-for (i = 0; i < avctx->channels; i++) {
+for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
 s->ch_ctx[i].predictor = 0;
 ff_tta_filter_init(>ch_ctx[i].filter, ff_tta_filter_configs[s->bps 
- 1]);
 ff_tta_rice_init(>ch_ctx[i].rice, 10, 10);
 }
 
-for (i = 0; i < frame->nb_samples * avctx->channels; i++) {
+for (i = 0; i < frame->nb_samples * avctx->ch_layout.nb_channels; i++) {
 TTAChannel *c = >ch_ctx[cur_chan];
 TTAFilter *filter = >filter;
 TTARice *rice = >rice;
@@ -113,8 +113,8 @@ pkt_alloc:
 
 value = get_sample(frame, samples++, avctx->sample_fmt);
 
-if (avctx->channels > 1) {
-if (cur_chan < avctx->channels - 1)
+if (avctx->ch_layout.nb_channels > 1) {
+if (cur_chan < avctx->ch_layout.nb_channels - 1)
 value  = res = get_sample(frame, samples, avctx->sample_fmt) - 
value;
 else
 value -= res / 2;
@@ -176,7 +176,7 @@ pkt_alloc:
 if (k)
 put_bits(, k, outval & (ff_tta_shift_1[k] - 1));
 
-if (cur_chan < avctx->channels - 1)
+if (cur_chan < avctx->ch_layout.nb_channels - 1)
 cur_chan++;
 else
 cur_chan = 0;
-- 
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 263/281] truespeech: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/truespeech.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index a65ced15d7..30a7e86a75 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -64,12 +64,13 @@ static av_cold int truespeech_decode_init(AVCodecContext * 
avctx)
 {
 TSContext *c = avctx->priv_data;
 
-if (avctx->channels != 1) {
-avpriv_request_sample(avctx, "Channel count %d", avctx->channels);
+if (avctx->ch_layout.nb_channels != 1) {
+avpriv_request_sample(avctx, "Channel count %d", 
avctx->ch_layout.nb_channels);
 return AVERROR_PATCHWELCOME;
 }
 
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
 ff_bswapdsp_init(>bdsp);
-- 
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 262/281] tak: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/takdec.c | 41 +++--
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 926dbf611e..15543098b5 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -734,9 +734,14 @@ static int tak_decode_frame(AVCodecContext *avctx, void 
*data,
 avctx->sample_rate = s->ti.sample_rate;
 set_sample_rate_params(avctx);
 }
-if (s->ti.ch_layout)
-avctx->channel_layout = s->ti.ch_layout;
-avctx->channels = s->ti.channels;
+
+av_channel_layout_uninit(>ch_layout);
+if (s->ti.ch_layout) {
+av_channel_layout_from_mask(>ch_layout, s->ti.ch_layout);
+} else {
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = s->ti.channels;
+}
 
 s->nb_samples = s->ti.last_frame_samples ? s->ti.last_frame_samples
  : s->ti.frame_samples;
@@ -747,7 +752,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void 
*data,
 ff_thread_finish_setup(avctx);
 
 if (avctx->bits_per_raw_sample <= 16) {
-int buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
+int buf_size = av_samples_get_buffer_size(NULL, 
avctx->ch_layout.nb_channels,
   s->nb_samples,
   AV_SAMPLE_FMT_S32P, 0);
 if (buf_size < 0)
@@ -756,28 +761,28 @@ static int tak_decode_frame(AVCodecContext *avctx, void 
*data,
 if (!s->decode_buffer)
 return AVERROR(ENOMEM);
 ret = av_samples_fill_arrays((uint8_t **)s->decoded, NULL,
- s->decode_buffer, avctx->channels,
+ s->decode_buffer, 
avctx->ch_layout.nb_channels,
  s->nb_samples, AV_SAMPLE_FMT_S32P, 0);
 if (ret < 0)
 return ret;
 } else {
-for (chan = 0; chan < avctx->channels; chan++)
+for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++)
 s->decoded[chan] = (int32_t *)frame->extended_data[chan];
 }
 
 if (s->nb_samples < 16) {
-for (chan = 0; chan < avctx->channels; chan++) {
+for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++) {
 int32_t *decoded = s->decoded[chan];
 for (i = 0; i < s->nb_samples; i++)
 decoded[i] = get_sbits(gb, avctx->bits_per_raw_sample);
 }
 } else {
 if (s->ti.codec == TAK_CODEC_MONO_STEREO) {
-for (chan = 0; chan < avctx->channels; chan++)
+for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++)
 if (ret = decode_channel(s, chan))
 return ret;
 
-if (avctx->channels == 2) {
+if (avctx->ch_layout.nb_channels == 2) {
 s->nb_subframes = get_bits(gb, 1) + 1;
 if (s->nb_subframes > 1) {
 s->subframe_len[1] = get_bits(gb, 6);
@@ -792,13 +797,13 @@ static int tak_decode_frame(AVCodecContext *avctx, void 
*data,
 int ch_mask = 0;
 
 chan = get_bits(gb, 4) + 1;
-if (chan > avctx->channels)
+if (chan > avctx->ch_layout.nb_channels)
 return AVERROR_INVALIDDATA;
 
 for (i = 0; i < chan; i++) {
 int nbit = get_bits(gb, 4);
 
-if (nbit >= avctx->channels)
+if (nbit >= avctx->ch_layout.nb_channels)
 return AVERROR_INVALIDDATA;
 
 if (ch_mask & 1 << nbit)
@@ -808,10 +813,10 @@ static int tak_decode_frame(AVCodecContext *avctx, void 
*data,
 if (s->mcdparams[i].present) {
 s->mcdparams[i].index = get_bits(gb, 2);
 s->mcdparams[i].chan2 = get_bits(gb, 4);
-if (s->mcdparams[i].chan2 >= avctx->channels) {
+if (s->mcdparams[i].chan2 >= 
avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_ERROR,
"invalid channel 2 (%d) for %d 
channel(s)\n",
-   s->mcdparams[i].chan2, avctx->channels);
+   s->mcdparams[i].chan2, 
avctx->ch_layout.nb_channels);
 return AVERROR_INVALIDDATA;
 }
 if (s->mcdparams[i].index == 1) {
@@ -829,7 +834,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void 
*data,
 ch_mask |= 1 << nbit;
 }
 } else {
-chan = avctx->channels;
+chan = avctx->ch_layout.nb_channels;
 for (i = 0; i < chan; i++) {
 

[FFmpeg-devel] [PATCH 261/281] speex: convert to new channel layout API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/speexdec.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/speexdec.c b/libavcodec/speexdec.c
index dcbdf5e010..7b482f5390 100644
--- a/libavcodec/speexdec.c
+++ b/libavcodec/speexdec.c
@@ -1450,7 +1450,7 @@ static av_cold int speex_decode_init(AVCodecContext 
*avctx)
 if (s->rate <= 0)
 return AVERROR_INVALIDDATA;
 
-s->nb_channels = avctx->channels;
+s->nb_channels = avctx->ch_layout.nb_channels;
 if (s->nb_channels <= 0)
 return AVERROR_INVALIDDATA;
 
@@ -1492,7 +1492,9 @@ static av_cold int speex_decode_init(AVCodecContext 
*avctx)
 
 if (s->bitrate > 0)
 avctx->bit_rate = s->bitrate;
-avctx->channels = s->nb_channels;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = s->nb_channels;
 avctx->sample_rate = s->rate;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
@@ -1554,12 +1556,12 @@ static int speex_decode_frame(AVCodecContext *avctx, 
void *data,
 ret = speex_modes[s->mode].decode(avctx, >st[s->mode], >gb, dst 
+ i * s->frame_size);
 if (ret < 0)
 return ret;
-if (avctx->channels == 2)
+if (avctx->ch_layout.nb_channels == 2)
 speex_decode_stereo(dst + i * s->frame_size, s->frame_size, 
>stereo);
 }
 
 dst = (float *)frame->extended_data[0];
-s->fdsp->vector_fmul_scalar(dst, dst, scale, frame->nb_samples * 
frame->channels);
+s->fdsp->vector_fmul_scalar(dst, dst, scale, frame->nb_samples * 
frame->ch_layout.nb_channels);
 frame->nb_samples = s->frame_size * s->frames_per_packet;
 
 *got_frame_ptr = 1;
-- 
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 260/281] sonic: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/sonic.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index cf1cfb1460..34f1605b29 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -598,13 +598,13 @@ static av_cold int sonic_encode_init(AVCodecContext 
*avctx)
 
 s->version = 2;
 
-if (avctx->channels > MAX_CHANNELS)
+if (avctx->ch_layout.nb_channels > MAX_CHANNELS)
 {
 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are 
supported by now\n");
 return AVERROR(EINVAL); /* only stereo or mono for now */
 }
 
-if (avctx->channels == 2)
+if (avctx->ch_layout.nb_channels == 2)
 s->decorrelation = MID_SIDE;
 else
 s->decorrelation = 3;
@@ -637,7 +637,7 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
 for (i = 0; i < s->num_taps; i++)
 s->tap_quant[i] = ff_sqrt(i+1);
 
-s->channels = avctx->channels;
+s->channels = avctx->ch_layout.nb_channels;
 s->samplerate = avctx->sample_rate;
 
 s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
@@ -853,7 +853,7 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
 int i;
 int ret;
 
-s->channels = avctx->channels;
+s->channels = avctx->ch_layout.nb_channels;
 s->samplerate = avctx->sample_rate;
 
 if (!avctx->extradata)
@@ -896,7 +896,9 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are 
supported by now\n");
 return AVERROR_INVALIDDATA;
 }
-avctx->channels = s->channels;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = s->channels;
 
 s->lossless = get_bits1();
 if (!s->lossless)
@@ -989,7 +991,7 @@ static int sonic_decode_frame(AVCodecContext *avctx,
 
 if (buf_size == 0) return 0;
 
-frame->nb_samples = s->frame_size / avctx->channels;
+frame->nb_samples = s->frame_size / avctx->ch_layout.nb_channels;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 samples = (int16_t *)frame->data[0];
-- 
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 259/281] smacker: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/smacker.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 75ab5d7120..4a3999e4f1 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -572,11 +572,13 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 static av_cold int smka_decode_init(AVCodecContext *avctx)
 {
-if (avctx->channels < 1 || avctx->channels > 2) {
+int channels = avctx->ch_layout.nb_channels;
+if (channels < 1 || channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
 return AVERROR_INVALIDDATA;
 }
-avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : 
AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, channels);
 avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : 
AV_SAMPLE_FMT_S16;
 
 return 0;
@@ -623,7 +625,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 stereo = get_bits1();
 bits = get_bits1();
-if (stereo ^ (avctx->channels != 1)) {
+if (stereo ^ (avctx->ch_layout.nb_channels != 1)) {
 av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
 return AVERROR_INVALIDDATA;
 }
@@ -633,8 +635,8 @@ static int smka_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 
 /* get output buffer */
-frame->nb_samples = unp_size / (avctx->channels * (bits + 1));
-if (unp_size % (avctx->channels * (bits + 1))) {
+frame->nb_samples = unp_size / (avctx->ch_layout.nb_channels * (bits + 1));
+if (unp_size % (avctx->ch_layout.nb_channels * (bits + 1))) {
 av_log(avctx, AV_LOG_ERROR,
"The buffer does not contain an integer number of samples\n");
 return AVERROR_INVALIDDATA;
-- 
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 258/281] siren: convert to new channel layout API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/siren.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/siren.c b/libavcodec/siren.c
index bdb249144b..add1773069 100644
--- a/libavcodec/siren.c
+++ b/libavcodec/siren.c
@@ -398,8 +398,8 @@ static av_cold int siren_init(AVCodecContext *avctx)
 s->imdct_prev = s->imdct_buf[2];
 s->window = s->imdct_buf[3];
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
 s->rate_control_possibilities = 16;
-- 
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 257/281] sipr: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/sipr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
index a792b22c9f..6c7293b6ec 100644
--- a/libavcodec/sipr.c
+++ b/libavcodec/sipr.c
@@ -512,8 +512,8 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
 for (i = 0; i < 4; i++)
 ctx->energy_history[i] = -14;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
 return 0;
-- 
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 256/281] shorten: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/shorten.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index fde5c4b982..6cce675c9f 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -428,7 +428,11 @@ static int read_header(ShortenContext *s)
 s->channels = 0;
 return AVERROR_INVALIDDATA;
 }
-s->avctx->channels = s->channels;
+if (s->avctx->ch_layout.nb_channels != s->channels) {
+av_channel_layout_uninit(>avctx->ch_layout);
+s->avctx->ch_layout.nb_channels = s->channels;
+s->avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+}
 
 /* get blocksize if version > 0 */
 if (s->version > 0) {
-- 
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 255/281] sbc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/sbc_parser.c |  8 ++--
 libavcodec/sbcdec.c |  9 -
 libavcodec/sbcenc.c | 15 ++-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
index 8bf726b39e..2d427cc7cb 100644
--- a/libavcodec/sbc_parser.c
+++ b/libavcodec/sbc_parser.c
@@ -41,7 +41,9 @@ static int sbc_parse_header(AVCodecParserContext *s, 
AVCodecContext *avctx,
 return -1;
 
 if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
-avctx->channels = 1;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = 1;
 avctx->sample_rate = 16000;
 avctx->frame_size = 120;
 s->duration = avctx->frame_size;
@@ -64,7 +66,9 @@ static int sbc_parse_header(AVCodecParserContext *s, 
AVCodecContext *avctx,
  + mode == SBC_MODE_DUAL_CHANNEL) + 1) * blocks * bitpool
  + (joint * subbands)) + 7) / 8;
 
-avctx->channels = channels;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = channels;
 avctx->sample_rate = sample_rates[sr];
 avctx->frame_size = subbands * blocks;
 s->duration = avctx->frame_size;
diff --git a/libavcodec/sbcdec.c b/libavcodec/sbcdec.c
index e14d8c8958..1c053ad9a7 100644
--- a/libavcodec/sbcdec.c
+++ b/libavcodec/sbcdec.c
@@ -351,7 +351,9 @@ static int sbc_decode_frame(AVCodecContext *avctx,
 if (frame_length <= 0)
 return frame_length;
 
-avctx->channels = sbc->frame.channels;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = sbc->frame.channels;
 
 frame->nb_samples = sbc->frame.blocks * sbc->frame.subbands;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
@@ -374,8 +376,13 @@ const AVCodec ff_sbc_decoder = {
 .decode= sbc_decode_frame,
 .capabilities  = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
 .channel_layouts   = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
   AV_CH_LAYOUT_STEREO, 0},
+#endif
+.ch_layouts= (const AVChannelLayout[]) { 
AV_CHANNEL_LAYOUT_MONO,
+ 
AV_CHANNEL_LAYOUT_STEREO,
+ { 0 } },
 .sample_fmts   = (const enum AVSampleFormat[]) { 
AV_SAMPLE_FMT_S16P,
  
AV_SAMPLE_FMT_NONE },
 .supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },
diff --git a/libavcodec/sbcenc.c b/libavcodec/sbcenc.c
index 45156277b7..cff93e8917 100644
--- a/libavcodec/sbcenc.c
+++ b/libavcodec/sbcenc.c
@@ -202,7 +202,7 @@ static int sbc_encode_init(AVCodecContext *avctx)
 sbc->msbc = 1;
 
 if (sbc->msbc) {
-if (avctx->channels != 1) {
+if (avctx->ch_layout.nb_channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "mSBC require mono channel.\n");
 return AVERROR(EINVAL);
 }
@@ -227,7 +227,7 @@ static int sbc_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (avctx->channels == 1) {
+if (avctx->ch_layout.nb_channels == 1) {
 frame->mode = SBC_MODE_MONO;
 if (sbc->max_delay <= 3000 || avctx->bit_rate > 27)
 frame->subbands = 4;
@@ -251,7 +251,7 @@ static int sbc_encode_init(AVCodecContext *avctx)
 
 d = frame->blocks * ((frame->mode == SBC_MODE_DUAL_CHANNEL) + 1);
 frame->bitpool = (((avctx->bit_rate * frame->subbands * frame->blocks) 
/ avctx->sample_rate)
-  - 4 * frame->subbands * avctx->channels
+  - 4 * frame->subbands * avctx->ch_layout.nb_channels
   - (frame->mode == 
SBC_MODE_JOINT_STEREO)*frame->subbands - 32 + d/2) / d;
 if (avctx->global_quality > 0)
 frame->bitpool = avctx->global_quality / FF_QP2LAMBDA;
@@ -263,8 +263,8 @@ static int sbc_encode_init(AVCodecContext *avctx)
 if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
 frame->frequency = i;
 
-frame->channels = avctx->channels;
-frame->codesize = frame->subbands * frame->blocks * avctx->channels * 2;
+frame->channels = avctx->ch_layout.nb_channels;
+frame->codesize = frame->subbands * frame->blocks * 
avctx->ch_layout.nb_channels * 2;
 frame->crc_ctx = av_crc_get_table(AV_CRC_8_EBU);
 
 memset(>dsp.X, 0, sizeof(sbc->dsp.X));
@@ -353,8 +353,13 @@ const AVCodec ff_sbc_encoder = {
 .init  = sbc_encode_init,
 

[FFmpeg-devel] [PATCH 254/281] s302m: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/s302m.c| 31 +++
 libavcodec/s302menc.c | 18 +-
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index b09c1293a0..868f2f99af 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -72,19 +72,25 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, 
const uint8_t *buf,
 else
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
-avctx->channels= channels;
+av_channel_layout_uninit(>ch_layout);
 switch(channels) {
 case 2:
-avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 break;
 case 4:
-avctx->channel_layout = AV_CH_LAYOUT_QUAD;
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD;
 break;
 case 6:
-avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK;
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK;
 break;
 case 8:
-avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | 
AV_CH_LAYOUT_STEREO_DOWNMIX;
+av_channel_layout_from_mask(>ch_layout,
+AV_CH_LAYOUT_5POINT1_BACK | 
AV_CH_LAYOUT_STEREO_DOWNMIX);
+break;
+default:
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = channels;
+break;
 }
 
 return frame_size;
@@ -97,7 +103,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void 
*data,
 AVFrame *frame = data;
 const uint8_t *buf = avpkt->data;
 int buf_size   = avpkt->size;
-int block_size, ret;
+int block_size, ret, channels;
 int i;
 int non_pcm_data_type = -1;
 
@@ -110,13 +116,14 @@ static int s302m_decode_frame(AVCodecContext *avctx, void 
*data,
 
 /* get output buffer */
 block_size = (avctx->bits_per_raw_sample + 4) / 4;
-frame->nb_samples = 2 * (buf_size / block_size) / avctx->channels;
+channels = avctx->ch_layout.nb_channels;
+frame->nb_samples = 2 * (buf_size / block_size) / channels;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 
-avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_raw_sample + 
4) +
+avctx->bit_rate = 48000 * channels * (avctx->bits_per_raw_sample + 4) +
   32 * 48000 / frame->nb_samples;
-buf_size = (frame->nb_samples * avctx->channels / 2) * block_size;
+buf_size = (frame->nb_samples * channels / 2) * block_size;
 
 if (avctx->bits_per_raw_sample == 24) {
 uint32_t *o = (uint32_t *)frame->data[0];
@@ -131,7 +138,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void 
*data,
 buf += 7;
 }
 o = (uint32_t *)frame->data[0];
-if (avctx->channels == 2)
+if (channels == 2)
 for (i=0; inb_samples * 2 - 6; i+=2) {
 if (o[i] || o[i+1] || o[i+2] || o[i+3])
 break;
@@ -152,7 +159,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void 
*data,
 buf += 6;
 }
 o = (uint32_t *)frame->data[0];
-if (avctx->channels == 2)
+if (channels == 2)
 for (i=0; inb_samples * 2 - 6; i+=2) {
 if (o[i] || o[i+1] || o[i+2] || o[i+3])
 break;
@@ -172,7 +179,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void 
*data,
 buf += 5;
 }
 o = (uint16_t *)frame->data[0];
-if (avctx->channels == 2)
+if (channels == 2)
 for (i=0; inb_samples * 2 - 6; i+=2) {
 if (o[i] || o[i+1] || o[i+2] || o[i+3])
 break;
diff --git a/libavcodec/s302menc.c b/libavcodec/s302menc.c
index 528d712e79..56db25c76b 100644
--- a/libavcodec/s302menc.c
+++ b/libavcodec/s302menc.c
@@ -37,10 +37,10 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx)
 {
 S302MEncContext *s = avctx->priv_data;
 
-if (avctx->channels & 1 || avctx->channels > 8) {
+if (avctx->ch_layout.nb_channels & 1 || avctx->ch_layout.nb_channels > 8) {
 av_log(avctx, AV_LOG_ERROR,
"Encoding %d channel(s) is not allowed. Only 2, 4, 6 and 8 
channels are supported.\n",
-   avctx->channels);
+   avctx->ch_layout.nb_channels);
 return AVERROR(EINVAL);
 }
 
@@ -61,7 +61,7 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx)
 }
 
 avctx->frame_size = 0;
-avctx->bit_rate   = 48000 * avctx->channels *
+avctx->bit_rate   = 48000 * avctx->ch_layout.nb_channels *
(avctx->bits_per_raw_sample + 4);
 s->framing_index  = 0;
 
@@ -72,9 +72,9 @@ static int 

[FFmpeg-devel] [PATCH 253/281] roqaudioenc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/roqaudioenc.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c
index 530e6b68d8..d482fd213a 100644
--- a/libavcodec/roqaudioenc.c
+++ b/libavcodec/roqaudioenc.c
@@ -54,8 +54,9 @@ static av_cold int roq_dpcm_encode_close(AVCodecContext 
*avctx)
 static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
 {
 ROQDPCMContext *context = avctx->priv_data;
+int channels = avctx->ch_layout.nb_channels;
 
-if (avctx->channels > 2) {
+if (channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n");
 return AVERROR(EINVAL);
 }
@@ -65,10 +66,10 @@ static av_cold int roq_dpcm_encode_init(AVCodecContext 
*avctx)
 }
 
 avctx->frame_size = ROQ_FRAME_SIZE;
-avctx->bit_rate   = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * avctx->channels) *
+avctx->bit_rate   = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * channels) *
 (22050 / ROQ_FRAME_SIZE) * 8;
 
-context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * avctx->channels *
+context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * channels *
   sizeof(*context->frame_buffer));
 if (!context->frame_buffer)
 return AVERROR(ENOMEM);
@@ -123,17 +124,18 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 {
 int i, stereo, data_size, ret;
 const int16_t *in = frame ? (const int16_t *)frame->data[0] : NULL;
+int channels = avctx->ch_layout.nb_channels;
 uint8_t *out;
 ROQDPCMContext *context = avctx->priv_data;
 
-stereo = (avctx->channels == 2);
+stereo = (channels == 2);
 
 if (!in && context->input_frames >= 8)
 return 0;
 
 if (in && context->input_frames < 8) {
-memcpy(>frame_buffer[context->buffered_samples * 
avctx->channels],
-   in, avctx->frame_size * avctx->channels * sizeof(*in));
+memcpy(>frame_buffer[context->buffered_samples * channels],
+   in, avctx->frame_size * channels * sizeof(*in));
 context->buffered_samples += avctx->frame_size;
 if (context->input_frames == 0)
 context->first_pts = frame->pts;
@@ -151,9 +153,9 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 }
 
 if (context->input_frames == 7)
-data_size = avctx->channels * context->buffered_samples;
+data_size = channels * context->buffered_samples;
 else
-data_size = avctx->channels * avctx->frame_size;
+data_size = channels * avctx->frame_size;
 
 ret = ff_get_encode_buffer(avctx, avpkt, ROQ_HEADER_SIZE + data_size, 0);
 if (ret < 0)
@@ -175,7 +177,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 *out++ = dpcm_predict(>lastSample[i & 1], *in++);
 
 avpkt->pts  = context->input_frames <= 7 ? context->first_pts : 
frame->pts;
-avpkt->duration = data_size / avctx->channels;
+avpkt->duration = data_size / channels;
 
 context->input_frames++;
 if (!in)
-- 
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 252/281] ralf: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/ralf.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ralf.c b/libavcodec/ralf.c
index bb80119b0c..eac3e60371 100644
--- a/libavcodec/ralf.c
+++ b/libavcodec/ralf.c
@@ -128,7 +128,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 {
 RALFContext *ctx = avctx->priv_data;
 int i, j, k;
-int ret;
+int ret, channels;
 
 if (avctx->extradata_size < 24 || memcmp(avctx->extradata, "LSD:", 4)) {
 av_log(avctx, AV_LOG_ERROR, "Extradata is not groovy, dude\n");
@@ -141,17 +141,17 @@ static av_cold int decode_init(AVCodecContext *avctx)
 return AVERROR_PATCHWELCOME;
 }
 
-avctx->channels= AV_RB16(avctx->extradata + 8);
+channels   = AV_RB16(avctx->extradata + 8);
 avctx->sample_rate = AV_RB32(avctx->extradata + 12);
-if (avctx->channels < 1 || avctx->channels > 2
+if (channels < 1 || channels > 2
 || avctx->sample_rate < 8000 || avctx->sample_rate > 96000) {
 av_log(avctx, AV_LOG_ERROR, "Invalid coding parameters %d Hz %d ch\n",
-   avctx->sample_rate, avctx->channels);
+   avctx->sample_rate, channels);
 return AVERROR_INVALIDDATA;
 }
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
-avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
-   : AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, channels);
 
 ctx->max_frame_size = AV_RB32(avctx->extradata + 16);
 if (ctx->max_frame_size > (1 << 20) || !ctx->max_frame_size) {
@@ -358,7 +358,7 @@ static int decode_block(AVCodecContext *avctx, 
GetBitContext *gb,
 return AVERROR_INVALIDDATA;
 }
 
-if (avctx->channels > 1)
+if (avctx->ch_layout.nb_channels > 1)
 dmode = get_bits(gb, 2) + 1;
 else
 dmode = 0;
@@ -368,7 +368,7 @@ static int decode_block(AVCodecContext *avctx, 
GetBitContext *gb,
 bits[0] = 16;
 bits[1] = (mode[1] == 2) ? 17 : 16;
 
-for (ch = 0; ch < avctx->channels; ch++) {
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
 if ((ret = decode_channel(ctx, gb, ch, len, mode[ch], bits[ch])) < 0)
 return ret;
 if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {
@@ -484,7 +484,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame_ptr,
 while (get_bits_left() > 0) {
 if (ctx->num_blocks >= FF_ARRAY_ELEMS(ctx->block_size))
 return AVERROR_INVALIDDATA;
-ctx->block_size[ctx->num_blocks] = get_bits(, 13 + avctx->channels);
+ctx->block_size[ctx->num_blocks] = get_bits(, 13 + 
avctx->ch_layout.nb_channels);
 if (get_bits1()) {
 ctx->block_pts[ctx->num_blocks] = get_bits(, 9);
 } else {
-- 
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 251/281] ra288: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/ra288.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 4310ccdf20..424601991a 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -67,8 +67,8 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx)
 RA288Context *ractx = avctx->priv_data;
 AVFloatDSPContext *fdsp;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
 if (avctx->block_align != 38) {
-- 
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 250/281] ra144: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/ra144dec.c | 4 ++--
 libavcodec/ra144enc.c | 8 +++-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ra144dec.c b/libavcodec/ra144dec.c
index b6272b343b..86d0d6e889 100644
--- a/libavcodec/ra144dec.c
+++ b/libavcodec/ra144dec.c
@@ -39,8 +39,8 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx)
 ractx->lpc_coef[0] = ractx->lpc_tables[0];
 ractx->lpc_coef[1] = ractx->lpc_tables[1];
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
 return 0;
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 7a96354633..19d46ffe0c 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -51,11 +51,6 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx)
 RA144Context *ractx;
 int ret;
 
-if (avctx->channels != 1) {
-av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n",
-   avctx->channels);
-return -1;
-}
 avctx->frame_size = NBLOCKS * BLOCKSIZE;
 avctx->initial_padding = avctx->frame_size;
 avctx->bit_rate = 8000;
@@ -554,6 +549,9 @@ const AVCodec ff_ra_144_encoder = {
 .sample_fmts= (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
  AV_SAMPLE_FMT_NONE },
 .supported_samplerates = (const int[]){ 8000, 0 },
+#if FF_API_OLD_CHANNEL_LAYOUT
 .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO, 0 },
+#endif
+.ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } 
},
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
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 249/281] qdm2: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/qdm2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 5e4e741e59..de68e651cd 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -1687,13 +1687,13 @@ static av_cold int qdm2_decode_init(AVCodecContext 
*avctx)
 
 bytestream2_skip(, 4);
 
-avctx->channels = s->nb_channels = s->channels = bytestream2_get_be32();
+s->nb_channels = s->channels = bytestream2_get_be32();
 if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) {
 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
 return AVERROR_INVALIDDATA;
 }
-avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-   AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, s->channels);
 
 avctx->sample_rate = bytestream2_get_be32();
 avctx->bit_rate = bytestream2_get_be32();
-- 
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 248/281] qdmc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/qdmc.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c
index ae75ca524a..dfdd84870c 100644
--- a/libavcodec/qdmc.c
+++ b/libavcodec/qdmc.c
@@ -245,13 +245,14 @@ static av_cold int qdmc_decode_init(AVCodecContext *avctx)
 }
 bytestream2_skipu(, 4);
 
-avctx->channels = s->nb_channels = bytestream2_get_be32u();
+s->nb_channels = bytestream2_get_be32u();
 if (s->nb_channels <= 0 || s->nb_channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
 return AVERROR_INVALIDDATA;
 }
-avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-   AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = s->nb_channels == 2 ? 
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+ 
(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 avctx->sample_rate = bytestream2_get_be32u();
 avctx->bit_rate = bytestream2_get_be32u();
@@ -277,7 +278,7 @@ static av_cold int qdmc_decode_init(AVCodecContext *avctx)
 s->frame_size = 1 << s->frame_bits;
 s->subframe_size = s->frame_size >> 5;
 
-if (avctx->channels == 2)
+if (avctx->ch_layout.nb_channels == 2)
 x = 3 * x / 2;
 s->band_index = noise_bands_selector[FFMIN(6, llrint(floor(avctx->bit_rate 
* 3.0 / (double)x + 0.5)))];
 
-- 
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 247/281] qcelpdec: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/qcelpdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index b23013816b..9f3ef309db 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -87,8 +87,8 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx)
 QCELPContext *q = avctx->priv_data;
 int i;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
 for (i = 0; i < 10; i++)
-- 
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 243/281] on2avc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/on2avc.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index fa3eb4b219..1d5a9487b3 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -691,7 +691,7 @@ static int on2avc_reconstruct_channel_ext(On2AVCContext *c, 
AVFrame *dst, int of
 {
 int ch, i;
 
-for (ch = 0; ch < c->avctx->channels; ch++) {
+for (ch = 0; ch < c->avctx->ch_layout.nb_channels; ch++) {
 float *out   = (float*)dst->extended_data[ch] + offset;
 float *in= c->coeffs[ch];
 float *saved = c->delay[ch];
@@ -823,13 +823,13 @@ static int on2avc_decode_subframe(On2AVCContext *c, const 
uint8_t *buf,
 c->grouping[i] = !get_bits1();
 
 on2avc_read_ms_info(c, );
-for (i = 0; i < c->avctx->channels; i++)
+for (i = 0; i < c->avctx->ch_layout.nb_channels; i++)
 if ((ret = on2avc_read_channel_data(c, , i)) < 0)
 return AVERROR_INVALIDDATA;
-if (c->avctx->channels == 2 && c->ms_present)
+if (c->avctx->ch_layout.nb_channels == 2 && c->ms_present)
 on2avc_apply_ms(c);
 if (c->window_type < WINDOW_TYPE_EXT4) {
-for (i = 0; i < c->avctx->channels; i++)
+for (i = 0; i < c->avctx->ch_layout.nb_channels; i++)
 on2avc_reconstruct_channel(c, i, dst, offset);
 } else {
 on2avc_reconstruct_channel_ext(c, dst, offset);
@@ -910,21 +910,23 @@ static av_cold int on2avc_decode_init(AVCodecContext 
*avctx)
 On2AVCContext *c = avctx->priv_data;
 const uint8_t  *lens = ff_on2avc_cb_lens;
 const uint16_t *syms = ff_on2avc_cb_syms;
+int channels = avctx->ch_layout.nb_channels;
 int i, ret;
 
-if (avctx->channels > 2U) {
+if (channels > 2U) {
 avpriv_request_sample(avctx, "Decoding more than 2 channels");
 return AVERROR_PATCHWELCOME;
 }
 
 c->avctx = avctx;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
-avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
-   : AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (channels == 2) ? 
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+ 
(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 c->is_av500 = (avctx->codec_tag == 0x500);
 
-if (avctx->channels == 2)
+if (channels == 2)
 av_log(avctx, AV_LOG_WARNING,
"Stereo mode support is not good, patch is welcome\n");
 
@@ -936,7 +938,7 @@ static av_cold int on2avc_decode_init(AVCodecContext *avctx)
 for (; i < 128; i++)
 c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 0.5 - 0.01);
 
-if (avctx->sample_rate < 32000 || avctx->channels == 1)
+if (avctx->sample_rate < 32000 || channels == 1)
 memcpy(c->long_win, ff_on2avc_window_long_24000,
1024 * sizeof(*c->long_win));
 else
-- 
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 246/281] pcm: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/pcm-bluray.c  | 36 -
 libavcodec/pcm-dvd.c | 28 +++---
 libavcodec/pcm-dvdenc.c  | 27 -
 libavcodec/pcm.c | 39 ++--
 libavcodec/pcm_rechunk_bsf.c |  5 +++--
 5 files changed, 73 insertions(+), 62 deletions(-)

diff --git a/libavcodec/pcm-bluray.c b/libavcodec/pcm-bluray.c
index c2a6e82b1d..6250f25e72 100644
--- a/libavcodec/pcm-bluray.c
+++ b/libavcodec/pcm-bluray.c
@@ -54,14 +54,12 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
const uint8_t *header)
 {
 static const uint8_t bits_per_samples[4] = { 0, 16, 20, 24 };
-static const uint32_t channel_layouts[16] = {
-0, AV_CH_LAYOUT_MONO, 0, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_SURROUND,
-AV_CH_LAYOUT_2_1, AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_2_2,
-AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_7POINT0,
-AV_CH_LAYOUT_7POINT1, 0, 0, 0, 0
-};
-static const uint8_t channels[16] = {
-0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8, 0, 0, 0, 0
+static const AVChannelLayout channel_layouts[16] = {
+{ 0 }, AV_CHANNEL_LAYOUT_MONO, { 0 },
+AV_CHANNEL_LAYOUT_STEREO,  AV_CHANNEL_LAYOUT_SURROUND, 
AV_CHANNEL_LAYOUT_2_1,
+AV_CHANNEL_LAYOUT_4POINT0, AV_CHANNEL_LAYOUT_2_2,  
AV_CHANNEL_LAYOUT_5POINT0,
+AV_CHANNEL_LAYOUT_5POINT1, AV_CHANNEL_LAYOUT_7POINT0,  
AV_CHANNEL_LAYOUT_7POINT1,
+{ 0 }, { 0 }, { 0 }, { 0 },
 };
 uint8_t channel_layout = header[2] >> 4;
 
@@ -104,21 +102,21 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
  * differ from the actual meaningful number, e.g. mono audio still has two
  * channels, one being empty.
  */
-avctx->channel_layout  = channel_layouts[channel_layout];
-avctx->channels=channels[channel_layout];
-if (!avctx->channels) {
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = channel_layouts[channel_layout];
+if (!avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_ERROR, "reserved channel configuration (%d)\n",
channel_layout);
 return AVERROR_INVALIDDATA;
 }
 
-avctx->bit_rate = FFALIGN(avctx->channels, 2) * avctx->sample_rate *
+avctx->bit_rate = FFALIGN(avctx->ch_layout.nb_channels, 2) * 
avctx->sample_rate *
   avctx->bits_per_coded_sample;
 
 if (avctx->debug & FF_DEBUG_PICT_INFO)
 ff_dlog(avctx,
 "pcm_bluray_parse_header: %d channels, %d bits per sample, %d 
Hz, %"PRId64" bit/s\n",
-avctx->channels, avctx->bits_per_coded_sample,
+avctx->ch_layout.nb_channels, avctx->bits_per_coded_sample,
 avctx->sample_rate, avctx->bit_rate);
 return 0;
 }
@@ -148,7 +146,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, 
void *data,
 bytestream2_init(, src, buf_size);
 
 /* There's always an even number of channels in the source */
-num_source_channels = FFALIGN(avctx->channels, 2);
+num_source_channels = FFALIGN(avctx->ch_layout.nb_channels, 2);
 sample_size = (num_source_channels *
(avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
 samples = buf_size / sample_size;
@@ -161,7 +159,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, 
void *data,
 dst32 = (int32_t *)frame->data[0];
 
 if (samples) {
-switch (avctx->channel_layout) {
+switch (avctx->ch_layout.u.mask) {
 /* cases with same number of source and coded channels */
 case AV_CH_LAYOUT_STEREO:
 case AV_CH_LAYOUT_4POINT0:
@@ -189,10 +187,10 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, 
void *data,
 if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
 do {
 #if HAVE_BIGENDIAN
-bytestream2_get_buffer(, dst16, avctx->channels * 2);
-dst16 += avctx->channels;
+bytestream2_get_buffer(, dst16, 
avctx->ch_layout.nb_channels * 2);
+dst16 += avctx->ch_layout.nb_channels;
 #else
-channel = avctx->channels;
+channel = avctx->ch_layout.nb_channels;
 do {
 *dst16++ = bytestream2_get_be16u();
 } while (--channel);
@@ -201,7 +199,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, 
void *data,
 } while (--samples);
 } else {
 do {
-channel = avctx->channels;
+channel = avctx->ch_layout.nb_channels;
 do {
 *dst32++ = bytestream2_get_be24u() << 8;
 } while 

[FFmpeg-devel] [PATCH 242/281] nellymoser: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/nellymoserdec.c | 4 ++--
 libavcodec/nellymoserenc.c | 6 +-
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index ccfe881790..6870ffea0e 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -129,8 +129,8 @@ static av_cold int decode_init(AVCodecContext * avctx) {
 s->scale_bias = 1.0/(32768*8);
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 /* Generate overlap window */
 ff_init_ff_sine_windows(7);
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 41d9117065..abf7d82160 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -171,11 +171,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
 NellyMoserEncodeContext *s = avctx->priv_data;
 int ret;
 
-if (avctx->channels != 1) {
-av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n");
-return AVERROR(EINVAL);
-}
-
 if (avctx->sample_rate != 8000 && avctx->sample_rate != 16000 &&
 avctx->sample_rate != 11025 &&
 avctx->sample_rate != 22050 && avctx->sample_rate != 44100 &&
@@ -431,5 +426,6 @@ const AVCodec ff_nellymoser_encoder = {
 .close  = encode_end,
 .sample_fmts= (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
  AV_SAMPLE_FMT_NONE },
+.ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } 
},
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
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 245/281] pafaudio: convert to new channel layout API

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: James Almer 
---
 libavcodec/pafaudio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pafaudio.c b/libavcodec/pafaudio.c
index 969eb7fa97..8d0e65a829 100644
--- a/libavcodec/pafaudio.c
+++ b/libavcodec/pafaudio.c
@@ -29,12 +29,13 @@
 
 static av_cold int paf_audio_init(AVCodecContext *avctx)
 {
-if (avctx->channels != 2) {
+if (avctx->ch_layout.nb_channels != 2) {
 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
 return AVERROR_INVALIDDATA;
 }
 
-avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
 return 0;
-- 
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 244/281] opus: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/opus.c| 57 ++--
 libavcodec/opusdec.c |  4 +--
 libavcodec/opusenc.c | 15 ---
 libavcodec/opusenc_psy.c | 20 +++---
 4 files changed, 61 insertions(+), 35 deletions(-)

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index df8ba93fa9..c18ff47f71 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -296,14 +296,15 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 static const uint8_t default_channel_map[2] = { 0, 1 };
 
 int (*channel_reorder)(int, int) = channel_reorder_unknown;
+int channels = avctx->ch_layout.nb_channels;
 
 const uint8_t *extradata, *channel_map;
 int extradata_size;
-int version, channels, map_type, streams, stereo_streams, i, j;
-uint64_t layout;
+int version, map_type, streams, stereo_streams, i, j, ret;
+AVChannelLayout layout = { 0 };
 
 if (!avctx->extradata) {
-if (avctx->channels > 2) {
+if (channels > 2) {
 av_log(avctx, AV_LOG_ERROR,
"Multichannel configuration without extradata.\n");
 return AVERROR(EINVAL);
@@ -331,7 +332,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 if (avctx->internal)
 avctx->internal->skip_samples = avctx->delay;
 
-channels = avctx->extradata ? extradata[9] : (avctx->channels == 1) ? 1 : 
2;
+channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
 if (!channels) {
 av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the 
extradata\n");
 return AVERROR_INVALIDDATA;
@@ -346,9 +347,11 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 if (channels > 2) {
 av_log(avctx, AV_LOG_ERROR,
"Channel mapping 0 is only specified for up to 2 
channels\n");
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
-layout = (channels == 1) ? AV_CH_LAYOUT_MONO : 
AV_CH_LAYOUT_STEREO;
+layout = (channels == 1) ? 
(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+   
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 streams= 1;
 stereo_streams = channels - 1;
 channel_map= default_channel_map;
@@ -356,7 +359,8 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 if (extradata_size < 21 + channels) {
 av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
extradata_size);
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
 
 streams= extradata[19];
@@ -365,16 +369,18 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 streams + stereo_streams > 255) {
 av_log(avctx, AV_LOG_ERROR,
"Invalid stream/stereo stream count: %d/%d\n", streams, 
stereo_streams);
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
 
 if (map_type == 1) {
 if (channels > 8) {
 av_log(avctx, AV_LOG_ERROR,
"Channel mapping 1 is only specified for up to 8 
channels\n");
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
-layout = ff_vorbis_channel_layouts[channels - 1];
+av_channel_layout_copy(, _vorbis_ch_layouts[channels - 
1]);
 channel_reorder = channel_reorder_vorbis;
 } else if (map_type == 2) {
 int ambisonic_order = ff_sqrt(channels) - 1;
@@ -384,15 +390,20 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
"Channel mapping 2 is only specified for channel counts"
" which can be written as (n + 1)^2 or (n + 1)^2 + 2"
" for nonnegative integer n\n");
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
 if (channels > 227) {
 av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
-layout = 0;
-} else
-layout = 0;
+layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+layout.nb_channels = channels;
+} else {
+layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+layout.nb_channels = channels;
+}
 
 channel_map = extradata + 21;
 } else {
@@ -401,8 +412,10 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
 }
 
 s->channel_maps = av_calloc(channels, sizeof(*s->channel_maps));
-if 

[FFmpeg-devel] [PATCH 240/281] mpc8: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/mpc8.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index ae07093338..a0466ec135 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -169,8 +169,8 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
 c->frames = 1 << (get_bits(, 3) * 2);
 
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
-avctx->channel_layout = (channels==2) ? AV_CH_LAYOUT_STEREO : 
AV_CH_LAYOUT_MONO;
-avctx->channels = channels;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, channels);
 
 ff_thread_once(_static_once, mpc8_init_static);
 
@@ -358,7 +358,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void 
*data,
 
 ff_mpc_dequantize_and_synth(c, maxband - 1,
 (int16_t **)frame->extended_data,
-avctx->channels);
+avctx->ch_layout.nb_channels);
 
 c->cur_frame++;
 
-- 
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 241/281] mpegaudio: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/mp3_header_decompress_bsf.c |  2 +-
 libavcodec/mpegaudio_parser.c  |  4 +++-
 libavcodec/mpegaudiodec_template.c | 22 --
 libavcodec/mpegaudioenc_fixed.c|  5 +
 libavcodec/mpegaudioenc_float.c|  5 +
 libavcodec/mpegaudioenc_template.c |  2 +-
 6 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/libavcodec/mp3_header_decompress_bsf.c 
b/libavcodec/mp3_header_decompress_bsf.c
index ebf6bde1c2..0fd8b3a454 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -98,7 +98,7 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket 
*out)
 }
 memcpy(out->data + frame_size - buf_size, buf, buf_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
 
-if(ctx->par_in->channels==2){
+if (ctx->par_in->ch_layout.nb_channels == 2){
 uint8_t *p= out->data + frame_size - buf_size;
 if(lsf){
 FFSWAP(int, p[1], p[2]);
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 2549503d35..6f1272117b 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -84,7 +84,9 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
 
 if (s->header_count > header_threshold) {
 avctx->sample_rate= sr;
-avctx->channels   = channels;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = channels;
 s1->duration  = frame_size;
 avctx->codec_id   = codec_id;
 if (s->no_bitrate || !avctx->bit_rate) {
diff --git a/libavcodec/mpegaudiodec_template.c 
b/libavcodec/mpegaudiodec_template.c
index bbb6ff1120..30b315c450 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1580,8 +1580,9 @@ static int decode_frame(AVCodecContext * avctx, void 
*data, int *got_frame_ptr,
 return AVERROR_INVALIDDATA;
 }
 /* update codec info */
-avctx->channels   = s->nb_channels;
-avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : 
AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = s->nb_channels == 1 ? 
(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+ 
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 if (!avctx->bit_rate)
 avctx->bit_rate = s->bit_rate;
 
@@ -1661,8 +1662,9 @@ static int decode_frame_adu(AVCodecContext *avctx, void 
*data,
 }
 /* update codec info */
 avctx->sample_rate = s->sample_rate;
-avctx->channels= s->nb_channels;
-avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : 
AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = s->nb_channels == 1 ? 
(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+ 
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 if (!avctx->bit_rate)
 avctx->bit_rate = s->bit_rate;
 
@@ -1756,8 +1758,8 @@ static av_cold int decode_init_mp3on4(AVCodecContext * 
avctx)
 }
 s->frames = mp3Frames[cfg.chan_config];
 s->coff   = chan_offset[cfg.chan_config];
-avctx->channels   = ff_mpeg4audio_channels[cfg.chan_config];
-avctx->channel_layout = chan_layout[cfg.chan_config];
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_from_mask(>ch_layout, 
chan_layout[cfg.chan_config]);
 
 if (cfg.sample_rate < 16000)
 s->syncword = 0xffe0;
@@ -1854,8 +1856,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, 
void *data,
 return AVERROR_INVALIDDATA;
 }
 
-if (ch + m->nb_channels > avctx->channels ||
-s->coff[fr] + m->nb_channels > avctx->channels) {
+if (ch + m->nb_channels > avctx->ch_layout.nb_channels ||
+s->coff[fr] + m->nb_channels > avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
 "channel count\n");
 return AVERROR_INVALIDDATA;
@@ -1880,7 +1882,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, 
void *data,
 
 avctx->bit_rate += m->bit_rate;
 }
-if (ch != avctx->channels) {
+if (ch != avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_ERROR, "failed to decode all channels\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1888,7 +1890,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, 
void *data,
 /* update codec info */
 avctx->sample_rate = s->mp3decctx[0]->sample_rate;
 
-frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT));
+frame->nb_samples = out_size / 

[FFmpeg-devel] [PATCH 239/281] mpc7: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/mpc7.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index c1a63203d6..c3ca9cfe31 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -79,8 +79,8 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
 LOCAL_ALIGNED_16(uint8_t, buf, [16]);
 
 /* Musepack SV7 is always stereo */
-if (avctx->channels != 2) {
-avpriv_request_sample(avctx, "%d channels", avctx->channels);
+if (avctx->ch_layout.nb_channels != 2) {
+avpriv_request_sample(avctx, "%d channels", 
avctx->ch_layout.nb_channels);
 return AVERROR_PATCHWELCOME;
 }
 
@@ -110,7 +110,8 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
 c->frames_to_skip = 0;
 
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
-avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 
 ff_thread_once(_static_once, mpc7_init_static);
 
-- 
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 238/281] mlp: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/mlp.c|   9 +++
 libavcodec/mlp.h|   5 ++
 libavcodec/mlp_parser.c |  12 ++--
 libavcodec/mlpdec.c | 120 +++-
 libavcodec/mlpenc.c | 106 ++-
 5 files changed, 153 insertions(+), 99 deletions(-)

diff --git a/libavcodec/mlp.c b/libavcodec/mlp.c
index dcec145eb0..3f54b2e448 100644
--- a/libavcodec/mlp.c
+++ b/libavcodec/mlp.c
@@ -57,12 +57,21 @@ const ChannelInformation ff_mlp_ch_info[21] = {
 { 0x3F, 0x04, 0x02, 0x00 },
 };
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 const uint64_t ff_mlp_channel_layouts[12] = {
 AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_2_1,
 AV_CH_LAYOUT_QUAD, AV_CH_LAYOUT_2POINT1, AV_CH_LAYOUT_SURROUND,
 AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_3POINT1,
 AV_CH_LAYOUT_4POINT1, AV_CH_LAYOUT_5POINT1_BACK, 0,
 };
+#endif
+
+const AVChannelLayout ff_mlp_ch_layouts[12] = {
+AV_CHANNEL_LAYOUT_MONO, AV_CHANNEL_LAYOUT_STEREO, AV_CHANNEL_LAYOUT_2_1,
+AV_CHANNEL_LAYOUT_QUAD, AV_CHANNEL_LAYOUT_2POINT1, 
AV_CHANNEL_LAYOUT_SURROUND,
+AV_CHANNEL_LAYOUT_4POINT0, AV_CHANNEL_LAYOUT_5POINT0_BACK, 
AV_CHANNEL_LAYOUT_3POINT1,
+AV_CHANNEL_LAYOUT_4POINT1, AV_CHANNEL_LAYOUT_5POINT1_BACK, { 0 },
+};
 
 #if CONFIG_SMALL
 #define CRC_TABLE_SIZE 257
diff --git a/libavcodec/mlp.h b/libavcodec/mlp.h
index e45eba55ae..8a3e4566a3 100644
--- a/libavcodec/mlp.h
+++ b/libavcodec/mlp.h
@@ -24,6 +24,8 @@
 
 #include 
 
+#include "libavutil/channel_layout.h"
+
 #define SYNC_MLP0xbb
 #define SYNC_TRUEHD 0xba
 
@@ -135,7 +137,10 @@ typedef struct {
  */
 extern const ChannelInformation ff_mlp_ch_info[21];
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 extern const uint64_t ff_mlp_channel_layouts[12];
+#endif
+extern const AVChannelLayout ff_mlp_ch_layouts[12];
 
 /** MLP uses checksums that seem to be based on the standard CRC algorithm, but
  *  are not (in implementation terms, the table lookup and XOR are reversed).
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index 9fea7db955..d391390dd5 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -175,22 +175,18 @@ static int mlp_parse(AVCodecParserContext *s,
 avctx->frame_size =
 s->duration = mh.access_unit_size;
 
-if(!avctx->channels || !avctx->channel_layout) {
+av_channel_layout_uninit(>ch_layout);
 if (mh.stream_type == 0xbb) {
 /* MLP stream */
-avctx->channels   = mh.channels_mlp;
-avctx->channel_layout = mh.channel_layout_mlp;
+av_channel_layout_from_mask(>ch_layout, 
mh.channel_layout_mlp);
 } else { /* mh.stream_type == 0xba */
 /* TrueHD stream */
 if (!mh.channels_thd_stream2) {
-avctx->channels   = mh.channels_thd_stream1;
-avctx->channel_layout = mh.channel_layout_thd_stream1;
+av_channel_layout_from_mask(>ch_layout, 
mh.channel_layout_thd_stream1);
 } else {
-avctx->channels   = mh.channels_thd_stream2;
-avctx->channel_layout = mh.channel_layout_thd_stream2;
+av_channel_layout_from_mask(>ch_layout, 
mh.channel_layout_thd_stream2);
 }
 }
-}
 
 if (!mh.is_vbr) /* Stream is CBR */
 avctx->bit_rate = mh.peak_bitrate;
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 29fac54542..d4b8226ec6 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -32,6 +32,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/thread.h"
+#include "libavutil/opt.h"
 #include "get_bits.h"
 #include "internal.h"
 #include "libavutil/crc.h"
@@ -132,8 +133,11 @@ typedef struct SubStream {
 } SubStream;
 
 typedef struct MLPDecodeContext {
+const AVClass  *class;
 AVCodecContext *avctx;
 
+AVChannelLayout downmix_layout;
+
 /// Current access unit being read has a major sync.
 int is_major_sync_unit;
 
@@ -169,39 +173,41 @@ typedef struct MLPDecodeContext {
 MLPDSPContext dsp;
 } MLPDecodeContext;
 
-static const uint64_t thd_channel_order[] = {
-AV_CH_FRONT_LEFT, AV_CH_FRONT_RIGHT, // LR
-AV_CH_FRONT_CENTER,  // C
-AV_CH_LOW_FREQUENCY, // LFE
-AV_CH_SIDE_LEFT, AV_CH_SIDE_RIGHT,   // LRs
-AV_CH_TOP_FRONT_LEFT, AV_CH_TOP_FRONT_RIGHT, // LRvh
-AV_CH_FRONT_LEFT_OF_CENTER, AV_CH_FRONT_RIGHT_OF_CENTER, // LRc
-AV_CH_BACK_LEFT, AV_CH_BACK_RIGHT,   // LRrs
-AV_CH_BACK_CENTER,   // Cs
-AV_CH_TOP_CENTER,// Ts
-AV_CH_SURROUND_DIRECT_LEFT, AV_CH_SURROUND_DIRECT_RIGHT, // LRsd
-AV_CH_WIDE_LEFT, AV_CH_WIDE_RIGHT,

[FFmpeg-devel] [PATCH 237/281] mf: convert to new channel layout API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/mfenc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 410ad64d8d..043026112a 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -288,7 +288,7 @@ static IMFSample *mf_a_avframe_to_sample(AVCodecContext 
*avctx, const AVFrame *f
 size_t bps;
 IMFSample *sample;
 
-bps = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->channels;
+bps = av_get_bytes_per_sample(avctx->sample_fmt) * 
avctx->ch_layout.nb_channels;
 len = frame->nb_samples * bps;
 
 sample = ff_create_memory_sample(frame->data[0], len, 
c->in_info.cbAlignment);
@@ -536,7 +536,7 @@ static int64_t mf_enca_output_score(AVCodecContext *avctx, 
IMFMediaType *type)
 score |= 1LL << 32;
 
 hr = IMFAttributes_GetUINT32(type, _MT_AUDIO_NUM_CHANNELS, );
-if (!FAILED(hr) && t == avctx->channels)
+if (!FAILED(hr) && t == avctx->ch_layout.nb_channels)
 score |= 2LL << 32;
 
 hr = IMFAttributes_GetGUID(type, _MT_SUBTYPE, );
@@ -591,7 +591,7 @@ static int64_t mf_enca_input_score(AVCodecContext *avctx, 
IMFMediaType *type)
 score |= 2;
 
 hr = IMFAttributes_GetUINT32(type, _MT_AUDIO_NUM_CHANNELS, );
-if (!FAILED(hr) && t == avctx->channels)
+if (!FAILED(hr) && t == avctx->ch_layout.nb_channels)
 score |= 4;
 
 return score;
@@ -615,7 +615,7 @@ static int mf_enca_input_adjust(AVCodecContext *avctx, 
IMFMediaType *type)
 }
 
 hr = IMFAttributes_GetUINT32(type, _MT_AUDIO_NUM_CHANNELS, );
-if (FAILED(hr) || t != avctx->channels) {
+if (FAILED(hr) || t != avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_ERROR, "unsupported input channel number set\n");
 return AVERROR(EINVAL);
 }
-- 
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 236/281] metasound: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/metasound.c | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/libavcodec/metasound.c b/libavcodec/metasound.c
index 57851a43c5..32d5e153be 100644
--- a/libavcodec/metasound.c
+++ b/libavcodec/metasound.c
@@ -65,8 +65,9 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, 
int g_coef,
const float *shape, float *speech)
 {
 const TwinVQModeTab *mtab = tctx->mtab;
+int channels = tctx->avctx->ch_layout.nb_channels;
 int isampf   = tctx->avctx->sample_rate / 1000;
-int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels);
+int ibps = tctx->avctx->bit_rate / (1000 * channels);
 int width;
 
 float ratio = (float)mtab->size / isampf;
@@ -75,7 +76,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, 
int g_coef,
 
 float pgain_base, pgain_step, ppc_gain;
 
-if (tctx->avctx->channels == 1) {
+if (channels == 1) {
 min_period = log2(ratio * 0.2);
 max_period = min_period + log2(6);
 } else {
@@ -85,7 +86,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, 
int g_coef,
 period_range = max_period - min_period;
 period   = min_period + period_coef * period_range /
((1 << mtab->ppc_period_bit) - 1);
-if (tctx->avctx->channels == 1)
+if (channels == 1)
 period = powf(2.0, period);
 else
 period = (int)(period * 400 + 0.5) / 400.0;
@@ -103,7 +104,7 @@ static void decode_ppc(TwinVQContext *tctx, int 
period_coef, int g_coef,
 if (isampf == 22 && ibps == 32)
 width = (int)((2.0 / period + 1) * width + 0.5);
 
-pgain_base = tctx->avctx->channels == 2 ? 25000.0 : 2.0;
+pgain_base = channels == 2 ? 25000.0 : 2.0;
 pgain_step = pgain_base / ((1 << mtab->pgain_bit) - 1);
 ppc_gain   = 1.0 / 8192 *
  twinvq_mulawinv(pgain_step * g_coef + pgain_step / 2,
@@ -123,8 +124,9 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t 
*in, int use_hist,
 int bark_n_coef = mtab->fmode[ftype].bark_n_coef;
 int fw_cb_len   = mtab->fmode[ftype].bark_env_size / bark_n_coef;
 int idx = 0;
+int channels= tctx->avctx->ch_layout.nb_channels;
 
-if (tctx->avctx->channels == 1)
+if (channels == 1)
 val = 0.5;
 for (i = 0; i < fw_cb_len; i++)
 for (j = 0; j < bark_n_coef; j++, idx++) {
@@ -132,7 +134,7 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t 
*in, int use_hist,
  (1.0 / 2048);
 float st;
 
-if (tctx->avctx->channels == 1)
+if (channels == 1)
 st = use_hist ?
 tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0;
 else
@@ -167,7 +169,7 @@ static int metasound_read_bitstream(AVCodecContext *avctx, 
TwinVQContext *tctx,
 {
 TwinVQFrameData *bits;
 const TwinVQModeTab *mtab = tctx->mtab;
-int channels  = tctx->avctx->channels;
+int channels  = tctx->avctx->ch_layout.nb_channels;
 int sub;
 GetBitContext gb;
 int i, j, k, ret;
@@ -276,6 +278,7 @@ static av_cold int metasound_decode_init(AVCodecContext 
*avctx)
 TwinVQContext *tctx = avctx->priv_data;
 uint32_t tag;
 const MetasoundProps *props = codec_props;
+int channels;
 
 if (!avctx->extradata || avctx->extradata_size < 16) {
 av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
@@ -291,7 +294,7 @@ static av_cold int metasound_decode_init(AVCodecContext 
*avctx)
 }
 if (props->tag == tag) {
 avctx->sample_rate = props->sample_rate;
-avctx->channels= props->channels;
+channels   = props->channels;
 avctx->bit_rate= props->bit_rate * 1000;
 isampf = avctx->sample_rate / 1000;
 break;
@@ -299,17 +302,17 @@ static av_cold int metasound_decode_init(AVCodecContext 
*avctx)
 props++;
 }
 
-if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
+if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) {
 av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
-   avctx->channels);
+   channels);
 return AVERROR_INVALIDDATA;
 }
-avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
- : AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_default(>ch_layout, channels);
 
-ibps = avctx->bit_rate / (1000 * avctx->channels);
+ibps = avctx->bit_rate / (1000 * channels);
 
-switch ((avctx->channels << 16) + (isampf << 8) + ibps) {
+switch ((channels << 16) + (isampf << 8) + ibps) {
 case (1 << 16) + ( 8 << 8) +  6:
  

[FFmpeg-devel] [PATCH 235/281] mace: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/mace.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index 506a0ddece..9ed4747ba9 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -226,7 +226,7 @@ static void chomp6(ChannelData *chd, int16_t *output, 
uint8_t val, int tab_idx)
 
 static av_cold int mace_decode_init(AVCodecContext * avctx)
 {
-if (avctx->channels > 2 || avctx->channels < 1)
+if (avctx->ch_layout.nb_channels > 2 || avctx->ch_layout.nb_channels < 1)
 return AVERROR(EINVAL);
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
 
@@ -239,31 +239,32 @@ static int mace_decode_frame(AVCodecContext *avctx, void 
*data,
 AVFrame *frame = data;
 const uint8_t *buf = avpkt->data;
 int buf_size = avpkt->size;
+int channels = avctx->ch_layout.nb_channels;
 int16_t **samples;
 MACEContext *ctx = avctx->priv_data;
 int i, j, k, l, ret;
 int is_mace3 = (avctx->codec_id == AV_CODEC_ID_MACE3);
 
-if (buf_size % (avctx->channels << is_mace3)) {
+if (buf_size % (channels << is_mace3)) {
 av_log(avctx, AV_LOG_ERROR, "buffer size %d is odd\n", buf_size);
-buf_size -= buf_size % (avctx->channels << is_mace3);
+buf_size -= buf_size % (channels << is_mace3);
 if (!buf_size)
 return AVERROR_INVALIDDATA;
 }
 
 /* get output buffer */
-frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels;
+frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / channels;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 samples = (int16_t **)frame->extended_data;
 
-for(i = 0; i < avctx->channels; i++) {
+for(i = 0; i < channels; i++) {
 int16_t *output = samples[i];
 
-for (j=0; j < buf_size / (avctx->channels << is_mace3); j++)
+for (j=0; j < buf_size / (channels << is_mace3); j++)
 for (k=0; k < (1 << is_mace3); k++) {
 uint8_t pkt = buf[(i << is_mace3) +
-  (j*avctx->channels << is_mace3) + k];
+  (j * channels << is_mace3) + k];
 
 uint8_t val[2][3] = {{pkt >> 5, (pkt >> 3) & 3, pkt & 7 },
  {pkt & 7 , (pkt >> 3) & 3, pkt >> 5}};
-- 
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 234/281] libvorbis: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libvorbisdec.c |  4 +++-
 libavcodec/libvorbisenc.c | 42 +++
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/libavcodec/libvorbisdec.c b/libavcodec/libvorbisdec.c
index 5686aaf096..7317b71ed6 100644
--- a/libavcodec/libvorbisdec.c
+++ b/libavcodec/libvorbisdec.c
@@ -112,7 +112,9 @@ static int oggvorbis_decode_init(AVCodecContext 
*avccontext) {
 }
 }
 
-avccontext->channels = context->vi.channels;
+av_channel_layout_uninit(>ch_layout);
+avccontext->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avccontext->ch_layout.nb_channels = context->vi.channels;
 avccontext->sample_rate = context->vi.rate;
 avccontext->sample_fmt = AV_SAMPLE_FMT_S16;
 avccontext->time_base= (AVRational){1, avccontext->sample_rate};
diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index fa0d5f4b42..640c7f1bf9 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -96,6 +96,7 @@ static int vorbis_error_to_averror(int ov_err)
 static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
 {
 LibvorbisEncContext *s = avctx->priv_data;
+int channels = avctx->ch_layout.nb_channels;
 double cfreq;
 int ret;
 
@@ -108,7 +109,7 @@ static av_cold int libvorbis_setup(vorbis_info *vi, 
AVCodecContext *avctx)
 /* default to 3 if the user did not set quality or bitrate */
 if (!(avctx->flags & AV_CODEC_FLAG_QSCALE))
 q = 3.0;
-if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels,
+if ((ret = vorbis_encode_setup_vbr(vi, channels,
avctx->sample_rate,
q / 10.0)))
 goto error;
@@ -117,7 +118,7 @@ static av_cold int libvorbis_setup(vorbis_info *vi, 
AVCodecContext *avctx)
 int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1;
 
 /* average bitrate */
-if ((ret = vorbis_encode_setup_managed(vi, avctx->channels,
+if ((ret = vorbis_encode_setup_managed(vi, channels,
avctx->sample_rate, maxrate,
avctx->bit_rate, minrate)))
 goto error;
@@ -141,32 +142,31 @@ static av_cold int libvorbis_setup(vorbis_info *vi, 
AVCodecContext *avctx)
 goto error;
 }
 
-if (avctx->channels == 3 &&
-avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) 
||
-avctx->channels == 4 &&
-avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
-avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
-avctx->channels == 5 &&
-avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
-avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
-avctx->channels == 6 &&
-avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
-avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
-avctx->channels == 7 &&
-avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) 
||
-avctx->channels == 8 &&
-avctx->channel_layout != AV_CH_LAYOUT_7POINT1) {
-if (avctx->channel_layout) {
+if ((channels == 3 &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND)) ||
+(channels == 4 &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2) &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD)) ||
+(channels == 5 &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0) &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) ||
+(channels == 6 &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1) &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK)) ||
+(channels == 7 &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1)) ||
+(channels == 8 &&
+ av_channel_layout_compare(>ch_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1))) {
+if (avctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
 char name[32];
-av_get_channel_layout_string(name, sizeof(name), avctx->channels,
- avctx->channel_layout);
+av_channel_layout_describe(>ch_layout, name, sizeof(name));
 av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: "
  "output stream will have 
incorrect "
  "channel layout.\n", name);
 } else {
 av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The 

[FFmpeg-devel] [PATCH 233/281] libvo-amrwbenc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libvo-amrwbenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 9c7c91b617..4beede0863 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -87,7 +87,7 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
 return AVERROR(ENOSYS);
 }
 
-if (avctx->channels != 1) {
+if (avctx->ch_layout.nb_channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
 return AVERROR(ENOSYS);
 }
-- 
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 232/281] libtwolame: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

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

diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c
index a71febc91f..9e1d589a0f 100644
--- a/libavcodec/libtwolame.c
+++ b/libavcodec/libtwolame.c
@@ -76,7 +76,7 @@ static av_cold int twolame_encode_init(AVCodecContext *avctx)
 twolame_set_copyright(s->glopts, s->copyright);
 twolame_set_original(s->glopts, s->original);
 
-twolame_set_num_channels(s->glopts, avctx->channels);
+twolame_set_num_channels(s->glopts, avctx->ch_layout.nb_channels);
 twolame_set_in_samplerate(s->glopts, avctx->sample_rate);
 twolame_set_out_samplerate(s->glopts, avctx->sample_rate);
 
-- 
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 231/281] libspeexdec: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libspeexdec.c | 19 ++-
 libavcodec/libspeexenc.c | 17 +
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c
index 6f032907fc..8029786b1f 100644
--- a/libavcodec/libspeexdec.c
+++ b/libavcodec/libspeexdec.c
@@ -42,7 +42,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
 LibSpeexContext *s = avctx->priv_data;
 const SpeexMode *mode;
 SpeexHeader *header = NULL;
-int spx_mode;
+int spx_mode, channels;
 
 if (avctx->extradata && avctx->extradata_size >= 80) {
 header = speex_packet_to_header(avctx->extradata,
@@ -68,7 +68,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
 spx_mode   = 0;
 } else if (header) {
 avctx->sample_rate = header->rate;
-avctx->channels= header->nb_channels;
+channels   = header->nb_channels;
 spx_mode   = header->mode;
 speex_header_free(header);
 } else {
@@ -94,14 +94,15 @@ static av_cold int libspeex_decode_init(AVCodecContext 
*avctx)
 if (!avctx->sample_rate)
 avctx->sample_rate = 8000 << spx_mode;
 
-if (avctx->channels < 1 || avctx->channels > 2) {
+if (channels < 1 || channels > 2) {
 /* libspeex can handle mono or stereo if initialized as stereo */
 av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d.\n"
-"Decoding as stereo.\n", avctx->channels);
-avctx->channels = 2;
+"Decoding as stereo.\n", channels);
+channels = 2;
 }
-avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-   AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = channels == 2 ? 
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+   (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 speex_bits_init(>bits);
 s->dec_state = speex_decoder_init(mode);
@@ -110,7 +111,7 @@ static av_cold int libspeex_decode_init(AVCodecContext 
*avctx)
 return -1;
 }
 
-if (avctx->channels == 2) {
+if (channels == 2) {
 SpeexCallback callback;
 callback.callback_id = SPEEX_INBAND_STEREO;
 callback.func = speex_std_stereo_request_handler;
@@ -163,7 +164,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, 
void *data,
 av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
 return AVERROR_INVALIDDATA;
 }
-if (avctx->channels == 2)
+if (avctx->ch_layout.nb_channels == 2)
 speex_decode_stereo_int(output, s->frame_size, >stereo);
 
 *got_frame_ptr = 1;
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index d095b41bee..058dafad39 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -28,8 +28,8 @@
  * order to control various encoding parameters.
  *
  * Channels
- * Speex only supports mono or stereo, so avctx->channels must be set to
- * 1 or 2.
+ * Speex only supports mono or stereo, so avctx->ch_layout.nb_channels must
+ * be set to 1 or 2.
  *
  * Sample Rate / Encoding Mode
  * Speex has 3 modes, each of which uses a specific sample rate.
@@ -114,7 +114,7 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
 {
 const char *mode_str = "unknown";
 
-av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->channels);
+av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", 
avctx->ch_layout.nb_channels);
 switch (s->header.mode) {
 case SPEEX_MODEID_NB:  mode_str = "narrowband"; break;
 case SPEEX_MODEID_WB:  mode_str = "wideband";   break;
@@ -146,15 +146,16 @@ static av_cold void print_enc_params(AVCodecContext 
*avctx,
 static av_cold int encode_init(AVCodecContext *avctx)
 {
 LibSpeexEncContext *s = avctx->priv_data;
+int channels = avctx->ch_layout.nb_channels;
 const SpeexMode *mode;
 uint8_t *header_data;
 int header_size;
 int32_t complexity;
 
 /* channels */
-if (avctx->channels < 1 || avctx->channels > 2) {
+if (channels < 1 || channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and "
-   "mono are supported\n", avctx->channels);
+   "mono are supported\n", channels);
 return AVERROR(EINVAL);
 }
 
@@ -175,7 +176,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n");
 return -1;
 }
-speex_init_header(>header, avctx->sample_rate, avctx->channels, mode);
+speex_init_header(>header, avctx->sample_rate, channels, mode);
 
 /* rate control method and parameters */
 if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
@@ -210,7 +211,7 @@ static av_cold int encode_init(AVCodecContext 

[FFmpeg-devel] [PATCH 230/281] libshine: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libshine.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libshine.c b/libavcodec/libshine.c
index fbc84846ae..ee8a63d66b 100644
--- a/libavcodec/libshine.c
+++ b/libavcodec/libshine.c
@@ -44,7 +44,7 @@ static av_cold int libshine_encode_init(AVCodecContext *avctx)
 {
 SHINEContext *s = avctx->priv_data;
 
-if (avctx->channels <= 0 || avctx->channels > 2){
+if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > 2){
 av_log(avctx, AV_LOG_ERROR, "only mono or stereo is supported\n");
 return AVERROR(EINVAL);
 }
@@ -52,9 +52,9 @@ static av_cold int libshine_encode_init(AVCodecContext *avctx)
 shine_set_config_mpeg_defaults(>config.mpeg);
 if (avctx->bit_rate)
 s->config.mpeg.bitr = avctx->bit_rate / 1000;
-s->config.mpeg.mode = avctx->channels == 2 ? STEREO : MONO;
+s->config.mpeg.mode = avctx->ch_layout.nb_channels == 2 ? STEREO : MONO;
 s->config.wave.samplerate = avctx->sample_rate;
-s->config.wave.channels   = avctx->channels == 2 ? PCM_STEREO : PCM_MONO;
+s->config.wave.channels   = avctx->ch_layout.nb_channels == 2 ? PCM_STEREO 
: PCM_MONO;
 if (shine_check_config(s->config.wave.samplerate, s->config.mpeg.bitr) < 
0) {
 av_log(avctx, AV_LOG_ERROR, "invalid configuration\n");
 return AVERROR(EINVAL);
-- 
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 229/281] libopus: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libopusdec.c  | 39 +---
 libavcodec/libopusenc.c  | 65 ++--
 libavcodec/vorbis.h  |  3 ++
 libavcodec/vorbis_data.c | 18 +++
 4 files changed, 79 insertions(+), 46 deletions(-)

diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index 86ef715205..abffd5f463 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -50,55 +50,60 @@ struct libopus_context {
 static av_cold int libopus_decode_init(AVCodecContext *avc)
 {
 struct libopus_context *opus = avc->priv_data;
-int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
+int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled, channels;
 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
 
-avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : 
(avc->channels == 1) ? 1 : 2;
-if (avc->channels <= 0) {
+channels = avc->extradata_size >= 10 ? avc->extradata[9] : (channels == 1) 
? 1 : 2;
+if (channels <= 0) {
 av_log(avc, AV_LOG_WARNING,
-   "Invalid number of channels %d, defaulting to stereo\n", 
avc->channels);
-avc->channels = 2;
+   "Invalid number of channels %d, defaulting to stereo\n", 
channels);
+channels = 2;
 }
 
 avc->sample_rate= 48000;
 avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
   AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
-avc->channel_layout = avc->channels > 8 ? 0 :
-  ff_vorbis_channel_layouts[avc->channels - 1];
+av_channel_layout_uninit(>ch_layout);
+if (channels > 8) {
+avc->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avc->ch_layout.nb_channels = channels;
+} else {
+av_channel_layout_copy(>ch_layout, _vorbis_ch_layouts[channels 
- 1]);
+}
 
 if (avc->extradata_size >= OPUS_HEAD_SIZE) {
 opus->pre_skip = AV_RL16(avc->extradata + 10);
 gain_db = sign_extend(AV_RL16(avc->extradata + 16), 16);
 channel_map = AV_RL8 (avc->extradata + 18);
 }
-if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
+if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + channels) {
 nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];
 nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];
-if (nb_streams + nb_coupled != avc->channels)
+if (nb_streams + nb_coupled != channels)
 av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
 mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
 } else {
-if (avc->channels > 2 || channel_map) {
+if (channels > 2 || channel_map) {
 av_log(avc, AV_LOG_ERROR,
-   "No channel mapping for %d channels.\n", avc->channels);
+   "No channel mapping for %d channels.\n", channels);
 return AVERROR(EINVAL);
 }
 nb_streams = 1;
-nb_coupled = avc->channels > 1;
+nb_coupled = channels > 1;
 mapping= mapping_arr;
 }
 
-if (avc->channels > 2 && avc->channels <= 8) {
-const uint8_t *vorbis_offset = 
ff_vorbis_channel_layout_offsets[avc->channels - 1];
+if (channels > 2 && channels <= 8) {
+const uint8_t *vorbis_offset = 
ff_vorbis_channel_layout_offsets[channels - 1];
 int ch;
 
 /* Remap channels from Vorbis order to ffmpeg order */
-for (ch = 0; ch < avc->channels; ch++)
+for (ch = 0; ch < channels; ch++)
 mapping_arr[ch] = mapping[vorbis_offset[ch]];
 mapping = mapping_arr;
 }
 
-opus->dec = opus_multistream_decoder_create(avc->sample_rate, 
avc->channels,
+opus->dec = opus_multistream_decoder_create(avc->sample_rate, channels,
 nb_streams, nb_coupled,
 mapping, );
 if (!opus->dec) {
@@ -178,7 +183,7 @@ static int libopus_decode(AVCodecContext *avc, void *data,
 
 #ifndef OPUS_SET_GAIN
 {
-int i = avc->channels * nb_samples;
+int i = avc->ch_layout.nb_channels * nb_samples;
 if (avc->sample_fmt == AV_SAMPLE_FMT_FLT) {
 float *pcm = (float *)frame->data[0];
 for (; i > 0; i--, pcm++)
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 45b23fcbb5..401a2c17c8 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -91,7 +91,7 @@ static void libopus_write_header(AVCodecContext *avctx, int 
stream_count,
  const uint8_t *channel_mapping)
 {
 uint8_t *p   = avctx->extradata;
-int channels = avctx->channels;
+int channels = avctx->ch_layout.nb_channels;
 
 bytestream_put_buffer(, "OpusHead", 8);
 bytestream_put_byte(, 1); /* Version */
@@ -180,9 +180,9 @@ static int libopus_configure_encoder(AVCodecContext *avctx, 

[FFmpeg-devel] [PATCH 228/281] libopencore-amr: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/libopencore-amr.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 2df1c5090f..aa5f0e774e 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -38,13 +38,13 @@ static int amr_decode_fix_avctx(AVCodecContext *avctx)
 if (!avctx->sample_rate)
 avctx->sample_rate = 8000 * is_amr_wb;
 
-if (avctx->channels > 1) {
+if (avctx->ch_layout.nb_channels > 1) {
 avpriv_report_missing_feature(avctx, "multi-channel AMR");
 return AVERROR_PATCHWELCOME;
 }
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 return 0;
 }
@@ -201,7 +201,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 return AVERROR(ENOSYS);
 }
 
-if (avctx->channels != 1) {
+if (avctx->ch_layout.nb_channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
 return AVERROR(ENOSYS);
 }
-- 
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 227/281] libmp3lame: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libmp3lame.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 5675864bb2..36ae57eb83 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -101,8 +101,9 @@ static av_cold int mp3lame_encode_init(AVCodecContext 
*avctx)
 return AVERROR(ENOMEM);
 
 
-lame_set_num_channels(s->gfp, avctx->channels);
-lame_set_mode(s->gfp, avctx->channels > 1 ? s->joint_stereo ? JOINT_STEREO 
: STEREO : MONO);
+lame_set_num_channels(s->gfp, avctx->ch_layout.nb_channels);
+lame_set_mode(s->gfp, avctx->ch_layout.nb_channels > 1 ?
+  s->joint_stereo ? JOINT_STEREO : STEREO : MONO);
 
 /* sample rate */
 lame_set_in_samplerate (s->gfp, avctx->sample_rate);
@@ -151,7 +152,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext 
*avctx)
 /* allocate float sample buffers */
 if (avctx->sample_fmt == AV_SAMPLE_FMT_FLTP) {
 int ch;
-for (ch = 0; ch < avctx->channels; ch++) {
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
 s->samples_flt[ch] = av_malloc_array(avctx->frame_size,
sizeof(*s->samples_flt[ch]));
 if (!s->samples_flt[ch]) {
@@ -208,7 +209,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 av_log(avctx, AV_LOG_ERROR, "inadequate AVFrame plane 
padding\n");
 return AVERROR(EINVAL);
 }
-for (ch = 0; ch < avctx->channels; ch++) {
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
 s->fdsp->vector_fmul_scalar(s->samples_flt[ch],
(const float *)frame->data[ch],
32768.0f,
-- 
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 226/281] libgsm: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/libgsmdec.c | 4 ++--
 libavcodec/libgsmenc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libgsmdec.c b/libavcodec/libgsmdec.c
index ae4a952d99..aa028bc262 100644
--- a/libavcodec/libgsmdec.c
+++ b/libavcodec/libgsmdec.c
@@ -48,8 +48,8 @@ typedef struct LibGSMDecodeContext {
 static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
 LibGSMDecodeContext *s = avctx->priv_data;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 if (!avctx->sample_rate)
 avctx->sample_rate = 8000;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c
index a2f6c1c62e..f73f254d50 100644
--- a/libavcodec/libgsmenc.c
+++ b/libavcodec/libgsmenc.c
@@ -49,9 +49,9 @@ static av_cold int libgsm_encode_close(AVCodecContext *avctx) 
{
 }
 
 static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
-if (avctx->channels > 1) {
+if (avctx->ch_layout.nb_channels > 1) {
 av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
-   avctx->channels);
+   avctx->ch_layout.nb_channels);
 return -1;
 }
 
-- 
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 225/281] libilbc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/libilbc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c
index 04192e3045..cfffe7d520 100644
--- a/libavcodec/libilbc.c
+++ b/libavcodec/libilbc.c
@@ -78,8 +78,8 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
 
 WebRtcIlbcfix_InitDecode(>decoder, mode, s->enhance);
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_rate= 8000;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
@@ -161,7 +161,7 @@ static av_cold int ilbc_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (avctx->channels != 1) {
+if (avctx->ch_layout.nb_channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
 return AVERROR(EINVAL);
 }
-- 
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 224/281] libfdk-aac: convert to new channel layout API

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/libfdk-aacdec.c | 32 
 libavcodec/libfdk-aacenc.c | 35 +++
 2 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
index ffa1fdcce3..1a38aefff9 100644
--- a/libavcodec/libfdk-aacdec.c
+++ b/libavcodec/libfdk-aacdec.c
@@ -58,6 +58,7 @@ typedef struct FDKAACDecContext {
 int drc_cut;
 int level_limit;
 int output_delay;
+AVChannelLayout downmix_layout;
 } FDKAACDecContext;
 
 
@@ -88,6 +89,7 @@ static const AVOption fdk_aac_dec_options[] = {
 { "drc_effect","Dynamic Range Control: effect type, where e.g. [0] is none 
and [6] is general",
  OFFSET(drc_effect), AV_OPT_TYPE_INT,   { .i64 = -1},  
-1, 8,   AD, NULL},
 #endif
+{ "downmix", "Request a specific channel layout from the decoder", 
OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = AD },
 { NULL }
 };
 
@@ -197,17 +199,15 @@ static int get_stream_info(AVCodecContext *avctx)
 ch_error = 1;
 }
 }
-if (!ch_error &&
-av_get_channel_layout_nb_channels(ch_layout) != info->numChannels) {
+
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_from_mask(>ch_layout, ch_layout);
+if (!ch_error && avctx->ch_layout.nb_channels != info->numChannels) {
 av_log(avctx, AV_LOG_WARNING, "unsupported channel configuration\n");
 ch_error = 1;
 }
 if (ch_error)
-avctx->channel_layout = 0;
-else
-avctx->channel_layout = ch_layout;
-
-avctx->channels = info->numChannels;
+avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
 
 return 0;
 }
@@ -249,11 +249,19 @@ static av_cold int fdk_aac_decode_init(AVCodecContext 
*avctx)
 return AVERROR_UNKNOWN;
 }
 
-if (avctx->request_channel_layout > 0 &&
-avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (avctx->request_channel_layout) {
+av_channel_layout_uninit(>downmix_layout);
+av_channel_layout_from_mask(>downmix_layout, 
avctx->request_channel_layout);
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+if (s->downmix_layout.nb_channels > 0 &&
+s->downmix_layout.order != AV_CHANNEL_ORDER_NATIVE) {
 int downmix_channels = -1;
 
-switch (avctx->request_channel_layout) {
+switch (s->downmix_layout.u.mask) {
 case AV_CH_LAYOUT_STEREO:
 case AV_CH_LAYOUT_STEREO_DOWNMIX:
 downmix_channels = 2;
@@ -262,7 +270,7 @@ static av_cold int fdk_aac_decode_init(AVCodecContext 
*avctx)
 downmix_channels = 1;
 break;
 default:
-av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
+av_log(avctx, AV_LOG_WARNING, "Invalid downmix option\n");
 break;
 }
 
@@ -385,7 +393,7 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void 
*data,
avctx->time_base);
 
 memcpy(frame->extended_data[0], s->decoder_buffer,
-   avctx->channels * avctx->frame_size *
+   avctx->ch_layout.nb_channels * avctx->frame_size *
av_get_bytes_per_sample(avctx->sample_fmt));
 
 *got_frame_ptr = 1;
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 7ee2f13ac7..d43f45d9ee 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -128,7 +128,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
 int aot = FF_PROFILE_AAC_LOW + 1;
 int sce = 0, cpe = 0;
 
-if ((err = aacEncOpen(>handle, 0, avctx->channels)) != AACENC_OK) {
+if ((err = aacEncOpen(>handle, 0, avctx->ch_layout.nb_channels)) != 
AACENC_OK) {
 av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
aac_get_error(err));
 goto error;
@@ -159,7 +159,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
 goto error;
 }
 
-switch (avctx->channels) {
+switch (avctx->ch_layout.nb_channels) {
 case 1: mode = MODE_1;   sce = 1; cpe = 0; break;
 case 2:
 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
@@ -193,7 +193,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
 case 8:
 sce = 2;
 cpe = 3;
-if (avctx->channel_layout == AV_CH_LAYOUT_7POINT1) {
+if (avctx->ch_layout.u.mask == AV_CH_LAYOUT_7POINT1) {
 mode = MODE_7_1_REAR_SURROUND;
 } else {
 // MODE_1_2_2_2_1 and MODE_7_1_FRONT_CENTER use the same channel 
layout
@@ -203,7 +203,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
 #endif
 default:
 av_log(avctx, AV_LOG_ERROR,
-   "Unsupported number of channels %d\n", avctx->channels);
+   "Unsupported number of channels 

[FFmpeg-devel] [PATCH 223/281] libcodec2: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libcodec2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libcodec2.c b/libavcodec/libcodec2.c
index eb66867f82..da9e170d21 100644
--- a/libavcodec/libcodec2.c
+++ b/libavcodec/libcodec2.c
@@ -85,9 +85,9 @@ libcodec2_init_common_error:
 static av_cold int libcodec2_init_decoder(AVCodecContext *avctx)
 {
 avctx->sample_rate  = 8000;
-avctx->channels = 1;
 avctx->sample_fmt   = AV_SAMPLE_FMT_S16;
-avctx->channel_layout   = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 if (avctx->extradata_size != CODEC2_EXTRADATA_SIZE) {
 av_log(avctx, AV_LOG_ERROR, "must have exactly %i bytes of extradata 
(got %i)\n",
-- 
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 222/281] libcelt: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/libcelt_dec.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libcelt_dec.c b/libavcodec/libcelt_dec.c
index c0fb4013c9..6ee6e29443 100644
--- a/libavcodec/libcelt_dec.c
+++ b/libavcodec/libcelt_dec.c
@@ -61,13 +61,13 @@ static av_cold int libcelt_dec_init(AVCodecContext *c)
 struct libcelt_context *celt = c->priv_data;
 int err;
 
-if (!c->channels || !c->frame_size ||
-c->frame_size > INT_MAX / sizeof(int16_t) / c->channels)
+if (!c->ch_layout.nb_channels || !c->frame_size ||
+c->frame_size > INT_MAX / sizeof(int16_t) / c->ch_layout.nb_channels)
 return AVERROR(EINVAL);
 celt->mode = celt_mode_create(c->sample_rate, c->frame_size, );
 if (!celt->mode)
 return ff_celt_error_to_averror(err);
-celt->dec = celt_decoder_create_custom(celt->mode, c->channels, );
+celt->dec = celt_decoder_create_custom(celt->mode, 
c->ch_layout.nb_channels, );
 if (!celt->dec) {
 celt_mode_destroy(celt->mode);
 return ff_celt_error_to_averror(err);
@@ -119,8 +119,8 @@ static int libcelt_dec_decode(AVCodecContext *c, void *data,
 return ff_celt_error_to_averror(err);
 if (celt->discard) {
 frame->nb_samples -= celt->discard;
-memmove(pcm, pcm + celt->discard * c->channels,
-frame->nb_samples * c->channels * sizeof(int16_t));
+memmove(pcm, pcm + celt->discard * c->ch_layout.nb_channels,
+frame->nb_samples * c->ch_layout.nb_channels * 
sizeof(int16_t));
 celt->discard = 0;
 }
 *got_frame_ptr = 1;
-- 
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 221/281] interplayacm: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/interplayacm.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/interplayacm.c b/libavcodec/interplayacm.c
index c11178a9ee..7b4e539239 100644
--- a/libavcodec/interplayacm.c
+++ b/libavcodec/interplayacm.c
@@ -79,12 +79,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
 if (avctx->extradata_size < 14)
 return AVERROR_INVALIDDATA;
 
-if (avctx->channels <= 0) {
-av_log(avctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", 
avctx->channels);
+if (avctx->ch_layout.nb_channels <= 0) {
+av_log(avctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", 
avctx->ch_layout.nb_channels);
 return AVERROR_INVALIDDATA;
 }
 
-s->max_samples = AV_RL32(avctx->extradata + 4) / avctx->channels;
+s->max_samples = AV_RL32(avctx->extradata + 4) / 
avctx->ch_layout.nb_channels;
 if (s->max_samples == 0)
 s->max_samples = UINT64_MAX;
 s->level = AV_RL16(avctx->extradata + 12) & 0xf;
@@ -585,7 +585,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 if ((ret = init_get_bits8(gb, buf, buf_size)) < 0)
 return ret;
 
-frame->nb_samples = FFMIN(s->block_len / avctx->channels, s->max_samples);
+frame->nb_samples = FFMIN(s->block_len / avctx->ch_layout.nb_channels, 
s->max_samples);
 s->max_samples -= FFMIN(frame->nb_samples, s->max_samples);
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
@@ -596,7 +596,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 return ret;
 
 samples = (int16_t *)frame->data[0];
-for (n = 0; n < frame->nb_samples * avctx->channels; n++) {
+for (n = 0; n < frame->nb_samples * avctx->ch_layout.nb_channels; n++) {
 int val = s->block[n] >> s->level;
 *samples++ = val;
 }
-- 
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 220/281] imc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/imc.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 116c273ba0..89b2ac33e6 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -206,15 +206,17 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
 return AVERROR_PATCHWELCOME;
 }
 
-if (avctx->codec_id == AV_CODEC_ID_IMC)
-avctx->channels = 1;
+if (avctx->codec_id == AV_CODEC_ID_IMC) {
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+}
 
-if (avctx->channels > 2) {
+if (avctx->ch_layout.nb_channels > 2) {
 avpriv_request_sample(avctx, "Number of channels > 2");
 return AVERROR_PATCHWELCOME;
 }
 
-for (j = 0; j < avctx->channels; j++) {
+for (j = 0; j < avctx->ch_layout.nb_channels; j++) {
 q->chctx[j].decoder_reset = 1;
 
 for (i = 0; i < BANDS; i++)
@@ -270,8 +272,6 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
 ff_bswapdsp_init(>bdsp);
 
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
-avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
- : AV_CH_LAYOUT_STEREO;
 
 ff_thread_once(_static_once, imc_init_static);
 
@@ -1013,7 +1013,7 @@ static int imc_decode_block(AVCodecContext *avctx, 
IMCContext *q, int ch)
 
 memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
 
-imc_imdct256(q, chctx, avctx->channels);
+imc_imdct256(q, chctx, avctx->ch_layout.nb_channels);
 
 return 0;
 }
@@ -1032,7 +1032,7 @@ static int imc_decode_frame(AVCodecContext *avctx, void 
*data,
 
 q->avctx = avctx;
 
-if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
+if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1042,7 +1042,7 @@ static int imc_decode_frame(AVCodecContext *avctx, void 
*data,
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 
-for (i = 0; i < avctx->channels; i++) {
+for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
 q->out_samples = (float *)frame->extended_data[i];
 
 q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
@@ -1055,14 +1055,14 @@ static int imc_decode_frame(AVCodecContext *avctx, void 
*data,
 return ret;
 }
 
-if (avctx->channels == 2) {
+if (avctx->ch_layout.nb_channels == 2) {
 q->butterflies_float((float *)frame->extended_data[0],
  (float *)frame->extended_data[1], COEFFS);
 }
 
 *got_frame_ptr = 1;
 
-return IMC_BLOCK_SIZE * avctx->channels;
+return IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels;
 }
 
 static av_cold int imc_decode_close(AVCodecContext * avctx)
-- 
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 219/281] ilbc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/ilbcdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ilbcdec.c b/libavcodec/ilbcdec.c
index 4d0465087f..27423d12f8 100644
--- a/libavcodec/ilbcdec.c
+++ b/libavcodec/ilbcdec.c
@@ -1456,8 +1456,8 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
 else
 return AVERROR_INVALIDDATA;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_rate= 8000;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
-- 
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 218/281] hcom: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

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

diff --git a/libavcodec/hcom.c b/libavcodec/hcom.c
index 3030e37d46..d30d6402d1 100644
--- a/libavcodec/hcom.c
+++ b/libavcodec/hcom.c
@@ -44,7 +44,7 @@ static av_cold int hcom_init(AVCodecContext *avctx)
 {
 HCOMContext *s = avctx->priv_data;
 
-if (avctx->channels != 1) {
+if (avctx->ch_layout.nb_channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
 return AVERROR_INVALIDDATA;
 }
-- 
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 214/281] g726: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/g726.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 2a0148c1d5..082f9b07ad 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -324,7 +324,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if(avctx->channels != 1){
+if (avctx->ch_layout.nb_channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n");
 return AVERROR(EINVAL);
 }
@@ -436,12 +436,12 @@ static av_cold int g726_decode_init(AVCodecContext *avctx)
 {
 G726Context* c = avctx->priv_data;
 
-if(avctx->channels > 1){
+if (avctx->ch_layout.nb_channels > 1){
 avpriv_request_sample(avctx, "Decoding more than one channel");
 return AVERROR_PATCHWELCOME;
 }
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 c->little_endian = !strcmp(avctx->codec->name, "g726le");
 
-- 
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 213/281] g723_1: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/g723_1_parser.c |  2 +-
 libavcodec/g723_1dec.c | 19 ++-
 libavcodec/g723_1enc.c |  8 +++-
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/libavcodec/g723_1_parser.c b/libavcodec/g723_1_parser.c
index b6b3fcb84b..2ed1a8ab19 100644
--- a/libavcodec/g723_1_parser.c
+++ b/libavcodec/g723_1_parser.c
@@ -37,7 +37,7 @@ static int g723_1_parse(AVCodecParserContext *s1, 
AVCodecContext *avctx,
 int next = END_NOT_FOUND;
 
 if (buf_size > 0)
-next = frame_size[buf[0] & 3] * FFMAX(1, avctx->channels);
+next = frame_size[buf[0] & 3] * FFMAX(1, avctx->ch_layout.nb_channels);
 
 if (ff_combine_frame(pc, next, , _size) < 0 || !buf_size) {
 *poutbuf  = NULL;
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index 7d75adbd7a..8f381b1331 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -117,12 +117,12 @@ static av_cold int g723_1_decode_init(AVCodecContext 
*avctx)
 G723_1_Context *s = avctx->priv_data;
 
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
-if (avctx->channels < 1 || avctx->channels > 2) {
-av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported 
(requested channels: %d).\n", avctx->channels);
+if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
+av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported 
(requested channels: %d).\n",
+   avctx->ch_layout.nb_channels);
 return AVERROR(EINVAL);
 }
-avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO : 
AV_CH_LAYOUT_STEREO;
-for (int ch = 0; ch < avctx->channels; ch++) {
+for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
 G723_1_ChannelContext *p = >ch[ch];
 
 p->pf_gain = 1 << 12;
@@ -932,6 +932,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void 
*data,
 const uint8_t *buf = avpkt->data;
 int buf_size   = avpkt->size;
 int dec_mode   = buf[0] & 3;
+int channels   = avctx->ch_layout.nb_channels;
 
 PPFParam ppf[SUBFRAMES];
 int16_t cur_lsp[LPC_ORDER];
@@ -940,7 +941,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void 
*data,
 int16_t *out;
 int bad_frame = 0, i, j, ret;
 
-if (buf_size < frame_size[dec_mode] * avctx->channels) {
+if (buf_size < frame_size[dec_mode] * channels) {
 if (buf_size)
 av_log(avctx, AV_LOG_WARNING,
"Expected %d bytes, got %d - skipping packet\n",
@@ -953,12 +954,12 @@ static int g723_1_decode_frame(AVCodecContext *avctx, 
void *data,
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 
-for (int ch = 0; ch < avctx->channels; ch++) {
+for (int ch = 0; ch < channels; ch++) {
 G723_1_ChannelContext *p = >ch[ch];
 int16_t *audio = p->audio;
 
-if (unpack_bitstream(p, buf + ch * (buf_size / avctx->channels),
- buf_size / avctx->channels) < 0) {
+if (unpack_bitstream(p, buf + ch * (buf_size / channels),
+ buf_size / channels) < 0) {
 bad_frame = 1;
 if (p->past_frame_type == ACTIVE_FRAME)
 p->cur_frame_type = ACTIVE_FRAME;
@@ -1090,7 +1091,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, 
void *data,
 
 *got_frame_ptr = 1;
 
-return frame_size[dec_mode] * avctx->channels;
+return frame_size[dec_mode] * channels;
 }
 
 #define OFFSET(x) offsetof(G723_1_Context, x)
diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c
index 2a8149b4cd..7e893fafc7 100644
--- a/libavcodec/g723_1enc.c
+++ b/libavcodec/g723_1enc.c
@@ -99,11 +99,6 @@ static av_cold int g723_1_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (avctx->channels != 1) {
-av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
-return AVERROR(EINVAL);
-}
-
 if (avctx->bit_rate == 6300) {
 p->cur_rate = RATE_6300;
 } else if (avctx->bit_rate == 5300) {
@@ -1256,5 +1251,8 @@ const AVCodec ff_g723_1_encoder = {
 .sample_fmts= (const enum AVSampleFormat[]) {
 AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
 },
+.ch_layouts = (const AVChannelLayout[]){
+AV_CHANNEL_LAYOUT_MONO, { 0 }
+},
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
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 217/281] hca: convert to new channel layout API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/hcadec.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c
index c98f8eb379..9757fcc74b 100644
--- a/libavcodec/hcadec.c
+++ b/libavcodec/hcadec.c
@@ -114,7 +114,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 c->crc_table = av_crc_get_table(AV_CRC_16_ANSI);
 
-if (avctx->channels <= 0 || avctx->channels > 16)
+if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > 16)
 return AVERROR(EINVAL);
 
 ret = init_get_bits8(gb, avctx->extradata, avctx->extradata_size);
@@ -194,7 +194,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 if (!c->track_count)
 c->track_count = 1;
 
-b = avctx->channels / c->track_count;
+b = avctx->ch_layout.nb_channels / c->track_count;
 if (c->stereo_band_count && b > 1) {
 int8_t *x = r;
 
@@ -239,7 +239,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 if (c->base_band_count + c->stereo_band_count + (unsigned 
long)c->hfr_group_count > 128ULL)
 return AVERROR_INVALIDDATA;
 
-for (int i = 0; i < avctx->channels; i++) {
+for (int i = 0; i < avctx->ch_layout.nb_channels; i++) {
 c->ch[i].chan_type = r[i];
 c->ch[i].count = c->base_band_count + ((r[i] != 2) ? 
c->stereo_band_count : 0);
 c->ch[i].hfr_scale = >ch[i].scale_factors[c->base_band_count + 
c->stereo_band_count];
@@ -413,20 +413,20 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 
 packed_noise_level = (get_bits(gb, 9) << 8) - get_bits(gb, 7);
 
-for (ch = 0; ch < avctx->channels; ch++)
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
 unpack(c, >ch[ch], c->hfr_group_count, packed_noise_level, c->ath);
 
 for (int i = 0; i < 8; i++) {
-for (ch = 0; ch < avctx->channels; ch++)
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
 dequantize_coefficients(c, >ch[ch]);
-for (ch = 0; ch < avctx->channels; ch++)
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
 reconstruct_hfr(c, >ch[ch], c->hfr_group_count, 
c->bands_per_hfr_group,
 c->stereo_band_count + c->base_band_count, 
c->total_band_count);
-for (ch = 0; ch < avctx->channels - 1; ch++)
+for (ch = 0; ch < avctx->ch_layout.nb_channels - 1; ch++)
 apply_intensity_stereo(c, >ch[ch], >ch[ch+1], i,
c->total_band_count - c->base_band_count,
c->base_band_count, c->stereo_band_count);
-for (ch = 0; ch < avctx->channels; ch++)
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
 run_imdct(c, >ch[ch], i, samples[ch] + i * 128);
 }
 
-- 
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 216/281] gsmdec: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/gsmdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/gsmdec.c b/libavcodec/gsmdec.c
index c169112311..e3c87af513 100644
--- a/libavcodec/gsmdec.c
+++ b/libavcodec/gsmdec.c
@@ -34,8 +34,8 @@
 
 static av_cold int gsm_init(AVCodecContext *avctx)
 {
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 if (!avctx->sample_rate)
 avctx->sample_rate = 8000;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
-- 
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 212/281] g722: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/g722dec.c | 4 ++--
 libavcodec/g722enc.c | 5 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index 5ca0d0e2b1..879ea296cb 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -59,8 +59,8 @@ static av_cold int g722_decode_init(AVCodecContext * avctx)
 {
 G722Context *c = avctx->priv_data;
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
 c->band[0].scale_factor = 8;
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 75b926ef8e..6010a6d5ae 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -381,6 +381,11 @@ const AVCodec ff_adpcm_g722_encoder = {
 .close   = g722_encode_close,
 .encode2 = g722_encode_frame,
 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, 
AV_SAMPLE_FMT_NONE },
+#if FF_API_OLD_CHANNEL_LAYOUT
 .channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO, 0 },
+#endif
+.ch_layouts = (const AVChannelLayout[]){
+AV_CHANNEL_LAYOUT_MONO, { 0 }
+},
 .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | 
FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
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 215/281] g729: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/g729_parser.c |  2 +-
 libavcodec/g729dec.c | 20 +++-
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavcodec/g729_parser.c b/libavcodec/g729_parser.c
index 8c06ce4ee6..d66df141f9 100644
--- a/libavcodec/g729_parser.c
+++ b/libavcodec/g729_parser.c
@@ -48,7 +48,7 @@ static int g729_parse(AVCodecParserContext *s1, 
AVCodecContext *avctx,
 s->block_size = (avctx->bit_rate < 8000) ? G729D_6K4_BLOCK_SIZE : 
G729_8K_BLOCK_SIZE;
 if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)
 s->block_size++;
-s->block_size *= avctx->channels;
+s->block_size *= avctx->ch_layout.nb_channels;
 s->duration   = avctx->frame_size;
 }
 
diff --git a/libavcodec/g729dec.c b/libavcodec/g729dec.c
index 7525ab7491..5a90f9fc1c 100644
--- a/libavcodec/g729dec.c
+++ b/libavcodec/g729dec.c
@@ -350,10 +350,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
 {
 G729Context *s = avctx->priv_data;
 G729ChannelContext *ctx;
+int channels = avctx->ch_layout.nb_channels;
 int c,i,k;
 
-if (avctx->channels < 1 || avctx->channels > 2) {
-av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported 
(requested channels: %d).\n", avctx->channels);
+if (channels < 1 || channels > 2) {
+av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported 
(requested channels: %d).\n", channels);
 return AVERROR(EINVAL);
 }
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
@@ -362,11 +363,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
 avctx->frame_size = SUBFRAME_SIZE << 1;
 
 ctx =
-s->channel_context = av_mallocz(sizeof(G729ChannelContext) * 
avctx->channels);
+s->channel_context = av_mallocz(sizeof(G729ChannelContext) * channels);
 if (!ctx)
 return AVERROR(ENOMEM);
 
-for (c = 0; c < avctx->channels; c++) {
+for (c = 0; c < channels; c++) {
 ctx->gain_coeff = 16384; // 1.0 in (1.14)
 
 for (k = 0; k < MA_NP + 1; k++) {
@@ -412,6 +413,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame_ptr,
 G729Formats packet_type;
 G729Context *s = avctx->priv_data;
 G729ChannelContext *ctx = s->channel_context;
+int channels = avctx->ch_layout.nb_channels;
 int16_t lp[2][11];   // (3.12)
 uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer
 uint8_t quantizer_1st;///< first stage vector of quantizer
@@ -430,14 +432,14 @@ static int decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame_ptr,
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 
-if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == 
AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels) == 0) {
+if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == 
AV_CODEC_ID_ACELP_KELVIN)) * channels) == 0) {
 packet_type = FORMAT_G729_8K;
 format = _g729_8k;
 //Reset voice decision
 ctx->onset = 0;
 ctx->voice_decision = DECISION_VOICE;
 av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s");
-} else if (buf_size == G729D_6K4_BLOCK_SIZE * avctx->channels && 
avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
+} else if (buf_size == G729D_6K4_BLOCK_SIZE * channels && avctx->codec_id 
!= AV_CODEC_ID_ACELP_KELVIN) {
 packet_type = FORMAT_G729D_6K4;
 format = _g729d_6k4;
 av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s");
@@ -446,13 +448,13 @@ static int decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame_ptr,
 return AVERROR_INVALIDDATA;
 }
 
-for (c = 0; c < avctx->channels; c++) {
+for (c = 0; c < channels; c++) {
 int frame_erasure = 0; ///< frame erasure detected during decoding
 int bad_pitch = 0; ///< parity check failed
 int is_periodic = 0;   ///< whether one of the subframes is declared 
as periodic or not
 out_frame = (int16_t*)frame->data[c];
 if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN) {
-if (*buf != ((avctx->channels - 1 - c) * 0x80 | 2))
+if (*buf != ((avctx->ch_layout.nb_channels - 1 - c) * 0x80 | 2))
 avpriv_request_sample(avctx, "First byte value %x for channel 
%d", *buf, c);
 buf++;
 }
@@ -739,7 +741,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame_ptr,
 }
 
 *got_frame_ptr = 1;
-return (format->block_size + (avctx->codec_id == 
AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels;
+return (format->block_size + (avctx->codec_id == 
AV_CODEC_ID_ACELP_KELVIN)) * channels;
 }
 
 static av_cold int decode_close(AVCodecContext *avctx)
-- 
2.34.1

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

[FFmpeg-devel] [PATCH 211/281] flac: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/flac.c| 39 +--
 libavcodec/flac.h|  2 +-
 libavcodec/flac_parser.c |  7 ++-
 libavcodec/flacdec.c |  9 -
 libavcodec/flacenc.c | 26 +-
 5 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index 7b075d4bd3..51014faea1 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -29,15 +29,15 @@
 
 static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
 
-static const uint64_t flac_channel_layouts[8] = {
-AV_CH_LAYOUT_MONO,
-AV_CH_LAYOUT_STEREO,
-AV_CH_LAYOUT_SURROUND,
-AV_CH_LAYOUT_QUAD,
-AV_CH_LAYOUT_5POINT0,
-AV_CH_LAYOUT_5POINT1,
-AV_CH_LAYOUT_6POINT1,
-AV_CH_LAYOUT_7POINT1
+static const AVChannelLayout flac_channel_layouts[8] = {
+AV_CHANNEL_LAYOUT_MONO,
+AV_CHANNEL_LAYOUT_STEREO,
+AV_CHANNEL_LAYOUT_SURROUND,
+AV_CHANNEL_LAYOUT_QUAD,
+AV_CHANNEL_LAYOUT_5POINT0,
+AV_CHANNEL_LAYOUT_5POINT1,
+AV_CHANNEL_LAYOUT_6POINT1,
+AV_CHANNEL_LAYOUT_7POINT1
 };
 
 static int64_t get_utf8(GetBitContext *gb)
@@ -193,12 +193,19 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
 return 1;
 }
 
-void ff_flac_set_channel_layout(AVCodecContext *avctx)
+void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels)
 {
-if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
-avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
+if (channels == avctx->ch_layout.nb_channels &&
+avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
+avctx->ch_layout.u.mask)
+return;
+
+av_channel_layout_uninit(>ch_layout);
+if (channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
+avctx->ch_layout = flac_channel_layouts[channels - 1];
 else
-avctx->channel_layout = 0;
+avctx->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
+  .nb_channels = channels };
 }
 
 int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
@@ -229,13 +236,9 @@ int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct 
FLACStreaminfo *s,
 return AVERROR_INVALIDDATA;
 }
 
-avctx->channels = s->channels;
 avctx->sample_rate = s->samplerate;
 avctx->bits_per_raw_sample = s->bps;
-
-if (!avctx->channel_layout ||
-av_get_channel_layout_nb_channels(avctx->channel_layout) != 
avctx->channels)
-ff_flac_set_channel_layout(avctx);
+ff_flac_set_channel_layout(avctx, s->channels);
 
 s->samples = get_bits64(, 36);
 
diff --git a/libavcodec/flac.h b/libavcodec/flac.h
index 991ab43f3c..cb220ab4c0 100644
--- a/libavcodec/flac.h
+++ b/libavcodec/flac.h
@@ -131,7 +131,7 @@ int ff_flac_get_max_frame_size(int blocksize, int ch, int 
bps);
 int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
 FLACFrameInfo *fi, int log_level_offset);
 
-void ff_flac_set_channel_layout(AVCodecContext *avctx);
+void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels);
 
 /**
  * Parse the metadata block parameters from the header.
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index cd9a2cb574..81b6f12ab3 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -628,11 +628,8 @@ static int get_best_header(FLACParseContext *fpc, const 
uint8_t **poutbuf,
 check_header_mismatch(fpc, header, child, 0);
 }
 
-if (header->fi.channels != fpc->avctx->channels ||
-!fpc->avctx->channel_layout) {
-fpc->avctx->channels = header->fi.channels;
-ff_flac_set_channel_layout(fpc->avctx);
-}
+ff_flac_set_channel_layout(fpc->avctx, header->fi.channels);
+
 fpc->avctx->sample_rate = header->fi.samplerate;
 fpc->pc->duration   = header->fi.blocksize;
 *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 09051cc663..eaa2dc6cf1 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -483,15 +483,14 @@ static int decode_frame(FLACContext *s)
 if (   s->flac_stream_info.channels
 && fi.channels != s->flac_stream_info.channels
 && s->got_streaminfo) {
-s->flac_stream_info.channels = s->avctx->channels = fi.channels;
-ff_flac_set_channel_layout(s->avctx);
+s->flac_stream_info.channels = fi.channels;
+ff_flac_set_channel_layout(s->avctx, fi.channels);
 ret = allocate_buffers(s);
 if (ret < 0)
 return ret;
 }
-s->flac_stream_info.channels = s->avctx->channels = fi.channels;
-if (!s->avctx->channel_layout)
-ff_flac_set_channel_layout(s->avctx);
+s->flac_stream_info.channels = fi.channels;
+

[FFmpeg-devel] [PATCH 210/281] ffwavesynth: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/ffwavesynth.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ffwavesynth.c b/libavcodec/ffwavesynth.c
index a1211facb9..229a89663d 100644
--- a/libavcodec/ffwavesynth.c
+++ b/libavcodec/ffwavesynth.c
@@ -314,7 +314,7 @@ static av_cold int wavesynth_init(AVCodecContext *avc)
 struct wavesynth_context *ws = avc->priv_data;
 int i, r;
 
-if (avc->channels > WS_MAX_CHANNELS) {
+if (avc->ch_layout.nb_channels > WS_MAX_CHANNELS) {
 av_log(avc, AV_LOG_ERROR,
"This implementation is limited to %d channels.\n",
WS_MAX_CHANNELS);
@@ -438,11 +438,11 @@ static int wavesynth_decode(AVCodecContext *avc, void 
*rframe, int *rgot_frame,
 return r;
 pcm = (int16_t *)frame->data[0];
 for (s = 0; s < duration; s++, ts+=(uint64_t)1) {
-memset(channels, 0, avc->channels * sizeof(*channels));
+memset(channels, 0, avc->ch_layout.nb_channels * sizeof(*channels));
 if (ts >= ws->next_ts)
 wavesynth_enter_intervals(ws, ts);
 wavesynth_synth_sample(ws, ts, channels);
-for (c = 0; c < avc->channels; c++)
+for (c = 0; c < avc->ch_layout.nb_channels; c++)
 *(pcm++) = channels[c] >> 16;
 }
 ws->cur_ts += (uint64_t)duration;
-- 
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 209/281] fastaudio: convert to new channel layout API

2022-01-12 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/fastaudio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/fastaudio.c b/libavcodec/fastaudio.c
index a07c5e60a7..7a8ff7dec3 100644
--- a/libavcodec/fastaudio.c
+++ b/libavcodec/fastaudio.c
@@ -78,7 +78,7 @@ static av_cold int fastaudio_init(AVCodecContext *avctx)
 for (int i = 0; i < 8; i++)
 s->table[7][i] = i * 0.34f / 3.f - 0.2f;
 
-s->ch = av_calloc(avctx->channels, sizeof(*s->ch));
+s->ch = av_calloc(avctx->ch_layout.nb_channels, sizeof(*s->ch));
 if (!s->ch)
 return AVERROR(ENOMEM);
 
@@ -113,7 +113,7 @@ static int fastaudio_decode(AVCodecContext *avctx, void 
*data,
 int subframes;
 int ret;
 
-subframes = pkt->size / (40 * avctx->channels);
+subframes = pkt->size / (40 * avctx->ch_layout.nb_channels);
 frame->nb_samples = subframes * 256;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
@@ -121,7 +121,7 @@ static int fastaudio_decode(AVCodecContext *avctx, void 
*data,
 bytestream2_init(, pkt->data, pkt->size);
 
 for (int subframe = 0; subframe < subframes; subframe++) {
-for (int channel = 0; channel < avctx->channels; channel++) {
+for (int channel = 0; channel < avctx->ch_layout.nb_channels; 
channel++) {
 ChannelItems *ch = >ch[channel];
 float result[256] = { 0 };
 unsigned src[10];
-- 
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 208/281] evrc: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/evrcdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/evrcdec.c b/libavcodec/evrcdec.c
index 59fcb14c52..a17f3bc2be 100644
--- a/libavcodec/evrcdec.c
+++ b/libavcodec/evrcdec.c
@@ -235,8 +235,8 @@ static av_cold int evrc_decode_init(AVCodecContext *avctx)
 int i, n, idx = 0;
 float denom = 2.0 / (2.0 * 8.0 + 1.0);
 
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
 for (i = 0; i < FILTER_ORDER; i++) {
-- 
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 207/281] dvaudio: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/dvaudiodec.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dvaudiodec.c b/libavcodec/dvaudiodec.c
index 82e6dbe36c..f3b1dee075 100644
--- a/libavcodec/dvaudiodec.c
+++ b/libavcodec/dvaudiodec.c
@@ -36,11 +36,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
 DVAudioContext *s = avctx->priv_data;
 int i;
 
-if (avctx->channels != 2) {
-av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
-return AVERROR(EINVAL);
-}
-
 if (avctx->codec_tag == 0x0215) {
 s->block_size = 7200;
 } else if (avctx->codec_tag == 0x0216) {
@@ -55,7 +50,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 s->is_pal = s->block_size == 8640;
 s->is_12bit = avctx->bits_per_coded_sample == 12;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
-avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 
 for (i = 0; i < FF_ARRAY_ELEMS(s->shuffle); i++) {
 const unsigned a = s->is_pal ? 18 : 15;
-- 
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 206/281] dst: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/dstdec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/dstdec.c b/libavcodec/dstdec.c
index 6d0b25f4c3..78427bd15c 100644
--- a/libavcodec/dstdec.c
+++ b/libavcodec/dstdec.c
@@ -80,8 +80,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 DSTContext *s = avctx->priv_data;
 int i;
 
-if (avctx->channels > DST_MAX_CHANNELS) {
-avpriv_request_sample(avctx, "Channel count %d", avctx->channels);
+if (avctx->ch_layout.nb_channels > DST_MAX_CHANNELS) {
+avpriv_request_sample(avctx, "Channel count %d", 
avctx->ch_layout.nb_channels);
 return AVERROR_PATCHWELCOME;
 }
 
@@ -97,7 +97,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
-for (i = 0; i < avctx->channels; i++)
+for (i = 0; i < avctx->ch_layout.nb_channels; i++)
 memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
 
 ff_init_dsd_data();
@@ -243,7 +243,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 unsigned map_ch_to_pelem[DST_MAX_CHANNELS];
 unsigned i, ch, same_map, dst_x_bit;
 unsigned half_prob[DST_MAX_CHANNELS];
-const int channels = avctx->channels;
+const int channels = avctx->ch_layout.nb_channels;
 DSTContext *s = avctx->priv_data;
 GetBitContext *gb = >gb;
 ArithCoder *ac = >ac;
-- 
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 205/281] dss_sp: convert to new channel layout API

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/dss_sp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dss_sp.c b/libavcodec/dss_sp.c
index 050b412496..c8da3bffaf 100644
--- a/libavcodec/dss_sp.c
+++ b/libavcodec/dss_sp.c
@@ -290,10 +290,10 @@ static const int32_t dss_sp_sinc[67] = {
 static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
 {
 DssSpContext *p = avctx->priv_data;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
-avctx->channels   = 1;
 avctx->sample_rate= 11025;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 p->pulse_dec_mode = 1;
 p->avctx  = avctx;
-- 
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 204/281] dsicinav: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/dsicinaudio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dsicinaudio.c b/libavcodec/dsicinaudio.c
index 39869ac0cd..a543f6dd09 100644
--- a/libavcodec/dsicinaudio.c
+++ b/libavcodec/dsicinaudio.c
@@ -80,8 +80,8 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx)
 cin->initial_decode_frame = 1;
 cin->delta= 0;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
-avctx->channels   = 1;
-avctx->channel_layout = AV_CH_LAYOUT_MONO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
 return 0;
 }
-- 
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 203/281] dsd: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/dsddec.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c
index 19fb75ee85..02698ee116 100644
--- a/libavcodec/dsddec.c
+++ b/libavcodec/dsddec.c
@@ -44,17 +44,17 @@ static av_cold int decode_init(AVCodecContext *avctx)
 int i;
 uint8_t silence;
 
-if (!avctx->channels)
+if (!avctx->ch_layout.nb_channels)
 return AVERROR_INVALIDDATA;
 
 ff_init_dsd_data();
 
-s = av_malloc_array(sizeof(DSDContext), avctx->channels);
+s = av_malloc_array(sizeof(DSDContext), avctx->ch_layout.nb_channels);
 if (!s)
 return AVERROR(ENOMEM);
 
 silence = avctx->codec_id == AV_CODEC_ID_DSD_LSBF || avctx->codec_id == 
AV_CODEC_ID_DSD_LSBF_PLANAR ? DSD_SILENCE_REVERSED : DSD_SILENCE;
-for (i = 0; i < avctx->channels; i++) {
+for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
 s[i].pos = 0;
 memset(s[i].buf, silence, sizeof(s[i].buf));
 }
@@ -84,7 +84,7 @@ static int dsd_channel(AVCodecContext *avctx, void *tdata, 
int j, int threadnr)
 src_stride = 1;
 } else {
 src_next   = 1;
-src_stride = avctx->channels;
+src_stride = avctx->ch_layout.nb_channels;
 }
 
 ff_dsd2pcm_translate([j], frame->nb_samples, lsbf,
@@ -101,17 +101,17 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 AVFrame *frame = data;
 int ret;
 
-frame->nb_samples = avpkt->size / avctx->channels;
+frame->nb_samples = avpkt->size / avctx->ch_layout.nb_channels;
 
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 
 td.frame = frame;
 td.avpkt = avpkt;
-avctx->execute2(avctx, dsd_channel, , NULL, avctx->channels);
+avctx->execute2(avctx, dsd_channel, , NULL, 
avctx->ch_layout.nb_channels);
 
 *got_frame_ptr = 1;
-return frame->nb_samples * avctx->channels;
+return frame->nb_samples * avctx->ch_layout.nb_channels;
 }
 
 #define DSD_DECODER(id_, name_, long_name_) \
-- 
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 202/281] dpcm: convert to new channel layout API

2022-01-12 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/dpcm.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index d9ea23adb3..95052282ae 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -132,7 +132,7 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
 DPCMContext *s = avctx->priv_data;
 int i;
 
-if (avctx->channels < 1 || avctx->channels > 2) {
+if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
 return AVERROR(EINVAL);
 }
@@ -215,7 +215,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void 
*data,
 int out = 0, ret;
 int predictor[2];
 int ch = 0;
-int stereo = avctx->channels - 1;
+int stereo = avctx->ch_layout.nb_channels - 1;
 int16_t *output_samples, *samples_end;
 GetByteContext gb;
 
@@ -229,10 +229,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void 
*data,
 out = buf_size - 8;
 break;
 case AV_CODEC_ID_INTERPLAY_DPCM:
-out = buf_size - 6 - avctx->channels;
+out = buf_size - 6 - avctx->ch_layout.nb_channels;
 break;
 case AV_CODEC_ID_XAN_DPCM:
-out = buf_size - 2 * avctx->channels;
+out = buf_size - 2 * avctx->ch_layout.nb_channels;
 break;
 case AV_CODEC_ID_SOL_DPCM:
 if (avctx->codec_tag != 3)
@@ -250,12 +250,12 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void 
*data,
 av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
 return AVERROR(EINVAL);
 }
-if (out % avctx->channels) {
+if (out % avctx->ch_layout.nb_channels) {
 av_log(avctx, AV_LOG_WARNING, "channels have differing number of 
samples\n");
 }
 
 /* get output buffer */
-frame->nb_samples = (out + avctx->channels - 1) / avctx->channels;
+frame->nb_samples = (out + avctx->ch_layout.nb_channels - 1) / 
avctx->ch_layout.nb_channels;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 output_samples = (int16_t *)frame->data[0];
@@ -287,7 +287,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void 
*data,
 case AV_CODEC_ID_INTERPLAY_DPCM:
 bytestream2_skipu(, 6);  /* skip over the stream mask and stream 
length */
 
-for (ch = 0; ch < avctx->channels; ch++) {
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
 predictor[ch] = sign_extend(bytestream2_get_le16u(), 16);
 *output_samples++ = predictor[ch];
 }
@@ -307,7 +307,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void 
*data,
 {
 int shift[2] = { 4, 4 };
 
-for (ch = 0; ch < avctx->channels; ch++)
+for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
 predictor[ch] = sign_extend(bytestream2_get_le16u(), 16);
 
 ch = 0;
-- 
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 201/281] dolby_e: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/dolby_e.c| 52 -
 libavcodec/dolby_e.h|  2 ++
 libavcodec/dolby_e_parser.c | 11 +---
 3 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 6c0d54be4c..a9106a7632 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -23,6 +23,7 @@
 #include "libavutil/thread.h"
 #include "libavutil/mem.h"
 #include "libavutil/mem_internal.h"
+#include "libavutil/opt.h"
 
 #include "internal.h"
 #include "get_bits.h"
@@ -39,6 +40,11 @@
 #define MAX_MSTR_EXP2
 #define MAX_BIAS_EXP50
 
+enum DBEOutputChannelOrder {
+CHANNEL_ORDER_DEFAULT,
+CHANNEL_ORDER_CODED,
+};
+
 typedef struct DBEGroup {
 uint8_t nb_exponent;
 uint8_t nb_bias_exp[MAX_MSTR_EXP];
@@ -70,6 +76,7 @@ typedef struct DBEChannel {
 } DBEChannel;
 
 typedef struct DBEDecodeContext {
+const AVClass   *class;
 AVCodecContext  *avctx;
 DBEContext  dectx;
 
@@ -1057,7 +1064,7 @@ static int filter_frame(DBEDecodeContext *s, AVFrame 
*frame)
 reorder = ch_reorder_4;
 else if (metadata->nb_channels == 6)
 reorder = ch_reorder_6;
-else if (metadata->nb_programs == 1 && !(s->avctx->request_channel_layout 
& AV_CH_LAYOUT_NATIVE))
+else if (metadata->nb_programs == 1 && metadata->output_channel_order == 
CHANNEL_ORDER_DEFAULT)
 reorder = ch_reorder_8;
 else
 reorder = ch_reorder_n;
@@ -1093,19 +1100,23 @@ static int dolby_e_decode_frame(AVCodecContext *avctx, 
void *data,
 s->metadata.multi_prog_warned = 1;
 }
 
+av_channel_layout_uninit(>ch_layout);
 switch (s->metadata.nb_channels) {
 case 4:
-avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
 break;
 case 6:
-avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
 break;
 case 8:
-avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1;
+break;
+default:
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = s->metadata.nb_channels;
 break;
 }
 
-avctx->channels= s->metadata.nb_channels;
 avctx->sample_rate = s->metadata.sample_rate;
 avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
 
@@ -1252,17 +1263,46 @@ static av_cold int dolby_e_init(AVCodecContext *avctx)
 if (!(s->fdsp = avpriv_float_dsp_alloc(0)))
 return AVERROR(ENOMEM);
 
-s->dectx.metadata.multi_prog_warned = !!(avctx->request_channel_layout & 
AV_CH_LAYOUT_NATIVE);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)
+s->dectx.metadata.output_channel_order = CHANNEL_ORDER_CODED;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+s->dectx.metadata.multi_prog_warned = 
s->dectx.metadata.output_channel_order == CHANNEL_ORDER_CODED;
 s->dectx.avctx = s->avctx = avctx;
 return 0;
 }
 
+#define OFFSET(x) offsetof(DBEDecodeContext, x)
+#define FLAGS (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
+static const AVOption options[] = {
+{ "channel_order", "Order in which the channels are to be exported",
+OFFSET(dectx.metadata.output_channel_order), AV_OPT_TYPE_INT,
+{ .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, FLAGS, "channel_order" },
+  { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST,
+{ .i64 = CHANNEL_ORDER_DEFAULT }, .flags = FLAGS, "channel_order" },
+  { "coded","order in which the channels are coded in the bitstream",
+0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = FLAGS, 
"channel_order" },
+
+  { NULL },
+};
+
+static const AVClass dolby_e_decoder_class = {
+.class_name = "Dolby E decoder",
+.item_name  = av_default_item_name,
+.option = options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 const AVCodec ff_dolby_e_decoder = {
 .name   = "dolby_e",
 .long_name  = NULL_IF_CONFIG_SMALL("Dolby E"),
 .type   = AVMEDIA_TYPE_AUDIO,
 .id = AV_CODEC_ID_DOLBY_E,
 .priv_data_size = sizeof(DBEDecodeContext),
+.priv_class = _e_decoder_class,
 .init   = dolby_e_init,
 .decode = dolby_e_decode_frame,
 .close  = dolby_e_close,
diff --git a/libavcodec/dolby_e.h b/libavcodec/dolby_e.h
index 9f0c065729..b2eadfea4a 100644
--- a/libavcodec/dolby_e.h
+++ b/libavcodec/dolby_e.h
@@ -59,6 +59,8 @@ typedef struct DolbyEHeaderInfo {
  */
 int multi_prog_warned;
 
+int output_channel_order;
+
 int sample_rate;
 /** @} */
 } DolbyEHeaderInfo;
diff --git a/libavcodec/dolby_e_parser.c b/libavcodec/dolby_e_parser.c

[FFmpeg-devel] [PATCH 200/281] dca: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavcodec/dca_core.c |  6 ++--
 libavcodec/dca_lbr.c  | 20 +++-
 libavcodec/dca_xll.c  |  2 +-
 libavcodec/dcadec.c   | 71 ++-
 libavcodec/dcadec.h   |  7 +
 libavcodec/dcaenc.c   | 39 
 6 files changed, 100 insertions(+), 45 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 758e3447a6..ebe44c2d15 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -2148,7 +2148,7 @@ static int filter_frame_fixed(DCACoreDecoder *s, AVFrame 
*frame)
nsamples, s->ch_mask);
 }
 
-for (i = 0; i < avctx->channels; i++) {
+for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
 int32_t *samples = s->output_samples[s->ch_remap[i]];
 int32_t *plane = (int32_t *)frame->extended_data[i];
 for (n = 0; n < nsamples; n++)
@@ -2180,11 +2180,11 @@ static int filter_frame_float(DCACoreDecoder *s, 
AVFrame *frame)
 return ret;
 
 // Build reverse speaker to channel mapping
-for (i = 0; i < avctx->channels; i++)
+for (i = 0; i < avctx->ch_layout.nb_channels; i++)
 output_samples[s->ch_remap[i]] = (float *)frame->extended_data[i];
 
 // Allocate space for extra channels
-nchannels = av_popcount(s->ch_mask) - avctx->channels;
+nchannels = av_popcount(s->ch_mask) - avctx->ch_layout.nb_channels;
 if (nchannels > 0) {
 av_fast_malloc(>output_buffer, >output_size,
nsamples * nchannels * sizeof(float));
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 481a8df7e6..c11f2f7e18 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -107,10 +107,6 @@ static const uint8_t lfe_index[7] = {
 1, 2, 3, 0, 1, 2, 3
 };
 
-static const uint8_t channel_counts[7] = {
-1, 2, 3, 2, 3, 4, 5
-};
-
 static const uint16_t channel_layouts[7] = {
 AV_CH_LAYOUT_MONO,
 AV_CH_LAYOUT_STEREO,
@@ -1731,9 +1727,8 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame 
*frame)
 AVCodecContext *avctx = s->avctx;
 int i, ret, nchannels, ch_conf = (s->ch_mask & 0x7) - 1;
 const int8_t *reorder;
+uint64_t channel_mask = channel_layouts[ch_conf];
 
-avctx->channel_layout = channel_layouts[ch_conf];
-avctx->channels = nchannels = channel_counts[ch_conf];
 avctx->sample_rate = s->sample_rate;
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 avctx->bits_per_raw_sample = 0;
@@ -1741,13 +1736,22 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame 
*frame)
 avctx->bit_rate = s->bit_rate_scaled;
 
 if (s->flags & LBR_FLAG_LFE_PRESENT) {
-avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
-avctx->channels++;
+channel_mask |= AV_CH_LOW_FREQUENCY;
 reorder = channel_reorder_lfe[ch_conf];
 } else {
 reorder = channel_reorder_nolfe[ch_conf];
 }
 
+av_channel_layout_uninit(>ch_layout);
+av_channel_layout_from_mask(>ch_layout, channel_mask);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->channels = avctx->ch_layout.nb_channels;
+avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+avctx->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 frame->nb_samples = 1024 << s->freq_range;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index ab14dbcc88..a4ff3f9aa2 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -1442,7 +1442,7 @@ int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame 
*frame)
s->output_mask);
 }
 
-for (i = 0; i < avctx->channels; i++) {
+for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
 int32_t *samples = s->output_samples[ch_remap[i]];
 if (frame->format == AV_SAMPLE_FMT_S16P) {
 int16_t *plane = (int16_t *)frame->extended_data[i];
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 43694b51f7..239ed9ac91 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -42,13 +42,17 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int 
*ch_remap, int dca_mask
 13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4,  5,
 };
 
+DCAContext *s = avctx->priv_data;
+
 int dca_ch, wav_ch, nchannels = 0;
 
-if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
+av_channel_layout_uninit(>ch_layout);
+if (s->output_channel_order == CHANNEL_ORDER_CODED) {
 for (dca_ch = 0; dca_ch < DCA_SPEAKER_COUNT; dca_ch++)
 if (dca_mask & (1U << dca_ch))
 ch_remap[nchannels++] = dca_ch;
-avctx->channel_layout = dca_mask;
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = nchannels;
 } else {
 int wav_mask = 0;
 int 

[FFmpeg-devel] [PATCH 199/281] cook: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/cook.c| 25 ++---
 libavcodec/cook_parser.c |  4 ++--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 3720772102..6f9bdb55e0 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -1054,7 +1054,7 @@ static void dump_cook_context(COOKContext *q)
 PRINT("js_vlc_bits", q->subpacket[0].js_vlc_bits);
 }
 ff_dlog(q->avctx, "COOKContext\n");
-PRINT("nb_channels", q->avctx->channels);
+PRINT("nb_channels", q->avctx->ch_layout.nb_channels);
 PRINT("bit_rate", (int)q->avctx->bit_rate);
 PRINT("sample_rate", q->avctx->sample_rate);
 PRINT("samples_per_channel", q->subpacket[0].samples_per_channel);
@@ -1079,6 +1079,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
 unsigned int channel_mask = 0;
 int samples_per_frame = 0;
 int ret;
+int channels = avctx->ch_layout.nb_channels;
+
 q->avctx = avctx;
 
 /* Take care of the codec specific extradata. */
@@ -1091,7 +1093,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
 bytestream2_init(, avctx->extradata, avctx->extradata_size);
 
 /* Take data from the AVCodecContext (RM container). */
-if (!avctx->channels) {
+if (!channels) {
 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1123,7 +1125,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
 q->subpacket[s].js_vlc_bits  = bytestream2_get_be16();
 
 /* Initialize extradata related variables. */
-q->subpacket[s].samples_per_channel = samples_per_frame / 
avctx->channels;
+q->subpacket[s].samples_per_channel = samples_per_frame / channels;
 q->subpacket[s].bits_per_subpacket = avctx->block_align * 8;
 
 /* Initialize default data states. */
@@ -1138,21 +1140,21 @@ static av_cold int cook_decode_init(AVCodecContext 
*avctx)
 q->subpacket[s].joint_stereo = 0;
 switch (q->subpacket[s].cookversion) {
 case MONO:
-if (avctx->channels != 1) {
+if (channels != 1) {
 avpriv_request_sample(avctx, "Container channels != 1");
 return AVERROR_PATCHWELCOME;
 }
 av_log(avctx, AV_LOG_DEBUG, "MONO\n");
 break;
 case STEREO:
-if (avctx->channels != 1) {
+if (channels != 1) {
 q->subpacket[s].bits_per_subpdiv = 1;
 q->subpacket[s].num_channels = 2;
 }
 av_log(avctx, AV_LOG_DEBUG, "STEREO\n");
 break;
 case JOINT_STEREO:
-if (avctx->channels != 2) {
+if (channels != 2) {
 avpriv_request_sample(avctx, "Container channels != 2");
 return AVERROR_PATCHWELCOME;
 }
@@ -1174,7 +1176,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_DEBUG, "MULTI_CHANNEL\n");
 channel_mask |= q->subpacket[s].channel_mask = 
bytestream2_get_be32();
 
-if 
(av_get_channel_layout_nb_channels(q->subpacket[s].channel_mask) > 1) {
+if (channels > 1) {
 q->subpacket[s].total_subbands = q->subpacket[s].subbands +
  
q->subpacket[s].js_subband_start;
 q->subpacket[s].joint_stereo = 1;
@@ -1233,8 +1235,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
 q->subpacket[s].gains2.now  = q->subpacket[s].gain_3;
 q->subpacket[s].gains2.previous = q->subpacket[s].gain_4;
 
-if (q->num_subpackets + q->subpacket[s].num_channels > 
q->avctx->channels) {
-av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels 
%d\n", q->num_subpackets, q->avctx->channels);
+if (q->num_subpackets + q->subpacket[s].num_channels > channels) {
+av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels 
%d\n", q->num_subpackets, channels);
 return AVERROR_INVALIDDATA;
 }
 
@@ -1282,10 +1284,11 @@ static av_cold int cook_decode_init(AVCodecContext 
*avctx)
 }
 
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
+av_channel_layout_uninit(>ch_layout);
 if (channel_mask)
-avctx->channel_layout = channel_mask;
+av_channel_layout_from_mask(>ch_layout, channel_mask);
 else
-avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : 
AV_CH_LAYOUT_MONO;
+av_channel_layout_default(>ch_layout, channels);
 
 
 dump_cook_context(q);
diff --git a/libavcodec/cook_parser.c b/libavcodec/cook_parser.c
index a05ebf94b8..0d9473845e 100644
--- a/libavcodec/cook_parser.c
+++ b/libavcodec/cook_parser.c
@@ -41,8 +41,8 @@ static int cook_parse(AVCodecParserContext *s1, 

[FFmpeg-devel] [PATCH 198/281] cng: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/cngdec.c | 3 ++-
 libavcodec/cngenc.c | 6 +-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavcodec/cngdec.c b/libavcodec/cngdec.c
index ecfd4abfc9..30d36f7326 100644
--- a/libavcodec/cngdec.c
+++ b/libavcodec/cngdec.c
@@ -56,7 +56,8 @@ static av_cold int cng_decode_init(AVCodecContext *avctx)
 CNGContext *p = avctx->priv_data;
 
 avctx->sample_fmt  = AV_SAMPLE_FMT_S16;
-avctx->channels= 1;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 avctx->sample_rate = 8000;
 
 p->order= 12;
diff --git a/libavcodec/cngenc.c b/libavcodec/cngenc.c
index 830311f955..d77bbac40e 100644
--- a/libavcodec/cngenc.c
+++ b/libavcodec/cngenc.c
@@ -48,11 +48,6 @@ static av_cold int cng_encode_init(AVCodecContext *avctx)
 CNGContext *p = avctx->priv_data;
 int ret;
 
-if (avctx->channels != 1) {
-av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
-return AVERROR(EINVAL);
-}
-
 avctx->frame_size = 640;
 p->order = 10;
 if ((ret = ff_lpc_init(>lpc, avctx->frame_size, p->order, 
FF_LPC_TYPE_LEVINSON)) < 0)
@@ -113,5 +108,6 @@ const AVCodec ff_comfortnoise_encoder = {
 .close  = cng_encode_close,
 .sample_fmts= (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
  AV_SAMPLE_FMT_NONE },
+.ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } 
},
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
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 197/281] bmvaudio: convert to new channel layout API

2022-01-12 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/bmvaudio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/bmvaudio.c b/libavcodec/bmvaudio.c
index a7eae46103..d81dba8821 100644
--- a/libavcodec/bmvaudio.c
+++ b/libavcodec/bmvaudio.c
@@ -31,8 +31,8 @@ static const int bmv_aud_mults[16] = {
 
 static av_cold int bmv_aud_decode_init(AVCodecContext *avctx)
 {
-avctx->channels   = 2;
-avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+av_channel_layout_uninit(>ch_layout);
+avctx->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
 return 0;
-- 
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".


  1   2   3   4   >