[FFmpeg-devel] [PATCH] avformat/utils: fix logic error in ff_mkdir_p

2022-01-24 Thread Peter Ross
Fix ticket# 9605

Signed-off-by: Peter Ross 
---
 libavformat/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index e643821fc9..1164cebe68 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1135,7 +1135,7 @@ int ff_mkdir_p(const char *path)
 }
 }
 
-if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
+if ((*(pos - 1) != '/') && (*(pos - 1) != '\\')) {
 ret = mkdir(temp, 0755);
 }
 
-- 
2.34.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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

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


[FFmpeg-devel] [PATCH] avformat/img2dec: increase probe score for fourcc variants

2022-01-24 Thread Peter Ross
Signed-off-by: Peter Ross 
---
 libavformat/img2dec.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 2583ca2465..8608252d83 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -1112,7 +1112,6 @@ static int photocd_probe(const AVProbeData *p)
 static int gem_probe(const AVProbeData *p)
 {
 const uint8_t *b = p->buf;
-int ret = 0;
 if ( AV_RB16(b ) >= 1 && AV_RB16(b) <= 3  &&
  AV_RB16(b +  2) >= 8 && AV_RB16(b + 2) <= 779 &&
 (AV_RB16(b +  4) > 0  && AV_RB16(b + 4) <= 32) && /* planes */
@@ -1121,13 +1120,13 @@ static int gem_probe(const AVProbeData *p)
  AV_RB16(b + 10) &&
  AV_RB16(b + 12) &&
  AV_RB16(b + 14)) {
-ret = AVPROBE_SCORE_EXTENSION / 4;
 if (AV_RN32(b + 16) == AV_RN32("STTT") ||
 AV_RN32(b + 16) == AV_RN32("TIMG") ||
 AV_RN32(b + 16) == AV_RN32("XIMG"))
-ret += 1;
+return AVPROBE_SCORE_EXTENSION + 1;
+return AVPROBE_SCORE_EXTENSION / 4;
 }
-return ret;
+return 0;
 }
 
 #define IMAGEAUTO_DEMUXER_0(imgname, codecid)
-- 
2.34.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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

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


Re: [FFmpeg-devel] [PATCH] Fix setsockopt IP_MULTICAST_TTL on OpenBSD

2022-01-24 Thread lance . lmwang
On Wed, Jan 12, 2022 at 12:13:13AM -0500, Brad Smith wrote:
> Fix setsockopt() usage on OpenBSD with IP_MULTICAST_TTL. The field
> type should be an unsigned char on anything but Linux.
> 
> 
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 180d96a988..29aa865fff 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -163,7 +163,13 @@ static int udp_set_multicast_ttl(int sockfd, int 
> mcastTTL,
>  {
>  #ifdef IP_MULTICAST_TTL
>  if (addr->sa_family == AF_INET) {
> -if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, , 
> sizeof(mcastTTL)) < 0) {
> +#ifdef __linux__
> +int ttl = mcastTTL;
> +#else
> +unsigned char ttl = mcastTTL;
> +#endif


I don't have BSD system for test, but I prefer to use socklen_t, please try 
with my proposal patch:

---
 libavformat/udp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 83c042d079..b9baa0a803 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -164,7 +164,9 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
 {
 #ifdef IP_MULTICAST_TTL
 if (addr->sa_family == AF_INET) {
-if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, , 
sizeof(mcastTTL)) < 0) {
+socklen_t ttl = mcastTTL;
+
+if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, , 
sizeof(ttl)) < 0) {
 ff_log_net_error(logctx, AV_LOG_ERROR, 
"setsockopt(IP_MULTICAST_TTL)");
 return ff_neterrno();


> +
> +if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, , 
> sizeof(ttl)) < 0) {
>  ff_log_net_error(NULL, AV_LOG_ERROR, 
> "setsockopt(IP_MULTICAST_TTL)");
>  return ff_neterrno();
>  }
> ___
> 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".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH V2 1/3] libavcodec/qsvenc: Add max slice size support to hevc_qsv

2022-01-24 Thread Xiang, Haihao
On Tue, 2022-01-25 at 15:12 +0800, Wenbin Chen wrote:
> Add max_slice_size option to hevc_qsv as well.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   | 3 +++
>  libavcodec/qsvenc.c | 9 -
>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index e3adbf4325..8966610263 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3397,6 +3397,9 @@ Enable rate distortion optimization.
>  @item @var{max_frame_size}
>  Maximum encoded frame size in bytes.
>  
> +@item @var{max_slice_size}
> +Maximum encoded slice size in bytes.
> +
>  @item @var{p_strategy}
>  Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
>  
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 413e5ae8f6..f311cd9ce4 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -877,11 +877,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 QSV_HAVE_MAX_SLICE_SIZE
> -if (q->max_slice_size >= 0)
> -q->extco2.MaxSliceSize = q->max_slice_size;
> -#endif
> -
>  #if QSV_HAVE_TRELLIS
>  if (avctx->trellis >= 0)
>  q->extco2.Trellis = (avctx->trellis == 0) ? MFX_TRELLIS_OFF :
> (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
> @@ -907,6 +902,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_MAX_SLICE_SIZE
> +if (q->max_slice_size >= 0)
> +q->extco2.MaxSliceSize = q->max_slice_size;
> +#endif
>  #if QSV_HAVE_DISABLEDEBLOCKIDC
>  q->extco2.DisableDeblockingIdc = q->dblk_idc;
>  #endif

Patchset LGTM, will apply. 

-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".


[FFmpeg-devel] [PATCH V2 3/3] libavcodec/qsvenc: Add intra refresh to hevc_qsv and add new intra refresh parameter

2022-01-24 Thread Wenbin Chen
Add intra refresh support to hevc_qsv as well.
Add an new intra refresh type: "horizontal", and an new param
ref_cycle_dist. This param specify the distance between the
beginnings of the intra-refresh cycles in frames.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi| 26 +-
 libavcodec/qsvenc.c  | 21 ++---
 libavcodec/qsvenc.h  |  1 +
 libavcodec/qsvenc_h264.c |  7 +--
 libavcodec/qsvenc_hevc.c |  9 +
 5 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6c1c4df57a..4e35e50e4d 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3344,7 +3344,8 @@ Specifies intra refresh type. The major goal of intra 
refresh is improvement of
 error resilience without significant impact on encoded bitstream size caused by
 I frames. The SDK encoder achieves this by encoding part of each frame in
 refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical} 
means
-vertical refresh, by column of MBs.
+vertical refresh, by column of MBs. To enable intra refresh, B frame should be
+set to 0.
 
 @item @var{int_ref_cycle_size}
 Specifies number of pictures within refresh cycle starting from 2. 0 and 1 are
@@ -3355,6 +3356,9 @@ Specifies QP difference for inserted intra MBs. This is 
signed value in
 [-51, 51] range if target encoding bit-depth for luma samples is 8 and this
 range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth respectively.
 
+@item @var{int_ref_cycle_dist}
+Distance between the beginnings of the intra-refresh cycles in frames.
+
 @item @var{profile}
 @table @samp
 @item unknown
@@ -3463,6 +3467,26 @@ Insert picture timing SEI with pic_struct_syntax element.
 @item @var{transform_skip}
 Turn this option ON to enable transformskip. It is supported on platform equal
 or newer than ICL.
+
+@item @var{int_ref_type}
+Specifies intra refresh type. The major goal of intra refresh is improvement of
+error resilience without significant impact on encoded bitstream size caused by
+I frames. The SDK encoder achieves this by encoding part of each frame in
+refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical} 
means
+vertical refresh, by column of MBs. To enable intra refresh, B frame should be
+set to 0.
+
+@item @var{int_ref_cycle_size}
+Specifies number of pictures within refresh cycle starting from 2. 0 and 1 are
+invalid values.
+
+@item @var{int_ref_qp_delta}
+Specifies QP difference for inserted intra MBs. This is signed value in
+[-51, 51] range if target encoding bit-depth for luma samples is 8 and this
+range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth respectively.
+
+@item @var{int_ref_cycle_dist}
+Distance between the beginnings of the intra-refresh cycles in frames.
 @end table
 
 @subsection MPEG2 Options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index a8d876d6d9..c31776d536 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -364,6 +364,10 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 #if QSV_VERSION_ATLEAST(1, 26)
 av_log(avctx, AV_LOG_VERBOSE, "TransformSkip: %s \n", 
print_threestate(co3->TransformSkip));
 #endif
+
+#if QSV_VERSION_ATLEAST(1, 16)
+av_log(avctx, AV_LOG_VERBOSE, "IntRefCycleDist: %"PRId16"\n", 
co3->IntRefCycleDist);
+#endif
 }
 
 static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
@@ -865,13 +869,6 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 
 #if QSV_HAVE_CO2
 if (avctx->codec_id == AV_CODEC_ID_H264) {
-if (q->int_ref_type >= 0)
-q->extco2.IntRefType = q->int_ref_type;
-if (q->int_ref_cycle_size >= 0)
-q->extco2.IntRefCycleSize = q->int_ref_cycle_size;
-if (q->int_ref_qp_delta != INT16_MIN)
-q->extco2.IntRefQPDelta = q->int_ref_qp_delta;
-
 if (q->bitrate_limit >= 0)
 q->extco2.BitrateLimit = q->bitrate_limit ? 
MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
 if (q->mbbrc >= 0)
@@ -900,6 +897,12 @@ 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 (q->int_ref_type >= 0)
+q->extco2.IntRefType = q->int_ref_type;
+if (q->int_ref_cycle_size >= 0)
+q->extco2.IntRefCycleSize = q->int_ref_cycle_size;
+if (q->int_ref_qp_delta != INT16_MIN)
+q->extco2.IntRefQPDelta = q->int_ref_qp_delta;
 #if QSV_HAVE_MAX_SLICE_SIZE
 if (q->max_slice_size >= 0)
 q->extco2.MaxSliceSize = q->max_slice_size;
@@ -973,6 +976,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 av_log(avctx, AV_LOG_WARNING,
  

[FFmpeg-devel] [PATCH V2 1/3] libavcodec/qsvenc: Add max slice size support to hevc_qsv

2022-01-24 Thread Wenbin Chen
Add max_slice_size option to hevc_qsv as well.

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

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e3adbf4325..8966610263 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3397,6 +3397,9 @@ Enable rate distortion optimization.
 @item @var{max_frame_size}
 Maximum encoded frame size in bytes.
 
+@item @var{max_slice_size}
+Maximum encoded slice size in bytes.
+
 @item @var{p_strategy}
 Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 413e5ae8f6..f311cd9ce4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -877,11 +877,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 QSV_HAVE_MAX_SLICE_SIZE
-if (q->max_slice_size >= 0)
-q->extco2.MaxSliceSize = q->max_slice_size;
-#endif
-
 #if QSV_HAVE_TRELLIS
 if (avctx->trellis >= 0)
 q->extco2.Trellis = (avctx->trellis == 0) ? MFX_TRELLIS_OFF : 
(MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
@@ -907,6 +902,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_MAX_SLICE_SIZE
+if (q->max_slice_size >= 0)
+q->extco2.MaxSliceSize = q->max_slice_size;
+#endif
 #if QSV_HAVE_DISABLEDEBLOCKIDC
 q->extco2.DisableDeblockingIdc = q->dblk_idc;
 #endif
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH V2 2/3] libavcodec/qsvenc: Add b_strategy option to hevc_qsv

2022-01-24 Thread Wenbin Chen
Add b_strategy option to hevc_qsv. By enabling this option, encoder can
use b frames as reference.

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

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 8966610263..6c1c4df57a 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3403,6 +3403,9 @@ Maximum encoded slice 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{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.
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f311cd9ce4..a8d876d6d9 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -888,8 +888,6 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extco2.LookAheadDS = q->look_ahead_downsampling;
 q->extco2.RepeatPPS   = q->repeat_pps ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 
-if (q->b_strategy >= 0)
-q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID : 
MFX_B_REF_OFF;
 if (q->adaptive_i >= 0)
 q->extco2.AdaptiveI = q->adaptive_i ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 if (q->adaptive_b >= 0)
@@ -910,6 +908,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extco2.DisableDeblockingIdc = q->dblk_idc;
 #endif
 
+#if QSV_VERSION_ATLEAST(1, 8)
+if (q->b_strategy >= 0)
+q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID : 
MFX_B_REF_OFF;
+#endif
 #if QSV_VERSION_ATLEAST(1, 9)
 if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
avctx->qmax) {
 av_log(avctx, AV_LOG_ERROR, "qmin and or qmax are set but 
invalid, please make sure min <= max\n");
-- 
2.32.0

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

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


Re: [FFmpeg-devel] [PATCH] Fix setsockopt IP_MULTICAST_TTL on OpenBSD

2022-01-24 Thread Brad Smith
On Mon, Jan 24, 2022 at 01:40:47PM +0100, Michael Niedermayer wrote:
> On Sun, Jan 23, 2022 at 02:55:38PM -0500, Brad Smith wrote:
> > On 1/23/2022 6:57 AM, Michael Niedermayer wrote:
> > 
> > > On Wed, Jan 12, 2022 at 12:13:13AM -0500, Brad Smith wrote:
> > > > Fix setsockopt() usage on OpenBSD with IP_MULTICAST_TTL. The field
> > > > type should be an unsigned char on anything but Linux.
> > > > 
> > > > 
> > > > diff --git a/libavformat/udp.c b/libavformat/udp.c
> > > > index 180d96a988..29aa865fff 100644
> > > > --- a/libavformat/udp.c
> > > > +++ b/libavformat/udp.c
> > > > @@ -163,7 +163,13 @@ static int udp_set_multicast_ttl(int sockfd, int 
> > > > mcastTTL,
> > > >   {
> > > >   #ifdef IP_MULTICAST_TTL
> > > >   if (addr->sa_family == AF_INET) {
> > > > -if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, 
> > > > , sizeof(mcastTTL)) < 0) {
> > > > +#ifdef __linux__
> > > > +int ttl = mcastTTL;
> > > > +#else
> > > > +unsigned char ttl = mcastTTL;
> > > > +#endif
> > > this "ifdef __linux__" feels like the wrong thing to check, dont you 
> > > agree ?
> > 
> > Not sure what you mean.
> 
> "__linux__" seems the wrong property to check for
> this is not
> #ifdef __linux__
> osname = "linux"
> #else
> 
> i would have expected more something like
> #if HAVE_INT_TTL
> int ttl = mcastTTL;
> #else
> 
> or maybe even something along the lines of
> 
> WHATEVER_TTL_TYPE ttl = mcastTTL;
> 
> thx

Ok, how about something like this?


diff --git a/configure b/configure
index 493493b4c5..055ff3c206 100755
--- a/configure
+++ b/configure
@@ -3838,6 +3838,8 @@ doc_deps_any="manpages htmlpages podpages txtpages"
 
 logfile="ffbuild/config.log"
 
+multicast_ttl_type='unsigned char'
+
 # installation paths
 prefix_default="/usr/local"
 bindir_default='${prefix}/bin'
@@ -5653,6 +5655,7 @@ case $target_os in
 linux)
 enable section_data_rel_ro
 enabled_any arm aarch64 && enable_weak linux_perf
+multicast_ttl_type='int'
 ;;
 irix*)
 target_os=irix
@@ -7784,6 +7787,7 @@ cat > $TMPH 

Re: [FFmpeg-devel] [PATCH 3/3] libavcodec/qsvenc: Add intra refresh to hevc_qsv and add new intra refresh parameter

2022-01-24 Thread Chen, Wenbin
> On Mon, 2022-01-24 at 10:59 +0800, Wenbin Chen wrote:
> > Add intra refresh support to hevc_qsv as well.
> > Add an new intra refresh type: "horizontal", and an new param
> > ref_cycle_dist. This param specify the distance between the
> > beginnings of the intra-refresh cycles in frames.
> >
> > Signed-off-by: Wenbin Chen 
> > ---
> >  doc/encoders.texi| 26 +-
> >  libavcodec/qsvenc.c  | 23 ++-
> >  libavcodec/qsvenc.h  |  1 +
> >  libavcodec/qsvenc_h264.c |  7 +--
> >  libavcodec/qsvenc_hevc.c |  9 +
> >  5 files changed, 54 insertions(+), 12 deletions(-)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 6c1c4df57a..4e35e50e4d 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -3344,7 +3344,8 @@ Specifies intra refresh type. The major goal of
> intra
> > refresh is improvement of
> >  error resilience without significant impact on encoded bitstream size
> caused
> > by
> >  I frames. The SDK encoder achieves this by encoding part of each frame in
> >  refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical}
> > means
> > -vertical refresh, by column of MBs.
> > +vertical refresh, by column of MBs. To enable intra refresh, B frame
> should
> > be
> > +set to 0.
> >
> >  @item @var{int_ref_cycle_size}
> >  Specifies number of pictures within refresh cycle starting from 2. 0 and 1
> > are
> > @@ -3355,6 +3356,9 @@ Specifies QP difference for inserted intra MBs.
> This is
> > signed value in
> >  [-51, 51] range if target encoding bit-depth for luma samples is 8 and this
> >  range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth
> > respectively.
> >
> > +@item @var{int_ref_cycle_dist}
> > +Distance between the beginnings of the intra-refresh cycles in frames.
> > +
> >  @item @var{profile}
> >  @table @samp
> >  @item unknown
> > @@ -3463,6 +3467,26 @@ Insert picture timing SEI with pic_struct_syntax
> > element.
> >  @item @var{transform_skip}
> >  Turn this option ON to enable transformskip. It is supported on platform
> > equal
> >  or newer than ICL.
> > +
> > +@item @var{int_ref_type}
> > +Specifies intra refresh type. The major goal of intra refresh is
> improvement
> > of
> > +error resilience without significant impact on encoded bitstream size
> caused
> > by
> > +I frames. The SDK encoder achieves this by encoding part of each frame in
> > +refresh cycle using intra MBs. @var{none} means no refresh.
> @var{vertical}
> > means
> > +vertical refresh, by column of MBs. To enable intra refresh, B frame
> should
> > be
> > +set to 0.
> > +
> > +@item @var{int_ref_cycle_size}
> > +Specifies number of pictures within refresh cycle starting from 2. 0 and 1
> > are
> > +invalid values.
> > +
> > +@item @var{int_ref_qp_delta}
> > +Specifies QP difference for inserted intra MBs. This is signed value in
> > +[-51, 51] range if target encoding bit-depth for luma samples is 8 and this
> > +range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth
> > respectively.
> > +
> > +@item @var{int_ref_cycle_dist}
> > +Distance between the beginnings of the intra-refresh cycles in frames.
> >  @end table
> >
> >  @subsection MPEG2 Options
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index a8d876d6d9..af1529936e 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -267,8 +267,10 @@ static void dump_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q,
> >
> >  #if QSV_HAVE_CO2
> >  av_log(avctx, AV_LOG_VERBOSE,
> > -   "RecoveryPointSEI: %s IntRefType: %"PRIu16"; IntRefCycleSize:
> > %"PRIu16"; IntRefQPDelta: %"PRId16"\n",
> > -   print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2-
> > >IntRefCycleSize, co2->IntRefQPDelta);
> > +   "RecoveryPointSEI: %s IntRefType: %"PRIu16"; IntRefCycleSize:
> > %"PRIu16
> > +   "; IntRefQPDelta: %"PRId16"; IntRefCycleDist: %"PRId16"\n",
> > +   print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2-
> > >IntRefCycleSize,
> > +   co2->IntRefQPDelta, co3->IntRefCycleDist);
> 
> 
> IntRefCycleDist is a member of mfxExtCodingOption3, and was introduced in
> mfx
> version 1.16, so it should be used under QSV_HAVE_CO3 &&
> QSV_VERSION_ATLEAST(1,
> 16), not QSV_HAVE_CO2.
> 
> Thanks
> Haihao

Thanks for review. I will fix this.

Thanks
Wenbin

> 
> 
> >
> >  av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %d; ", co2-
> >MaxFrameSize);
> >  #if QSV_HAVE_MAX_SLICE_SIZE
> > @@ -865,13 +867,6 @@ static int init_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q)
> >
> >  #if QSV_HAVE_CO2
> >  if (avctx->codec_id == AV_CODEC_ID_H264) {
> > -if (q->int_ref_type >= 0)
> > -q->extco2.IntRefType = q->int_ref_type;
> > -if (q->int_ref_cycle_size >= 0)
> > -q->extco2.IntRefCycleSize = q->int_ref_cycle_size;
> > -if (q->int_ref_qp_delta != INT16_MIN)
> > -  

Re: [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add max slice size support to hevc_qsv

2022-01-24 Thread Xiang, Haihao
On Mon, 2022-01-24 at 10:59 +0800, Wenbin Chen wrote:
> Add max_slice_size option to hevc_qsv as well.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   | 3 +++
>  libavcodec/qsvenc.c | 9 -
>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index e3adbf4325..8966610263 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3397,6 +3397,9 @@ Enable rate distortion optimization.
>  @item @var{max_frame_size}
>  Maximum encoded frame size in bytes.
>  
> +@item @var{max_slice_size}
> +Maximum encoded slice size in bytes.
> +
>  @item @var{p_strategy}
>  Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0).
>  
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 413e5ae8f6..f311cd9ce4 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -877,11 +877,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 QSV_HAVE_MAX_SLICE_SIZE
> -if (q->max_slice_size >= 0)
> -q->extco2.MaxSliceSize = q->max_slice_size;
> -#endif
> -
>  #if QSV_HAVE_TRELLIS
>  if (avctx->trellis >= 0)
>  q->extco2.Trellis = (avctx->trellis == 0) ? MFX_TRELLIS_OFF :
> (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
> @@ -907,6 +902,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_MAX_SLICE_SIZE
> +if (q->max_slice_size >= 0)
> +q->extco2.MaxSliceSize = q->max_slice_size;
> +#endif
>  #if QSV_HAVE_DISABLEDEBLOCKIDC
>  q->extco2.DisableDeblockingIdc = q->dblk_idc;
>  #endif

LGTM, thx

___
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 2/3] libavcodec/qsvenc: Add b_strategy option to hevc_qsv

2022-01-24 Thread Xiang, Haihao
On Mon, 2022-01-24 at 10:59 +0800, Wenbin Chen wrote:
> Add b_strategy option to hevc_qsv. By enabling this option, encoder can
> use b frames as reference.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi   | 3 +++
>  libavcodec/qsvenc.c | 6 --
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 8966610263..6c1c4df57a 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3403,6 +3403,9 @@ Maximum encoded slice 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{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.
>  
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index f311cd9ce4..a8d876d6d9 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -888,8 +888,6 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->extco2.LookAheadDS = q->look_ahead_downsampling;
>  q->extco2.RepeatPPS   = q->repeat_pps ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  
> -if (q->b_strategy >= 0)
> -q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID :
> MFX_B_REF_OFF;
>  if (q->adaptive_i >= 0)
>  q->extco2.AdaptiveI = q->adaptive_i ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  if (q->adaptive_b >= 0)
> @@ -910,6 +908,10 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->extco2.DisableDeblockingIdc = q->dblk_idc;
>  #endif
>  
> +#if QSV_VERSION_ATLEAST(1, 8)
> +if (q->b_strategy >= 0)
> +q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID :
> MFX_B_REF_OFF;
> +#endif
>  #if QSV_VERSION_ATLEAST(1, 9)
>  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx-
> >qmax) {
>  av_log(avctx, AV_LOG_ERROR, "qmin and or qmax are set but
> invalid, please make sure min <= max\n");

LGTM, thx

-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 3/3] libavcodec/qsvenc: Add intra refresh to hevc_qsv and add new intra refresh parameter

2022-01-24 Thread Xiang, Haihao
On Mon, 2022-01-24 at 10:59 +0800, Wenbin Chen wrote:
> Add intra refresh support to hevc_qsv as well.
> Add an new intra refresh type: "horizontal", and an new param
> ref_cycle_dist. This param specify the distance between the
> beginnings of the intra-refresh cycles in frames.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  doc/encoders.texi| 26 +-
>  libavcodec/qsvenc.c  | 23 ++-
>  libavcodec/qsvenc.h  |  1 +
>  libavcodec/qsvenc_h264.c |  7 +--
>  libavcodec/qsvenc_hevc.c |  9 +
>  5 files changed, 54 insertions(+), 12 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 6c1c4df57a..4e35e50e4d 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3344,7 +3344,8 @@ Specifies intra refresh type. The major goal of intra
> refresh is improvement of
>  error resilience without significant impact on encoded bitstream size caused
> by
>  I frames. The SDK encoder achieves this by encoding part of each frame in
>  refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical}
> means
> -vertical refresh, by column of MBs.
> +vertical refresh, by column of MBs. To enable intra refresh, B frame should
> be
> +set to 0.
>  
>  @item @var{int_ref_cycle_size}
>  Specifies number of pictures within refresh cycle starting from 2. 0 and 1
> are
> @@ -3355,6 +3356,9 @@ Specifies QP difference for inserted intra MBs. This is
> signed value in
>  [-51, 51] range if target encoding bit-depth for luma samples is 8 and this
>  range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth
> respectively.
>  
> +@item @var{int_ref_cycle_dist}
> +Distance between the beginnings of the intra-refresh cycles in frames.
> +
>  @item @var{profile}
>  @table @samp
>  @item unknown
> @@ -3463,6 +3467,26 @@ Insert picture timing SEI with pic_struct_syntax
> element.
>  @item @var{transform_skip}
>  Turn this option ON to enable transformskip. It is supported on platform
> equal
>  or newer than ICL.
> +
> +@item @var{int_ref_type}
> +Specifies intra refresh type. The major goal of intra refresh is improvement
> of
> +error resilience without significant impact on encoded bitstream size caused
> by
> +I frames. The SDK encoder achieves this by encoding part of each frame in
> +refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical}
> means
> +vertical refresh, by column of MBs. To enable intra refresh, B frame should
> be
> +set to 0.
> +
> +@item @var{int_ref_cycle_size}
> +Specifies number of pictures within refresh cycle starting from 2. 0 and 1
> are
> +invalid values.
> +
> +@item @var{int_ref_qp_delta}
> +Specifies QP difference for inserted intra MBs. This is signed value in
> +[-51, 51] range if target encoding bit-depth for luma samples is 8 and this
> +range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth
> respectively.
> +
> +@item @var{int_ref_cycle_dist}
> +Distance between the beginnings of the intra-refresh cycles in frames.
>  @end table
>  
>  @subsection MPEG2 Options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index a8d876d6d9..af1529936e 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -267,8 +267,10 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  
>  #if QSV_HAVE_CO2
>  av_log(avctx, AV_LOG_VERBOSE,
> -   "RecoveryPointSEI: %s IntRefType: %"PRIu16"; IntRefCycleSize:
> %"PRIu16"; IntRefQPDelta: %"PRId16"\n",
> -   print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2-
> >IntRefCycleSize, co2->IntRefQPDelta);
> +   "RecoveryPointSEI: %s IntRefType: %"PRIu16"; IntRefCycleSize:
> %"PRIu16
> +   "; IntRefQPDelta: %"PRId16"; IntRefCycleDist: %"PRId16"\n",
> +   print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2-
> >IntRefCycleSize,
> +   co2->IntRefQPDelta, co3->IntRefCycleDist);


IntRefCycleDist is a member of mfxExtCodingOption3, and was introduced in mfx
version 1.16, so it should be used under QSV_HAVE_CO3 && QSV_VERSION_ATLEAST(1,
16), not QSV_HAVE_CO2. 

Thanks
Haihao


>  
>  av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %d; ", co2->MaxFrameSize);
>  #if QSV_HAVE_MAX_SLICE_SIZE
> @@ -865,13 +867,6 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  
>  #if QSV_HAVE_CO2
>  if (avctx->codec_id == AV_CODEC_ID_H264) {
> -if (q->int_ref_type >= 0)
> -q->extco2.IntRefType = q->int_ref_type;
> -if (q->int_ref_cycle_size >= 0)
> -q->extco2.IntRefCycleSize = q->int_ref_cycle_size;
> -if (q->int_ref_qp_delta != INT16_MIN)
> -q->extco2.IntRefQPDelta = q->int_ref_qp_delta;
> -
>  if (q->bitrate_limit >= 0)
>  q->extco2.BitrateLimit = q->bitrate_limit ?
> MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
>  if (q->mbbrc >= 0)
> @@ -900,6 +895,12 @@ static int init_video_param(AVCodecContext 

Re: [FFmpeg-devel] [PATCH 001/293 v8] avutil/channel_layout: Add a new channel layout API

2022-01-24 Thread James Almer




On 1/24/2022 6:08 PM, Marton Balint wrote:



On Mon, 24 Jan 2022, James Almer wrote:


From: Anton Khirnov 

The new API is more extensible and allows for custom layouts.
More accurate information is exported, eg for decoders that do not
set a channel layout, lavc will not make one up for them.

Deprecate the old API working with just uint64_t bitmasks.

Expanded and completed by Vittorio Giovara 
and James Almer .
Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
Changes since last version:

*Both av_channel_layout_describe() and av_channel_layout_from_string() 
now

support a "2 channels (FL+LFE)" syntax, to signal native (usually
non-standard) or custom order layouts.
*a single decimal value is now interpreted as a mask by
av_channel_layout_from_string(), same as a single hexadecimal value.
*De-duplicated code by simplifying 
av_channel_layout_channel_from_string().


AV_CHAN_UNKWNOWN is fixed in the Amibsonic patch, but it should be fixed 
in this patch.


Constant rebases and amends can do that, sorry. Fixed in the github branch.




+/**
+ * Check whether a channel layout is valid, i.e. can possibly 
describe audio

+ * data.
+ *
+ * @param channel_layout input channel layout
+ * @return 1 if channel_layout is valid, 0 otherwise.
+ */
+int av_channel_layout_check(const AVChannelLayout *channel_layout);


I still find the name av_channel_layout_valid() more readable, but feel 
free to keep it as is if you disagree.


If others also prefer it then I'll change it. I personally don't find
av_channel_layout_check() worse than av_channel_layout_valid().



Thanks,
Marton
___
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 001/293 v8] avutil/channel_layout: Add a new channel layout API

2022-01-24 Thread Marton Balint




On Mon, 24 Jan 2022, James Almer wrote:


From: Anton Khirnov 

The new API is more extensible and allows for custom layouts.
More accurate information is exported, eg for decoders that do not
set a channel layout, lavc will not make one up for them.

Deprecate the old API working with just uint64_t bitmasks.

Expanded and completed by Vittorio Giovara 
and James Almer .
Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
Changes since last version:

*Both av_channel_layout_describe() and av_channel_layout_from_string() now
support a "2 channels (FL+LFE)" syntax, to signal native (usually
non-standard) or custom order layouts.
*a single decimal value is now interpreted as a mask by
av_channel_layout_from_string(), same as a single hexadecimal value.
*De-duplicated code by simplifying av_channel_layout_channel_from_string().


AV_CHAN_UNKWNOWN is fixed in the Amibsonic patch, but it should be fixed 
in this patch.



+/**
+ * Check whether a channel layout is valid, i.e. can possibly describe audio
+ * data.
+ *
+ * @param channel_layout input channel layout
+ * @return 1 if channel_layout is valid, 0 otherwise.
+ */
+int av_channel_layout_check(const AVChannelLayout *channel_layout);


I still find the name av_channel_layout_valid() more readable, but feel 
free to keep it as is if you disagree.


Thanks,
Marton
___
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 001/293 v8] avutil/channel_layout: Add a new channel layout API

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

The new API is more extensible and allows for custom layouts.
More accurate information is exported, eg for decoders that do not
set a channel layout, lavc will not make one up for them.

Deprecate the old API working with just uint64_t bitmasks.

Expanded and completed by Vittorio Giovara 
and James Almer .
Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
Changes since last version:

*Both av_channel_layout_describe() and av_channel_layout_from_string() now
 support a "2 channels (FL+LFE)" syntax, to signal native (usually
 non-standard) or custom order layouts.
*a single decimal value is now interpreted as a mask by
 av_channel_layout_from_string(), same as a single hexadecimal value.
*De-duplicated code by simplifying av_channel_layout_channel_from_string().

The entire set can still be found in
https://github.com/jamrial/FFmpeg/commits/channel_layout4

 libavutil/channel_layout.c | 661 +
 libavutil/channel_layout.h | 551 +--
 libavutil/version.h|   1 +
 3 files changed, 1110 insertions(+), 103 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index ac773a9e63..fe3e94ee86 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -30,6 +30,7 @@
 #include "channel_layout.h"
 #include "bprint.h"
 #include "common.h"
+#include "opt.h"
 
 struct channel_name {
 const char *name;
@@ -37,81 +38,147 @@ struct channel_name {
 };
 
 static const struct channel_name channel_names[] = {
- [0] = { "FL","front left"},
- [1] = { "FR","front right"   },
- [2] = { "FC","front center"  },
- [3] = { "LFE",   "low frequency" },
- [4] = { "BL","back left" },
- [5] = { "BR","back right"},
- [6] = { "FLC",   "front left-of-center"  },
- [7] = { "FRC",   "front right-of-center" },
- [8] = { "BC","back center"   },
- [9] = { "SL","side left" },
-[10] = { "SR","side right"},
-[11] = { "TC","top center"},
-[12] = { "TFL",   "top front left"},
-[13] = { "TFC",   "top front center"  },
-[14] = { "TFR",   "top front right"   },
-[15] = { "TBL",   "top back left" },
-[16] = { "TBC",   "top back center"   },
-[17] = { "TBR",   "top back right"},
-[29] = { "DL","downmix left"  },
-[30] = { "DR","downmix right" },
-[31] = { "WL","wide left" },
-[32] = { "WR","wide right"},
-[33] = { "SDL",   "surround direct left"  },
-[34] = { "SDR",   "surround direct right" },
-[35] = { "LFE2",  "low frequency 2"   },
-[36] = { "TSL",   "top side left" },
-[37] = { "TSR",   "top side right"},
-[38] = { "BFC",   "bottom front center"   },
-[39] = { "BFL",   "bottom front left" },
-[40] = { "BFR",   "bottom front right"},
+[AV_CHAN_FRONT_LEFT   ] = { "FL","front left"},
+[AV_CHAN_FRONT_RIGHT  ] = { "FR","front right"   },
+[AV_CHAN_FRONT_CENTER ] = { "FC","front center"  },
+[AV_CHAN_LOW_FREQUENCY] = { "LFE",   "low frequency" },
+[AV_CHAN_BACK_LEFT] = { "BL","back left" },
+[AV_CHAN_BACK_RIGHT   ] = { "BR","back right"},
+[AV_CHAN_FRONT_LEFT_OF_CENTER ] = { "FLC",   "front left-of-center"  },
+[AV_CHAN_FRONT_RIGHT_OF_CENTER] = { "FRC",   "front right-of-center" },
+[AV_CHAN_BACK_CENTER  ] = { "BC","back center"   },
+[AV_CHAN_SIDE_LEFT] = { "SL","side left" },
+[AV_CHAN_SIDE_RIGHT   ] = { "SR","side right"},
+[AV_CHAN_TOP_CENTER   ] = { "TC","top center"},
+[AV_CHAN_TOP_FRONT_LEFT   ] = { "TFL",   "top front left"},
+[AV_CHAN_TOP_FRONT_CENTER ] = { "TFC",   "top front center"  },
+[AV_CHAN_TOP_FRONT_RIGHT  ] = { "TFR",   "top front right"   },
+[AV_CHAN_TOP_BACK_LEFT] = { "TBL",   "top back left" },
+[AV_CHAN_TOP_BACK_CENTER  ] = { "TBC",   "top back center"   },
+[AV_CHAN_TOP_BACK_RIGHT   ] = { "TBR",   "top back right"},
+[AV_CHAN_STEREO_LEFT  ] = { "DL","downmix left"  },
+[AV_CHAN_STEREO_RIGHT ] = { "DR","downmix right" },
+[AV_CHAN_WIDE_LEFT] = { "WL","wide left" },
+[AV_CHAN_WIDE_RIGHT   ] = { "WR","wide right"},
+

[FFmpeg-devel] [PATCH v2 18/18] avcodec/h264_parse: Move ff_h264_get_profile() to h264_ps.h

2022-01-24 Thread Andreas Rheinhardt
It is a more fitting place for it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_parse.h| 5 -
 libavcodec/h264_ps.h   | 5 +
 libavcodec/mediacodecdec.c | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 201d983952..4ee863df66 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -124,11 +124,6 @@ int ff_h264_decode_extradata(const uint8_t *data, int 
size, H264ParamSets *ps,
  int *is_avc, int *nal_length_size,
  int err_recognition, void *logctx);
 
-/**
- * compute profile from sps
- */
-int ff_h264_get_profile(const SPS *sps);
-
 static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
 {
 #if HAVE_BIGENDIAN
diff --git a/libavcodec/h264_ps.h b/libavcodec/h264_ps.h
index 3f1ab72e38..dc52835ed4 100644
--- a/libavcodec/h264_ps.h
+++ b/libavcodec/h264_ps.h
@@ -152,6 +152,11 @@ typedef struct H264ParamSets {
 int overread_warning_printed[2];
 } H264ParamSets;
 
+/**
+ * compute profile from sps
+ */
+int ff_h264_get_profile(const SPS *sps);
+
 /**
  * Decode SPS
  */
diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index 04d5026e68..e8af00ec00 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -33,6 +33,7 @@
 #include "avcodec.h"
 #include "decode.h"
 #include "h264_parse.h"
+#include "h264_ps.h"
 #include "hevc_parse.h"
 #include "hwconfig.h"
 #include "internal.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 17/18] avcodec/h264_*: Remove unnecessary internal.h inclusions

2022-01-24 Thread Andreas Rheinhardt
Also remove some other unnecessary headers while at it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_cabac.c  | 1 -
 libavcodec/h264_cavlc.c  | 1 -
 libavcodec/h264_direct.c | 1 -
 libavcodec/h264_loopfilter.c | 3 ---
 libavcodec/h264_mvpred.h | 2 --
 5 files changed, 8 deletions(-)

diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index 884d392022..703b27aa96 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -34,7 +34,6 @@
 #include "config.h"
 #include "cabac.h"
 #include "cabac_functions.h"
-#include "internal.h"
 #include "h264dec.h"
 #include "h264data.h"
 #include "h264_mvpred.h"
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index fa8ba5dac7..9191df0303 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -28,7 +28,6 @@
 #define CABAC(h) 0
 #define UNCHECKED_BITSTREAM_READER 1
 
-#include "internal.h"
 #include "h264dec.h"
 #include "h264_mvpred.h"
 #include "h264data.h"
diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c
index 8f07981130..93c2e1e438 100644
--- a/libavcodec/h264_direct.c
+++ b/libavcodec/h264_direct.c
@@ -25,7 +25,6 @@
  * @author Michael Niedermayer 
  */
 
-#include "internal.h"
 #include "avcodec.h"
 #include "h264dec.h"
 #include "h264_ps.h"
diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c
index 558ec6c02d..2440cfa831 100644
--- a/libavcodec/h264_loopfilter.c
+++ b/libavcodec/h264_loopfilter.c
@@ -28,13 +28,10 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem_internal.h"
-#include "internal.h"
 #include "avcodec.h"
 #include "h264dec.h"
 #include "h264_ps.h"
-#include "mathops.h"
 #include "mpegutils.h"
-#include "rectangle.h"
 
 /* Deblocking filter (p153) */
 static const uint8_t alpha_table[52*3] = {
diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h
index 19d9ee462d..46ae2738f9 100644
--- a/libavcodec/h264_mvpred.h
+++ b/libavcodec/h264_mvpred.h
@@ -28,8 +28,6 @@
 #ifndef AVCODEC_H264_MVPRED_H
 #define AVCODEC_H264_MVPRED_H
 
-#include "internal.h"
-#include "avcodec.h"
 #include "h264dec.h"
 #include "mpegutils.h"
 #include "libavutil/avassert.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 16/18] avcodec/h264dec: Remove unnecessary headers

2022-01-24 Thread Andreas Rheinhardt
E.g. the inclusion of parser.h comes from a time when
the parser used a H264Context.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264dec.c | 1 +
 libavcodec/h264dec.h | 3 ---
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index ed9a74b0c6..a47caa95e8 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -30,6 +30,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 #include "libavutil/video_enc_params.h"
 
 #include "internal.h"
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index f623d60893..79835e2d09 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -31,7 +31,6 @@
 #include "libavutil/buffer.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem_internal.h"
-#include "libavutil/thread.h"
 
 #include "cabac.h"
 #include "error_resilience.h"
@@ -45,8 +44,6 @@
 #include "h264qpel.h"
 #include "h274.h"
 #include "mpegutils.h"
-#include "parser.h"
-#include "qpeldsp.h"
 #include "rectangle.h"
 #include "videodsp.h"
 
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 15/18] avcodec/h264*: Remove unnecessary h264_mvpred.h inclusions

2022-01-24 Thread Andreas Rheinhardt
This is only needed by h264_cabac.c and h264_cavlc.c.
Also fix up the other headers while at it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_picture.c | 9 -
 libavcodec/h264_slice.c   | 3 +--
 libavcodec/h264dec.c  | 9 -
 3 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index adf8a32378..dcd5874c2e 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -26,19 +26,10 @@
  */
 
 #include "libavutil/avassert.h"
-#include "libavutil/imgutils.h"
-#include "internal.h"
-#include "cabac.h"
-#include "cabac_functions.h"
 #include "error_resilience.h"
 #include "avcodec.h"
 #include "h264dec.h"
-#include "h264data.h"
-#include "h264chroma.h"
-#include "h264_mvpred.h"
-#include "mathops.h"
 #include "mpegutils.h"
-#include "rectangle.h"
 #include "thread.h"
 
 void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 32df9fd3ae..dc636c5e78 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -27,8 +27,8 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/display.h"
-#include "libavutil/imgutils.h"
 #include "libavutil/film_grain_params.h"
+#include "libavutil/pixdesc.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
 #include "internal.h"
@@ -40,7 +40,6 @@
 #include "h264dec.h"
 #include "h264data.h"
 #include "h264chroma.h"
-#include "h264_mvpred.h"
 #include "h264_ps.h"
 #include "golomb.h"
 #include "mathops.h"
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 3706ae0e31..ed9a74b0c6 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -28,29 +28,20 @@
 #define UNCHECKED_BITSTREAM_READER 1
 
 #include "libavutil/avassert.h"
-#include "libavutil/display.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
-#include "libavutil/stereo3d.h"
 #include "libavutil/video_enc_params.h"
 
 #include "internal.h"
-#include "bytestream.h"
-#include "cabac.h"
-#include "cabac_functions.h"
 #include "error_resilience.h"
 #include "avcodec.h"
 #include "h264.h"
 #include "h264dec.h"
 #include "h2645_parse.h"
 #include "h264data.h"
-#include "h264chroma.h"
-#include "h264_mvpred.h"
 #include "h264_ps.h"
 #include "golomb.h"
 #include "hwconfig.h"
-#include "mathops.h"
-#include "me_cmp.h"
 #include "mpegutils.h"
 #include "profiles.h"
 #include "rectangle.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 14/18] lavc/svq3: stop including h264dec.h

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

The only thing that is actually used directly from there is the
PART_NOT_AVAILABLE constant, which can be trivially copied to svq3
decoder itself.

Otherwise it only depends on other indirectly included headers.
---
 libavcodec/svq3.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index a3f434ff8d..f06404da9d 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -49,13 +49,16 @@
 #include "internal.h"
 #include "avcodec.h"
 #include "mpegutils.h"
-#include "h264dec.h"
 #include "h264data.h"
+#include "h264dsp.h"
+#include "h264pred.h"
+#include "h264_parse.h"
 #include "golomb.h"
 #include "hpeldsp.h"
 #include "mathops.h"
 #include "rectangle.h"
 #include "tpeldsp.h"
+#include "videodsp.h"
 
 #if CONFIG_ZLIB
 #include 
@@ -63,6 +66,8 @@
 
 #include "svq1.h"
 
+#define PART_NOT_AVAILABLE -2
+
 /**
  * @file
  * svq3 decoder.
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 13/18] lavc/x86/h264_qpel: stop unnecessarily including h264dec

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/x86/h264_qpel.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/x86/h264_qpel.c b/libavcodec/x86/h264_qpel.c
index 320d98933a..dda50ded89 100644
--- a/libavcodec/x86/h264_qpel.c
+++ b/libavcodec/x86/h264_qpel.c
@@ -24,7 +24,6 @@
 #include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/h264dec.h"
 #include "libavcodec/h264qpel.h"
 #include "libavcodec/pixels.h"
 #include "fpel.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 12/18] lavc/vdpau: stop unnecessarily including h264dec

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/vdpau.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 7c29746adb..f96ac15e2a 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -26,7 +26,6 @@
 #include "avcodec.h"
 #include "decode.h"
 #include "internal.h"
-#include "h264dec.h"
 #include "vc1.h"
 #include "vdpau.h"
 #include "vdpau_internal.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 11/18] lavc/h264: move MB_TYPE defs from h264dec.h to h264_parse

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

Allows to stop including h264dec.h in h264data.c.
---
 libavcodec/h264_parse.h | 3 +++
 libavcodec/h264data.c   | 2 +-
 libavcodec/h264dec.h| 2 --
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 52b224f4c5..201d983952 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -33,6 +33,9 @@
 #include "get_bits.h"
 #include "h264_ps.h"
 
+#define MB_TYPE_REF0   MB_TYPE_ACPRED // dirty but it fits in 16 bit
+#define MB_TYPE_8x8DCT 0x0100
+
 // This table must be here because scan8[constant] must be known at compiletime
 static const uint8_t scan8[16 * 3 + 3] = {
 4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
diff --git a/libavcodec/h264data.c b/libavcodec/h264data.c
index eb8728a9db..3e9e68cb04 100644
--- a/libavcodec/h264data.c
+++ b/libavcodec/h264data.c
@@ -30,7 +30,7 @@
 
 #include "libavutil/avutil.h"
 
-#include "h264dec.h"
+#include "h264_parse.h"
 #include "h264data.h"
 #include "mpegutils.h"
 
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 5266420fa1..f623d60893 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -95,8 +95,6 @@
 #define CHROMA422(h) ((h)->ps.sps->chroma_format_idc == 2)
 #define CHROMA444(h) ((h)->ps.sps->chroma_format_idc == 3)
 
-#define MB_TYPE_REF0   MB_TYPE_ACPRED // dirty but it fits in 16 bit
-#define MB_TYPE_8x8DCT 0x0100
 #define IS_REF0(a) ((a) & MB_TYPE_REF0)
 #define IS_8x8DCT(a)   ((a) & MB_TYPE_8x8DCT)
 
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 10/18] lavc/h264_parse: stop including h264dec.h

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

It is unnecessary and only files that are parts of the decoder (as
opposed to standalone code called by the decoder) are allowed to include
h264dec.h
---
 libavcodec/h264_parse.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 1c1d1c04b0..97ddf0e437 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -20,9 +20,11 @@
 #include "get_bits.h"
 #include "golomb.h"
 #include "h264.h"
-#include "h264dec.h"
+#include "h264pred.h"
 #include "h264_parse.h"
 #include "h264_ps.h"
+#include "h2645_parse.h"
+#include "mpegutils.h"
 
 int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
   const int *ref_count, int slice_type_nos,
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 06/18] lavc/h264: replace MAX_DELAYED_PIC_COUNT by H264_MAX_DPB_FRAMES

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/h264_ps.c|  4 ++--
 libavcodec/h264_slice.c | 12 ++--
 libavcodec/h264dec.h|  6 ++
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index e21c2b56ac..f68d5bf81c 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -485,7 +485,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 sps->ref_frame_count = get_ue_golomb_31(gb);
 if (avctx->codec_tag == MKTAG('S', 'M', 'V', '2'))
 sps->ref_frame_count = FFMAX(2, sps->ref_frame_count);
-if (sps->ref_frame_count > MAX_DELAYED_PIC_COUNT) {
+if (sps->ref_frame_count > H264_MAX_DPB_FRAMES) {
 av_log(avctx, AV_LOG_ERROR,
"too many reference frames %d\n", sps->ref_frame_count);
 goto fail;
@@ -590,7 +590,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
  * level */
 if (!sps->bitstream_restriction_flag &&
 (sps->ref_frame_count || avctx->strict_std_compliance >= 
FF_COMPLIANCE_STRICT)) {
-sps->num_reorder_frames = MAX_DELAYED_PIC_COUNT - 1;
+sps->num_reorder_frames = H264_MAX_DPB_FRAMES - 1;
 for (i = 0; i < FF_ARRAY_ELEMS(level_max_dpb_mbs); i++) {
 if (level_max_dpb_mbs[i][0] == sps->level_idc) {
 sps->num_reorder_frames = FFMIN(level_max_dpb_mbs[i][1] / 
(sps->mb_width * sps->mb_height),
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index d6d4497fc9..32df9fd3ae 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1456,7 +1456,7 @@ static int h264_select_output_frame(H264Context *h)
 }
 
 for (i = 0; 1; i++) {
-if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){
+if(i == H264_MAX_DPB_FRAMES || cur->poc < h->last_pocs[i]){
 if(i)
 h->last_pocs[i-1] = cur->poc;
 break;
@@ -1464,13 +1464,13 @@ static int h264_select_output_frame(H264Context *h)
 h->last_pocs[i-1]= h->last_pocs[i];
 }
 }
-out_of_order = MAX_DELAYED_PIC_COUNT - i;
+out_of_order = H264_MAX_DPB_FRAMES - i;
 if(   cur->f->pict_type == AV_PICTURE_TYPE_B
-   || (h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > INT_MIN && 
h->last_pocs[MAX_DELAYED_PIC_COUNT-1] - 
(int64_t)h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > 2))
+   || (h->last_pocs[H264_MAX_DPB_FRAMES-2] > INT_MIN && 
h->last_pocs[H264_MAX_DPB_FRAMES-1] - 
(int64_t)h->last_pocs[H264_MAX_DPB_FRAMES-2] > 2))
 out_of_order = FFMAX(out_of_order, 1);
-if (out_of_order == MAX_DELAYED_PIC_COUNT) {
+if (out_of_order == H264_MAX_DPB_FRAMES) {
 av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, 
h->last_pocs[0]);
-for (i = 1; i < MAX_DELAYED_PIC_COUNT; i++)
+for (i = 1; i < H264_MAX_DPB_FRAMES; i++)
 h->last_pocs[i] = INT_MIN;
 h->last_pocs[0] = cur->poc;
 cur->mmco_reset = 1;
@@ -1484,7 +1484,7 @@ static int h264_select_output_frame(H264Context *h)
 while (h->delayed_pic[pics])
 pics++;
 
-av_assert0(pics <= MAX_DELAYED_PIC_COUNT);
+av_assert0(pics <= H264_MAX_DPB_FRAMES);
 
 h->delayed_pic[pics++] = cur;
 if (cur->reference == 0)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index c7662f930e..7553dd808c 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -52,8 +52,6 @@
 
 #define H264_MAX_PICTURE_COUNT 36
 
-#define MAX_DELAYED_PIC_COUNT  16
-
 /* Compiling in interlaced support reduces the speed
  * of progressive decoding by about 2%. */
 #define ALLOW_INTERLACE
@@ -465,8 +463,8 @@ typedef struct H264Context {
 H264Ref default_ref[2];
 H264Picture *short_ref[32];
 H264Picture *long_ref[32];
-H264Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size?
-int last_pocs[MAX_DELAYED_PIC_COUNT];
+H264Picture *delayed_pic[H264_MAX_DPB_FRAMES + 2]; // FIXME size?
+int last_pocs[H264_MAX_DPB_FRAMES];
 H264Picture *next_output_pic;
 int next_outputed_poc;
 int poc_offset; ///< PicOrderCnt_offset from SMPTE RDD-2006
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 09/18] lavc/h264data.h: stop including h264dec.h

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

This header does not need anything from there.
---
 libavcodec/h264data.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264data.h b/libavcodec/h264data.h
index 2968b08b7e..988352aa9a 100644
--- a/libavcodec/h264data.h
+++ b/libavcodec/h264data.h
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "h264dec.h"
+#include "h264.h"
 
 extern const uint8_t ff_h264_golomb_to_pict_type[5];
 extern const uint8_t ff_h264_golomb_to_intra4x4_cbp[48];
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 08/18] lavc/h264: move some shared code from h264dec to h264_parse

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/h264_parse.h  | 32 
 libavcodec/h264dec.h | 26 --
 tests/checkasm/h264dsp.c |  1 +
 3 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 05732326d3..52b224f4c5 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -24,9 +24,32 @@
 #ifndef AVCODEC_H264_PARSE_H
 #define AVCODEC_H264_PARSE_H
 
+#include "config.h"
+
+#include 
+
+#include "libavutil/attributes.h"
+
 #include "get_bits.h"
 #include "h264_ps.h"
 
+// This table must be here because scan8[constant] must be known at compiletime
+static const uint8_t scan8[16 * 3 + 3] = {
+4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
+6 +  1 * 8, 7 +  1 * 8, 6 +  2 * 8, 7 +  2 * 8,
+4 +  3 * 8, 5 +  3 * 8, 4 +  4 * 8, 5 +  4 * 8,
+6 +  3 * 8, 7 +  3 * 8, 6 +  4 * 8, 7 +  4 * 8,
+4 +  6 * 8, 5 +  6 * 8, 4 +  7 * 8, 5 +  7 * 8,
+6 +  6 * 8, 7 +  6 * 8, 6 +  7 * 8, 7 +  7 * 8,
+4 +  8 * 8, 5 +  8 * 8, 4 +  9 * 8, 5 +  9 * 8,
+6 +  8 * 8, 7 +  8 * 8, 6 +  9 * 8, 7 +  9 * 8,
+4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
+6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
+4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
+6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
+0 +  0 * 8, 0 +  5 * 8, 0 + 10 * 8
+};
+
 /**
  * Memory management control operation opcode.
  */
@@ -103,4 +126,13 @@ int ff_h264_decode_extradata(const uint8_t *data, int 
size, H264ParamSets *ps,
  */
 int ff_h264_get_profile(const SPS *sps);
 
+static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
+{
+#if HAVE_BIGENDIAN
+return (b & 0x) + (a << 16);
+#else
+return (a & 0x) + (b << 16);
+#endif
+}
+
 #endif /* AVCODEC_H264_PARSE_H */
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 7553dd808c..5266420fa1 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -642,32 +642,6 @@ void ff_h264_filter_mb(const H264Context *h, 
H264SliceContext *sl, int mb_x, int
 #define LUMA_DC_BLOCK_INDEX   48
 #define CHROMA_DC_BLOCK_INDEX 49
 
-// This table must be here because scan8[constant] must be known at compiletime
-static const uint8_t scan8[16 * 3 + 3] = {
-4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
-6 +  1 * 8, 7 +  1 * 8, 6 +  2 * 8, 7 +  2 * 8,
-4 +  3 * 8, 5 +  3 * 8, 4 +  4 * 8, 5 +  4 * 8,
-6 +  3 * 8, 7 +  3 * 8, 6 +  4 * 8, 7 +  4 * 8,
-4 +  6 * 8, 5 +  6 * 8, 4 +  7 * 8, 5 +  7 * 8,
-6 +  6 * 8, 7 +  6 * 8, 6 +  7 * 8, 7 +  7 * 8,
-4 +  8 * 8, 5 +  8 * 8, 4 +  9 * 8, 5 +  9 * 8,
-6 +  8 * 8, 7 +  8 * 8, 6 +  9 * 8, 7 +  9 * 8,
-4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
-6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
-4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
-6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
-0 +  0 * 8, 0 +  5 * 8, 0 + 10 * 8
-};
-
-static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
-{
-#if HAVE_BIGENDIAN
-return (b & 0x) + (a << 16);
-#else
-return (a & 0x) + (b << 16);
-#endif
-}
-
 /**
  * Get the chroma qp.
  */
diff --git a/tests/checkasm/h264dsp.c b/tests/checkasm/h264dsp.c
index 7392452957..3c95f9d74d 100644
--- a/tests/checkasm/h264dsp.c
+++ b/tests/checkasm/h264dsp.c
@@ -23,6 +23,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavcodec/h264dsp.h"
 #include "libavcodec/h264data.h"
+#include "libavcodec/h264_parse.h"
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 07/18] lavc/h264_parser: add missing headers

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/h264_parser.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index aee7cdb934..4002bcad77 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -40,8 +40,11 @@
 #include "get_bits.h"
 #include "golomb.h"
 #include "h264.h"
+#include "h264dsp.h"
+#include "h264_parse.h"
 #include "h264_sei.h"
 #include "h264_ps.h"
+#include "h2645_parse.h"
 #include "h264data.h"
 #include "internal.h"
 #include "mpegutils.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 04/18] lavc/h264dec.h: Move MMCOOpcode to h264_parse.h

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

Both parser and decoder use these, so h264_parse is the proper place for
them.
---
 libavcodec/h264_parse.h | 13 +
 libavcodec/h264dec.h| 13 -
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 4d01620125..05732326d3 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -27,6 +27,19 @@
 #include "get_bits.h"
 #include "h264_ps.h"
 
+/**
+ * Memory management control operation opcode.
+ */
+typedef enum MMCOOpcode {
+MMCO_END = 0,
+MMCO_SHORT2UNUSED,
+MMCO_LONG2UNUSED,
+MMCO_SHORT2LONG,
+MMCO_SET_MAX_LONG,
+MMCO_RESET,
+MMCO_LONG,
+} MMCOOpcode;
+
 typedef struct H264PredWeightTable {
 int use_weight;
 int use_weight_chroma;
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 38a4e96e26..c7662f930e 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -102,19 +102,6 @@
 #define IS_REF0(a) ((a) & MB_TYPE_REF0)
 #define IS_8x8DCT(a)   ((a) & MB_TYPE_8x8DCT)
 
-/**
- * Memory management control operation opcode.
- */
-typedef enum MMCOOpcode {
-MMCO_END = 0,
-MMCO_SHORT2UNUSED,
-MMCO_LONG2UNUSED,
-MMCO_SHORT2LONG,
-MMCO_SET_MAX_LONG,
-MMCO_RESET,
-MMCO_LONG,
-} MMCOOpcode;
-
 /**
  * Memory management control operation.
  */
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 05/18] lavc/h264: replace MAX_DELAYED_PIC_COUNT with FF_ARRAY_ELEMS where appropriate

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/h264_refs.c  | 2 +-
 libavcodec/h264_slice.c | 2 +-
 libavcodec/h264dec.c| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 93526b11e2..94b473257f 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -729,7 +729,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
 h->poc.frame_num = h->cur_pic_ptr->frame_num = 0;
 h->mmco_reset = 1;
 h->cur_pic_ptr->mmco_reset = 1;
-for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++)
+for (j = 0; j < FF_ARRAY_ELEMS(h->last_pocs); j++)
 h->last_pocs[j] = INT_MIN;
 break;
 default: av_assert0(0);
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 4833282191..d6d4497fc9 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -428,7 +428,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
 copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1);
 copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1);
 copy_picture_range(h->delayed_pic, h1->delayed_pic,
-   MAX_DELAYED_PIC_COUNT + 2, h, h1);
+   FF_ARRAY_ELEMS(h->delayed_pic), h, h1);
 
 h->frame_recovered   = h1->frame_recovered;
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 7f10026340..3706ae0e31 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -308,7 +308,7 @@ static int h264_init_context(AVCodecContext *avctx, 
H264Context *h)
 h->sei.unregistered.x264_build = -1;
 
 h->next_outputed_poc = INT_MIN;
-for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++)
 h->last_pocs[i] = INT_MIN;
 
 ff_h264_sei_uninit(>sei);
@@ -445,7 +445,7 @@ static void idr(H264Context *h)
 h->poc.prev_frame_num_offset = 0;
 h->poc.prev_poc_msb  = 1<<16;
 h->poc.prev_poc_lsb  = -1;
-for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++)
 h->last_pocs[i] = INT_MIN;
 }
 
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 03/18] lavc/h264: replace MAX_MMCO_COUNT with H264_MAX_MMCO_COUNT

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

They apparently serve the same purpose; the latter is one larger and has
a comment explaining how the value is derived, so seems more
trustworthy.
---
 libavcodec/h264_parser.c | 2 +-
 libavcodec/h264_refs.c   | 2 +-
 libavcodec/h264dec.h | 6 ++
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 881cab7536..aee7cdb934 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -219,7 +219,7 @@ static int scan_mmco_reset(AVCodecParserContext *s, 
GetBitContext *gb,
 
 if (get_bits1(gb)) { // adaptive_ref_pic_marking_mode_flag
 int i;
-for (i = 0; i < MAX_MMCO_COUNT; i++) {
+for (i = 0; i < H264_MAX_MMCO_COUNT; i++) {
 MMCOOpcode opcode = get_ue_golomb_31(gb);
 if (opcode > (unsigned) MMCO_LONG) {
 av_log(logctx, AV_LOG_ERROR,
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index dae8bd278a..93526b11e2 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -849,7 +849,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, 
GetBitContext *gb,
 } else {
 sl->explicit_ref_marking = get_bits1(gb);
 if (sl->explicit_ref_marking) {
-for (i = 0; i < MAX_MMCO_COUNT; i++) {
+for (i = 0; i < FF_ARRAY_ELEMS(sl->mmco); i++) {
 MMCOOpcode opcode = get_ue_golomb_31(gb);
 
 mmco[i].opcode = opcode;
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index dffd723ba6..38a4e96e26 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -52,8 +52,6 @@
 
 #define H264_MAX_PICTURE_COUNT 36
 
-#define MAX_MMCO_COUNT 66
-
 #define MAX_DELAYED_PIC_COUNT  16
 
 /* Compiling in interlaced support reduces the speed
@@ -330,7 +328,7 @@ typedef struct H264SliceContext {
 uint8_t cabac_state[1024];
 int cabac_init_idc;
 
-MMCO mmco[MAX_MMCO_COUNT];
+MMCO mmco[H264_MAX_MMCO_COUNT];
 int  nb_mmco;
 int explicit_ref_marking;
 
@@ -489,7 +487,7 @@ typedef struct H264Context {
 /**
  * memory management control operations buffer.
  */
-MMCO mmco[MAX_MMCO_COUNT];
+MMCO mmco[H264_MAX_MMCO_COUNT];
 int  nb_mmco;
 int mmco_reset;
 int explicit_ref_marking;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 02/18] avcodec/h264dec: Move pack8to16 to its only user

2022-01-24 Thread Andreas Rheinhardt
Namely to h264_cabac.c.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_cabac.c | 9 +
 libavcodec/h264dec.h| 9 -
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index 040fa0a257..884d392022 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -1281,6 +1281,15 @@ void ff_h264_init_cabac_states(const H264Context *h, 
H264SliceContext *sl)
 }
 }
 
+static av_always_inline uint16_t pack8to16(unsigned a, unsigned b)
+{
+#if HAVE_BIGENDIAN
+return (b & 0xFF) + (a << 8);
+#else
+return (a & 0xFF) + (b << 8);
+#endif
+}
+
 static int decode_cabac_field_decoding_flag(const H264Context *h, 
H264SliceContext *sl)
 {
 const int mbb_xy = sl->mb_xy - 2*h->mb_stride;
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 1128dddfd1..dffd723ba6 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -685,15 +685,6 @@ static av_always_inline uint32_t pack16to32(unsigned a, 
unsigned b)
 #endif
 }
 
-static av_always_inline uint16_t pack8to16(unsigned a, unsigned b)
-{
-#if HAVE_BIGENDIAN
-return (b & 0xFF) + (a << 8);
-#else
-return (a & 0xFF) + (b << 8);
-#endif
-}
-
 /**
  * Get the chroma qp.
  */
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 01/18] avcodec/h264dec: Move find_start_code() to its only user

2022-01-24 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_parser.c |  9 +
 libavcodec/h264dec.h | 11 ---
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index cfbf6f4486..881cab7536 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -64,6 +64,15 @@ typedef struct H264ParseContext {
 int last_frame_num, last_picture_structure;
 } H264ParseContext;
 
+static int find_start_code(const uint8_t *buf, int buf_size,
+  int buf_index, int next_avc)
+{
+uint32_t state = -1;
+
+buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, 
) - buf - 1;
+
+return FFMIN(buf_index, buf_size);
+}
 
 static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
int buf_size, void *logctx)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 87c4e4e539..1128dddfd1 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -44,7 +44,6 @@
 #include "h264pred.h"
 #include "h264qpel.h"
 #include "h274.h"
-#include "internal.h"
 #include "mpegutils.h"
 #include "parser.h"
 #include "qpeldsp.h"
@@ -833,16 +832,6 @@ static av_always_inline int get_dct8x8_allowed(const 
H264Context *h, H264SliceCo
   0x0001000100010001ULL));
 }
 
-static inline int find_start_code(const uint8_t *buf, int buf_size,
-   int buf_index, int next_avc)
-{
-uint32_t state = -1;
-
-buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, 
) - buf - 1;
-
-return FFMIN(buf_index, buf_size);
-}
-
 int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup);
 
 int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src);
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 18/18] avcodec/h264_parse: Move ff_h264_get_profile() to h264_ps.h

2022-01-24 Thread Andreas Rheinhardt
It is a more fitting place for it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_parse.h| 5 -
 libavcodec/h264_ps.h   | 5 +
 libavcodec/mediacodecdec.c | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 3901b46ac2..4b79bd63eb 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -124,11 +124,6 @@ int ff_h264_decode_extradata(const uint8_t *data, int 
size, H264ParamSets *ps,
  int *is_avc, int *nal_length_size,
  int err_recognition, void *logctx);
 
-/**
- * compute profile from sps
- */
-int ff_h264_get_profile(const SPS *sps);
-
 static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
 {
 #if HAVE_BIGENDIAN
diff --git a/libavcodec/h264_ps.h b/libavcodec/h264_ps.h
index 3f1ab72e38..dc52835ed4 100644
--- a/libavcodec/h264_ps.h
+++ b/libavcodec/h264_ps.h
@@ -152,6 +152,11 @@ typedef struct H264ParamSets {
 int overread_warning_printed[2];
 } H264ParamSets;
 
+/**
+ * compute profile from sps
+ */
+int ff_h264_get_profile(const SPS *sps);
+
 /**
  * Decode SPS
  */
diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index 04d5026e68..e8af00ec00 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -33,6 +33,7 @@
 #include "avcodec.h"
 #include "decode.h"
 #include "h264_parse.h"
+#include "h264_ps.h"
 #include "hevc_parse.h"
 #include "hwconfig.h"
 #include "internal.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 17/18] avcodec/h264_*: Remove unnecessary internal.h inclusions

2022-01-24 Thread Andreas Rheinhardt
Also remove some other unnecessary headers while at it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_cabac.c  | 1 -
 libavcodec/h264_cavlc.c  | 1 -
 libavcodec/h264_direct.c | 1 -
 libavcodec/h264_loopfilter.c | 3 ---
 libavcodec/h264_mvpred.h | 2 --
 5 files changed, 8 deletions(-)

diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index 040fa0a257..31a0832a5e 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -34,7 +34,6 @@
 #include "config.h"
 #include "cabac.h"
 #include "cabac_functions.h"
-#include "internal.h"
 #include "h264dec.h"
 #include "h264data.h"
 #include "h264_mvpred.h"
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index fa8ba5dac7..9191df0303 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -28,7 +28,6 @@
 #define CABAC(h) 0
 #define UNCHECKED_BITSTREAM_READER 1
 
-#include "internal.h"
 #include "h264dec.h"
 #include "h264_mvpred.h"
 #include "h264data.h"
diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c
index 8f07981130..93c2e1e438 100644
--- a/libavcodec/h264_direct.c
+++ b/libavcodec/h264_direct.c
@@ -25,7 +25,6 @@
  * @author Michael Niedermayer 
  */
 
-#include "internal.h"
 #include "avcodec.h"
 #include "h264dec.h"
 #include "h264_ps.h"
diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c
index 558ec6c02d..2440cfa831 100644
--- a/libavcodec/h264_loopfilter.c
+++ b/libavcodec/h264_loopfilter.c
@@ -28,13 +28,10 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem_internal.h"
-#include "internal.h"
 #include "avcodec.h"
 #include "h264dec.h"
 #include "h264_ps.h"
-#include "mathops.h"
 #include "mpegutils.h"
-#include "rectangle.h"
 
 /* Deblocking filter (p153) */
 static const uint8_t alpha_table[52*3] = {
diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h
index 19d9ee462d..46ae2738f9 100644
--- a/libavcodec/h264_mvpred.h
+++ b/libavcodec/h264_mvpred.h
@@ -28,8 +28,6 @@
 #ifndef AVCODEC_H264_MVPRED_H
 #define AVCODEC_H264_MVPRED_H
 
-#include "internal.h"
-#include "avcodec.h"
 #include "h264dec.h"
 #include "mpegutils.h"
 #include "libavutil/avassert.h"
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 16/18] avcodec/h264_parse: Move find_start_code() to its only user

2022-01-24 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_parse.h  | 13 +
 libavcodec/h264_parser.c |  9 +
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 9b6391edda..3901b46ac2 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -28,11 +28,10 @@
 
 #include 
 
-#include "libavutil/common.h"
+#include "libavutil/attributes.h"
 
 #include "get_bits.h"
 #include "h264_ps.h"
-#include "internal.h"
 
 #define MB_TYPE_REF0   MB_TYPE_ACPRED // dirty but it fits in 16 bit
 #define MB_TYPE_8x8DCT 0x0100
@@ -130,16 +129,6 @@ int ff_h264_decode_extradata(const uint8_t *data, int 
size, H264ParamSets *ps,
  */
 int ff_h264_get_profile(const SPS *sps);
 
-static inline int find_start_code(const uint8_t *buf, int buf_size,
-  int buf_index, int next_avc)
-{
-uint32_t state = -1;
-
-buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, 
) - buf - 1;
-
-return FFMIN(buf_index, buf_size);
-}
-
 static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
 {
 #if HAVE_BIGENDIAN
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index b221459c1b..d9cbb7d6d5 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -67,6 +67,15 @@ typedef struct H264ParseContext {
 int last_frame_num, last_picture_structure;
 } H264ParseContext;
 
+static int find_start_code(const uint8_t *buf, int buf_size,
+  int buf_index, int next_avc)
+{
+uint32_t state = -1;
+
+buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, 
) - buf - 1;
+
+return FFMIN(buf_index, buf_size);
+}
 
 static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
int buf_size, void *logctx)
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 15/18] avcodec/h264dec: Remove unnecessary headers

2022-01-24 Thread Andreas Rheinhardt
E.g. the inclusion of parser.h comes from a time when
the parser used a H264Context.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264dec.c | 1 +
 libavcodec/h264dec.h | 4 
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index ed9a74b0c6..a47caa95e8 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -30,6 +30,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 #include "libavutil/video_enc_params.h"
 
 #include "internal.h"
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 6b72588854..79835e2d09 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -31,7 +31,6 @@
 #include "libavutil/buffer.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem_internal.h"
-#include "libavutil/thread.h"
 
 #include "cabac.h"
 #include "error_resilience.h"
@@ -44,10 +43,7 @@
 #include "h264pred.h"
 #include "h264qpel.h"
 #include "h274.h"
-#include "internal.h"
 #include "mpegutils.h"
-#include "parser.h"
-#include "qpeldsp.h"
 #include "rectangle.h"
 #include "videodsp.h"
 
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 14/18] avcodec/h264*: Remove unnecessary h264_mvpred.h inclusions

2022-01-24 Thread Andreas Rheinhardt
This is only needed by h264_cabac.c and h264_cavlc.c.
Also fix up the other headers while at it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_picture.c | 9 -
 libavcodec/h264_slice.c   | 3 +--
 libavcodec/h264dec.c  | 9 -
 3 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index adf8a32378..dcd5874c2e 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -26,19 +26,10 @@
  */
 
 #include "libavutil/avassert.h"
-#include "libavutil/imgutils.h"
-#include "internal.h"
-#include "cabac.h"
-#include "cabac_functions.h"
 #include "error_resilience.h"
 #include "avcodec.h"
 #include "h264dec.h"
-#include "h264data.h"
-#include "h264chroma.h"
-#include "h264_mvpred.h"
-#include "mathops.h"
 #include "mpegutils.h"
-#include "rectangle.h"
 #include "thread.h"
 
 void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 32df9fd3ae..dc636c5e78 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -27,8 +27,8 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/display.h"
-#include "libavutil/imgutils.h"
 #include "libavutil/film_grain_params.h"
+#include "libavutil/pixdesc.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
 #include "internal.h"
@@ -40,7 +40,6 @@
 #include "h264dec.h"
 #include "h264data.h"
 #include "h264chroma.h"
-#include "h264_mvpred.h"
 #include "h264_ps.h"
 #include "golomb.h"
 #include "mathops.h"
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 3706ae0e31..ed9a74b0c6 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -28,29 +28,20 @@
 #define UNCHECKED_BITSTREAM_READER 1
 
 #include "libavutil/avassert.h"
-#include "libavutil/display.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
-#include "libavutil/stereo3d.h"
 #include "libavutil/video_enc_params.h"
 
 #include "internal.h"
-#include "bytestream.h"
-#include "cabac.h"
-#include "cabac_functions.h"
 #include "error_resilience.h"
 #include "avcodec.h"
 #include "h264.h"
 #include "h264dec.h"
 #include "h2645_parse.h"
 #include "h264data.h"
-#include "h264chroma.h"
-#include "h264_mvpred.h"
 #include "h264_ps.h"
 #include "golomb.h"
 #include "hwconfig.h"
-#include "mathops.h"
-#include "me_cmp.h"
 #include "mpegutils.h"
 #include "profiles.h"
 #include "rectangle.h"
-- 
2.32.0

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

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


Re: [FFmpeg-devel] [PATCH 13/13] lavc/svq3: stop including h264dec.h

2022-01-24 Thread Andreas Rheinhardt
Anton Khirnov:
> The only thing that is actually used directly from there is the
> PART_NOT_AVAILABLE constant, which can be trivially copied to svq3
> decoder itself.
> 
> Otherwise it only depends on other indirectly included headers.
> ---
>  libavcodec/svq3.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
> index a3f434ff8d..f06404da9d 100644
> --- a/libavcodec/svq3.c
> +++ b/libavcodec/svq3.c
> @@ -49,13 +49,16 @@
>  #include "internal.h"
>  #include "avcodec.h"
>  #include "mpegutils.h"
> -#include "h264dec.h"
>  #include "h264data.h"
> +#include "h264dsp.h"
> +#include "h264pred.h"
> +#include "h264_parse.h"
>  #include "golomb.h"
>  #include "hpeldsp.h"
>  #include "mathops.h"
>  #include "rectangle.h"
>  #include "tpeldsp.h"
> +#include "videodsp.h"
>  
>  #if CONFIG_ZLIB
>  #include 
> @@ -63,6 +66,8 @@
>  
>  #include "svq1.h"
>  
> +#define PART_NOT_AVAILABLE -2
> +
>  /**
>   * @file
>   * svq3 decoder.

I think a better place for this is h264pred.h.

- Andreas
___
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 02/13] lavc/h264_parser: stop accessing H264Context

2022-01-24 Thread James Almer




On 1/24/2022 2:00 PM, Anton Khirnov wrote:

Parsers should not mess with decoder private data. It is also completely
unnecessary here.
---
  libavcodec/h264_parser.c | 8 +++-
  1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index e3a11702c5..816b04845e 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -247,7 +247,6 @@ static inline int parse_nal_units(AVCodecParserContext *s,
const uint8_t * const buf, int buf_size)
  {
  H264ParseContext *p = s->priv_data;
-H264Context *h = avctx->priv_data;
  H2645RBSP rbsp = { NULL };
  H2645NAL nal = { NULL };
  int buf_index, next_avc;
@@ -553,11 +552,10 @@ static inline int parse_nal_units(AVCodecParserContext *s,
  p->last_picture_structure = s->picture_structure;
  p->last_frame_num = p->poc.frame_num;
  }
-if (h && sps->timing_info_present_flag) {
+if (sps->timing_info_present_flag) {
  int64_t den = sps->time_scale;
-if (p->sei.unregistered.x264_build >= 0)
-h->x264_build = p->sei.unregistered.x264_build;
-if (h->x264_build < 44U)
+if (p->sei.unregistered.x264_build >= 0 &&


I don't think this check is needed. < 44U should in theory ensure the 
default of -1 is converted to unsigned and the check will evaluate to false.


See my patch (I don't mind if you amend yours and push this with your 
authorship).



+p->sei.unregistered.x264_build < 44U)
  den *= 2;
  av_reduce(>framerate.den, >framerate.num,
sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 
<< 30);

___
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 13/13] lavc/svq3: stop including h264dec.h

2022-01-24 Thread Anton Khirnov
The only thing that is actually used directly from there is the
PART_NOT_AVAILABLE constant, which can be trivially copied to svq3
decoder itself.

Otherwise it only depends on other indirectly included headers.
---
 libavcodec/svq3.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index a3f434ff8d..f06404da9d 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -49,13 +49,16 @@
 #include "internal.h"
 #include "avcodec.h"
 #include "mpegutils.h"
-#include "h264dec.h"
 #include "h264data.h"
+#include "h264dsp.h"
+#include "h264pred.h"
+#include "h264_parse.h"
 #include "golomb.h"
 #include "hpeldsp.h"
 #include "mathops.h"
 #include "rectangle.h"
 #include "tpeldsp.h"
+#include "videodsp.h"
 
 #if CONFIG_ZLIB
 #include 
@@ -63,6 +66,8 @@
 
 #include "svq1.h"
 
+#define PART_NOT_AVAILABLE -2
+
 /**
  * @file
  * svq3 decoder.
-- 
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 07/13] lavc/h264: move some shared code from h264dec to h264_parse

2022-01-24 Thread Anton Khirnov
---
 libavcodec/h264_parse.h  | 37 +
 libavcodec/h264dec.h | 35 ---
 tests/checkasm/h264dsp.c |  1 +
 3 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 9f329db77a..95a80c425f 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -24,6 +24,8 @@
 #ifndef AVCODEC_H264_PARSE_H
 #define AVCODEC_H264_PARSE_H
 
+#include "config.h"
+
 #include 
 
 #include "libavutil/common.h"
@@ -32,6 +34,23 @@
 #include "h264_ps.h"
 #include "internal.h"
 
+// This table must be here because scan8[constant] must be known at compiletime
+static const uint8_t scan8[16 * 3 + 3] = {
+4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
+6 +  1 * 8, 7 +  1 * 8, 6 +  2 * 8, 7 +  2 * 8,
+4 +  3 * 8, 5 +  3 * 8, 4 +  4 * 8, 5 +  4 * 8,
+6 +  3 * 8, 7 +  3 * 8, 6 +  4 * 8, 7 +  4 * 8,
+4 +  6 * 8, 5 +  6 * 8, 4 +  7 * 8, 5 +  7 * 8,
+6 +  6 * 8, 7 +  6 * 8, 6 +  7 * 8, 7 +  7 * 8,
+4 +  8 * 8, 5 +  8 * 8, 4 +  9 * 8, 5 +  9 * 8,
+6 +  8 * 8, 7 +  8 * 8, 6 +  9 * 8, 7 +  9 * 8,
+4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
+6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
+4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
+6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
+0 +  0 * 8, 0 +  5 * 8, 0 + 10 * 8
+};
+
 /**
  * Memory management control operation opcode.
  */
@@ -118,4 +137,22 @@ static inline int find_start_code(const uint8_t *buf, int 
buf_size,
 return FFMIN(buf_index, buf_size);
 }
 
+static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
+{
+#if HAVE_BIGENDIAN
+return (b & 0x) + (a << 16);
+#else
+return (a & 0x) + (b << 16);
+#endif
+}
+
+static av_always_inline uint16_t pack8to16(unsigned a, unsigned b)
+{
+#if HAVE_BIGENDIAN
+return (b & 0xFF) + (a << 8);
+#else
+return (a & 0xFF) + (b << 8);
+#endif
+}
+
 #endif /* AVCODEC_H264_PARSE_H */
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 4a56463340..4441cf6613 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -643,41 +643,6 @@ void ff_h264_filter_mb(const H264Context *h, 
H264SliceContext *sl, int mb_x, int
 #define LUMA_DC_BLOCK_INDEX   48
 #define CHROMA_DC_BLOCK_INDEX 49
 
-// This table must be here because scan8[constant] must be known at compiletime
-static const uint8_t scan8[16 * 3 + 3] = {
-4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
-6 +  1 * 8, 7 +  1 * 8, 6 +  2 * 8, 7 +  2 * 8,
-4 +  3 * 8, 5 +  3 * 8, 4 +  4 * 8, 5 +  4 * 8,
-6 +  3 * 8, 7 +  3 * 8, 6 +  4 * 8, 7 +  4 * 8,
-4 +  6 * 8, 5 +  6 * 8, 4 +  7 * 8, 5 +  7 * 8,
-6 +  6 * 8, 7 +  6 * 8, 6 +  7 * 8, 7 +  7 * 8,
-4 +  8 * 8, 5 +  8 * 8, 4 +  9 * 8, 5 +  9 * 8,
-6 +  8 * 8, 7 +  8 * 8, 6 +  9 * 8, 7 +  9 * 8,
-4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
-6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
-4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
-6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
-0 +  0 * 8, 0 +  5 * 8, 0 + 10 * 8
-};
-
-static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
-{
-#if HAVE_BIGENDIAN
-return (b & 0x) + (a << 16);
-#else
-return (a & 0x) + (b << 16);
-#endif
-}
-
-static av_always_inline uint16_t pack8to16(unsigned a, unsigned b)
-{
-#if HAVE_BIGENDIAN
-return (b & 0xFF) + (a << 8);
-#else
-return (a & 0xFF) + (b << 8);
-#endif
-}
-
 /**
  * Get the chroma qp.
  */
diff --git a/tests/checkasm/h264dsp.c b/tests/checkasm/h264dsp.c
index 7392452957..3c95f9d74d 100644
--- a/tests/checkasm/h264dsp.c
+++ b/tests/checkasm/h264dsp.c
@@ -23,6 +23,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavcodec/h264dsp.h"
 #include "libavcodec/h264data.h"
+#include "libavcodec/h264_parse.h"
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
-- 
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 11/13] lavc/vdpau: stop unnecessarily including h264dec

2022-01-24 Thread Anton Khirnov
---
 libavcodec/vdpau.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 7c29746adb..f96ac15e2a 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -26,7 +26,6 @@
 #include "avcodec.h"
 #include "decode.h"
 #include "internal.h"
-#include "h264dec.h"
 #include "vc1.h"
 #include "vdpau.h"
 #include "vdpau_internal.h"
-- 
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 12/13] lavc/x86/h264_qpel: stop unnecessarily including h264dec

2022-01-24 Thread Anton Khirnov
---
 libavcodec/x86/h264_qpel.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/x86/h264_qpel.c b/libavcodec/x86/h264_qpel.c
index 320d98933a..dda50ded89 100644
--- a/libavcodec/x86/h264_qpel.c
+++ b/libavcodec/x86/h264_qpel.c
@@ -24,7 +24,6 @@
 #include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/h264dec.h"
 #include "libavcodec/h264qpel.h"
 #include "libavcodec/pixels.h"
 #include "fpel.h"
-- 
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 10/13] lavc/h264: move MB_TYPE defs from h264dec.h to h264_parse

2022-01-24 Thread Anton Khirnov
Allows to stop including h264dec.h in h264data.c.
---
 libavcodec/h264_parse.h | 3 +++
 libavcodec/h264data.c   | 2 +-
 libavcodec/h264dec.h| 2 --
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 95a80c425f..9b6391edda 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -34,6 +34,9 @@
 #include "h264_ps.h"
 #include "internal.h"
 
+#define MB_TYPE_REF0   MB_TYPE_ACPRED // dirty but it fits in 16 bit
+#define MB_TYPE_8x8DCT 0x0100
+
 // This table must be here because scan8[constant] must be known at compiletime
 static const uint8_t scan8[16 * 3 + 3] = {
 4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
diff --git a/libavcodec/h264data.c b/libavcodec/h264data.c
index eb8728a9db..3e9e68cb04 100644
--- a/libavcodec/h264data.c
+++ b/libavcodec/h264data.c
@@ -30,7 +30,7 @@
 
 #include "libavutil/avutil.h"
 
-#include "h264dec.h"
+#include "h264_parse.h"
 #include "h264data.h"
 #include "mpegutils.h"
 
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 4441cf6613..6b72588854 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -96,8 +96,6 @@
 #define CHROMA422(h) ((h)->ps.sps->chroma_format_idc == 2)
 #define CHROMA444(h) ((h)->ps.sps->chroma_format_idc == 3)
 
-#define MB_TYPE_REF0   MB_TYPE_ACPRED // dirty but it fits in 16 bit
-#define MB_TYPE_8x8DCT 0x0100
 #define IS_REF0(a) ((a) & MB_TYPE_REF0)
 #define IS_8x8DCT(a)   ((a) & MB_TYPE_8x8DCT)
 
-- 
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 08/13] lavc/h264data.h: stop including h264dec.h

2022-01-24 Thread Anton Khirnov
This header does not need anything from there.
---
 libavcodec/h264data.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264data.h b/libavcodec/h264data.h
index 2968b08b7e..988352aa9a 100644
--- a/libavcodec/h264data.h
+++ b/libavcodec/h264data.h
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "h264dec.h"
+#include "h264.h"
 
 extern const uint8_t ff_h264_golomb_to_pict_type[5];
 extern const uint8_t ff_h264_golomb_to_intra4x4_cbp[48];
-- 
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 06/13] lavc/h264_parser: add missing headers

2022-01-24 Thread Anton Khirnov
---
 libavcodec/h264_parser.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 816b04845e..b221459c1b 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -40,8 +40,11 @@
 #include "get_bits.h"
 #include "golomb.h"
 #include "h264.h"
+#include "h264dsp.h"
+#include "h264_parse.h"
 #include "h264_sei.h"
 #include "h264_ps.h"
+#include "h2645_parse.h"
 #include "h264data.h"
 #include "internal.h"
 #include "mpegutils.h"
-- 
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 09/13] lavc/h264_parse: stop including h264dec.h

2022-01-24 Thread Anton Khirnov
It is unnecessary and only files that are parts of the decoder (as
opposed to standalone code called by the decoder) are allowed to include
h264dec.h
---
 libavcodec/h264_parse.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 1c1d1c04b0..97ddf0e437 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -20,9 +20,11 @@
 #include "get_bits.h"
 #include "golomb.h"
 #include "h264.h"
-#include "h264dec.h"
+#include "h264pred.h"
 #include "h264_parse.h"
 #include "h264_ps.h"
+#include "h2645_parse.h"
+#include "mpegutils.h"
 
 int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
   const int *ref_count, int slice_type_nos,
-- 
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 03/13] lavc/h264dec.h: move find_start_code and MMCOOpcode to h264_parse.h

2022-01-24 Thread Anton Khirnov
Both parser and decoder use these, so h264_parse is the proper place for
them.
---
 libavcodec/h264_parse.h | 28 
 libavcodec/h264dec.h| 23 ---
 2 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 4d01620125..9f329db77a 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -24,8 +24,26 @@
 #ifndef AVCODEC_H264_PARSE_H
 #define AVCODEC_H264_PARSE_H
 
+#include 
+
+#include "libavutil/common.h"
+
 #include "get_bits.h"
 #include "h264_ps.h"
+#include "internal.h"
+
+/**
+ * Memory management control operation opcode.
+ */
+typedef enum MMCOOpcode {
+MMCO_END = 0,
+MMCO_SHORT2UNUSED,
+MMCO_LONG2UNUSED,
+MMCO_SHORT2LONG,
+MMCO_SET_MAX_LONG,
+MMCO_RESET,
+MMCO_LONG,
+} MMCOOpcode;
 
 typedef struct H264PredWeightTable {
 int use_weight;
@@ -90,4 +108,14 @@ int ff_h264_decode_extradata(const uint8_t *data, int size, 
H264ParamSets *ps,
  */
 int ff_h264_get_profile(const SPS *sps);
 
+static inline int find_start_code(const uint8_t *buf, int buf_size,
+  int buf_index, int next_avc)
+{
+uint32_t state = -1;
+
+buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, 
) - buf - 1;
+
+return FFMIN(buf_index, buf_size);
+}
+
 #endif /* AVCODEC_H264_PARSE_H */
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index ca3001ec4b..1e1f84ef33 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -103,19 +103,6 @@
 #define IS_REF0(a) ((a) & MB_TYPE_REF0)
 #define IS_8x8DCT(a)   ((a) & MB_TYPE_8x8DCT)
 
-/**
- * Memory management control operation opcode.
- */
-typedef enum MMCOOpcode {
-MMCO_END = 0,
-MMCO_SHORT2UNUSED,
-MMCO_LONG2UNUSED,
-MMCO_SHORT2LONG,
-MMCO_SET_MAX_LONG,
-MMCO_RESET,
-MMCO_LONG,
-} MMCOOpcode;
-
 /**
  * Memory management control operation.
  */
@@ -831,16 +818,6 @@ static av_always_inline int get_dct8x8_allowed(const 
H264Context *h, H264SliceCo
   0x0001000100010001ULL));
 }
 
-static inline int find_start_code(const uint8_t *buf, int buf_size,
-   int buf_index, int next_avc)
-{
-uint32_t state = -1;
-
-buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, 
) - buf - 1;
-
-return FFMIN(buf_index, buf_size);
-}
-
 int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup);
 
 int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src);
-- 
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 02/13] lavc/h264_parser: stop accessing H264Context

2022-01-24 Thread Anton Khirnov
Parsers should not mess with decoder private data. It is also completely
unnecessary here.
---
 libavcodec/h264_parser.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index e3a11702c5..816b04845e 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -247,7 +247,6 @@ static inline int parse_nal_units(AVCodecParserContext *s,
   const uint8_t * const buf, int buf_size)
 {
 H264ParseContext *p = s->priv_data;
-H264Context *h = avctx->priv_data;
 H2645RBSP rbsp = { NULL };
 H2645NAL nal = { NULL };
 int buf_index, next_avc;
@@ -553,11 +552,10 @@ static inline int parse_nal_units(AVCodecParserContext *s,
 p->last_picture_structure = s->picture_structure;
 p->last_frame_num = p->poc.frame_num;
 }
-if (h && sps->timing_info_present_flag) {
+if (sps->timing_info_present_flag) {
 int64_t den = sps->time_scale;
-if (p->sei.unregistered.x264_build >= 0)
-h->x264_build = p->sei.unregistered.x264_build;
-if (h->x264_build < 44U)
+if (p->sei.unregistered.x264_build >= 0 &&
+p->sei.unregistered.x264_build < 44U)
 den *= 2;
 av_reduce(>framerate.den, >framerate.num,
   sps->num_units_in_tick * avctx->ticks_per_frame, 
den, 1 << 30);
-- 
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 05/13] lavc/h264: replace MAX_DELAYED_PIC_COUNT by H264_MAX_DPB_FRAMES

2022-01-24 Thread Anton Khirnov
---
 libavcodec/h264_ps.c|  4 ++--
 libavcodec/h264_slice.c | 12 ++--
 libavcodec/h264dec.h|  6 ++
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index e21c2b56ac..f68d5bf81c 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -485,7 +485,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 sps->ref_frame_count = get_ue_golomb_31(gb);
 if (avctx->codec_tag == MKTAG('S', 'M', 'V', '2'))
 sps->ref_frame_count = FFMAX(2, sps->ref_frame_count);
-if (sps->ref_frame_count > MAX_DELAYED_PIC_COUNT) {
+if (sps->ref_frame_count > H264_MAX_DPB_FRAMES) {
 av_log(avctx, AV_LOG_ERROR,
"too many reference frames %d\n", sps->ref_frame_count);
 goto fail;
@@ -590,7 +590,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
  * level */
 if (!sps->bitstream_restriction_flag &&
 (sps->ref_frame_count || avctx->strict_std_compliance >= 
FF_COMPLIANCE_STRICT)) {
-sps->num_reorder_frames = MAX_DELAYED_PIC_COUNT - 1;
+sps->num_reorder_frames = H264_MAX_DPB_FRAMES - 1;
 for (i = 0; i < FF_ARRAY_ELEMS(level_max_dpb_mbs); i++) {
 if (level_max_dpb_mbs[i][0] == sps->level_idc) {
 sps->num_reorder_frames = FFMIN(level_max_dpb_mbs[i][1] / 
(sps->mb_width * sps->mb_height),
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index d6d4497fc9..32df9fd3ae 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1456,7 +1456,7 @@ static int h264_select_output_frame(H264Context *h)
 }
 
 for (i = 0; 1; i++) {
-if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){
+if(i == H264_MAX_DPB_FRAMES || cur->poc < h->last_pocs[i]){
 if(i)
 h->last_pocs[i-1] = cur->poc;
 break;
@@ -1464,13 +1464,13 @@ static int h264_select_output_frame(H264Context *h)
 h->last_pocs[i-1]= h->last_pocs[i];
 }
 }
-out_of_order = MAX_DELAYED_PIC_COUNT - i;
+out_of_order = H264_MAX_DPB_FRAMES - i;
 if(   cur->f->pict_type == AV_PICTURE_TYPE_B
-   || (h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > INT_MIN && 
h->last_pocs[MAX_DELAYED_PIC_COUNT-1] - 
(int64_t)h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > 2))
+   || (h->last_pocs[H264_MAX_DPB_FRAMES-2] > INT_MIN && 
h->last_pocs[H264_MAX_DPB_FRAMES-1] - 
(int64_t)h->last_pocs[H264_MAX_DPB_FRAMES-2] > 2))
 out_of_order = FFMAX(out_of_order, 1);
-if (out_of_order == MAX_DELAYED_PIC_COUNT) {
+if (out_of_order == H264_MAX_DPB_FRAMES) {
 av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, 
h->last_pocs[0]);
-for (i = 1; i < MAX_DELAYED_PIC_COUNT; i++)
+for (i = 1; i < H264_MAX_DPB_FRAMES; i++)
 h->last_pocs[i] = INT_MIN;
 h->last_pocs[0] = cur->poc;
 cur->mmco_reset = 1;
@@ -1484,7 +1484,7 @@ static int h264_select_output_frame(H264Context *h)
 while (h->delayed_pic[pics])
 pics++;
 
-av_assert0(pics <= MAX_DELAYED_PIC_COUNT);
+av_assert0(pics <= H264_MAX_DPB_FRAMES);
 
 h->delayed_pic[pics++] = cur;
 if (cur->reference == 0)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 1e1f84ef33..4a56463340 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -53,8 +53,6 @@
 
 #define H264_MAX_PICTURE_COUNT 36
 
-#define MAX_DELAYED_PIC_COUNT  16
-
 /* Compiling in interlaced support reduces the speed
  * of progressive decoding by about 2%. */
 #define ALLOW_INTERLACE
@@ -466,8 +464,8 @@ typedef struct H264Context {
 H264Ref default_ref[2];
 H264Picture *short_ref[32];
 H264Picture *long_ref[32];
-H264Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size?
-int last_pocs[MAX_DELAYED_PIC_COUNT];
+H264Picture *delayed_pic[H264_MAX_DPB_FRAMES + 2]; // FIXME size?
+int last_pocs[H264_MAX_DPB_FRAMES];
 H264Picture *next_output_pic;
 int next_outputed_poc;
 int poc_offset; ///< PicOrderCnt_offset from SMPTE RDD-2006
-- 
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 04/13] lavc/h264: replace MAX_DELAYED_PIC_COUNT with FF_ARRAY_ELEMS where appropriate

2022-01-24 Thread Anton Khirnov
---
 libavcodec/h264_refs.c  | 2 +-
 libavcodec/h264_slice.c | 2 +-
 libavcodec/h264dec.c| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 93526b11e2..94b473257f 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -729,7 +729,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
 h->poc.frame_num = h->cur_pic_ptr->frame_num = 0;
 h->mmco_reset = 1;
 h->cur_pic_ptr->mmco_reset = 1;
-for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++)
+for (j = 0; j < FF_ARRAY_ELEMS(h->last_pocs); j++)
 h->last_pocs[j] = INT_MIN;
 break;
 default: av_assert0(0);
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 4833282191..d6d4497fc9 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -428,7 +428,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
 copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1);
 copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1);
 copy_picture_range(h->delayed_pic, h1->delayed_pic,
-   MAX_DELAYED_PIC_COUNT + 2, h, h1);
+   FF_ARRAY_ELEMS(h->delayed_pic), h, h1);
 
 h->frame_recovered   = h1->frame_recovered;
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 7f10026340..3706ae0e31 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -308,7 +308,7 @@ static int h264_init_context(AVCodecContext *avctx, 
H264Context *h)
 h->sei.unregistered.x264_build = -1;
 
 h->next_outputed_poc = INT_MIN;
-for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++)
 h->last_pocs[i] = INT_MIN;
 
 ff_h264_sei_uninit(>sei);
@@ -445,7 +445,7 @@ static void idr(H264Context *h)
 h->poc.prev_frame_num_offset = 0;
 h->poc.prev_poc_msb  = 1<<16;
 h->poc.prev_poc_lsb  = -1;
-for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++)
 h->last_pocs[i] = INT_MIN;
 }
 
-- 
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 01/13] lavc/h264: replace MAX_MMCO_COUNT with H264_MAX_MMCO_COUNT

2022-01-24 Thread Anton Khirnov
They apparently serve the same purpose; the latter is one larger and has
a comment explaining how the value is derived, so seems more
trustworthy.
---
 libavcodec/h264_parser.c | 2 +-
 libavcodec/h264_refs.c   | 2 +-
 libavcodec/h264dec.h | 6 ++
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index bb84cea821..e3a11702c5 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -210,7 +210,7 @@ static int scan_mmco_reset(AVCodecParserContext *s, 
GetBitContext *gb,
 
 if (get_bits1(gb)) { // adaptive_ref_pic_marking_mode_flag
 int i;
-for (i = 0; i < MAX_MMCO_COUNT; i++) {
+for (i = 0; i < H264_MAX_MMCO_COUNT; i++) {
 MMCOOpcode opcode = get_ue_golomb_31(gb);
 if (opcode > (unsigned) MMCO_LONG) {
 av_log(logctx, AV_LOG_ERROR,
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index dae8bd278a..93526b11e2 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -849,7 +849,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, 
GetBitContext *gb,
 } else {
 sl->explicit_ref_marking = get_bits1(gb);
 if (sl->explicit_ref_marking) {
-for (i = 0; i < MAX_MMCO_COUNT; i++) {
+for (i = 0; i < FF_ARRAY_ELEMS(sl->mmco); i++) {
 MMCOOpcode opcode = get_ue_golomb_31(gb);
 
 mmco[i].opcode = opcode;
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 87c4e4e539..ca3001ec4b 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -53,8 +53,6 @@
 
 #define H264_MAX_PICTURE_COUNT 36
 
-#define MAX_MMCO_COUNT 66
-
 #define MAX_DELAYED_PIC_COUNT  16
 
 /* Compiling in interlaced support reduces the speed
@@ -331,7 +329,7 @@ typedef struct H264SliceContext {
 uint8_t cabac_state[1024];
 int cabac_init_idc;
 
-MMCO mmco[MAX_MMCO_COUNT];
+MMCO mmco[H264_MAX_MMCO_COUNT];
 int  nb_mmco;
 int explicit_ref_marking;
 
@@ -490,7 +488,7 @@ typedef struct H264Context {
 /**
  * memory management control operations buffer.
  */
-MMCO mmco[MAX_MMCO_COUNT];
+MMCO mmco[H264_MAX_MMCO_COUNT];
 int  nb_mmco;
 int mmco_reset;
 int explicit_ref_marking;
-- 
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] avcodec/h264_parser: don't alter decoder private data

2022-01-24 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/h264_parser.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index bb84cea821..cfbf6f4486 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -247,7 +247,6 @@ static inline int parse_nal_units(AVCodecParserContext *s,
   const uint8_t * const buf, int buf_size)
 {
 H264ParseContext *p = s->priv_data;
-H264Context *h = avctx->priv_data;
 H2645RBSP rbsp = { NULL };
 H2645NAL nal = { NULL };
 int buf_index, next_avc;
@@ -553,11 +552,9 @@ static inline int parse_nal_units(AVCodecParserContext *s,
 p->last_picture_structure = s->picture_structure;
 p->last_frame_num = p->poc.frame_num;
 }
-if (h && sps->timing_info_present_flag) {
+if (sps->timing_info_present_flag) {
 int64_t den = sps->time_scale;
-if (p->sei.unregistered.x264_build >= 0)
-h->x264_build = p->sei.unregistered.x264_build;
-if (h->x264_build < 44U)
+if (p->sei.unregistered.x264_build < 44U)
 den *= 2;
 av_reduce(>framerate.den, >framerate.num,
   sps->num_units_in_tick * avctx->ticks_per_frame, 
den, 1 << 30);
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 5/5] Add AudioToolbox audio input device.

2022-01-24 Thread Romain Beauxis
Le lun. 24 janv. 2022 à 10:19, Marvin Scholz  a écrit :
>
>
>
> On 24 Jan 2022, at 16:42, Romain Beauxis wrote:
>
> > Hi Marvin,
> >
> > Le mer. 19 janv. 2022 à 10:59, Marvin Scholz  a
> > écrit :
> >> On 19 Jan 2022, at 15:42, Romain Beauxis wrote:
> >>
> >> Hi, thanks for the patch. I've not done a full code review yet, just
> >> a
> >> few
> >> initial remarks below:
> >>
> >>> This patch adds support for a new, audio-specific input device using
> >>> the documented and battle-tested AUHAL input. This provides a
> >>> pendant
> >>> to the AudioToolbox audio-only output.
> >>>
> >>> A couple of advantages for this:
> >>> * It avoids a lot of the complexity of supporting audio and video in
> >>> a
> >>> single input
> >>> * The AUHAL API seems tested, documented and robust
> >>> * This implementation hopefully gives good control over audio
> >>> latency
> >>> and also minimizes data copy
> >
> > Thanks!
> >
> > Do you need more time for this review? We discovered another issue
> > with the dynamic array of video devices and I'd like to send a revised
> > series soon.
>
> Well if you want to address the things I mentioned last time
> it will anyway change a bunch of things probably, so it
> might be easier if I just wait for the new patch.
>
> Additionally it might be useful to send it independent of the
> whole patchset as IIUC it does not really depend on any of the
> previous patches.

Will do, thanks!

> > Also, I think I'll reorder the patches so that the most
> > trivial one (unique device name, probing API call updates) can be
> > applied right away.
> >
> > Let me know!
> > Romain
> >
> >>> From: Romain Beauxis 
> >>> To: ffmpeg-devel@ffmpeg.org
> >>> Subject: [PATCH] Add AudioToolbox audio input device.
> >>> Date: 18. January 2022 at 23:29
> >>> Signed-off-by: Romain Beauxis 
> >>> ---
> >>>  configure  |   5 +
> >>>  doc/indevs.texi|  44 
> >>>  libavdevice/Makefile   |   1 +
> >>>  libavdevice/alldevices.c   |   1 +
> >>>  libavdevice/audiotoolbox_dec.m | 466
> >>> +
> >>>  5 files changed, 517 insertions(+)
> >>>  create mode 100644 libavdevice/audiotoolbox_dec.m
> >>>
> >>> diff --git a/configure b/configure
> >>> index 1413122d87..80e39aae44 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -204,6 +204,7 @@ External library support:
> >>>--disable-avfoundation   disable Apple AVFoundation framework
> >>> [autodetect]
> >>>--enable-avisynthenable reading of AviSynth script files
> >>> [no]
> >>>--disable-bzlib  disable bzlib [autodetect]
> >>> +  --disable-coremedia  disable Apple CoreMedia framework
> >>> [autodetect]
> >>>--disable-coreimage  disable Apple CoreImage framework
> >>> [autodetect]
> >>>--enable-chromaprint enable audio fingerprinting with
> >>> chromaprint [no]
> >>>--enable-frei0r  enable frei0r video filtering [no]
> >>> @@ -1750,6 +1751,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
> >>>  appkit
> >>>  avfoundation
> >>>  bzlib
> >>> +coremedia
> >>>  coreimage
> >>>  iconv
> >>>  libxcb
> >>> @@ -3493,6 +3495,8 @@ alsa_outdev_deps="alsa"
> >>>  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
> >>>  avfoundation_indev_suggest="coregraphics applicationservices"
> >>>  avfoundation_indev_extralibs="-framework Foundation"
> >>> +audiotoolbox_indev_deps="coremedia audiotoolbox"
> >>> +audiotoolbox_indev_extralibs="-framework CoreMedia -framework
> >>> AudioToolbox"
> >>>  audiotoolbox_outdev_deps="audiotoolbox pthreads"
> >>>  audiotoolbox_outdev_extralibs="-framework AudioToolbox -framework
> >>> CoreAudio"
> >>>  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
> >>> dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
> >>> @@ -6340,6 +6344,7 @@ check_lib camera2ndk "stdbool.h stdint.h
> >>> camera/NdkCameraManager.h" ACameraManag
> >>>  enabled appkit   && check_apple_framework AppKit
> >>>  enabled audiotoolbox && check_apple_framework AudioToolbox
> >>>  enabled avfoundation && check_apple_framework AVFoundation
> >>> +enabled coremedia&& check_apple_framework CoreMedia
> >>>  enabled coreimage&& check_apple_framework CoreImage
> >>>  enabled metal&& check_apple_framework Metal
> >>>  enabled videotoolbox && check_apple_framework VideoToolbox
> >>> diff --git a/doc/indevs.texi b/doc/indevs.texi
> >>> index 858c0fa4e4..30a91d304f 100644
> >>> --- a/doc/indevs.texi
> >>> +++ b/doc/indevs.texi
> >>> @@ -103,6 +103,50 @@ Set the maximum number of frames to buffer.
> >>> Default is 5.
> >>>
> >>>  @end table
> >>>
> >>> +@section AudioToolbox
> >>> +
> >>> +AudioToolbox input device.
> >>> +
> >>> +Allows native input from CoreAudio devices on OSX.
> >> Nit: Nowadays it's macOS instead of OSX
> >>
> >>> +
> >>> +All available devices can be enumerated by using
> >>> @option{-list_devices true}, listing
> >>> +all device names, and corresponding unique ID.

Re: [FFmpeg-devel] [PATCH 5/5] Add AudioToolbox audio input device.

2022-01-24 Thread Marvin Scholz



On 24 Jan 2022, at 16:42, Romain Beauxis wrote:


Hi Marvin,

Le mer. 19 janv. 2022 à 10:59, Marvin Scholz  a 
écrit :

On 19 Jan 2022, at 15:42, Romain Beauxis wrote:

Hi, thanks for the patch. I've not done a full code review yet, just 
a

few
initial remarks below:


This patch adds support for a new, audio-specific input device using
the documented and battle-tested AUHAL input. This provides a 
pendant

to the AudioToolbox audio-only output.

A couple of advantages for this:
* It avoids a lot of the complexity of supporting audio and video in 
a

single input
* The AUHAL API seems tested, documented and robust
* This implementation hopefully gives good control over audio 
latency

and also minimizes data copy


Thanks!

Do you need more time for this review? We discovered another issue
with the dynamic array of video devices and I'd like to send a revised
series soon.


Well if you want to address the things I mentioned last time
it will anyway change a bunch of things probably, so it
might be easier if I just wait for the new patch.

Additionally it might be useful to send it independent of the
whole patchset as IIUC it does not really depend on any of the
previous patches.


Also, I think I'll reorder the patches so that the most
trivial one (unique device name, probing API call updates) can be
applied right away.

Let me know!
Romain


From: Romain Beauxis 
To: ffmpeg-devel@ffmpeg.org
Subject: [PATCH] Add AudioToolbox audio input device.
Date: 18. January 2022 at 23:29
Signed-off-by: Romain Beauxis 
---
 configure  |   5 +
 doc/indevs.texi|  44 
 libavdevice/Makefile   |   1 +
 libavdevice/alldevices.c   |   1 +
 libavdevice/audiotoolbox_dec.m | 466
+
 5 files changed, 517 insertions(+)
 create mode 100644 libavdevice/audiotoolbox_dec.m

diff --git a/configure b/configure
index 1413122d87..80e39aae44 100755
--- a/configure
+++ b/configure
@@ -204,6 +204,7 @@ External library support:
   --disable-avfoundation   disable Apple AVFoundation framework
[autodetect]
   --enable-avisynthenable reading of AviSynth script files
[no]
   --disable-bzlib  disable bzlib [autodetect]
+  --disable-coremedia  disable Apple CoreMedia framework
[autodetect]
   --disable-coreimage  disable Apple CoreImage framework
[autodetect]
   --enable-chromaprint enable audio fingerprinting with
chromaprint [no]
   --enable-frei0r  enable frei0r video filtering [no]
@@ -1750,6 +1751,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
 appkit
 avfoundation
 bzlib
+coremedia
 coreimage
 iconv
 libxcb
@@ -3493,6 +3495,8 @@ alsa_outdev_deps="alsa"
 avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
 avfoundation_indev_suggest="coregraphics applicationservices"
 avfoundation_indev_extralibs="-framework Foundation"
+audiotoolbox_indev_deps="coremedia audiotoolbox"
+audiotoolbox_indev_extralibs="-framework CoreMedia -framework
AudioToolbox"
 audiotoolbox_outdev_deps="audiotoolbox pthreads"
 audiotoolbox_outdev_extralibs="-framework AudioToolbox -framework
CoreAudio"
 bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
@@ -6340,6 +6344,7 @@ check_lib camera2ndk "stdbool.h stdint.h
camera/NdkCameraManager.h" ACameraManag
 enabled appkit   && check_apple_framework AppKit
 enabled audiotoolbox && check_apple_framework AudioToolbox
 enabled avfoundation && check_apple_framework AVFoundation
+enabled coremedia&& check_apple_framework CoreMedia
 enabled coreimage&& check_apple_framework CoreImage
 enabled metal&& check_apple_framework Metal
 enabled videotoolbox && check_apple_framework VideoToolbox
diff --git a/doc/indevs.texi b/doc/indevs.texi
index 858c0fa4e4..30a91d304f 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -103,6 +103,50 @@ Set the maximum number of frames to buffer.
Default is 5.

 @end table

+@section AudioToolbox
+
+AudioToolbox input device.
+
+Allows native input from CoreAudio devices on OSX.

Nit: Nowadays it's macOS instead of OSX


+
+All available devices can be enumerated by using
@option{-list_devices true}, listing
+all device names, and corresponding unique ID.


Instead of adding another device that uses a custom list-devices 
option,

could you
instead implement the .get_device_list callback? (See alsa or pulse
modules for an
example) Then listing would work properly with the `ffmpeg -sources`
command and
devices could be iterated over using the avdevice APIs as well.

(Ideally we would have that for AVFoundation too but its really hard 
now

to do that
in a backwards compatible manner)


+
+@subsection Options
+
+AudioToolbox supports the following options:
+
+@table @option
+
+@item channels
+Set the number of channels. Default is device's default.
+
+@item frames_queue_length
+Maximum of buffers in the input queue
+
+@item buffer_frame_size
+Buffer frame size, gouverning 

[FFmpeg-devel] Patch review request

2022-01-24 Thread Petri Rocha, Daniel
Hi,


I have submitted a patch few months ago which makes it possible to load images 
referenced in image elements through a file URL scheme.

Here is the patch:


https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210803094534.1000-1-daniel.pe...@tum.de/


The current alternative to display images is to encode them as Base64. This 
takes up a lot of redundant space in use cases where a series of SVG frames are 
being read in as a slideshow, each of these frames having to contain the entire 
raw data instead of just a reference to a file.


Feedback on this would be greatly appreciated - I'd be happy to make the 
necessary changes to see this enhancement merged.


With kind regards,

Daniel Petri

___
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 5/5] Add AudioToolbox audio input device.

2022-01-24 Thread Romain Beauxis
Hi Marvin,

Le mer. 19 janv. 2022 à 10:59, Marvin Scholz  a écrit :
> On 19 Jan 2022, at 15:42, Romain Beauxis wrote:
>
> Hi, thanks for the patch. I've not done a full code review yet, just a
> few
> initial remarks below:
>
> > This patch adds support for a new, audio-specific input device using
> > the documented and battle-tested AUHAL input. This provides a pendant
> > to the AudioToolbox audio-only output.
> >
> > A couple of advantages for this:
> > * It avoids a lot of the complexity of supporting audio and video in a
> > single input
> > * The AUHAL API seems tested, documented and robust
> > * This implementation hopefully gives good control over audio latency
> > and also minimizes data copy

Thanks!

Do you need more time for this review? We discovered another issue
with the dynamic array of video devices and I'd like to send a revised
series soon. Also, I think I'll reorder the patches so that the most
trivial one (unique device name, probing API call updates) can be
applied right away.

Let me know!
Romain

> > From: Romain Beauxis 
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [PATCH] Add AudioToolbox audio input device.
> > Date: 18. January 2022 at 23:29
> > Signed-off-by: Romain Beauxis 
> > ---
> >  configure  |   5 +
> >  doc/indevs.texi|  44 
> >  libavdevice/Makefile   |   1 +
> >  libavdevice/alldevices.c   |   1 +
> >  libavdevice/audiotoolbox_dec.m | 466
> > +
> >  5 files changed, 517 insertions(+)
> >  create mode 100644 libavdevice/audiotoolbox_dec.m
> >
> > diff --git a/configure b/configure
> > index 1413122d87..80e39aae44 100755
> > --- a/configure
> > +++ b/configure
> > @@ -204,6 +204,7 @@ External library support:
> >--disable-avfoundation   disable Apple AVFoundation framework
> > [autodetect]
> >--enable-avisynthenable reading of AviSynth script files
> > [no]
> >--disable-bzlib  disable bzlib [autodetect]
> > +  --disable-coremedia  disable Apple CoreMedia framework
> > [autodetect]
> >--disable-coreimage  disable Apple CoreImage framework
> > [autodetect]
> >--enable-chromaprint enable audio fingerprinting with
> > chromaprint [no]
> >--enable-frei0r  enable frei0r video filtering [no]
> > @@ -1750,6 +1751,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
> >  appkit
> >  avfoundation
> >  bzlib
> > +coremedia
> >  coreimage
> >  iconv
> >  libxcb
> > @@ -3493,6 +3495,8 @@ alsa_outdev_deps="alsa"
> >  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
> >  avfoundation_indev_suggest="coregraphics applicationservices"
> >  avfoundation_indev_extralibs="-framework Foundation"
> > +audiotoolbox_indev_deps="coremedia audiotoolbox"
> > +audiotoolbox_indev_extralibs="-framework CoreMedia -framework
> > AudioToolbox"
> >  audiotoolbox_outdev_deps="audiotoolbox pthreads"
> >  audiotoolbox_outdev_extralibs="-framework AudioToolbox -framework
> > CoreAudio"
> >  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
> > dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
> > @@ -6340,6 +6344,7 @@ check_lib camera2ndk "stdbool.h stdint.h
> > camera/NdkCameraManager.h" ACameraManag
> >  enabled appkit   && check_apple_framework AppKit
> >  enabled audiotoolbox && check_apple_framework AudioToolbox
> >  enabled avfoundation && check_apple_framework AVFoundation
> > +enabled coremedia&& check_apple_framework CoreMedia
> >  enabled coreimage&& check_apple_framework CoreImage
> >  enabled metal&& check_apple_framework Metal
> >  enabled videotoolbox && check_apple_framework VideoToolbox
> > diff --git a/doc/indevs.texi b/doc/indevs.texi
> > index 858c0fa4e4..30a91d304f 100644
> > --- a/doc/indevs.texi
> > +++ b/doc/indevs.texi
> > @@ -103,6 +103,50 @@ Set the maximum number of frames to buffer.
> > Default is 5.
> >
> >  @end table
> >
> > +@section AudioToolbox
> > +
> > +AudioToolbox input device.
> > +
> > +Allows native input from CoreAudio devices on OSX.
> Nit: Nowadays it's macOS instead of OSX
>
> > +
> > +All available devices can be enumerated by using
> > @option{-list_devices true}, listing
> > +all device names, and corresponding unique ID.
>
> Instead of adding another device that uses a custom list-devices option,
> could you
> instead implement the .get_device_list callback? (See alsa or pulse
> modules for an
> example) Then listing would work properly with the `ffmpeg -sources`
> command and
> devices could be iterated over using the avdevice APIs as well.
>
> (Ideally we would have that for AVFoundation too but its really hard now
> to do that
> in a backwards compatible manner)
>
> > +
> > +@subsection Options
> > +
> > +AudioToolbox supports the following options:
> > +
> > +@table @option
> > +
> > +@item channels
> > +Set the number of channels. Default is device's default.
> > +
> > +@item frames_queue_length
> > +Maximum of buffers in the input queue
> > +
> > 

[FFmpeg-devel] [PATCH] ffmpeg: add packet duration to muxer logging

2022-01-24 Thread Jan Ekström
From: Jaakko Perttilä 

Especially useful when debugging subtitle output.

Signed-off-by: Jan Ekström 
---
 fftools/ffmpeg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c89d94520f..af65be157e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -853,10 +853,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 
 if (debug_ts) {
 av_log(NULL, AV_LOG_INFO, "muxer <- type:%s "
-"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s 
size:%d\n",
+"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s 
duration:%s duration_time:%s size:%d\n",
 av_get_media_type_string(ost->enc_ctx->codec_type),
 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, 
>st->time_base),
 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, 
>st->time_base),
+av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, 
>st->time_base),
 pkt->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 v2 31/31] avutil/fifo: Deprecate old FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

Users should switch to the superior AVFifo API.

Unfortunately AVFifoBuffer fields cannot be marked as deprecated because
it would trigger a warning wherever fifo.h is #included, due to
inlined av_fifo_peek2().
---
 doc/APIchanges  |  8 
 libavutil/fifo.c|  4 
 libavutil/fifo.h| 45 -
 libavutil/version.h |  3 ++-
 4 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 75e0b1f49a..db6b2ab809 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,14 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-01-xx - xx - lavu 57.20.100 - fifo.h
+  Deprecate AVFifoBuffer and the API around it, namely av_fifo_alloc(),
+  av_fifo_alloc_array(), av_fifo_free(), av_fifo_freep(), av_fifo_reset(),
+  av_fifo_size(), av_fifo_space(), av_fifo_generic_peek_at(),
+  av_fifo_generic_peek(), av_fifo_generic_read(), av_fifo_generic_write(),
+  av_fifo_realloc2(), av_fifo_grow(), av_fifo_drain() and av_fifo_peek2().
+  Users should switch to the AVFifo-API.
+
 2022-01-xx - xx - lavu 57.19.100 - fifo.h
   Add a new FIFO API, which allows setting a FIFO element size.
   This API operates on these elements rather than on bytes.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 5a09dd3877..818e39694b 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -285,6 +285,8 @@ void av_fifo_freep2(AVFifo **f)
 }
 
 
+#if FF_API_FIFO_OLD_API
+FF_DISABLE_DEPRECATION_WARNINGS
 #define OLD_FIFO_SIZE_MAX (size_t)FFMIN3(INT_MAX, UINT32_MAX, SIZE_MAX)
 
 AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
@@ -497,3 +499,5 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
 f->rptr -= f->end - f->buffer;
 f->rndx += size;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 55548fbeb4..40852c0f70 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -220,6 +220,7 @@ void av_fifo_reset2(AVFifo *f);
 void av_fifo_freep2(AVFifo **f);
 
 
+#if FF_API_FIFO_OLD_API
 typedef struct AVFifoBuffer {
 uint8_t *buffer;
 uint8_t *rptr, *wptr, *end;
@@ -230,7 +231,9 @@ typedef struct AVFifoBuffer {
  * Initialize an AVFifoBuffer.
  * @param size of FIFO
  * @return AVFifoBuffer or NULL in case of memory allocation failure
+ * @deprecated use av_fifo_alloc2()
  */
+attribute_deprecated
 AVFifoBuffer *av_fifo_alloc(unsigned int size);
 
 /**
@@ -238,25 +241,33 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size);
  * @param nmemb number of elements
  * @param size  size of the single element
  * @return AVFifoBuffer or NULL in case of memory allocation failure
+ * @deprecated use av_fifo_alloc2()
  */
+attribute_deprecated
 AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size);
 
 /**
  * Free an AVFifoBuffer.
  * @param f AVFifoBuffer to free
+ * @deprecated use the AVFifo API with av_fifo_freep2()
  */
+attribute_deprecated
 void av_fifo_free(AVFifoBuffer *f);
 
 /**
  * Free an AVFifoBuffer and reset pointer to NULL.
  * @param f AVFifoBuffer to free
+ * @deprecated use the AVFifo API with av_fifo_freep2()
  */
+attribute_deprecated
 void av_fifo_freep(AVFifoBuffer **f);
 
 /**
  * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in 
particular it is emptied.
  * @param f AVFifoBuffer to reset
+ * @deprecated use av_fifo_reset2() with the new AVFifo-API
  */
+attribute_deprecated
 void av_fifo_reset(AVFifoBuffer *f);
 
 /**
@@ -264,7 +275,9 @@ void av_fifo_reset(AVFifoBuffer *f);
  * amount of data you can read from it.
  * @param f AVFifoBuffer to read from
  * @return size
+ * @deprecated use av_fifo_can_read() with the new AVFifo-API
  */
+attribute_deprecated
 int av_fifo_size(const AVFifoBuffer *f);
 
 /**
@@ -272,7 +285,9 @@ int av_fifo_size(const AVFifoBuffer *f);
  * amount of data you can write into it.
  * @param f AVFifoBuffer to write into
  * @return size
+ * @deprecated use av_fifo_can_write() with the new AVFifo-API
  */
+attribute_deprecated
 int av_fifo_space(const AVFifoBuffer *f);
 
 /**
@@ -285,7 +300,11 @@ int av_fifo_space(const AVFifoBuffer *f);
  * @param dest data destination
  *
  * @return a non-negative number on success, a negative error code on failure
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_peek() when func == NULL,
+ * av_fifo_peek_to_cb() otherwise
  */
+attribute_deprecated
 int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, int offset, int 
buf_size, void (*func)(void*, void*, int));
 
 /**
@@ -297,7 +316,11 @@ int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, 
int offset, int buf_siz
  * @param dest data destination
  *
  * @return a non-negative number on success, a negative error code on failure
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_peek() when func == NULL,
+ * av_fifo_peek_to_cb() otherwise
  */
+attribute_deprecated
 int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int 

[FFmpeg-devel] [PATCH v2 30/31] ffmpeg: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 fftools/ffmpeg.c| 69 -
 fftools/ffmpeg.h|  6 ++--
 fftools/ffmpeg_filter.c | 14 -
 fftools/ffmpeg_opt.c|  4 +--
 4 files changed, 37 insertions(+), 56 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d134b025f..d909fa58a7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -527,23 +527,17 @@ static void ffmpeg_cleanup(int ret)
 for (j = 0; j < fg->nb_inputs; j++) {
 InputFilter *ifilter = fg->inputs[j];
 struct InputStream *ist = ifilter->ist;
+AVFrame *frame;
 
-while (av_fifo_size(ifilter->frame_queue)) {
-AVFrame *frame;
-av_fifo_generic_read(ifilter->frame_queue, ,
- sizeof(frame), NULL);
+while (av_fifo_read(ifilter->frame_queue, , 1) >= 0)
 av_frame_free();
-}
-av_fifo_freep(>frame_queue);
+av_fifo_freep2(>frame_queue);
 av_freep(>displaymatrix);
 if (ist->sub2video.sub_queue) {
-while (av_fifo_size(ist->sub2video.sub_queue)) {
-AVSubtitle sub;
-av_fifo_generic_read(ist->sub2video.sub_queue,
- , sizeof(sub), NULL);
+AVSubtitle sub;
+while (av_fifo_read(ist->sub2video.sub_queue, , 1) >= 0)
 avsubtitle_free();
-}
-av_fifo_freep(>sub2video.sub_queue);
+av_fifo_freep2(>sub2video.sub_queue);
 }
 av_buffer_unref(>hw_frames_ctx);
 av_freep(>name);
@@ -608,12 +602,10 @@ static void ffmpeg_cleanup(int ret)
 avcodec_parameters_free(>ref_par);
 
 if (ost->muxing_queue) {
-while (av_fifo_size(ost->muxing_queue)) {
-AVPacket *pkt;
-av_fifo_generic_read(ost->muxing_queue, , sizeof(pkt), 
NULL);
+AVPacket *pkt;
+while (av_fifo_read(ost->muxing_queue, , 1) >= 0)
 av_packet_free();
-}
-av_fifo_freep(>muxing_queue);
+av_fifo_freep2(>muxing_queue);
 }
 
 av_freep(_streams[i]);
@@ -749,11 +741,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 if (!of->header_written) {
 AVPacket *tmp_pkt;
 /* the muxer is not initialized yet, buffer the packet */
-if (!av_fifo_space(ost->muxing_queue)) {
-size_t cur_size = av_fifo_size(ost->muxing_queue);
+if (!av_fifo_can_write(ost->muxing_queue)) {
+size_t cur_size = av_fifo_can_read(ost->muxing_queue);
 unsigned int are_we_over_size =
 (ost->muxing_queue_data_size + pkt->size) > 
ost->muxing_queue_data_threshold;
-size_t limit= are_we_over_size ? ost->max_muxing_queue_size : 
INT_MAX;
+size_t limit= are_we_over_size ? ost->max_muxing_queue_size : 
SIZE_MAX;
 size_t new_size = FFMIN(2 * cur_size, limit);
 
 if (new_size <= cur_size) {
@@ -762,7 +754,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
ost->file_index, ost->st->index);
 exit_program(1);
 }
-ret = av_fifo_realloc2(ost->muxing_queue, new_size);
+ret = av_fifo_grow2(ost->muxing_queue, new_size - cur_size);
 if (ret < 0)
 exit_program(1);
 }
@@ -774,7 +766,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 exit_program(1);
 av_packet_move_ref(tmp_pkt, pkt);
 ost->muxing_queue_data_size += tmp_pkt->size;
-av_fifo_generic_write(ost->muxing_queue, _pkt, sizeof(tmp_pkt), 
NULL);
+av_fifo_write(ost->muxing_queue, _pkt, 1);
 return;
 }
 
@@ -2195,15 +2187,11 @@ static int ifilter_send_frame(InputFilter *ifilter, 
AVFrame *frame, int keep_ref
 if (!tmp)
 return AVERROR(ENOMEM);
 
-if (!av_fifo_space(ifilter->frame_queue)) {
-ret = av_fifo_realloc2(ifilter->frame_queue, 2 * 
av_fifo_size(ifilter->frame_queue));
-if (ret < 0) {
-av_frame_free();
-return ret;
-}
-}
-av_fifo_generic_write(ifilter->frame_queue, , sizeof(tmp), 
NULL);
-return 0;
+ret = av_fifo_write(ifilter->frame_queue, , 1);
+if (ret < 0)
+av_frame_free();
+
+return ret;
 }
 
 ret = reap_filters(1);
@@ -2526,15 +2514,13 @@ static int transcode_subtitles(InputStream *ist, 
AVPacket *pkt, int *got_output,
 sub2video_update(ist, INT64_MIN, );
 } else if (ist->nb_filters) {
 if (!ist->sub2video.sub_queue)
- 

[FFmpeg-devel] [PATCH v2 29/31] ffplay: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 fftools/ffplay.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index e7b20be76b..ac48d8765d 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -115,7 +115,7 @@ typedef struct MyAVPacketList {
 } MyAVPacketList;
 
 typedef struct PacketQueue {
-AVFifoBuffer *pkt_list;
+AVFifo *pkt_list;
 int nb_packets;
 int size;
 int64_t duration;
@@ -424,19 +424,18 @@ int64_t get_valid_channel_layout(int64_t channel_layout, 
int channels)
 static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
 {
 MyAVPacketList pkt1;
+int ret;
 
 if (q->abort_request)
return -1;
 
-if (av_fifo_space(q->pkt_list) < sizeof(pkt1)) {
-if (av_fifo_grow(q->pkt_list, sizeof(pkt1)) < 0)
-return -1;
-}
 
 pkt1.pkt = pkt;
 pkt1.serial = q->serial;
 
-av_fifo_generic_write(q->pkt_list, , sizeof(pkt1), NULL);
+ret = av_fifo_write(q->pkt_list, , 1);
+if (ret < 0)
+return ret;
 q->nb_packets++;
 q->size += pkt1.pkt->size + sizeof(pkt1);
 q->duration += pkt1.pkt->duration;
@@ -477,7 +476,7 @@ static int packet_queue_put_nullpacket(PacketQueue *q, 
AVPacket *pkt, int stream
 static int packet_queue_init(PacketQueue *q)
 {
 memset(q, 0, sizeof(PacketQueue));
-q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList));
+q->pkt_list = av_fifo_alloc2(1, sizeof(MyAVPacketList), 
AV_FIFO_FLAG_AUTO_GROW);
 if (!q->pkt_list)
 return AVERROR(ENOMEM);
 q->mutex = SDL_CreateMutex();
@@ -499,10 +498,8 @@ static void packet_queue_flush(PacketQueue *q)
 MyAVPacketList pkt1;
 
 SDL_LockMutex(q->mutex);
-while (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
-av_fifo_generic_read(q->pkt_list, , sizeof(pkt1), NULL);
+while (av_fifo_read(q->pkt_list, , 1) >= 0)
 av_packet_free();
-}
 q->nb_packets = 0;
 q->size = 0;
 q->duration = 0;
@@ -513,7 +510,7 @@ static void packet_queue_flush(PacketQueue *q)
 static void packet_queue_destroy(PacketQueue *q)
 {
 packet_queue_flush(q);
-av_fifo_freep(>pkt_list);
+av_fifo_freep2(>pkt_list);
 SDL_DestroyMutex(q->mutex);
 SDL_DestroyCond(q->cond);
 }
@@ -551,8 +548,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, 
int block, int *seria
 break;
 }
 
-if (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
-av_fifo_generic_read(q->pkt_list, , sizeof(pkt1), NULL);
+if (av_fifo_read(q->pkt_list, , 1) >= 0) {
 q->nb_packets--;
 q->size -= pkt1.pkt->size + sizeof(pkt1);
 q->duration -= pkt1.pkt->duration;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 28/31] lavfi/vf_deshake_opencl: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavfilter/vf_deshake_opencl.c | 92 +++--
 1 file changed, 29 insertions(+), 63 deletions(-)

diff --git a/libavfilter/vf_deshake_opencl.c b/libavfilter/vf_deshake_opencl.c
index 9c761ba5ad..c2b5bef897 100644
--- a/libavfilter/vf_deshake_opencl.c
+++ b/libavfilter/vf_deshake_opencl.c
@@ -134,7 +134,7 @@ typedef struct DebugMatches {
 // for each frame
 typedef struct AbsoluteFrameMotion {
 // Array with the various ringbuffers, indexed via the RingbufferIndices 
enum
-AVFifoBuffer *ringbuffers[RingbufCount];
+AVFifo *ringbuffers[RingbufCount];
 
 // Offset to get to the current frame being processed
 // (not in bytes)
@@ -144,7 +144,7 @@ typedef struct AbsoluteFrameMotion {
 int data_start_offset;
 int data_end_offset;
 
-AVFifoBuffer *debug_matches;
+AVFifo *debug_matches;
 } AbsoluteFrameMotion;
 
 // Takes care of freeing the arrays within the DebugMatches inside of the
@@ -156,18 +156,10 @@ static void free_debug_matches(AbsoluteFrameMotion *afm) {
 return;
 }
 
-while (av_fifo_size(afm->debug_matches) > 0) {
-av_fifo_generic_read(
-afm->debug_matches,
-,
-sizeof(DebugMatches),
-NULL
-);
-
+while (av_fifo_read(afm->debug_matches, , 1) >= 0)
 av_freep();
-}
 
-av_fifo_freep(>debug_matches);
+av_fifo_freep2(>debug_matches);
 }
 
 // Stores the translation, scale, rotation, and skew deltas between two frames
@@ -853,7 +845,7 @@ static IterIndices start_end_for(DeshakeOpenCLContext 
*deshake_ctx, int length)
 // clipping the offset into the appropriate range
 static void ringbuf_float_at(
 DeshakeOpenCLContext *deshake_ctx,
-AVFifoBuffer *values,
+AVFifo *values,
 float *val,
 int offset
 ) {
@@ -863,7 +855,7 @@ static void ringbuf_float_at(
 } else {
 // This expression represents the last valid index in the buffer,
 // which we use repeatedly at the end of the video.
-clip_end = deshake_ctx->smooth_window - (av_fifo_space(values) / 
sizeof(float)) - 1;
+clip_end = deshake_ctx->smooth_window - av_fifo_can_write(values) - 1;
 }
 
 if (deshake_ctx->abs_motion.data_start_offset != -1) {
@@ -881,13 +873,7 @@ static void ringbuf_float_at(
 clip_end
 );
 
-av_fifo_generic_peek_at(
-values,
-val,
-offset_clipped * sizeof(float),
-sizeof(float),
-NULL
-);
+av_fifo_peek(values, val, 1, offset_clipped);
 }
 
 // Returns smoothed current frame value of the given buffer of floats based on 
the
@@ -905,7 +891,7 @@ static float smooth(
 float *gauss_kernel,
 int length,
 float max_val,
-AVFifoBuffer *values
+AVFifo *values
 ) {
 float new_large_s = 0, new_small_s = 0, new_best = 0, old, diff_between,
   percent_of_max, inverted_percent;
@@ -1069,7 +1055,7 @@ static av_cold void deshake_opencl_uninit(AVFilterContext 
*avctx)
 cl_int cle;
 
 for (int i = 0; i < RingbufCount; i++)
-av_fifo_freep(>abs_motion.ringbuffers[i]);
+av_fifo_freep2(>abs_motion.ringbuffers[i]);
 
 if (ctx->debug_on)
 free_debug_matches(>abs_motion);
@@ -1188,10 +1174,8 @@ static int deshake_opencl_init(AVFilterContext *avctx)
 }
 
 for (int i = 0; i < RingbufCount; i++) {
-ctx->abs_motion.ringbuffers[i] = av_fifo_alloc_array(
-ctx->smooth_window,
-sizeof(float)
-);
+ctx->abs_motion.ringbuffers[i] = av_fifo_alloc2(ctx->smooth_window,
+sizeof(float), 0);
 
 if (!ctx->abs_motion.ringbuffers[i]) {
 err = AVERROR(ENOMEM);
@@ -1200,9 +1184,9 @@ static int deshake_opencl_init(AVFilterContext *avctx)
 }
 
 if (ctx->debug_on) {
-ctx->abs_motion.debug_matches = av_fifo_alloc_array(
+ctx->abs_motion.debug_matches = av_fifo_alloc2(
 ctx->smooth_window / 2,
-sizeof(DebugMatches)
+sizeof(DebugMatches), 0
 );
 
 if (!ctx->abs_motion.debug_matches) {
@@ -1424,12 +1408,9 @@ static int filter_frame(AVFilterLink *link, AVFrame 
*input_frame)
 const float luma_h_over_chroma_h = ((float)input_frame->height / 
(float)chroma_height);
 
 if (deshake_ctx->debug_on) {
-av_fifo_generic_read(
+av_fifo_read(
 deshake_ctx->abs_motion.debug_matches,
-_matches,
-sizeof(DebugMatches),
-NULL
-);
+_matches, 1);
 }
 
 if (input_frame->pkt_duration) {
@@ -1441,13 +1422,9 @@ static int filter_frame(AVFilterLink *link, AVFrame 
*input_frame)
 
 // Get the absolute transform data for this frame
 for (int i = 0; i < RingbufCount; i++) {
-av_fifo_generic_peek_at(
-deshake_ctx->abs_motion.ringbuffers[i],
-_vals[i],
-deshake_ctx->abs_motion.curr_frame_offset * sizeof(float),
-

[FFmpeg-devel] [PATCH v2 27/31] lavfi/qsvvpp: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavfilter/qsvvpp.c | 46 ++--
 libavfilter/qsvvpp.h |  2 +-
 2 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d1218355c7..35769dfd60 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -40,6 +40,11 @@
 
 static const AVRational default_tb = { 1, 9 };
 
+typedef struct QSVAsyncFrame {
+mfxSyncPoint  sync;
+QSVFrame *frame;
+} QSVAsyncFrame;
+
 static const struct {
 int mfx_iopattern;
 const char *desc;
@@ -642,16 +647,6 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 return 0;
 }
 
-static unsigned int qsv_fifo_item_size(void)
-{
-return sizeof(mfxSyncPoint) + sizeof(QSVFrame*);
-}
-
-static unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
-{
-return  av_fifo_size(fifo)/qsv_fifo_item_size();
-}
-
 int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam 
*param)
 {
 int i;
@@ -727,7 +722,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext 
**vpp, QSVVPPParam *p
 s->got_frame = 0;
 
 /** keep fifo size at least 1. Even when async_depth is 0, fifo is used. */
-s->async_fifo  = av_fifo_alloc((param->async_depth + 1) * 
qsv_fifo_item_size());
+s->async_fifo  = av_fifo_alloc2(param->async_depth + 1, 
sizeof(QSVAsyncFrame), 0);
 s->async_depth = param->async_depth;
 if (!s->async_fifo) {
 ret = AVERROR(ENOMEM);
@@ -789,7 +784,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp)
 av_freep(>surface_ptrs_out);
 av_freep(>ext_buffers);
 av_freep(>frame_infos);
-av_fifo_free(s->async_fifo);
+av_fifo_freep2(>async_fifo);
 av_freep(vpp);
 
 return 0;
@@ -799,24 +794,23 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 {
 AVFilterContext  *ctx = inlink->dst;
 AVFilterLink *outlink = ctx->outputs[0];
+QSVAsyncFrame aframe;
 mfxSyncPoint  sync;
 QSVFrame *in_frame, *out_frame, *tmp;
 int   ret, filter_ret;
 
-while (s->eof && qsv_fifo_size(s->async_fifo)) {
-av_fifo_generic_read(s->async_fifo, , sizeof(tmp), NULL);
-av_fifo_generic_read(s->async_fifo, , sizeof(sync), NULL);
-if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0)
+while (s->eof && av_fifo_read(s->async_fifo, , 1) >= 0) {
+if (MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000) < 0)
 av_log(ctx, AV_LOG_WARNING, "Sync failed.\n");
 
-filter_ret = s->filter_frame(outlink, tmp->frame);
+filter_ret = s->filter_frame(outlink, aframe.frame->frame);
 if (filter_ret < 0) {
-av_frame_free(>frame);
+av_frame_free(>frame);
 return filter_ret;
 }
-tmp->queued--;
+aframe.frame->queued--;
 s->got_frame = 1;
-tmp->frame = NULL;
+aframe.frame->frame = NULL;
 };
 
 if (!picref)
@@ -853,16 +847,14 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
  default_tb, outlink->time_base);
 
 out_frame->queued++;
-av_fifo_generic_write(s->async_fifo, _frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_write(s->async_fifo, , sizeof(sync), NULL);
-
+aframe = (QSVAsyncFrame){ sync, out_frame };
+av_fifo_write(s->async_fifo, , 1);
 
-if (qsv_fifo_size(s->async_fifo) > s->async_depth) {
-av_fifo_generic_read(s->async_fifo, , sizeof(tmp), NULL);
-av_fifo_generic_read(s->async_fifo, , sizeof(sync), NULL);
+if (av_fifo_can_read(s->async_fifo) > s->async_depth) {
+av_fifo_read(s->async_fifo, , 1);
 
 do {
-ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
+ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, 
1000);
 } while (ret == MFX_WRN_IN_EXECUTION);
 
 filter_ret = s->filter_frame(outlink, tmp->frame);
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index e0f4c8f5bb..4fe07ab1f7 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -73,7 +73,7 @@ typedef struct QSVVPPContext {
 int async_depth;
 int eof;
 /** order with frame_out, sync */
-AVFifoBuffer *async_fifo;
+AVFifo *async_fifo;
 } QSVVPPContext;
 
 typedef struct QSVVPPCrop {
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 26/31] lavu/threadmessage: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavutil/threadmessage.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
index 764b7fb813..6f25da76d7 100644
--- a/libavutil/threadmessage.c
+++ b/libavutil/threadmessage.c
@@ -24,7 +24,7 @@
 
 struct AVThreadMessageQueue {
 #if HAVE_THREADS
-AVFifoBuffer *fifo;
+AVFifo *fifo;
 pthread_mutex_t lock;
 pthread_cond_t cond_recv;
 pthread_cond_t cond_send;
@@ -64,7 +64,7 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
 av_free(rmq);
 return AVERROR(ret);
 }
-if (!(rmq->fifo = av_fifo_alloc(elsize * nelem))) {
+if (!(rmq->fifo = av_fifo_alloc2(nelem, elsize, 0))) {
 pthread_cond_destroy(>cond_send);
 pthread_cond_destroy(>cond_recv);
 pthread_mutex_destroy(>lock);
@@ -93,7 +93,7 @@ void av_thread_message_queue_free(AVThreadMessageQueue **mq)
 #if HAVE_THREADS
 if (*mq) {
 av_thread_message_flush(*mq);
-av_fifo_freep(&(*mq)->fifo);
+av_fifo_freep2(&(*mq)->fifo);
 pthread_cond_destroy(&(*mq)->cond_send);
 pthread_cond_destroy(&(*mq)->cond_recv);
 pthread_mutex_destroy(&(*mq)->lock);
@@ -107,9 +107,9 @@ int av_thread_message_queue_nb_elems(AVThreadMessageQueue 
*mq)
 #if HAVE_THREADS
 int ret;
 pthread_mutex_lock(>lock);
-ret = av_fifo_size(mq->fifo);
+ret = av_fifo_can_read(mq->fifo);
 pthread_mutex_unlock(>lock);
-return ret / mq->elsize;
+return ret;
 #else
 return AVERROR(ENOSYS);
 #endif
@@ -121,14 +121,14 @@ static int 
av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
void *msg,
unsigned flags)
 {
-while (!mq->err_send && av_fifo_space(mq->fifo) < mq->elsize) {
+while (!mq->err_send && !av_fifo_can_write(mq->fifo)) {
 if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
 return AVERROR(EAGAIN);
 pthread_cond_wait(>cond_send, >lock);
 }
 if (mq->err_send)
 return mq->err_send;
-av_fifo_generic_write(mq->fifo, msg, mq->elsize, NULL);
+av_fifo_write(mq->fifo, msg, 1);
 /* one message is sent, signal one receiver */
 pthread_cond_signal(>cond_recv);
 return 0;
@@ -138,14 +138,14 @@ static int 
av_thread_message_queue_recv_locked(AVThreadMessageQueue *mq,
void *msg,
unsigned flags)
 {
-while (!mq->err_recv && av_fifo_size(mq->fifo) < mq->elsize) {
+while (!mq->err_recv && !av_fifo_can_read(mq->fifo)) {
 if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
 return AVERROR(EAGAIN);
 pthread_cond_wait(>cond_recv, >lock);
 }
-if (av_fifo_size(mq->fifo) < mq->elsize)
+if (!av_fifo_can_read(mq->fifo))
 return mq->err_recv;
-av_fifo_generic_read(mq->fifo, msg, mq->elsize, NULL);
+av_fifo_read(mq->fifo, msg, 1);
 /* one message space appeared, signal one sender */
 pthread_cond_signal(>cond_send);
 return 0;
@@ -208,25 +208,25 @@ void 
av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
 }
 
 #if HAVE_THREADS
-static void free_func_wrap(void *arg, void *msg, int size)
+static int free_func_wrap(void *arg, void *buf, size_t *nb_elems)
 {
 AVThreadMessageQueue *mq = arg;
-mq->free_func(msg);
+uint8_t *msg = buf;
+for (size_t i = 0; i < *nb_elems; i++)
+mq->free_func(msg + i * mq->elsize);
+return 0;
 }
 #endif
 
 void av_thread_message_flush(AVThreadMessageQueue *mq)
 {
 #if HAVE_THREADS
-int used, off;
-void *free_func = mq->free_func;
+size_t used;
 
 pthread_mutex_lock(>lock);
-used = av_fifo_size(mq->fifo);
-if (free_func)
-for (off = 0; off < used; off += mq->elsize)
-av_fifo_generic_peek_at(mq->fifo, mq, off, mq->elsize, 
free_func_wrap);
-av_fifo_drain(mq->fifo, used);
+used = av_fifo_can_read(mq->fifo);
+if (mq->free_func)
+av_fifo_read_to_cb(mq->fifo, free_func_wrap, mq, );
 /* only the senders need to be notified since the queue is empty and there
  * is nothing to read */
 pthread_cond_broadcast(>cond_send);
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 25/31] lavu/audio_fifo: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavutil/audio_fifo.c | 44 --
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/libavutil/audio_fifo.c b/libavutil/audio_fifo.c
index 243efc39e4..b1355e55a0 100644
--- a/libavutil/audio_fifo.c
+++ b/libavutil/audio_fifo.c
@@ -32,7 +32,7 @@
 #include "samplefmt.h"
 
 struct AVAudioFifo {
-AVFifoBuffer **buf; /**< single buffer for interleaved, 
per-channel buffers for planar */
+AVFifo **buf;   /**< single buffer for interleaved, 
per-channel buffers for planar */
 int nb_buffers; /**< number of buffers */
 int nb_samples; /**< number of samples currently in the 
FIFO */
 int allocated_samples;  /**< current allocated size, in samples */
@@ -48,7 +48,7 @@ void av_audio_fifo_free(AVAudioFifo *af)
 if (af->buf) {
 int i;
 for (i = 0; i < af->nb_buffers; i++) {
-av_fifo_freep(>buf[i]);
+av_fifo_freep2(>buf[i]);
 }
 av_freep(>buf);
 }
@@ -80,7 +80,7 @@ AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat 
sample_fmt, int channels,
 goto error;
 
 for (i = 0; i < af->nb_buffers; i++) {
-af->buf[i] = av_fifo_alloc(buf_size);
+af->buf[i] = av_fifo_alloc2(buf_size, 1, 0);
 if (!af->buf[i])
 goto error;
 }
@@ -95,15 +95,19 @@ error:
 
 int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)
 {
+const size_t cur_size = av_fifo_can_read (af->buf[0]) +
+av_fifo_can_write(af->buf[0]);
 int i, ret, buf_size;
 
 if ((ret = av_samples_get_buffer_size(_size, af->channels, nb_samples,
   af->sample_fmt, 1)) < 0)
 return ret;
 
-for (i = 0; i < af->nb_buffers; i++) {
-if ((ret = av_fifo_realloc2(af->buf[i], buf_size)) < 0)
-return ret;
+if (buf_size > cur_size) {
+for (i = 0; i < af->nb_buffers; i++) {
+if ((ret = av_fifo_grow2(af->buf[i], buf_size - cur_size)) < 0)
+return ret;
+}
 }
 af->allocated_samples = nb_samples;
 return 0;
@@ -126,8 +130,8 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int 
nb_samples)
 
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++) {
-ret = av_fifo_generic_write(af->buf[i], data[i], size, NULL);
-if (ret != size)
+ret = av_fifo_write(af->buf[i], data[i], size);
+if (ret < 0)
 return AVERROR_BUG;
 }
 af->nb_samples += nb_samples;
@@ -137,21 +141,7 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int 
nb_samples)
 
 int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
 {
-int i, ret, size;
-
-if (nb_samples < 0)
-return AVERROR(EINVAL);
-nb_samples = FFMIN(nb_samples, af->nb_samples);
-if (!nb_samples)
-return 0;
-
-size = nb_samples * af->sample_size;
-for (i = 0; i < af->nb_buffers; i++) {
-if ((ret = av_fifo_generic_peek(af->buf[i], data[i], size, NULL)) < 0)
-return AVERROR_BUG;
-}
-
-return nb_samples;
+return av_audio_fifo_peek_at(af, data, nb_samples, 0);
 }
 
 int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int 
offset)
@@ -171,7 +161,7 @@ int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int 
nb_samples, int offs
 offset *= af->sample_size;
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++) {
-if ((ret = av_fifo_generic_peek_at(af->buf[i], data[i], offset, size, 
NULL)) < 0)
+if ((ret = av_fifo_peek(af->buf[i], data[i], size, offset)) < 0)
 return AVERROR_BUG;
 }
 
@@ -190,7 +180,7 @@ int av_audio_fifo_read(AVAudioFifo *af, void **data, int 
nb_samples)
 
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++) {
-if (av_fifo_generic_read(af->buf[i], data[i], size, NULL) < 0)
+if (av_fifo_read(af->buf[i], data[i], size) < 0)
 return AVERROR_BUG;
 }
 af->nb_samples -= nb_samples;
@@ -209,7 +199,7 @@ int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
 if (nb_samples) {
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++)
-av_fifo_drain(af->buf[i], size);
+av_fifo_drain2(af->buf[i], size);
 af->nb_samples -= nb_samples;
 }
 return 0;
@@ -220,7 +210,7 @@ void av_audio_fifo_reset(AVAudioFifo *af)
 int i;
 
 for (i = 0; i < af->nb_buffers; i++)
-av_fifo_reset(af->buf[i]);
+av_fifo_reset2(af->buf[i]);
 
 af->nb_samples = 0;
 }
-- 
2.32.0

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

To unsubscribe, visit link above, or email

[FFmpeg-devel] [PATCH v2 24/31] lavu/audio_fifo: drop an unnecessary include

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

Nothing in audio_fifo.h uses anything from fifo.h
---
 libavutil/audio_fifo.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavutil/audio_fifo.h b/libavutil/audio_fifo.h
index d8a9194a8d..9d570b04c0 100644
--- a/libavutil/audio_fifo.h
+++ b/libavutil/audio_fifo.h
@@ -28,7 +28,6 @@
 #define AVUTIL_AUDIO_FIFO_H
 
 #include "avutil.h"
-#include "fifo.h"
 #include "samplefmt.h"
 
 /**
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 23/31] lavd/jack: switch to the new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavdevice/jack.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavdevice/jack.c b/libavdevice/jack.c
index 0d5465e407..b9a167bed3 100644
--- a/libavdevice/jack.c
+++ b/libavdevice/jack.c
@@ -50,8 +50,8 @@ typedef struct JackData {
 jack_port_t **  ports;
 int nports;
 TimeFilter *timefilter;
-AVFifoBuffer *  new_pkts;
-AVFifoBuffer *  filled_pkts;
+AVFifo *new_pkts;
+AVFifo *filled_pkts;
 int pkt_xrun;
 int jack_xrun;
 } JackData;
@@ -81,13 +81,14 @@ static int process_callback(jack_nframes_t nframes, void 
*arg)
   self->buffer_size);
 
 /* Check if an empty packet is available, and if there's enough space to 
send it back once filled */
-if ((av_fifo_size(self->new_pkts) < sizeof(pkt)) || 
(av_fifo_space(self->filled_pkts) < sizeof(pkt))) {
+if (!av_fifo_can_read(self->new_pkts) ||
+!av_fifo_can_write(self->filled_pkts)) {
 self->pkt_xrun = 1;
 return 0;
 }
 
 /* Retrieve empty (but allocated) packet */
-av_fifo_generic_read(self->new_pkts, , sizeof(pkt), NULL);
+av_fifo_read(self->new_pkts, , 1);
 
 pkt_data  = (float *) pkt.data;
 latency   = 0;
@@ -106,7 +107,7 @@ static int process_callback(jack_nframes_t nframes, void 
*arg)
 pkt.pts = (cycle_time - (double) latency / (self->nports * 
self->sample_rate)) * 100.0;
 
 /* Send the now filled packet back, and increase packet counter */
-av_fifo_generic_write(self->filled_pkts, , sizeof(pkt), NULL);
+av_fifo_write(self->filled_pkts, , 1);
 sem_post(>packet_count);
 
 return 0;
@@ -134,12 +135,12 @@ static int supply_new_packets(JackData *self, 
AVFormatContext *context)
 /* Supply the process callback with new empty packets, by filling the new
  * packets FIFO buffer with as many packets as possible. process_callback()
  * can't do this by itself, because it can't allocate memory in realtime. 
*/
-while (av_fifo_space(self->new_pkts) >= sizeof(pkt)) {
+while (av_fifo_can_write(self->new_pkts)) {
 if ((test = av_new_packet(, pkt_size)) < 0) {
 av_log(context, AV_LOG_ERROR, "Could not create packet of size 
%d\n", pkt_size);
 return test;
 }
-av_fifo_generic_write(self->new_pkts, , sizeof(pkt), NULL);
+av_fifo_write(self->new_pkts, , 1);
 }
 return 0;
 }
@@ -193,9 +194,9 @@ static int start_jack(AVFormatContext *context)
 }
 
 /* Create FIFO buffers */
-self->filled_pkts = av_fifo_alloc_array(FIFO_PACKETS_NUM, 
sizeof(AVPacket));
+self->filled_pkts = av_fifo_alloc2(FIFO_PACKETS_NUM, sizeof(AVPacket), 0);
 /* New packets FIFO with one extra packet for safety against underruns */
-self->new_pkts= av_fifo_alloc_array((FIFO_PACKETS_NUM + 1), 
sizeof(AVPacket));
+self->new_pkts= av_fifo_alloc2((FIFO_PACKETS_NUM + 1), 
sizeof(AVPacket), 0);
 if (!self->new_pkts) {
 jack_client_close(self->client);
 return AVERROR(ENOMEM);
@@ -209,14 +210,13 @@ static int start_jack(AVFormatContext *context)
 
 }
 
-static void free_pkt_fifo(AVFifoBuffer **fifo)
+static void free_pkt_fifo(AVFifo **fifop)
 {
+AVFifo *fifo = *fifop;
 AVPacket pkt;
-while (av_fifo_size(*fifo)) {
-av_fifo_generic_read(*fifo, , sizeof(pkt), NULL);
+while (av_fifo_read(fifo, , 1) >= 0)
 av_packet_unref();
-}
-av_fifo_freep(fifo);
+av_fifo_freep2(fifop);
 }
 
 static void stop_jack(JackData *self)
@@ -313,7 +313,7 @@ static int audio_read_packet(AVFormatContext *context, 
AVPacket *pkt)
 }
 
 /* Retrieve the packet filled with audio data by process_callback() */
-av_fifo_generic_read(self->filled_pkts, pkt, sizeof(*pkt), NULL);
+av_fifo_read(self->filled_pkts, pkt, 1);
 
 if ((test = supply_new_packets(self, context)))
 return test;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 22/31] lavf/async: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavformat/async.c | 68 ++---
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/libavformat/async.c b/libavformat/async.c
index 5a81507ef1..547417aa1e 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -47,7 +47,7 @@
 
 typedef struct RingBuffer
 {
-AVFifoBuffer *fifo;
+AVFifo   *fifo;
 int   read_back_capacity;
 
 int   read_pos;
@@ -83,7 +83,7 @@ typedef struct Context {
 static int ring_init(RingBuffer *ring, unsigned int capacity, int 
read_back_capacity)
 {
 memset(ring, 0, sizeof(RingBuffer));
-ring->fifo = av_fifo_alloc(capacity + read_back_capacity);
+ring->fifo = av_fifo_alloc2(capacity + read_back_capacity, 1, 0);
 if (!ring->fifo)
 return AVERROR(ENOMEM);
 
@@ -93,45 +93,59 @@ static int ring_init(RingBuffer *ring, unsigned int 
capacity, int read_back_capa
 
 static void ring_destroy(RingBuffer *ring)
 {
-av_fifo_freep(>fifo);
+av_fifo_freep2(>fifo);
 }
 
 static void ring_reset(RingBuffer *ring)
 {
-av_fifo_reset(ring->fifo);
+av_fifo_reset2(ring->fifo);
 ring->read_pos = 0;
 }
 
 static int ring_size(RingBuffer *ring)
 {
-return av_fifo_size(ring->fifo) - ring->read_pos;
+return av_fifo_can_read(ring->fifo) - ring->read_pos;
 }
 
 static int ring_space(RingBuffer *ring)
 {
-return av_fifo_space(ring->fifo);
+return av_fifo_can_write(ring->fifo);
 }
 
-static int ring_generic_read(RingBuffer *ring, void *dest, int buf_size, void 
(*func)(void*, void*, int))
+static int ring_read(RingBuffer *ring, void *dest, int buf_size)
 {
-int ret;
+int ret = 0;
 
 av_assert2(buf_size <= ring_size(ring));
-ret = av_fifo_generic_peek_at(ring->fifo, dest, ring->read_pos, buf_size, 
func);
+if (dest)
+ret = av_fifo_peek(ring->fifo, dest, buf_size, ring->read_pos);
 ring->read_pos += buf_size;
 
 if (ring->read_pos > ring->read_back_capacity) {
-av_fifo_drain(ring->fifo, ring->read_pos - ring->read_back_capacity);
+av_fifo_drain2(ring->fifo, ring->read_pos - ring->read_back_capacity);
 ring->read_pos = ring->read_back_capacity;
 }
 
 return ret;
 }
 
-static int ring_generic_write(RingBuffer *ring, void *src, int size, int 
(*func)(void*, void*, int))
+static int wrapped_url_read(void *src, void *dst, size_t *size)
+{
+URLContext *h   = src;
+Context*c   = h->priv_data;
+int ret;
+
+ret = ffurl_read(c->inner, dst, *size);
+*size = ret > 0 ? ret : 0;
+c->inner_io_error = ret < 0 ? ret : 0;
+
+return c->inner_io_error;
+}
+
+static int ring_write(RingBuffer *ring, URLContext *h, size_t size)
 {
 av_assert2(size <= ring_space(ring));
-return av_fifo_generic_write(ring->fifo, src, size, func);
+return av_fifo_write_from_cb(ring->fifo, wrapped_url_read, h, );
 }
 
 static int ring_size_of_read_back(RingBuffer *ring)
@@ -161,18 +175,6 @@ static int async_check_interrupt(void *arg)
 return c->abort_request;
 }
 
-static int wrapped_url_read(void *src, void *dst, int size)
-{
-URLContext *h   = src;
-Context*c   = h->priv_data;
-int ret;
-
-ret = ffurl_read(c->inner, dst, size);
-c->inner_io_error = ret < 0 ? ret : 0;
-
-return ret;
-}
-
 static void *async_buffer_task(void *arg)
 {
 URLContext   *h= arg;
@@ -221,7 +223,7 @@ static void *async_buffer_task(void *arg)
 pthread_mutex_unlock(>mutex);
 
 to_copy = FFMIN(4096, fifo_space);
-ret = ring_generic_write(ring, (void *)h, to_copy, wrapped_url_read);
+ret = ring_write(ring, h, to_copy);
 
 pthread_mutex_lock(>mutex);
 if (ret <= 0) {
@@ -327,11 +329,11 @@ static int async_close(URLContext *h)
 return 0;
 }
 
-static int async_read_internal(URLContext *h, void *dest, int size, int 
read_complete,
-   void (*func)(void*, void*, int))
+static int async_read_internal(URLContext *h, void *dest, int size)
 {
 Context  *c   = h->priv_data;
 RingBuffer   *ring= >ring;
+int read_complete = !dest;
 int   to_read = size;
 int   ret = 0;
 
@@ -346,8 +348,8 @@ static int async_read_internal(URLContext *h, void *dest, 
int size, int read_com
 fifo_size = ring_size(ring);
 to_copy   = FFMIN(to_read, fifo_size);
 if (to_copy > 0) {
-ring_generic_read(ring, dest, to_copy, func);
-if (!func)
+ring_read(ring, dest, to_copy);
+if (dest)
 dest = (uint8_t *)dest + to_copy;
 c->logical_pos += to_copy;
 to_read-= to_copy;
@@ -376,11 +378,7 @@ static int async_read_internal(URLContext *h, void *dest, 
int size, int read_com
 
 static int async_read(URLContext *h, unsigned char *buf, int size)
 {
-return async_read_internal(h, buf, size, 0, NULL);
-}
-
-static void 

[FFmpeg-devel] [PATCH v2 21/31] lavf/udp: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavformat/udp.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 83c042d079..1737aee1c2 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -98,7 +98,7 @@ typedef struct UDPContext {
 
 /* Circular Buffer variables for use in UDP receive code */
 int circular_buffer_size;
-AVFifoBuffer *fifo;
+AVFifo *fifo;
 int circular_buffer_error;
 int64_t bitrate; /* number of bits to send per second */
 int64_t burst_bits;
@@ -500,7 +500,7 @@ static void *circular_buffer_task_rx( void *_URLContext)
 continue;
 AV_WL32(s->tmp, len);
 
-if(av_fifo_space(s->fifo) < len + 4) {
+if (av_fifo_can_write(s->fifo) < len + 4) {
 /* No Space left */
 if (s->overrun_nonfatal) {
 av_log(h, AV_LOG_WARNING, "Circular buffer overrun. "
@@ -514,7 +514,7 @@ static void *circular_buffer_task_rx( void *_URLContext)
 goto end;
 }
 }
-av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
+av_fifo_write(s->fifo, s->tmp, len + 4);
 pthread_cond_signal(>cond);
 }
 
@@ -548,22 +548,22 @@ static void *circular_buffer_task_tx( void *_URLContext)
 uint8_t tmp[4];
 int64_t timestamp;
 
-len = av_fifo_size(s->fifo);
+len = av_fifo_can_read(s->fifo);
 
 while (len<4) {
 if (s->close_req)
 goto end;
 pthread_cond_wait(>cond, >mutex);
-len = av_fifo_size(s->fifo);
+len = av_fifo_can_read(s->fifo);
 }
 
-av_fifo_generic_read(s->fifo, tmp, 4, NULL);
+av_fifo_read(s->fifo, tmp, 4);
 len = AV_RL32(tmp);
 
 av_assert0(len >= 0);
 av_assert0(len <= sizeof(s->tmp));
 
-av_fifo_generic_read(s->fifo, s->tmp, len, NULL);
+av_fifo_read(s->fifo, s->tmp, len);
 
 pthread_mutex_unlock(>mutex);
 
@@ -906,7 +906,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 
 if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && 
s->circular_buffer_size)) {
 /* start the task going */
-s->fifo = av_fifo_alloc(s->circular_buffer_size);
+s->fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0);
 if (!s->fifo) {
 ret = AVERROR(ENOMEM);
 goto fail;
@@ -943,7 +943,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
  fail:
 if (udp_fd >= 0)
 closesocket(udp_fd);
-av_fifo_freep(>fifo);
+av_fifo_freep2(>fifo);
 ff_ip_reset_filters(>filters);
 return ret;
 }
@@ -970,19 +970,19 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
 if (s->fifo) {
 pthread_mutex_lock(>mutex);
 do {
-avail = av_fifo_size(s->fifo);
+avail = av_fifo_can_read(s->fifo);
 if (avail) { // >=size) {
 uint8_t tmp[4];
 
-av_fifo_generic_read(s->fifo, tmp, 4, NULL);
+av_fifo_read(s->fifo, tmp, 4);
 avail = AV_RL32(tmp);
 if(avail > size){
 av_log(h, AV_LOG_WARNING, "Part of datagram lost due to 
insufficient buffer size\n");
 avail = size;
 }
 
-av_fifo_generic_read(s->fifo, buf, avail, NULL);
-av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);
+av_fifo_read(s->fifo, buf, avail);
+av_fifo_drain2(s->fifo, AV_RL32(tmp) - avail);
 pthread_mutex_unlock(>mutex);
 return avail;
 } else if(s->circular_buffer_error){
@@ -1043,14 +1043,14 @@ static int udp_write(URLContext *h, const uint8_t *buf, 
int size)
 return err;
 }
 
-if(av_fifo_space(s->fifo) < size + 4) {
+if (av_fifo_can_write(s->fifo) < size + 4) {
 /* What about a partial packet tx ? */
 pthread_mutex_unlock(>mutex);
 return AVERROR(ENOMEM);
 }
 AV_WL32(tmp, size);
-av_fifo_generic_write(s->fifo, tmp, 4, NULL); /* size of packet */
-av_fifo_generic_write(s->fifo, (uint8_t *)buf, size, NULL); /* the 
data */
+av_fifo_write(s->fifo, tmp, 4); /* size of packet */
+av_fifo_write(s->fifo, buf, size); /* the data */
 pthread_cond_signal(>cond);
 pthread_mutex_unlock(>mutex);
 return size;
@@ -1112,7 +1112,7 @@ static int udp_close(URLContext *h)
 }
 #endif
 closesocket(s->udp_fd);
-av_fifo_freep(>fifo);
+av_fifo_freep2(>fifo);
 ff_ip_reset_filters(>filters);
 return 0;
 }
-- 
2.32.0

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

To unsubscribe, visit link above, or email

[FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavformat/swfenc.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 1fd2ad81a3..9eb22ee9b3 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -38,7 +38,7 @@ typedef struct SWFEncContext {
 int swf_frame_number;
 int video_frame_number;
 int tag;
-AVFifoBuffer *audio_fifo;
+AVFifo *audio_fifo;
 AVCodecParameters *audio_par, *video_par;
 AVStream *video_st;
 } SWFEncContext;
@@ -211,7 +211,7 @@ static int swf_write_header(AVFormatContext *s)
 }
 if (par->codec_id == AV_CODEC_ID_MP3) {
 swf->audio_par = par;
-swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE);
+swf->audio_fifo = av_fifo_alloc2(AUDIO_FIFO_SIZE, 1, 0);
 if (!swf->audio_fifo)
 return AVERROR(ENOMEM);
 } else {
@@ -362,6 +362,12 @@ static int swf_write_header(AVFormatContext *s)
 return 0;
 }
 
+static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
+{
+avio_write(opaque, buf, *nb_elems);
+return 0;
+}
+
 static int swf_write_video(AVFormatContext *s,
AVCodecParameters *par, const uint8_t *buf, int 
size, unsigned pkt_flags)
 {
@@ -454,12 +460,12 @@ static int swf_write_video(AVFormatContext *s,
 swf->swf_frame_number++;
 
 /* streaming sound always should be placed just before showframe tags */
-if (swf->audio_par && av_fifo_size(swf->audio_fifo)) {
-int frame_size = av_fifo_size(swf->audio_fifo);
+if (swf->audio_par && av_fifo_can_read(swf->audio_fifo)) {
+size_t frame_size = av_fifo_can_read(swf->audio_fifo);
 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
 avio_wl16(pb, swf->sound_samples);
 avio_wl16(pb, 0); // seek samples
-av_fifo_generic_read(swf->audio_fifo, pb, frame_size, 
(void*)avio_write);
+av_fifo_read_to_cb(swf->audio_fifo, fifo_avio_wrapper, pb, 
_size);
 put_swf_end_tag(s);
 
 /* update FIFO */
@@ -482,12 +488,12 @@ static int swf_write_audio(AVFormatContext *s,
 if (swf->swf_frame_number == 16000)
 av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames 
reached\n");
 
-if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) {
+if (av_fifo_can_write(swf->audio_fifo) < size) {
 av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
 return -1;
 }
 
-av_fifo_generic_write(swf->audio_fifo, buf, size, NULL);
+av_fifo_write(swf->audio_fifo, buf, size);
 swf->sound_samples += av_get_audio_frame_duration2(par, size);
 
 /* if audio only stream make sure we add swf frames */
@@ -535,7 +541,7 @@ static void swf_deinit(AVFormatContext *s)
 {
 SWFEncContext *swf = s->priv_data;
 
-av_fifo_freep(>audio_fifo);
+av_fifo_freep2(>audio_fifo);
 }
 
 #if CONFIG_SWF_MUXER
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 19/31] lavf/mpegenc: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavformat/mpegenc.c | 40 +++-
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index b1d8bf9c38..64248695bd 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -45,7 +45,7 @@ typedef struct PacketDesc {
 } PacketDesc;
 
 typedef struct StreamInfo {
-AVFifoBuffer *fifo;
+AVFifo *fifo;
 uint8_t id;
 int max_buffer_size; /* in bytes */
 int buffer_index;
@@ -459,7 +459,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
av_get_media_type_string(st->codecpar->codec_type), i);
 return AVERROR(EINVAL);
 }
-stream->fifo = av_fifo_alloc(16);
+stream->fifo = av_fifo_alloc2(16, 1, 0);
 if (!stream->fifo)
 return AVERROR(ENOMEM);
 }
@@ -626,6 +626,12 @@ static int get_nb_frames(AVFormatContext *ctx, StreamInfo 
*stream, int len)
 return nb_frames;
 }
 
+static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
+{
+avio_write(opaque, buf, *nb_elems);
+return 0;
+}
+
 /* flush the packet on stream stream_index */
 static int flush_packet(AVFormatContext *ctx, int stream_index,
 int64_t pts, int64_t dts, int64_t scr, int 
trailer_size)
@@ -741,6 +747,7 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 packet_size -= pad_packet_bytes + zero_trail_bytes;
 
 if (packet_size > 0) {
+size_t fifo_data;
 /* packet header size */
 packet_size -= 6;
 
@@ -776,7 +783,7 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 startcode = 0x100 + id;
 }
 
-stuffing_size = payload_size - av_fifo_size(stream->fifo);
+stuffing_size = payload_size - av_fifo_can_read(stream->fifo);
 
 // first byte does not fit -> reset pts/dts + stuffing
 if (payload_size <= trailer_size && pts != AV_NOPTS_VALUE) {
@@ -814,7 +821,7 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 stuffing_size = 0;
 
 if (startcode == PRIVATE_STREAM_1 && id >= 0xa0) {
-if (payload_size < av_fifo_size(stream->fifo))
+if (payload_size < av_fifo_can_read(stream->fifo))
 stuffing_size += payload_size % stream->lpcm_align;
 }
 
@@ -907,11 +914,10 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 }
 
 /* output data */
-av_assert0(payload_size - stuffing_size <= av_fifo_size(stream->fifo));
-av_fifo_generic_read(stream->fifo, ctx->pb,
- payload_size - stuffing_size,
- (void (*)(void*, void*, int))avio_write);
-stream->bytes_to_iframe -= payload_size - stuffing_size;
+fifo_data = payload_size - stuffing_size;
+av_assert0(fifo_data <= av_fifo_can_read(stream->fifo));
+av_fifo_read_to_cb(stream->fifo, fifo_avio_wrapper, ctx->pb, 
_data);
+stream->bytes_to_iframe -= fifo_data;
 } else {
 payload_size  =
 stuffing_size = 0;
@@ -1005,7 +1011,7 @@ retry:
 for (i = 0; i < ctx->nb_streams; i++) {
 AVStream *st = ctx->streams[i];
 StreamInfo *stream = st->priv_data;
-const int avail_data = av_fifo_size(stream->fifo);
+const size_t avail_data = av_fifo_can_read(stream->fifo);
 const int space = stream->max_buffer_size - stream->buffer_index;
 int rel_space = 1024LL * space / stream->max_buffer_size;
 PacketDesc *next_pkt = stream->premux_packet;
@@ -1075,7 +1081,7 @@ retry:
 st = ctx->streams[best_i];
 stream = st->priv_data;
 
-av_assert0(av_fifo_size(stream->fifo) > 0);
+av_assert0(av_fifo_can_read(stream->fifo) > 0);
 
 av_assert0(avail_space >= s->packet_size || ignore_constraints);
 
@@ -1095,7 +1101,7 @@ retry:
 es_size = flush_packet(ctx, best_i, timestamp_packet->pts,
timestamp_packet->dts, scr, trailer_size);
 } else {
-av_assert0(av_fifo_size(stream->fifo) == trailer_size);
+av_assert0(av_fifo_can_read(stream->fifo) == trailer_size);
 es_size = flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 
scr,
trailer_size);
 }
@@ -1199,7 +1205,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, 
AVPacket *pkt)
 pkt_desc->unwritten_size =
 pkt_desc->size   = size;
 
-ret = av_fifo_realloc2(stream->fifo, av_fifo_size(stream->fifo) + size);
+ret = av_fifo_grow2(stream->fifo, size);
 if (ret < 0)
 return ret;
 
@@ -1208,13 +1214,13 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, 
AVPacket *pkt)
 if (is_iframe &&
 (s->packet_number == 0 || pts != AV_NOPTS_VALUE &&
  (pts - stream->vobu_start_pts >= 36000))) {
-stream->bytes_to_iframe = 

[FFmpeg-devel] [PATCH v2 18/31] lavf/dvenc: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavformat/dvenc.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 03b63cff89..e1188109c6 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -49,7 +49,7 @@ struct DVMuxContext {
 const AVDVProfile*  sys;   /* current DV profile, e.g.: 525/60, 
625/50 */
 int   n_ast; /* number of stereo audio streams (up to 
2) */
 AVStream *ast[4];/* stereo audio streams */
-AVFifoBuffer *audio_data[4]; /* FIFO for storing excessive amounts of 
PCM */
+AVFifo   *audio_data[4]; /* FIFO for storing excessive amounts of 
PCM */
 int   frames;/* current frame number */
 int64_t   start_time;/* recording start time */
 int   has_audio; /* frame under construction has audio */
@@ -202,7 +202,7 @@ static void dv_inject_audio(DVMuxContext *c, int channel, 
uint8_t* frame_ptr)
 continue;
 
 // FIXME: maybe we have to admit that DV is a big-endian PCM
-av_fifo_generic_peek_at(c->audio_data[channel], frame_ptr + d, 
of * 2, 2, NULL);
+av_fifo_peek(c->audio_data[channel], frame_ptr + d, 2, of * 2);
 FFSWAP(uint8_t, frame_ptr[d], frame_ptr[d + 1]);
 }
 frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
@@ -272,16 +272,16 @@ static int dv_assemble_frame(AVFormatContext *s,
 for (i = 0; i < c->n_ast && st != c->ast[i]; i++);
 
   /* FIXME: we have to have more sensible approach than this one */
-if (av_fifo_size(c->audio_data[i]) + data_size >= 
100*MAX_AUDIO_FRAME_SIZE) {
+if (av_fifo_can_write(c->audio_data[i]) < data_size) {
 av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient 
video data or severe sync problem.\n", c->frames);
 return AVERROR(EINVAL);
 }
-av_fifo_generic_write(c->audio_data[i], data, data_size, NULL);
+av_fifo_write(c->audio_data[i], data, data_size);
 
 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, 
st->codecpar->sample_rate);
 
 /* Let us see if we've got enough audio for one DV frame. */
-c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << i);
+c->has_audio |= ((reqasize <= av_fifo_can_read(c->audio_data[i])) << 
i);
 
 break;
 default:
@@ -295,8 +295,8 @@ static int dv_assemble_frame(AVFormatContext *s,
 for (i=0; i < c->n_ast; i++) {
 dv_inject_audio(c, i, *frame);
 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, 
c->ast[i]->codecpar->sample_rate);
-av_fifo_drain(c->audio_data[i], reqasize);
-c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << 
i);
+av_fifo_drain2(c->audio_data[i], reqasize);
+c->has_audio |= ((reqasize <= av_fifo_can_read(c->audio_data[i])) 
<< i);
 }
 
 c->has_video = 0;
@@ -374,9 +374,11 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
 ff_parse_creation_time_metadata(s, >start_time, 1);
 
 for (i=0; i < c->n_ast; i++) {
-if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc_array(100, 
MAX_AUDIO_FRAME_SIZE))) {
+if (!c->ast[i])
+   continue;
+c->audio_data[i] = av_fifo_alloc2(100 * MAX_AUDIO_FRAME_SIZE, 1, 0);
+if (!c->audio_data[i])
 goto bail_out;
-}
 }
 
 return c;
@@ -438,7 +440,7 @@ static void dv_deinit(AVFormatContext *s)
 DVMuxContext *c = s->priv_data;
 
 for (int i = 0; i < c->n_ast; i++)
-av_fifo_freep(>audio_data[i]);
+av_fifo_freep2(>audio_data[i]);
 }
 
 const AVOutputFormat ff_dv_muxer = {
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 17/31] lavf/dvenc: return an error on audio/video desync

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavformat/dvenc.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index b76539b59f..03b63cff89 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -255,8 +255,10 @@ static int dv_assemble_frame(AVFormatContext *s,
 switch (st->codecpar->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
 /* FIXME: we have to have more sensible approach than this one */
-if (c->has_video)
+if (c->has_video) {
 av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient 
audio data or severe sync problem.\n", c->frames);
+return AVERROR(EINVAL);
+}
 if (data_size != c->sys->frame_size) {
 av_log(s, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n",
data_size, c->sys->frame_size);
@@ -270,8 +272,10 @@ static int dv_assemble_frame(AVFormatContext *s,
 for (i = 0; i < c->n_ast && st != c->ast[i]; i++);
 
   /* FIXME: we have to have more sensible approach than this one */
-if (av_fifo_size(c->audio_data[i]) + data_size >= 
100*MAX_AUDIO_FRAME_SIZE)
+if (av_fifo_size(c->audio_data[i]) + data_size >= 
100*MAX_AUDIO_FRAME_SIZE) {
 av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient 
video data or severe sync problem.\n", c->frames);
+return AVERROR(EINVAL);
+}
 av_fifo_generic_write(c->audio_data[i], data, data_size, NULL);
 
 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, 
st->codecpar->sample_rate);
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 16/31] avcodec/qsvenc: Reindent after the previous commit

2022-01-24 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/qsvenc.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index a12f7bce42..a1093ae768 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1832,17 +1832,17 @@ int ff_qsv_enc_close(AVCodecContext *avctx, 
QSVEncContext *q)
 QSVPacket pkt;
 while (av_fifo_read(q->async_fifo, , 1) >= 0) {
 #if QSV_VERSION_ATLEAST(1, 26)
-if (avctx->codec_id == AV_CODEC_ID_H264) {
-mfxExtBuffer **enc_buf = pkt.bs->ExtParam;
-mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo 
*)(*enc_buf);
-av_freep(_info);
-av_freep(_buf);
-}
+if (avctx->codec_id == AV_CODEC_ID_H264) {
+mfxExtBuffer **enc_buf = pkt.bs->ExtParam;
+mfxExtAVCEncodedFrameInfo *enc_info = 
(mfxExtAVCEncodedFrameInfo *)(*enc_buf);
+av_freep(_info);
+av_freep(_buf);
+}
 #endif
-av_freep();
-av_freep();
-av_packet_unref();
-}
+av_freep();
+av_freep();
+av_packet_unref();
+}
 av_fifo_freep2(>async_fifo);
 }
 
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 15/31] lavc/qsvenc: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/qsvenc.c | 126 +++-
 libavcodec/qsvenc.h |   2 +-
 2 files changed, 55 insertions(+), 73 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index acb82f321c..a12f7bce42 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -88,6 +88,12 @@ static const struct profile_names vp9_profiles[] = {
 #endif
 };
 
+typedef struct QSVPacket {
+AVPacketpkt;
+mfxSyncPoint   *sync;
+mfxBitstream   *bs;
+} QSVPacket;
+
 static const char *print_profile(enum AVCodecID codec_id, mfxU16 profile)
 {
 const struct profile_names *profiles;
@@ -1315,16 +1321,6 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
-static inline unsigned int qsv_fifo_item_size(void)
-{
-return sizeof(AVPacket) + sizeof(mfxSyncPoint*) + sizeof(mfxBitstream*);
-}
-
-static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
-{
-return av_fifo_size(fifo)/qsv_fifo_item_size();
-}
-
 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
 {
 int iopattern = 0;
@@ -1333,7 +1329,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext 
*q)
 
 q->param.AsyncDepth = q->async_depth;
 
-q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
+q->async_fifo = av_fifo_alloc2(q->async_depth, sizeof(QSVPacket), 0);
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 
@@ -1636,15 +1632,13 @@ static void print_interlace_msg(AVCodecContext *avctx, 
QSVEncContext *q)
 static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
 const AVFrame *frame)
 {
-AVPacket new_pkt = { 0 };
-mfxBitstream *bs = NULL;
+QSVPacket pkt = { { 0 } };
 #if QSV_VERSION_ATLEAST(1, 26)
 mfxExtAVCEncodedFrameInfo *enc_info = NULL;
 mfxExtBuffer **enc_buf = NULL;
 #endif
 
 mfxFrameSurface1 *surf = NULL;
-mfxSyncPoint *sync = NULL;
 QSVFrame *qsv_frame = NULL;
 mfxEncodeCtrl* enc_ctrl = NULL;
 int ret;
@@ -1667,17 +1661,17 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 }
 }
 
-ret = av_new_packet(_pkt, q->packet_size);
+ret = av_new_packet(, q->packet_size);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");
 return ret;
 }
 
-bs = av_mallocz(sizeof(*bs));
-if (!bs)
+pkt.bs = av_mallocz(sizeof(*pkt.bs));
+if (!pkt.bs)
 goto nomem;
-bs->Data  = new_pkt.data;
-bs->MaxLength = new_pkt.size;
+pkt.bs->Data  = pkt.pkt.data;
+pkt.bs->MaxLength = pkt.pkt.size;
 
 #if QSV_VERSION_ATLEAST(1, 26)
 if (avctx->codec_id == AV_CODEC_ID_H264) {
@@ -1687,13 +1681,13 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 
 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
 enc_info->Header.BufferSz = sizeof (*enc_info);
-bs->NumExtParam = 1;
+pkt.bs->NumExtParam = 1;
 enc_buf = av_mallocz(sizeof(mfxExtBuffer *));
 if (!enc_buf)
 goto nomem;
 enc_buf[0] = (mfxExtBuffer *)enc_info;
 
-bs->ExtParam = enc_buf;
+pkt.bs->ExtParam = enc_buf;
 }
 #endif
 
@@ -1701,12 +1695,12 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 q->set_encode_ctrl_cb(avctx, frame, _frame->enc_ctrl);
 }
 
-sync = av_mallocz(sizeof(*sync));
-if (!sync)
+pkt.sync = av_mallocz(sizeof(*pkt.sync));
+if (!pkt.sync)
 goto nomem;
 
 do {
-ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, bs, 
sync);
+ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, 
pkt.bs, pkt.sync);
 if (ret == MFX_WRN_DEVICE_BUSY)
 av_usleep(500);
 } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION);
@@ -1725,15 +1719,13 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 
 ret = 0;
 
-if (*sync) {
-av_fifo_generic_write(q->async_fifo, _pkt, sizeof(new_pkt), NULL);
-av_fifo_generic_write(q->async_fifo, ,sizeof(sync),NULL);
-av_fifo_generic_write(q->async_fifo, ,  sizeof(bs),NULL);
+if (*pkt.sync) {
+av_fifo_write(q->async_fifo, , 1);
 } else {
 free:
-av_freep();
-av_packet_unref(_pkt);
-av_freep();
+av_freep();
+av_packet_unref();
+av_freep();
 #if QSV_VERSION_ATLEAST(1, 26)
 if (avctx->codec_id == AV_CODEC_ID_H264) {
 av_freep(_info);
@@ -1757,60 +1749,56 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext 
*q,
 if (ret < 0)
 return ret;
 
-if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
-(!frame && av_fifo_size(q->async_fifo))) {
-AVPacket new_pkt;
-mfxBitstream *bs;
-mfxSyncPoint *sync;
+if ((av_fifo_can_read(q->async_fifo) >= q->async_depth) ||
+  

[FFmpeg-devel] [PATCH v2 14/31] lavc/qsvdec: switch to the new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/qsvdec.c | 88 ++---
 1 file changed, 35 insertions(+), 53 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d9e0fef1f1..56cd5c86c9 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -56,6 +56,11 @@ static const AVRational mfx_tb = { 1, 9 };
 AV_NOPTS_VALUE : pts_tb.num ? \
 av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
 
+typedef struct QSVAsyncFrame {
+mfxSyncPoint *sync;
+QSVFrame *frame;
+} QSVAsyncFrame;
+
 typedef struct QSVContext {
 // the session used for decoding
 mfxSession session;
@@ -71,7 +76,7 @@ typedef struct QSVContext {
  */
 QSVFrame *work_frames;
 
-AVFifoBuffer *async_fifo;
+AVFifo *async_fifo;
 int zero_consume_run;
 int buffered_count;
 int reinit_flag;
@@ -208,16 +213,6 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 return 0;
 }
 
-static inline unsigned int qsv_fifo_item_size(void)
-{
-return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
-}
-
-static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
-{
-return av_fifo_size(fifo) / qsv_fifo_item_size();
-}
-
 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum 
AVPixelFormat pix_fmt, mfxVideoParam *param)
 {
 mfxSession session = NULL;
@@ -235,7 +230,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 }
 
 if (!q->async_fifo) {
-q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
+q->async_fifo = av_fifo_alloc2(q->async_depth, sizeof(QSVAsyncFrame), 
0);
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 }
@@ -502,7 +497,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
   AVFrame *frame, int *got_frame,
   const AVPacket *avpkt)
 {
-QSVFrame *out_frame;
 mfxFrameSurface1 *insurf;
 mfxFrameSurface1 *outsurf;
 mfxSyncPoint *sync;
@@ -561,6 +555,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 }
 
 if (*sync) {
+QSVAsyncFrame aframe;
 QSVFrame *out_frame = find_frame(q, outsurf);
 
 if (!out_frame) {
@@ -571,35 +566,36 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 }
 
 out_frame->queued += 1;
-av_fifo_generic_write(q->async_fifo, _frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_write(q->async_fifo, ,  sizeof(sync),  
NULL);
+
+aframe = (QSVAsyncFrame){ sync, out_frame };
+av_fifo_write(q->async_fifo, , 1);
 } else {
 av_freep();
 }
 
-if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
-(!avpkt->size && av_fifo_size(q->async_fifo))) {
+if ((av_fifo_can_read(q->async_fifo) >= q->async_depth) ||
+(!avpkt->size && av_fifo_can_read(q->async_fifo))) {
+QSVAsyncFrame aframe;
 AVFrame *src_frame;
 
-av_fifo_generic_read(q->async_fifo, _frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_read(q->async_fifo, ,  sizeof(sync),  
NULL);
-out_frame->queued -= 1;
+av_fifo_read(q->async_fifo, , 1);
+aframe.frame->queued -= 1;
 
 if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
 do {
-ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
+ret = MFXVideoCORE_SyncOperation(q->session, *aframe.sync, 
1000);
 } while (ret == MFX_WRN_IN_EXECUTION);
 }
 
-av_freep();
+av_freep();
 
-src_frame = out_frame->frame;
+src_frame = aframe.frame->frame;
 
 ret = av_frame_ref(frame, src_frame);
 if (ret < 0)
 return ret;
 
-outsurf = _frame->surface;
+outsurf = >surface;
 
 frame->pts = MFX_PTS_TO_PTS(outsurf->Data.TimeStamp, 
avctx->pkt_timebase);
 
@@ -611,10 +607,10 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
 frame->interlaced_frame =
 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
-frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
+frame->pict_type = 
ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
 //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs 
are key frames.
 if (avctx->codec_id == AV_CODEC_ID_H264)
-frame->key_frame = !!(out_frame->dec_info.FrameType & 
MFX_FRAMETYPE_IDR);
+frame->key_frame = !!(aframe.frame->dec_info.FrameType & 
MFX_FRAMETYPE_IDR);
 
 /* update the surface properties */
 if (avctx->pix_fmt == AV_PIX_FMT_QSV)
@@ -633,14 +629,11 @@ static void qsv_decode_close_qsvcontext(QSVContext *q)
 if (q->session)
 MFXVideoDECODE_Close(q->session);
 
-while (q->async_fifo && av_fifo_size(q->async_fifo)) {
- 

[FFmpeg-devel] [PATCH v2 13/31] lavc/nvenc: switch to the new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/nvenc.c | 49 ++
 libavcodec/nvenc.h |  8 
 2 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 850c46022b..effd6381da 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1568,7 +1568,7 @@ static av_cold int nvenc_alloc_surface(AVCodecContext 
*avctx, int idx)
 
 ctx->surfaces[idx].output_surface = allocOut.bitstreamBuffer;
 
-av_fifo_generic_write(ctx->unused_surface_queue, _surface, 
sizeof(tmp_surface), NULL);
+av_fifo_write(ctx->unused_surface_queue, _surface, 1);
 
 return 0;
 }
@@ -1582,18 +1582,18 @@ static av_cold int nvenc_setup_surfaces(AVCodecContext 
*avctx)
 if (!ctx->surfaces)
 return AVERROR(ENOMEM);
 
-ctx->timestamp_list = av_fifo_alloc(ctx->nb_surfaces * sizeof(int64_t));
+ctx->timestamp_list = av_fifo_alloc2(ctx->nb_surfaces, sizeof(int64_t), 0);
 if (!ctx->timestamp_list)
 return AVERROR(ENOMEM);
 
-ctx->unused_surface_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(NvencSurface*));
+ctx->unused_surface_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(NvencSurface*), 0);
 if (!ctx->unused_surface_queue)
 return AVERROR(ENOMEM);
 
-ctx->output_surface_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(NvencSurface*));
+ctx->output_surface_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(NvencSurface*), 0);
 if (!ctx->output_surface_queue)
 return AVERROR(ENOMEM);
-ctx->output_surface_ready_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(NvencSurface*));
+ctx->output_surface_ready_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(NvencSurface*), 0);
 if (!ctx->output_surface_ready_queue)
 return AVERROR(ENOMEM);
 
@@ -1666,10 +1666,10 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
 p_nvenc->nvEncEncodePicture(ctx->nvencoder, );
 }
 
-av_fifo_freep(>timestamp_list);
-av_fifo_freep(>output_surface_ready_queue);
-av_fifo_freep(>output_surface_queue);
-av_fifo_freep(>unused_surface_queue);
+av_fifo_freep2(>timestamp_list);
+av_fifo_freep2(>output_surface_ready_queue);
+av_fifo_freep2(>output_surface_queue);
+av_fifo_freep2(>unused_surface_queue);
 
 if (ctx->surfaces && (avctx->pix_fmt == AV_PIX_FMT_CUDA || avctx->pix_fmt 
== AV_PIX_FMT_D3D11)) {
 for (i = 0; i < ctx->nb_registered_frames; i++) {
@@ -1777,11 +1777,10 @@ static NvencSurface *get_free_frame(NvencContext *ctx)
 {
 NvencSurface *tmp_surf;
 
-if (!(av_fifo_size(ctx->unused_surface_queue) > 0))
+if (av_fifo_read(ctx->unused_surface_queue, _surf, 1) < 0)
 // queue empty
 return NULL;
 
-av_fifo_generic_read(ctx->unused_surface_queue, _surf, 
sizeof(tmp_surf), NULL);
 return tmp_surf;
 }
 
@@ -1998,16 +1997,16 @@ static void 
nvenc_codec_specific_pic_params(AVCodecContext *avctx,
 }
 }
 
-static inline void timestamp_queue_enqueue(AVFifoBuffer* queue, int64_t 
timestamp)
+static inline void timestamp_queue_enqueue(AVFifo *queue, int64_t timestamp)
 {
-av_fifo_generic_write(queue, , sizeof(timestamp), NULL);
+av_fifo_write(queue, , 1);
 }
 
-static inline int64_t timestamp_queue_dequeue(AVFifoBuffer* queue)
+static inline int64_t timestamp_queue_dequeue(AVFifo *queue)
 {
 int64_t timestamp = AV_NOPTS_VALUE;
-if (av_fifo_size(queue) > 0)
-av_fifo_generic_read(queue, , sizeof(timestamp), NULL);
+// The following call might fail if the queue is empty.
+av_fifo_read(queue, , 1);
 
 return timestamp;
 }
@@ -2152,8 +2151,8 @@ static int output_ready(AVCodecContext *avctx, int flush)
 NvencContext *ctx = avctx->priv_data;
 int nb_ready, nb_pending;
 
-nb_ready   = av_fifo_size(ctx->output_surface_ready_queue)   / 
sizeof(NvencSurface*);
-nb_pending = av_fifo_size(ctx->output_surface_queue) / 
sizeof(NvencSurface*);
+nb_ready   = av_fifo_can_read(ctx->output_surface_ready_queue);
+nb_pending = av_fifo_can_read(ctx->output_surface_queue);
 if (flush)
 return nb_ready > 0;
 return (nb_ready > 0) && (nb_ready + nb_pending >= ctx->async_depth);
@@ -2442,16 +2441,14 @@ static int nvenc_send_frame(AVCodecContext *avctx, 
const AVFrame *frame)
 return nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
 
 if (frame && frame->buf[0]) {
-av_fifo_generic_write(ctx->output_surface_queue, _surf, 
sizeof(in_surf), NULL);
+av_fifo_write(ctx->output_surface_queue, _surf, 1);
 timestamp_queue_enqueue(ctx->timestamp_list, frame->pts);
 }
 
 /* all the pending buffers are now ready for output */
 if (nv_status == NV_ENC_SUCCESS) {
-while (av_fifo_size(ctx->output_surface_queue) > 0) {
-av_fifo_generic_read(ctx->output_surface_queue, _out_surf, 
sizeof(tmp_out_surf), NULL);
-

[FFmpeg-devel] [PATCH v2 12/31] lavc/libvpxenc: remove unneeded context variable

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

discard_hdr10_plus is 0 IFF hdr10_plus_fifo is non-NULL, so we can test
for the latter and avoid an extra variable.
---
 libavcodec/libvpxenc.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index ab5d31e4c4..8f94ba15dc 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -127,7 +127,6 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
-int discard_hdr10_plus;
 AVFifo *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
@@ -896,7 +895,6 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 AVDictionaryEntry* en = NULL;
 
-ctx->discard_hdr10_plus = 1;
 av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
 av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
 
@@ -916,7 +914,6 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 // Keep HDR10+ if it has bit depth higher than 8 and
 // it has PQ trc (SMPTE2084).
 if (enccfg.g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) 
{
-ctx->discard_hdr10_plus = 0;
 ctx->hdr10_plus_fifo = av_fifo_alloc2(1, sizeof(FrameHDR10Plus),
   AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->hdr10_plus_fifo)
@@ -1286,7 +1283,7 @@ static int storeframe(AVCodecContext *avctx, struct 
FrameListData *cx_frame,
 }
 if (cx_frame->frame_number != -1) {
 VPxContext *ctx = avctx->priv_data;
-if (!ctx->discard_hdr10_plus) {
+if (ctx->hdr10_plus_fifo) {
 int err = copy_hdr10_plus_to_pkt(ctx->hdr10_plus_fifo, pkt);
 if (err < 0)
 return err;
@@ -1701,7 +1698,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 }
 }
 
-if (!ctx->discard_hdr10_plus) {
+if (ctx->hdr10_plus_fifo) {
 AVFrameSideData *hdr10_plus_metadata;
 // Add HDR10+ metadata to queue.
 hdr10_plus_metadata = av_frame_get_side_data(frame, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 11/31] lavc/libvpxenc: switch to the new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/libvpxenc.c | 35 ++-
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 10e5a22fa9..ab5d31e4c4 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -128,7 +128,7 @@ typedef struct VPxEncoderContext {
 int corpus_complexity;
 int tpl_model;
 int discard_hdr10_plus;
-AVFifoBuffer *hdr10_plus_fifo;
+AVFifo *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -324,39 +324,23 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
-static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
-{
-int err = av_fifo_grow(fifo, sizeof(*data));
-if (err < 0)
-return err;
-av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
-return 0;
-}
-
-static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+static av_cold void free_hdr10_plus_fifo(AVFifo **fifo)
 {
 FrameHDR10Plus frame_hdr10_plus;
-while (av_fifo_size(*fifo) >= sizeof(frame_hdr10_plus)) {
-av_fifo_generic_read(*fifo, _hdr10_plus, 
sizeof(frame_hdr10_plus), NULL);
+while (av_fifo_read(*fifo, _hdr10_plus, 1) >= 0)
 av_buffer_unref(_hdr10_plus.hdr10_plus);
-}
-av_fifo_freep(fifo);
+av_fifo_freep2(fifo);
 }
 
-static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+static int copy_hdr10_plus_to_pkt(AVFifo *fifo, AVPacket *pkt)
 {
 FrameHDR10Plus frame_hdr10_plus;
 uint8_t *data;
-if (!pkt)
-return 0;
-if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+if (!pkt || av_fifo_peek(fifo, _hdr10_plus, 1, 0) < 0)
 return 0;
-av_fifo_generic_peek(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
 if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
 return 0;
-av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
-if (!frame_hdr10_plus.hdr10_plus)
-return 0;
+av_fifo_drain2(fifo, 1);
 
 data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
 if (!data) {
@@ -933,7 +917,8 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 // it has PQ trc (SMPTE2084).
 if (enccfg.g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) 
{
 ctx->discard_hdr10_plus = 0;
-ctx->hdr10_plus_fifo = av_fifo_alloc(sizeof(FrameHDR10Plus));
+ctx->hdr10_plus_fifo = av_fifo_alloc2(1, sizeof(FrameHDR10Plus),
+  AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->hdr10_plus_fifo)
 return AVERROR(ENOMEM);
 }
@@ -1727,7 +1712,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 data.hdr10_plus = av_buffer_ref(hdr10_plus_metadata->buf);
 if (!data.hdr10_plus)
 return AVERROR(ENOMEM);
-err = add_hdr10_plus(ctx->hdr10_plus_fifo, );
+err = av_fifo_write(ctx->hdr10_plus_fifo, , 1);
 if (err < 0) {
 av_buffer_unref(_plus);
 return err;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 10/31] lavc/libvorbisenc: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/libvorbisenc.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index fa0d5f4b42..b657f0157a 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -46,7 +46,7 @@ typedef struct LibvorbisEncContext {
 vorbis_info vi; /**< vorbis_info used during init   */
 vorbis_dsp_state vd;/**< DSP state used for analysis*/
 vorbis_block vb;/**< vorbis_block used for analysis */
-AVFifoBuffer *pkt_fifo; /**< output packet buffer   */
+AVFifo *pkt_fifo;   /**< output packet buffer   */
 int eof;/**< end-of-file flag   */
 int dsp_initialized;/**< vd has been initialized*/
 vorbis_comment vc;  /**< VorbisComment info */
@@ -196,7 +196,7 @@ static av_cold int libvorbis_encode_close(AVCodecContext 
*avctx)
 vorbis_dsp_clear(>vd);
 vorbis_info_clear(>vi);
 
-av_fifo_freep(>pkt_fifo);
+av_fifo_freep2(>pkt_fifo);
 ff_af_queue_close(>afq);
 
 av_vorbis_parse_free(>vp);
@@ -271,7 +271,7 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
 avctx->frame_size = LIBVORBIS_FRAME_SIZE;
 ff_af_queue_init(avctx, >afq);
 
-s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE);
+s->pkt_fifo = av_fifo_alloc2(BUFFER_SIZE, 1, 0);
 if (!s->pkt_fifo) {
 ret = AVERROR(ENOMEM);
 goto error;
@@ -327,12 +327,12 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 
 /* add any available packets to the output packet buffer */
 while ((ret = vorbis_bitrate_flushpacket(>vd, )) == 1) {
-if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) {
+if (av_fifo_can_write(s->pkt_fifo) < sizeof(ogg_packet) + 
op.bytes) {
 av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n");
 return AVERROR_BUG;
 }
-av_fifo_generic_write(s->pkt_fifo, , sizeof(ogg_packet), NULL);
-av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL);
+av_fifo_write(s->pkt_fifo, , sizeof(ogg_packet));
+av_fifo_write(s->pkt_fifo, op.packet, op.bytes);
 }
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
@@ -344,15 +344,13 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 return vorbis_error_to_averror(ret);
 }
 
-/* check for available packets */
-if (av_fifo_size(s->pkt_fifo) < sizeof(ogg_packet))
+/* Read an available packet if possible */
+if (av_fifo_read(s->pkt_fifo, , sizeof(ogg_packet)) < 0)
 return 0;
 
-av_fifo_generic_read(s->pkt_fifo, , sizeof(ogg_packet), NULL);
-
 if ((ret = ff_get_encode_buffer(avctx, avpkt, op.bytes, 0)) < 0)
 return ret;
-av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL);
+av_fifo_read(s->pkt_fifo, avpkt->data, op.bytes);
 
 avpkt->pts = ff_samples_to_time_base(avctx, op.granulepos);
 
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 09/31] lavc/cuviddec: convert to the new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/cuviddec.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index b1a3d674ab..1b525cd804 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -78,7 +78,7 @@ typedef struct CuvidContext
 AVBufferRef *hwdevice;
 AVBufferRef *hwframe;
 
-AVFifoBuffer *frame_queue;
+AVFifo  *frame_queue;
 
 int deint_mode;
 int deint_mode_current;
@@ -363,13 +363,13 @@ static int CUDAAPI cuvid_handle_picture_display(void 
*opaque, CUVIDPARSERDISPINF
 parsed_frame.dispinfo.progressive_frame = ctx->progressive_sequence;
 
 if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) {
-av_fifo_generic_write(ctx->frame_queue, _frame, 
sizeof(CuvidParsedFrame), NULL);
+av_fifo_write(ctx->frame_queue, _frame, 1);
 } else {
 parsed_frame.is_deinterlacing = 1;
-av_fifo_generic_write(ctx->frame_queue, _frame, 
sizeof(CuvidParsedFrame), NULL);
+av_fifo_write(ctx->frame_queue, _frame, 1);
 if (!ctx->drop_second_field) {
 parsed_frame.second_field = 1;
-av_fifo_generic_write(ctx->frame_queue, _frame, 
sizeof(CuvidParsedFrame), NULL);
+av_fifo_write(ctx->frame_queue, _frame, 1);
 }
 }
 
@@ -384,7 +384,7 @@ static int cuvid_is_buffer_full(AVCodecContext *avctx)
 if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave && 
!ctx->drop_second_field)
 delay *= 2;
 
-return (av_fifo_size(ctx->frame_queue) / sizeof(CuvidParsedFrame)) + delay 
>= ctx->nb_surfaces;
+return av_fifo_can_read(ctx->frame_queue) + delay >= ctx->nb_surfaces;
 }
 
 static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
@@ -458,6 +458,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
 AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
 CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
+CuvidParsedFrame parsed_frame;
 CUdeviceptr mapped_frame = 0;
 int ret = 0, eret = 0;
 
@@ -487,16 +488,13 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ret < 0)
 return ret;
 
-if (av_fifo_size(ctx->frame_queue)) {
+if (av_fifo_read(ctx->frame_queue, _frame, 1) >= 0) {
 const AVPixFmtDescriptor *pixdesc;
-CuvidParsedFrame parsed_frame;
 CUVIDPROCPARAMS params;
 unsigned int pitch = 0;
 int offset = 0;
 int i;
 
-av_fifo_generic_read(ctx->frame_queue, _frame, 
sizeof(CuvidParsedFrame), NULL);
-
 memset(, 0, sizeof(params));
 params.progressive_frame = parsed_frame.dispinfo.progressive_frame;
 params.second_field = parsed_frame.second_field;
@@ -657,7 +655,7 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
 CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
 
-av_fifo_freep(>frame_queue);
+av_fifo_freep2(>frame_queue);
 
 ctx->cudl->cuCtxPushCurrent(cuda_ctx);
 
@@ -834,7 +832,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
 goto error;
 }
 
-ctx->frame_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(CuvidParsedFrame));
+ctx->frame_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(CuvidParsedFrame), 0);
 if (!ctx->frame_queue) {
 ret = AVERROR(ENOMEM);
 goto error;
@@ -1030,7 +1028,7 @@ static void cuvid_flush(AVCodecContext *avctx)
 if (ret < 0)
 goto error;
 
-av_fifo_reset(ctx->frame_queue);
+av_fifo_reset2(ctx->frame_queue);
 
 if (ctx->cudecoder) {
 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 08/31] lavc/cuviddec: do not reallocate the fifo unnecessarily

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/cuviddec.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index f03bbd8c4b..b1a3d674ab 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -1030,13 +1030,7 @@ static void cuvid_flush(AVCodecContext *avctx)
 if (ret < 0)
 goto error;
 
-av_fifo_freep(>frame_queue);
-
-ctx->frame_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(CuvidParsedFrame));
-if (!ctx->frame_queue) {
-av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on 
flush\n");
-return;
-}
+av_fifo_reset(ctx->frame_queue);
 
 if (ctx->cudecoder) {
 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/amfenc.c | 43 ++-
 libavcodec/amfenc.h |  2 +-
 2 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index fb23ed738c..0e5117c5a3 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -117,8 +117,9 @@ static int amf_load_library(AVCodecContext *avctx)
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
-// hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
-ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
+// hardcoded to current HW queue size - will auto-realloc if too small
+ctx->timestamp_list = av_fifo_alloc2(avctx->max_b_frames + 16, 
sizeof(int64_t),
+ AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->timestamp_list) {
 return AVERROR(ENOMEM);
 }
@@ -403,7 +404,7 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 ctx->version = 0;
 ctx->delayed_drain = 0;
 av_frame_free(>delayed_frame);
-av_fifo_freep(>timestamp_list);
+av_fifo_freep2(>timestamp_list);
 
 return 0;
 }
@@ -432,18 +433,6 @@ static int amf_copy_surface(AVCodecContext *avctx, const 
AVFrame *frame,
 return 0;
 }
 
-static inline int timestamp_queue_enqueue(AVCodecContext *avctx, int64_t 
timestamp)
-{
-AmfContext *ctx = avctx->priv_data;
-if (av_fifo_space(ctx->timestamp_list) < sizeof(timestamp)) {
-if (av_fifo_grow(ctx->timestamp_list, sizeof(timestamp)) < 0) {
-return AVERROR(ENOMEM);
-}
-}
-av_fifo_generic_write(ctx->timestamp_list, , sizeof(timestamp), 
NULL);
-return 0;
-}
-
 static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer 
*buffer)
 {
 AmfContext  *ctx = avctx->priv_data;
@@ -479,21 +468,17 @@ static int amf_copy_buffer(AVCodecContext *avctx, 
AVPacket *pkt, AMFBuffer *buff
 pkt->pts = var.int64Value; // original pts
 
 
-AMF_RETURN_IF_FALSE(ctx, av_fifo_size(ctx->timestamp_list) > 0, 
AVERROR_UNKNOWN, "timestamp_list is empty\n");
-
-av_fifo_generic_read(ctx->timestamp_list, , sizeof(timestamp), 
NULL);
+AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, , 1) 
>= 0,
+AVERROR_UNKNOWN, "timestamp_list is empty\n");
 
 // calc dts shift if max_b_frames > 0
 if (avctx->max_b_frames > 0 && ctx->dts_delay == 0) {
 int64_t timestamp_last = AV_NOPTS_VALUE;
-AMF_RETURN_IF_FALSE(ctx, av_fifo_size(ctx->timestamp_list) > 0, 
AVERROR_UNKNOWN,
+size_t can_read = av_fifo_can_read(ctx->timestamp_list);
+
+AMF_RETURN_IF_FALSE(ctx, can_read > 0, AVERROR_UNKNOWN,
 "timestamp_list is empty while max_b_frames = %d\n", 
avctx->max_b_frames);
-av_fifo_generic_peek_at(
-ctx->timestamp_list,
-_last,
-(av_fifo_size(ctx->timestamp_list) / sizeof(timestamp) - 1) * 
sizeof(timestamp_last),
-sizeof(timestamp_last),
-NULL);
+av_fifo_peek(ctx->timestamp_list, _last, 1, can_read - 1);
 if (timestamp < 0 || timestamp_last < AV_NOPTS_VALUE) {
 return AVERROR(ERANGE);
 }
@@ -710,9 +695,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SubmitInput() failed with error %d\n", res);
 
 av_frame_unref(frame);
-if ((ret = timestamp_queue_enqueue(avctx, pts)) < 0) {
+ret = av_fifo_write(ctx->timestamp_list, , 1);
+if (ret < 0)
 return ret;
-}
 }
 }
 
@@ -751,9 +736,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 av_frame_unref(ctx->delayed_frame);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"Repeated SubmitInput() failed with error %d\n", res);
 
-if ((ret = timestamp_queue_enqueue(avctx, pts)) < 0) {
+ret = av_fifo_write(ctx->timestamp_list, , 1);
+if (ret < 0)
 return ret;
-}
 } else {
 av_log(avctx, AV_LOG_WARNING, "Data acquired but delayed 
frame submission got AMF_INPUT_FULL- should not happen\n");
 }
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 358b2ef778..1ab98d2f78 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -72,7 +72,7 @@ typedef struct AmfContext {
 AVFrame*delayed_frame;
 
 // shift dts back by max_b_frames in timing
-AVFifoBuffer   *timestamp_list;
+AVFifo *timestamp_list;
 int64_t dts_delay;
 
 // common encoder option options
-- 
2.32.0

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

[FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavcodec/avcodec.c  | 17 ++---
 libavcodec/decode.c   | 24 +---
 libavcodec/internal.h |  2 +-
 3 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..4df834c708 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 avci->es.in_frame = av_frame_alloc();
 avci->in_pkt = av_packet_alloc();
 avci->last_pkt_props = av_packet_alloc();
-avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props));
+avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
+ AV_FIFO_FLAG_AUTO_GROW);
 if (!avci->buffer_frame || !avci->buffer_pkt  ||
 !avci->es.in_frame  || !avci->in_pkt ||
 !avci->last_pkt_props || !avci->pkt_props) {
@@ -399,13 +400,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 av_packet_unref(avci->buffer_pkt);
 
 av_packet_unref(avci->last_pkt_props);
-while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) {
-av_fifo_generic_read(avci->pkt_props,
- avci->last_pkt_props, 
sizeof(*avci->last_pkt_props),
- NULL);
+while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
 av_packet_unref(avci->last_pkt_props);
-}
-av_fifo_reset(avci->pkt_props);
 
 av_frame_unref(avci->es.in_frame);
 av_packet_unref(avci->in_pkt);
@@ -464,12 +460,11 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 av_frame_free(>buffer_frame);
 av_packet_free(>buffer_pkt);
 if (avci->pkt_props) {
-while (av_fifo_size(avci->pkt_props) >= 
sizeof(*avci->last_pkt_props)) {
+while (av_fifo_can_read(avci->pkt_props)) {
 av_packet_unref(avci->last_pkt_props);
-av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
- sizeof(*avci->last_pkt_props), NULL);
+av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
 }
-av_fifo_freep(>pkt_props);
+av_fifo_freep2(>pkt_props);
 }
 av_packet_free(>last_pkt_props);
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0912f86a14..4023d2dd2e 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -165,26 +165,19 @@ static int extract_packet_props(AVCodecInternal *avci, 
const AVPacket *pkt)
 int ret = 0;
 
 if (IS_EMPTY(avci->last_pkt_props)) {
-if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) {
-av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
- sizeof(*avci->last_pkt_props), NULL);
-} else
+if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)
 return copy_packet_props(avci->last_pkt_props, pkt);
 }
 
-if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) {
-ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt));
-if (ret < 0)
-return ret;
-}
-
 ret = copy_packet_props(, pkt);
 if (ret < 0)
 return ret;
 
-av_fifo_generic_write(avci->pkt_props, , sizeof(tmp), NULL);
+ret = av_fifo_write(avci->pkt_props, , 1);
+if (ret < 0)
+av_packet_unref();
 
-return 0;
+return ret;
 }
 
 static int decode_bsfs_init(AVCodecContext *avctx)
@@ -543,9 +536,10 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 avci->draining_done = 1;
 
 if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
-IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= 
sizeof(*avci->last_pkt_props))
-av_fifo_generic_read(avci->pkt_props,
- avci->last_pkt_props, 
sizeof(*avci->last_pkt_props), NULL);
+IS_EMPTY(avci->last_pkt_props)) {
+// May fail if the FIFO is empty.
+av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
+}
 
 if (!ret) {
 frame->best_effort_timestamp = guess_correct_pts(avctx,
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 72ca1553f6..4e864535f1 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -149,7 +149,7 @@ typedef struct AVCodecInternal {
  * for decoding.
  */
 AVPacket *last_pkt_props;
-AVFifoBuffer *pkt_props;
+AVFifo *pkt_props;
 
 /**
  * temporary buffer used for encoders to store their bitstream
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 05/31] lavu/tests/fifo: switch to the new API

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

---
 libavutil/tests/fifo.c | 47 +++---
 1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c
index a17d913233..579602ccf3 100644
--- a/libavutil/tests/fifo.c
+++ b/libavutil/tests/fifo.c
@@ -23,78 +23,73 @@
 int main(void)
 {
 /* create a FIFO buffer */
-AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
+AVFifo *fifo = av_fifo_alloc2(13, sizeof(int), 0);
 int i, j, n, *p;
 
 /* fill data */
-for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
-av_fifo_generic_write(fifo, , sizeof(int), NULL);
+for (i = 0; av_fifo_can_write(fifo); i++)
+av_fifo_write(fifo, , 1);
 
 /* peek_at at FIFO */
-n = av_fifo_size(fifo) / sizeof(int);
+n = av_fifo_can_read(fifo);
 for (i = 0; i < n; i++) {
-av_fifo_generic_peek_at(fifo, , i * sizeof(int), sizeof(j), NULL);
+av_fifo_peek(fifo, , 1, i);
 printf("%d: %d\n", i, j);
 }
 printf("\n");
 
 /* generic peek at FIFO */
 
-n = av_fifo_size(fifo);
-p = malloc(n);
+n = av_fifo_can_read(fifo);
+p = malloc(n * av_fifo_elem_size(fifo));
 if (p == NULL) {
 fprintf(stderr, "failed to allocate memory.\n");
 exit(1);
 }
 
-(void) av_fifo_generic_peek(fifo, p, n, NULL);
+(void) av_fifo_peek(fifo, p, n, 0);
 
 /* read data at p */
-n /= sizeof(int);
 for(i = 0; i < n; ++i)
 printf("%d: %d\n", i, p[i]);
 
 putchar('\n');
 
 /* read data */
-for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
-av_fifo_generic_read(fifo, , sizeof(int), NULL);
+for (i = 0; av_fifo_can_read(fifo); i++) {
+av_fifo_read(fifo, , 1);
 printf("%d ", j);
 }
 printf("\n");
 
-/* test *ndx overflow */
-av_fifo_reset(fifo);
-fifo->rndx = fifo->wndx = ~(uint32_t)0 - 5;
-
 /* fill data */
-for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
-av_fifo_generic_write(fifo, , sizeof(int), NULL);
+for (i = 0; av_fifo_can_write(fifo); i++)
+av_fifo_write(fifo, , 1);
 
 /* peek_at at FIFO */
-n = av_fifo_size(fifo) / sizeof(int);
+n = av_fifo_can_read(fifo);
 for (i = 0; i < n; i++) {
-av_fifo_generic_peek_at(fifo, , i * sizeof(int), sizeof(j), NULL);
+av_fifo_peek(fifo, , 1, i);
 printf("%d: %d\n", i, j);
 }
 putchar('\n');
 
 /* test fifo_grow */
-(void) av_fifo_grow(fifo, 15 * sizeof(int));
+(void) av_fifo_grow2(fifo, 15);
 
 /* fill data */
-n = av_fifo_size(fifo) / sizeof(int);
-for (i = n; av_fifo_space(fifo) >= sizeof(int); ++i)
-av_fifo_generic_write(fifo, , sizeof(int), NULL);
+n = av_fifo_can_read(fifo);
+for (i = n; av_fifo_can_write(fifo); ++i)
+av_fifo_write(fifo, , 1);
 
 /* peek_at at FIFO */
-n = av_fifo_size(fifo) / sizeof(int);
+n = av_fifo_can_read(fifo);
 for (i = 0; i < n; i++) {
-av_fifo_generic_peek_at(fifo, , i * sizeof(int), sizeof(j), NULL);
+av_fifo_peek(fifo, , 1, i);
 printf("%d: %d\n", i, j);
 }
 
-av_fifo_free(fifo);
+av_fifo_freep2();
 free(p);
 
 return 0;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 04/31] lavu/fifo: add a flag for automatically growing the FIFO as needed

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

This will not increase the FIFO beyond 1MB, unless the caller explicitly
specifies otherwise.
---
 doc/APIchanges   |  2 +-
 libavutil/fifo.c | 39 +--
 libavutil/fifo.h | 15 ++-
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 57a9df9bef..75e0b1f49a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -21,7 +21,7 @@ API changes, most recent first:
   av_fifo_can_write(), av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(),
   av_fifo_write_from_cb(), av_fifo_read(), av_fifo_read_to_cb(),
   av_fifo_peek(), av_fifo_peek_to_cb(), av_fifo_drain2(), av_fifo_reset2(),
-  av_fifo_freep2().
+  av_fifo_freep2(), av_fifo_auto_grow_limit().
 
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 0e0d84258f..5a09dd3877 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -26,6 +26,9 @@
 #include "common.h"
 #include "fifo.h"
 
+// by default the FIFO can be auto-grown to 1MB
+#define AUTO_GROW_DEFAULT_BYTES (1024 * 1024)
+
 struct AVFifo {
 uint8_t *buffer;
 
@@ -33,6 +36,9 @@ struct AVFifo {
 size_t offset_r, offset_w;
 // distinguishes the ambiguous situation offset_r == offset_w
 intis_empty;
+
+unsigned int flags;
+size_t   auto_grow_limit;
 };
 
 AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
@@ -57,9 +63,17 @@ AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
 f->elem_size = elem_size;
 f->is_empty  = 1;
 
+f->flags   = flags;
+f->auto_grow_limit = FFMAX(AUTO_GROW_DEFAULT_BYTES / elem_size, 1);
+
 return f;
 }
 
+void av_fifo_auto_grow_limit(AVFifo *f, size_t max_elems)
+{
+f->auto_grow_limit = max_elems;
+}
+
 size_t av_fifo_elem_size(const AVFifo *f)
 {
 return f->elem_size;
@@ -107,6 +121,26 @@ int av_fifo_grow2(AVFifo *f, size_t inc)
 return 0;
 }
 
+static int fifo_check_space(AVFifo *f, size_t to_write)
+{
+const size_t can_write = av_fifo_can_write(f);
+const size_t need_grow = to_write > can_write ? to_write - can_write : 0;
+size_t can_grow;
+
+if (!need_grow)
+return 0;
+
+can_grow = f->auto_grow_limit > f->nb_elems ?
+   f->auto_grow_limit - f->nb_elems : 0;
+if ((f->flags & AV_FIFO_FLAG_AUTO_GROW) && need_grow <= can_grow) {
+// allocate a bit more than necessary, if we can
+const size_t inc = (need_grow < can_grow / 2 ) ? need_grow * 2 : 
can_grow;
+return av_fifo_grow2(f, inc);
+}
+
+return AVERROR(ENOSPC);
+}
+
 static int fifo_write_common(AVFifo *f, const uint8_t *buf, size_t *nb_elems,
  AVFifoCB read_cb, void *opaque)
 {
@@ -114,8 +148,9 @@ static int fifo_write_common(AVFifo *f, const uint8_t *buf, 
size_t *nb_elems,
 size_t offset_w = f->offset_w;
 int ret = 0;
 
-if (to_write > av_fifo_can_write(f))
-return AVERROR(ENOSPC);
+ret = fifo_check_space(f, to_write);
+if (ret < 0)
+return ret;
 
 while (to_write > 0) {
 size_tlen = FFMIN(f->nb_elems - offset_w, to_write);
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index f455022e3c..55548fbeb4 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -48,13 +48,20 @@ typedef struct AVFifo AVFifo;
  */
 typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems);
 
+/**
+ * Automatically resize the FIFO on writes, so that the data fits. This
+ * automatic resizing happens up to a limit that can be modified with
+ * av_fifo_auto_grow_limit().
+ */
+#define AV_FIFO_FLAG_AUTO_GROW  (1 << 0)
+
 /**
  * Allocate and initialize an AVFifo with a given element size.
  *
  * @param elems initial number of elements that can be stored in the FIFO
  * @param elem_size Size in bytes of a single element. Further operations on
  *  the returned FIFO will implicitly use this element size.
- * @param flags currently unused, must be 0
+ * @param flags a combination of AV_FIFO_FLAG_*
  *
  * @return newly-allocated AVFifo on success, a negative error code on failure
  */
@@ -67,6 +74,12 @@ AVFifo *av_fifo_alloc2(size_t elems, size_t elem_size,
  */
 size_t av_fifo_elem_size(const AVFifo *f);
 
+/**
+ * Set the maximum size (in elements) to which the FIFO can be resized
+ * automatically. Has no effect unless AV_FIFO_FLAG_AUTO_GROW is used.
+ */
+void av_fifo_auto_grow_limit(AVFifo *f, size_t max_elems);
+
 /**
  * @return number of elements available for reading from the given FIFO.
  */
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

Many AVFifoBuffer users operate on fixed-size elements (e.g. pointers),
but the current FIFO API deals exclusively in bytes, requiring extra
complexity in all these callers.

Add a new AVFifo API creating a FIFO with an element size
that may be larger than a byte. All operations on such a FIFO then
operate on complete elements.

This API does not reuse AVFifoBuffer and its API at all, but instead uses
an opaque struct called AVFifo. The AVFifoBuffer API will be deprecated
in a future commit once all of its users have been switched to the new
API.

Not reusing AVFifoBuffer also allowed to use the full range of size_t
from the beginning.
---
 doc/APIchanges  |   9 ++
 libavutil/fifo.c| 224 
 libavutil/fifo.h| 179 +++
 libavutil/version.h |   2 +-
 4 files changed, 413 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8df0364e4c..57a9df9bef 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,15 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-01-xx - xx - lavu 57.19.100 - fifo.h
+  Add a new FIFO API, which allows setting a FIFO element size.
+  This API operates on these elements rather than on bytes.
+  Add av_fifo_alloc2(), av_fifo_elem_size(), av_fifo_can_read(),
+  av_fifo_can_write(), av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(),
+  av_fifo_write_from_cb(), av_fifo_read(), av_fifo_read_to_cb(),
+  av_fifo_peek(), av_fifo_peek_to_cb(), av_fifo_drain2(), av_fifo_reset2(),
+  av_fifo_freep2().
+
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
 
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 55621f0dca..0e0d84258f 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -26,6 +26,230 @@
 #include "common.h"
 #include "fifo.h"
 
+struct AVFifo {
+uint8_t *buffer;
+
+size_t elem_size, nb_elems;
+size_t offset_r, offset_w;
+// distinguishes the ambiguous situation offset_r == offset_w
+intis_empty;
+};
+
+AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
+   unsigned int flags)
+{
+AVFifo *f;
+void *buffer;
+
+if (!elem_size)
+return NULL;
+
+buffer = av_realloc_array(NULL, nb_elems, elem_size);
+if (!buffer)
+return NULL;
+f = av_mallocz(sizeof(*f));
+if (!f) {
+av_free(buffer);
+return NULL;
+}
+f->buffer= buffer;
+f->nb_elems  = nb_elems;
+f->elem_size = elem_size;
+f->is_empty  = 1;
+
+return f;
+}
+
+size_t av_fifo_elem_size(const AVFifo *f)
+{
+return f->elem_size;
+}
+
+size_t av_fifo_can_read(const AVFifo *f)
+{
+if (f->offset_w <= f->offset_r && !f->is_empty)
+return f->nb_elems - f->offset_r + f->offset_w;
+return f->offset_w - f->offset_r;
+}
+
+size_t av_fifo_can_write(const AVFifo *f)
+{
+return f->nb_elems - av_fifo_can_read(f);
+}
+
+int av_fifo_grow2(AVFifo *f, size_t inc)
+{
+uint8_t *tmp;
+
+if (inc > SIZE_MAX - f->nb_elems)
+return AVERROR(EINVAL);
+
+tmp = av_realloc_array(f->buffer, f->nb_elems + inc, f->elem_size);
+if (!tmp)
+return AVERROR(ENOMEM);
+f->buffer = tmp;
+
+// move the data from the beginning of the ring buffer
+// to the newly allocated space
+if (f->offset_w <= f->offset_r && !f->is_empty) {
+const size_t copy = FFMIN(inc, f->offset_w);
+memcpy(tmp + f->nb_elems * f->elem_size, tmp, copy * f->elem_size);
+if (copy < f->offset_w) {
+memmove(tmp, tmp + copy * f->elem_size,
+(f->offset_w - copy) * f->elem_size);
+f->offset_w -= copy;
+} else
+f->offset_w = f->nb_elems + copy;
+}
+
+f->nb_elems += inc;
+
+return 0;
+}
+
+static int fifo_write_common(AVFifo *f, const uint8_t *buf, size_t *nb_elems,
+ AVFifoCB read_cb, void *opaque)
+{
+size_t to_write = *nb_elems;
+size_t offset_w = f->offset_w;
+int ret = 0;
+
+if (to_write > av_fifo_can_write(f))
+return AVERROR(ENOSPC);
+
+while (to_write > 0) {
+size_tlen = FFMIN(f->nb_elems - offset_w, to_write);
+uint8_t *wptr = f->buffer + offset_w * f->elem_size;
+
+if (read_cb) {
+ret = read_cb(opaque, wptr, );
+if (ret < 0 || len == 0)
+break;
+} else {
+memcpy(wptr, buf, len * f->elem_size);
+buf += len * f->elem_size;
+}
+offset_w += len;
+if (offset_w >= f->nb_elems)
+offset_w = 0;
+to_write -= len;
+}
+f->offset_w = offset_w;
+
+if (*nb_elems != to_write)
+f->is_empty = 0;
+*nb_elems -= to_write;
+
+return ret;
+}
+
+int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
+{
+return fifo_write_common(f, buf, _elems, NULL, NULL);
+}
+
+int 

[FFmpeg-devel] [PATCH v2 02/31] lavu/fifo: disallow overly large fifo sizes

2022-01-24 Thread Andreas Rheinhardt
From: Anton Khirnov 

The API currently allows creating FIFOs up to
- UINT_MAX: av_fifo_alloc(), av_fifo_realloc(), av_fifo_grow()
- SIZE_MAX: av_fifo_alloc_array()
However the usable limit is determined by
- rndx/wndx being uint32_t
- av_fifo_[size,space] returning int
so no FIFO should be larger than the smallest of
- INT_MAX
- UINT32_MAX
- SIZE_MAX
(which should be INT_MAX an all commonly used platforms).
Return an error on trying to allocate FIFOs larger than this limit.
---
 libavutil/fifo.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index e1f2175530..55621f0dca 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -20,14 +20,23 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "avassert.h"
 #include "common.h"
 #include "fifo.h"
 
+#define OLD_FIFO_SIZE_MAX (size_t)FFMIN3(INT_MAX, UINT32_MAX, SIZE_MAX)
+
 AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
 {
 AVFifoBuffer *f;
-void *buffer = av_realloc_array(NULL, nmemb, size);
+void *buffer;
+
+if (nmemb > OLD_FIFO_SIZE_MAX / size)
+return NULL;
+
+buffer = av_realloc_array(NULL, nmemb, size);
 if (!buffer)
 return NULL;
 f = av_mallocz(sizeof(AVFifoBuffer));
@@ -82,6 +91,9 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
 {
 unsigned int old_size = f->end - f->buffer;
 
+if (new_size > OLD_FIFO_SIZE_MAX)
+return AVERROR(EINVAL);
+
 if (old_size < new_size) {
 size_t offset_r = f->rptr - f->buffer;
 size_t offset_w = f->wptr - f->buffer;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()

2022-01-24 Thread Andreas Rheinhardt
Avoids code duplication. It furthermore properly checks
for buf_size to be > 0 before doing anything.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/fifo.c | 21 +
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index d741bdd395..e1f2175530 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -194,26 +194,7 @@ int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, 
int offset, int buf_siz
 int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size,
  void (*func)(void *, void *, int))
 {
-uint8_t *rptr = f->rptr;
-
-if (buf_size > av_fifo_size(f))
-return AVERROR(EINVAL);
-
-do {
-int len = FFMIN(f->end - rptr, buf_size);
-if (func)
-func(dest, rptr, len);
-else {
-memcpy(dest, rptr, len);
-dest = (uint8_t *)dest + len;
-}
-rptr += len;
-if (rptr >= f->end)
-rptr -= f->end - f->buffer;
-buf_size -= len;
-} while (buf_size > 0);
-
-return 0;
+return av_fifo_generic_peek_at(f, dest, 0, buf_size, func);
 }
 
 int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size,
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH v2 00/31] New FIFO API

2022-01-24 Thread Andreas Rheinhardt
This is a modified version of Anton's earlier patchset [1].
The main changes are that the new FIFO API is a clean break with
the old API (the new API uses a new structure (called AVFifo)
instead of sharing AVFifoBuffer with the old API) and that it
is now documented that one may attempt to read/write more
from/to the FIFO than is currently possible and that such
an attempt leads to an error being returned. This allows to
replace loops of the form

while (av_fifo_size(fifo)) {
TYPE element;
av_fifo_generic_read(fifo, , sizeof(element), NULL);
// do something with element, typically: free it
}

by

TYPE element;
while (av_fifo_read(fifo, , 1) >= 0)
// do something with element

- Andreas

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2022-January/291156.html

Andreas Rheinhardt (2):
  avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()
  avcodec/qsvenc: Reindent after the previous commit

Anton Khirnov (29):
  lavu/fifo: disallow overly large fifo sizes
  lavu/fifo: Add new AVFifo API based upon the notion of element size
  lavu/fifo: add a flag for automatically growing the FIFO as needed
  lavu/tests/fifo: switch to the new API
  lavc/avcodec: switch to new FIFO API
  lavc/amfenc: switch to new FIFO API
  lavc/cuviddec: do not reallocate the fifo unnecessarily
  lavc/cuviddec: convert to the new FIFO API
  lavc/libvorbisenc: switch to new FIFO API
  lavc/libvpxenc: switch to the new FIFO API
  lavc/libvpxenc: remove unneeded context variable
  lavc/nvenc: switch to the new FIFO API
  lavc/qsvdec: switch to the new FIFO API
  lavc/qsvenc: switch to new FIFO API
  lavf/dvenc: return an error on audio/video desync
  lavf/dvenc: switch to new FIFO API
  lavf/mpegenc: switch to new FIFO API
  lavf/swfenc: switch to new FIFO API
  lavf/udp: switch to new FIFO API
  lavf/async: switch to new FIFO API
  lavd/jack: switch to the new FIFO API
  lavu/audio_fifo: drop an unnecessary include
  lavu/audio_fifo: switch to new FIFO API
  lavu/threadmessage: switch to new FIFO API
  lavfi/qsvvpp: switch to new FIFO API
  lavfi/vf_deshake_opencl: switch to new FIFO API
  ffplay: switch to new FIFO API
  ffmpeg: switch to new FIFO API
  avutil/fifo: Deprecate old FIFO API

 doc/APIchanges  |  17 ++
 fftools/ffmpeg.c|  69 +++-
 fftools/ffmpeg.h|   6 +-
 fftools/ffmpeg_filter.c |  14 +-
 fftools/ffmpeg_opt.c|   4 +-
 fftools/ffplay.c|  22 +--
 libavcodec/amfenc.c |  43 ++---
 libavcodec/amfenc.h |   2 +-
 libavcodec/avcodec.c|  17 +-
 libavcodec/cuviddec.c   |  28 ++-
 libavcodec/decode.c |  24 +--
 libavcodec/internal.h   |   2 +-
 libavcodec/libvorbisenc.c   |  20 +--
 libavcodec/libvpxenc.c  |  42 ++---
 libavcodec/nvenc.c  |  49 +++---
 libavcodec/nvenc.h  |   8 +-
 libavcodec/qsvdec.c |  88 --
 libavcodec/qsvenc.c | 134 +++---
 libavcodec/qsvenc.h |   2 +-
 libavdevice/jack.c  |  30 ++--
 libavfilter/qsvvpp.c|  46 ++---
 libavfilter/qsvvpp.h|   2 +-
 libavfilter/vf_deshake_opencl.c |  92 --
 libavformat/async.c |  68 
 libavformat/dvenc.c |  28 +--
 libavformat/mpegenc.c   |  40 +++--
 libavformat/swfenc.c|  22 ++-
 libavformat/udp.c   |  34 ++--
 libavutil/audio_fifo.c  |  44 ++---
 libavutil/audio_fifo.h  |   1 -
 libavutil/fifo.c| 298 +---
 libavutil/fifo.h| 237 -
 libavutil/tests/fifo.c  |  47 +++--
 libavutil/threadmessage.c   |  38 ++--
 libavutil/version.h |   3 +-
 35 files changed, 986 insertions(+), 635 deletions(-)

-- 
2.32.0

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

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


Re: [FFmpeg-devel] [GASPP PATCH] Filter out -D parameters from the call to GCC/Clang to assemble

2022-01-24 Thread Martin Storsjö

On Tue, 18 Jan 2022, Martin Storsjö wrote:


Clang warns about unused -D parameters when operating on .s
files (or if invoked with "-x assembler") while GCC doesn't.
---
As noobdy else than me essentially maintains gas-preprocessor, I'll
go ahead and push this after a couple days if nobody speaks up.


Pushed now.

// Martin

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

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


Re: [FFmpeg-devel] [PATCH] Fix setsockopt IP_MULTICAST_TTL on OpenBSD

2022-01-24 Thread Michael Niedermayer
On Sun, Jan 23, 2022 at 02:55:38PM -0500, Brad Smith wrote:
> On 1/23/2022 6:57 AM, Michael Niedermayer wrote:
> 
> > On Wed, Jan 12, 2022 at 12:13:13AM -0500, Brad Smith wrote:
> > > Fix setsockopt() usage on OpenBSD with IP_MULTICAST_TTL. The field
> > > type should be an unsigned char on anything but Linux.
> > > 
> > > 
> > > diff --git a/libavformat/udp.c b/libavformat/udp.c
> > > index 180d96a988..29aa865fff 100644
> > > --- a/libavformat/udp.c
> > > +++ b/libavformat/udp.c
> > > @@ -163,7 +163,13 @@ static int udp_set_multicast_ttl(int sockfd, int 
> > > mcastTTL,
> > >   {
> > >   #ifdef IP_MULTICAST_TTL
> > >   if (addr->sa_family == AF_INET) {
> > > -if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, , 
> > > sizeof(mcastTTL)) < 0) {
> > > +#ifdef __linux__
> > > +int ttl = mcastTTL;
> > > +#else
> > > +unsigned char ttl = mcastTTL;
> > > +#endif
> > this "ifdef __linux__" feels like the wrong thing to check, dont you agree ?
> 
> Not sure what you mean.

"__linux__" seems the wrong property to check for
this is not
#ifdef __linux__
osname = "linux"
#else

i would have expected more something like
#if HAVE_INT_TTL
int ttl = mcastTTL;
#else

or maybe even something along the lines of

WHATEVER_TTL_TYPE ttl = mcastTTL;

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope


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

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


Re: [FFmpeg-devel] [PATCH v4] tests: add test for ffmpeg's fix_sub_duration feature

2022-01-24 Thread Jan Ekström
On Mon, Jan 24, 2022 at 12:43 PM Jan Ekström  wrote:
>
> On Mon, Jan 10, 2022 at 3:28 PM Jan Ekström  wrote:
> >
> > From: Jan Ekström 
> >
> > This long-existing feature calculates subtitle durations by keeping
> > it around until the following subtitle is decoded, and then utilizes
> > the following subtitle's pts as the end point of the previous one.
> >
>
> As there have been no comments for about two weeks, I will be
> rebasing/checking that FATE still passes and applying this, as this
> will heighten the test coverage for existing ffmpeg.c features.
>

Applied as 0a83ecbf48bdd591b264c3cbb70393bb518b1ecc .

Jan
___
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] avfilter: Added siti filter

2022-01-24 Thread Thilo Borgmann

Am 18.01.22 um 14:58 schrieb Thilo Borgmann:

Am 15.01.22 um 09:27 schrieb Paul B Mahol:

On Sat, Jan 15, 2022 at 9:25 AM Paul B Mahol  wrote:




On Fri, Jan 14, 2022 at 5:22 PM Thilo Borgmann 
wrote:


Hi,

Am 19.01.21 um 05:49 schrieb Lynne:

Jan 19, 2021, 01:07 by borba...@fb.com:


Calculate Spatial Info (SI) and Temporal Info (TI) scores for a video,

as defined

in ITU-T P.910: Subjective video quality assessment methods for

multimedia

applications.

Update: Fixed bracket style.



Thanks, looks much neater now.




I'm already adding the data to the frame's metadata, is the suggestion

to remove the file option altogether?




Yes. We want to avoid filters having their own file in/out options

rather

than using generic ones.


Updated the patch to apply to git HEAD.
Removed file output.
Made printing summary to console optional.



+
+#include "libavutil/imgutils.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+static const int X_FILTER[9] = {
+1, 0, -1,
+2, 0, -2,
+1, 0, -1
+};
+
+static const int Y_FILTER[9] = {
+1, 2, 1,
+0, 0, 0,
+-1, -2, -1
+};



We have optimized assembly to apply 3x3 matrices. Check out
libavfilter/x86/vf_convolution.asm:ff_filter_3x3_sse4
  vf_convolution already applies a sobel filter that way. Maybe
look into sharing some DSP code with it?


I checked a bit since I also want a common sobel for vf_edgedetect / my
patch for vf_blurriness.

For sobel, there is no direct asm implementation. We have a generic
filter_3x3 with sse4 optimization. To use sobel with that, you'd need to
run two times filter_3x3 plus one pass for gradient calculation.

As another difference, this filter (SITI) does on-the-fly conversion to
full-range pixel values during its sobel. While vf_edgedetect /
vf_bluriness use an abbreviation for the gradients during its sobel. Which
makes them both distinct enough not to fit into a general filter_3x3 or
filter_sobel from vf_convolution easily (and more overhead). So I think
it's not worth the effort to force them into a common function? (Especially
since we don't have a sobel_sse4 or something)

Patch without a common sobel attached.




Violations of code style.


Enhanced.



Also why filter description only shows SI part and TI part is missing?


Mentioned.

v2 attached.


Ping.

-Thilo
___
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 v4] tests: add test for ffmpeg's fix_sub_duration feature

2022-01-24 Thread Jan Ekström
On Mon, Jan 10, 2022 at 3:28 PM Jan Ekström  wrote:
>
> From: Jan Ekström 
>
> This long-existing feature calculates subtitle durations by keeping
> it around until the following subtitle is decoded, and then utilizes
> the following subtitle's pts as the end point of the previous one.
>

As there have been no comments for about two weeks, I will be
rebasing/checking that FATE still passes and applying this, as this
will heighten the test coverage for existing ffmpeg.c features.

Jan
___
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 3/3] lavc/qsvdec: export AVFilmGrainParams side data

2022-01-24 Thread Xiang, Haihao
From: Haihao Xiang 

When AV_CODEC_EXPORT_DATA_FILM_GRAIN is present, AV1 decoder should
disable film grain application and export the corresponding side data

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsv_internal.h |  3 ++
 libavcodec/qsvdec.c   | 91 +++
 2 files changed, 94 insertions(+)

diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 6a38e87d23..58186ea7ca 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -76,6 +76,9 @@ typedef struct QSVFrame {
 mfxFrameSurface1 surface;
 mfxEncodeCtrl enc_ctrl;
 mfxExtDecodedFrameInfo dec_info;
+#if QSV_VERSION_ATLEAST(1, 34)
+mfxExtAV1FilmGrainParam av1_film_grain_param;
+#endif
 mfxExtBuffer *ext_param[QSV_MAX_FRAME_EXT_PARAMS];
 int num_ext_params;
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8b83d5695f..32077ab31a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -38,6 +38,7 @@
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/film_grain_params.h"
 
 #include "avcodec.h"
 #include "internal.h"
@@ -404,6 +405,11 @@ static int qsv_decode_header(AVCodecContext *avctx, 
QSVContext *q,
 param->ExtParam= q->ext_buffers;
 param->NumExtParam = q->nb_ext_buffers;
 
+#if QSV_VERSION_ATLEAST(1, 34)
+if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) && avctx->codec_id == 
AV_CODEC_ID_AV1)
+param->mfx.FilmGrain = (avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_FILM_GRAIN) ? 0 : param->mfx.FilmGrain;
+#endif
+
 return 0;
 }
 
@@ -443,6 +449,14 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext 
*q, QSVFrame *frame)
 frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
 frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
 ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)>dec_info);
+#if QSV_VERSION_ATLEAST(1, 34)
+if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) && avctx->codec_id == 
AV_CODEC_ID_AV1) {
+frame->av1_film_grain_param.Header.BufferId = 
MFX_EXTBUFF_AV1_FILM_GRAIN_PARAM;
+frame->av1_film_grain_param.Header.BufferSz = 
sizeof(frame->av1_film_grain_param);
+frame->av1_film_grain_param.FilmGrainFlags = 0;
+ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer 
*)>av1_film_grain_param);
+}
+#endif
 
 frame->used = 1;
 
@@ -513,6 +527,73 @@ static QSVFrame *find_frame(QSVContext *q, 
mfxFrameSurface1 *surf)
 return NULL;
 }
 
+#if QSV_VERSION_ATLEAST(1, 34)
+static int qsv_export_film_grain(AVCodecContext *avctx, 
mfxExtAV1FilmGrainParam *ext_param, AVFrame *frame)
+{
+AVFilmGrainParams *fgp;
+AVFilmGrainAOMParams *aom;
+int i;
+
+if (!(ext_param->FilmGrainFlags & MFX_FILM_GRAIN_APPLY))
+return 0;
+
+fgp = av_film_grain_params_create_side_data(frame);
+
+if (!fgp)
+return AVERROR(ENOMEM);
+
+fgp->type = AV_FILM_GRAIN_PARAMS_AV1;
+fgp->seed = ext_param->GrainSeed;
+aom = >codec.aom;
+
+aom->chroma_scaling_from_luma = !!(ext_param->FilmGrainFlags & 
MFX_FILM_GRAIN_CHROMA_SCALING_FROM_LUMA);
+aom->scaling_shift = ext_param->GrainScalingMinus8 + 8;
+aom->ar_coeff_lag = ext_param->ArCoeffLag;
+aom->ar_coeff_shift = ext_param->ArCoeffShiftMinus6 + 6;
+aom->grain_scale_shift = ext_param->GrainScaleShift;
+aom->overlap_flag = !!(ext_param->FilmGrainFlags & MFX_FILM_GRAIN_OVERLAP);
+aom->limit_output_range = !!(ext_param->FilmGrainFlags & 
MFX_FILM_GRAIN_CLIP_TO_RESTRICTED_RANGE);
+
+aom->num_y_points = ext_param->NumYPoints;
+
+for (i = 0; i < aom->num_y_points; i++) {
+aom->y_points[i][0] = ext_param->PointY[i].Value;
+aom->y_points[i][1] = ext_param->PointY[i].Scaling;
+}
+
+aom->num_uv_points[0] = ext_param->NumCbPoints;
+
+for (i = 0; i < aom->num_uv_points[0]; i++) {
+aom->uv_points[0][i][0] = ext_param->PointCb[i].Value;
+aom->uv_points[0][i][1] = ext_param->PointCb[i].Scaling;
+}
+
+aom->num_uv_points[1] = ext_param->NumCrPoints;
+
+for (i = 0; i < aom->num_uv_points[1]; i++) {
+aom->uv_points[1][i][0] = ext_param->PointCr[i].Value;
+aom->uv_points[1][i][1] = ext_param->PointCr[i].Scaling;
+}
+
+for (i = 0; i < 24; i++)
+aom->ar_coeffs_y[i] = ext_param->ArCoeffsYPlus128[i] - 128;
+
+for (i = 0; i < 25; i++) {
+aom->ar_coeffs_uv[0][i] = ext_param->ArCoeffsCbPlus128[i] - 128;
+aom->ar_coeffs_uv[1][i] = ext_param->ArCoeffsCrPlus128[i] - 128;
+}
+
+aom->uv_mult[0] = ext_param->CbMult;
+aom->uv_mult[1] = ext_param->CrMult;
+aom->uv_mult_luma[0] = ext_param->CbLumaMult;
+aom->uv_mult_luma[1] = ext_param->CrLumaMult;
+aom->uv_offset[0] = ext_param->CbOffset;
+aom->uv_offset[1] = ext_param->CrOffset;
+
+return 0;
+}
+#endif
+
 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
   AVFrame *frame, int 

[FFmpeg-devel] [PATCH v2 2/3] lavc/qsvdec: track the runtime session version

2022-01-24 Thread Xiang, Haihao
From: Haihao Xiang 

We may check the runtime version for the given features

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvdec.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 783d252002..8b83d5695f 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -59,6 +59,7 @@ static const AVRational mfx_tb = { 1, 9 };
 typedef struct QSVContext {
 // the session used for decoding
 mfxSession session;
+mfxVersion ver;
 
 // the session we allocated internally, in case the caller did not provide
 // one
@@ -202,6 +203,18 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 q->session = q->internal_qs.session;
 }
 
+if (MFXQueryVersion(q->session, >ver) != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
+q->session = NULL;
+
+if (q->internal_qs.session) {
+MFXClose(q->internal_qs.session);
+q->internal_qs.session = NULL;
+}
+
+return AVERROR_EXTERNAL;
+}
+
 /* make sure the decoder is uninitialized */
 MFXVideoDECODE_Close(q->session);
 
-- 
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 v2 1/3] lavc/qsv: allow to add more parameter buffers to QSV frame

2022-01-24 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
v2: rebased the patchset against the latest FFmpeg and added code to
make sure the corresponding extra parameter buffer is added for AV1
only.

 libavcodec/qsv.c  | 27 +++
 libavcodec/qsv_internal.h |  8 +++-
 libavcodec/qsvdec.c   |  8 +---
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 9d08485c92..1a432dbd82 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -828,3 +828,30 @@ int ff_qsv_close_internal_session(QSVSession *qs)
 #endif
 return 0;
 }
+
+void ff_qsv_frame_add_ext_param (AVCodecContext *avctx, QSVFrame *frame,
+ mfxExtBuffer * param)
+{
+int i;
+
+for (i = 0; i < frame->num_ext_params; i++) {
+mfxExtBuffer *ext_buffer = frame->ext_param[i];
+
+if (ext_buffer->BufferId == param->BufferId) {
+av_log(avctx, AV_LOG_WARNING, "A buffer with the same type has 
been "
+   "added\n");
+return;
+}
+}
+
+if (frame->num_ext_params < QSV_MAX_FRAME_EXT_PARAMS) {
+frame->ext_param[frame->num_ext_params] = param;
+frame->num_ext_params++;
+frame->surface.Data.NumExtParam = frame->num_ext_params;
+} else {
+av_log(avctx, AV_LOG_WARNING, "Ignore this extra buffer because do not 
"
+   "have enough space\n");
+}
+
+
+}
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index fe9d5319c4..6a38e87d23 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -52,6 +52,8 @@
 
 #define QSV_MAX_ENC_PAYLOAD 2   // # of mfxEncodeCtrl payloads supported
 
+#define QSV_MAX_FRAME_EXT_PARAMS 4
+
 #define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
 (MFX_VERSION_MAJOR > (MAJOR) || \
  MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
@@ -74,7 +76,8 @@ typedef struct QSVFrame {
 mfxFrameSurface1 surface;
 mfxEncodeCtrl enc_ctrl;
 mfxExtDecodedFrameInfo dec_info;
-mfxExtBuffer *ext_param;
+mfxExtBuffer *ext_param[QSV_MAX_FRAME_EXT_PARAMS];
+int num_ext_params;
 
 mfxPayload *payloads[QSV_MAX_ENC_PAYLOAD]; ///< used for enc_ctrl.Payload
 
@@ -138,4 +141,7 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, 
mfxSession *session,
 
 int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame);
 
+void ff_qsv_frame_add_ext_param(AVCodecContext *avctx, QSVFrame *frame,
+mfxExtBuffer *param);
+
 #endif /* AVCODEC_QSV_INTERNAL_H */
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d9e0fef1f1..783d252002 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -423,11 +423,13 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext 
*q, QSVFrame *frame)
 
 frame->surface.Data.MemId = >frames_ctx.mids[ret];
 }
-frame->surface.Data.ExtParam= >ext_param;
-frame->surface.Data.NumExtParam = 1;
-frame->ext_param= (mfxExtBuffer*)>dec_info;
+
+frame->surface.Data.ExtParam= frame->ext_param;
+frame->surface.Data.NumExtParam = 0;
+frame->num_ext_params   = 0;
 frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
 frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
+ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)>dec_info);
 
 frame->used = 1;
 
-- 
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".