Re: [FFmpeg-devel] [PATCH] avcodec/mathops: Optimize generic mid_pred function

2022-12-04 Thread Junxian Zhu
Compile with generic mid_pred function written in the old way on the mips 
platform, and objdump its .o file, it will show like this, with more 
instructions and branch jump. ```code mid_pred(int, int, 
___
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] lavc/videotoolbox: validate vt context in the decoder callback

2022-12-04 Thread Alessandro Di Nepi
A gentle reminder for this patch: it's a simple fix that prevents crashing on 
iOS.

Thanks
___
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] lavc/videotoolbox: validate vt context in the decoder callback

2022-12-04 Thread Rick Kern
On Tue, Nov 29, 2022 at 11:47 AM Alessandro Di Nepi <
alessandro.din...@gmail.com> wrote:

> Just to add that this fix, once approved, should be cherry-picked to all
> the release branches where d7f4ad88a0df3c1339e142957bf2c40cd056b8ce has
> been cherry-picked.
> Basically, 4.4, 5.0, and 5.1.
>
> Thanks
> On 27 Nov 2022, 19:34 +0200, Alessandro Di Nepi <
> alessandro.din...@gmail.com>, wrote:
> > The commit d7f4ad88a0df3c1339e142957bf2c40cd056b8ce introduced a race
> > condition where the passed opaque pointer reference might be NULL,
> > when the decoding process starts.
> > This patch checks that vtctx has a value before accessing it.
> >
> > This patch fixes #10079.
> >
> > Signed-off-by: Alessandro Di Nepi 
> > ---
> > libavcodec/videotoolbox.c | 5 +
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> > index 1b1be8ddb4..615e2b087a 100644
> > --- a/libavcodec/videotoolbox.c
> > +++ b/libavcodec/videotoolbox.c
> > @@ -692,6 +692,11 @@ static void videotoolbox_decoder_callback(void
> *opaque,
> > {
> > VTContext *vtctx = opaque;
> >
> > + if (!vtctx) {
>

When this happens, does it continue happening, or is it transient? My main
concern is log spamming.


> > + av_log(NULL, AV_LOG_WARNING, "vt decoder cb: vt context is null");
> > + return;
> > + }
> > +
> > if (vtctx->frame) {
> > CVPixelBufferRelease(vtctx->frame);
> > vtctx->frame = NULL;
> > --
> > 2.37.1 (Apple Git-137.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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 4/7] avcodec/mediacodecenc: use bsf to handle crop

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

It's well known that mediacodec encoder requires 16x16 alignment.
Use our bsf to fix the crop info.
---
 configure  |  2 ++
 libavcodec/mediacodecenc.c | 65 +++---
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 0d754e7ae9..3bb0a091d4 100755
--- a/configure
+++ b/configure
@@ -3169,6 +3169,7 @@ h264_mediacodec_decoder_extralibs="-landroid"
 h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser"
 h264_mediacodec_encoder_deps="mediacodec"
 h264_mediacodec_encoder_extralibs="-landroid"
+h264_mediacodec_encoder_select="h264_metadata"
 h264_mf_encoder_deps="mediafoundation"
 h264_mmal_decoder_deps="mmal"
 h264_nvenc_encoder_deps="nvenc"
@@ -3190,6 +3191,7 @@ hevc_mediacodec_decoder_extralibs="-landroid"
 hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
 hevc_mediacodec_encoder_deps="mediacodec"
 hevc_mediacodec_encoder_extralibs="-landroid"
+hevc_mediacodec_encoder_select="hevc_metadata"
 hevc_mf_encoder_deps="mediafoundation"
 hevc_nvenc_encoder_deps="nvenc"
 hevc_nvenc_encoder_select="atsc_a53"
diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index d098880941..dce4a96d1f 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -28,6 +28,7 @@
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
+#include "bsf.h"
 #include "codec_internal.h"
 #include "encode.h"
 #include "hwconfig.h"
@@ -78,6 +79,7 @@ typedef struct MediaCodecEncContext {
 int eof_sent;
 
 AVFrame *frame;
+AVBSFContext *bsf;
 
 int bitrate_mode;
 int level;
@@ -119,6 +121,42 @@ static void mediacodec_output_format(AVCodecContext *avctx)
 ff_AMediaFormat_delete(out_format);
 }
 
+static int mediacodec_init_bsf(AVCodecContext *avctx)
+{
+MediaCodecEncContext *s = avctx->priv_data;
+char str[128];
+int ret;
+int crop_right = s->width - avctx->width;
+int crop_bottom = s->height - avctx->height;
+
+if (!crop_right && !crop_bottom)
+return 0;
+
+if (avctx->codec_id == AV_CODEC_ID_H264)
+ret = snprintf(str, sizeof(str), 
"h264_metadata=crop_right=%d:crop_bottom=%d",
+ crop_right, crop_bottom);
+else if (avctx->codec_id == AV_CODEC_ID_HEVC)
+ret = snprintf(str, sizeof(str), 
"hevc_metadata=crop_right=%d:crop_bottom=%d",
+ crop_right, crop_bottom);
+else
+return 0;
+
+if (ret >= sizeof(str))
+return AVERROR_BUFFER_TOO_SMALL;
+
+ret = av_bsf_list_parse_str(str, &s->bsf);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
+if (ret < 0)
+return ret;
+s->bsf->time_base_in = avctx->time_base;
+ret = av_bsf_init(s->bsf);
+
+return ret;
+}
+
 static av_cold int mediacodec_init(AVCodecContext *avctx)
 {
 const char *codec_mime = NULL;
@@ -159,7 +197,7 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 
 ff_AMediaFormat_setString(format, "mime", codec_mime);
 s->width = FFALIGN(avctx->width, 16);
-s->height = avctx->height;
+s->height = FFALIGN(avctx->height, 16);
 ff_AMediaFormat_setInt32(format, "width", s->width);
 ff_AMediaFormat_setInt32(format, "height", s->height);
 
@@ -252,6 +290,10 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 goto bailout;
 }
 
+ret = mediacodec_init_bsf(avctx);
+if (ret)
+goto bailout;
+
 mediacodec_output_format(avctx);
 
 s->frame = av_frame_alloc();
@@ -444,10 +486,24 @@ static int mediacodec_encode(AVCodecContext *avctx, 
AVPacket *pkt)
 // 2. Got a packet success
 // 3. No AVFrame is available yet (don't return if get_frame return EOF)
 while (1) {
+if (s->bsf) {
+ret = av_bsf_receive_packet(s->bsf, pkt);
+if (!ret)
+return 0;
+if (ret != AVERROR(EAGAIN))
+return ret;
+}
+
 ret = mediacodec_receive(avctx, pkt, &got_packet);
-if (!ret)
-return 0;
-else if (ret != AVERROR(EAGAIN))
+if (s->bsf) {
+if (!ret || ret == AVERROR_EOF)
+ret = av_bsf_send_packet(s->bsf, pkt);
+} else {
+if (!ret)
+return 0;
+}
+
+if (ret != AVERROR(EAGAIN))
 return ret;
 
 if (!s->frame->buf[0]) {
@@ -480,6 +536,7 @@ static av_cold int mediacodec_close(AVCodecContext *avctx)
 s->window = NULL;
 }
 
+av_bsf_free(&s->bsf);
 av_frame_free(&s->frame);
 
 return 0;
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 5/7] avcodec/mediacodecenc: remove the strategy to create DTS

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

Use input PTS as DTS has multiple problems:
1. If there is no reordering, it's better to just use the output
PTS as DTS, since encoder may change the timestamp value (do it
on purpose or rounding error).

2. If there is reordering, input PTS should be shift a few frames
as DTS to satisfy the requirement of PTS >= DTS. I can't find a
reliable way to determine how many frames to be shift. For example,
we don't known if the encoder use hierarchical B frames. The
max_num_reorder_frames can be get from VUI, but VUI is optional.

3. Encoder dropping frames makes the case worse. Android has an
BITRATE_MODE_CBR_FD option to allow it explicitly.
---
 libavcodec/mediacodecenc.c | 28 +---
 1 file changed, 1 insertion(+), 27 deletions(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index dce4a96d1f..4b0397d1ea 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -64,18 +64,6 @@ typedef struct MediaCodecEncContext {
 
 uint8_t *extradata;
 int extradata_size;
-
-// Since MediaCodec doesn't output DTS, use a timestamp queue to save pts
-// of AVFrame and generate DTS for AVPacket.
-//
-// This doesn't work when use Surface as input, in that case frames can be
-// sent to encoder without our notice. One exception is frames come from
-// our MediaCodec decoder wrapper, since we can control it's render by
-// av_mediacodec_release_buffer.
-int64_t timestamps[32];
-int ts_head;
-int ts_tail;
-
 int eof_sent;
 
 AVFrame *frame;
@@ -368,11 +356,6 @@ static int mediacodec_receive(AVCodecContext *avctx,
 }
 memcpy(pkt->data + extradata_size, out_buf + out_info.offset, 
out_info.size);
 pkt->pts = av_rescale_q(out_info.presentationTimeUs, AV_TIME_BASE_Q, 
avctx->time_base);
-if (s->ts_tail != s->ts_head) {
-pkt->dts = s->timestamps[s->ts_tail];
-s->ts_tail = (s->ts_tail + 1) % FF_ARRAY_ELEMS(s->timestamps);
-}
-
 if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
 pkt->flags |= AV_PKT_FLAG_KEY;
 ret = 0;
@@ -437,14 +420,8 @@ static int mediacodec_send(AVCodecContext *avctx,
 return ff_AMediaCodec_signalEndOfInputStream(codec);
 }
 
-
-if (frame->data[3]) {
-pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
-s->timestamps[s->ts_head] = frame->pts;
-s->ts_head = (s->ts_head + 1) % FF_ARRAY_ELEMS(s->timestamps);
-
+if (frame->data[3])
 av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 
1);
-}
 return 0;
 }
 
@@ -463,9 +440,6 @@ static int mediacodec_send(AVCodecContext *avctx,
 copy_frame_to_buffer(avctx, frame, input_buf, input_size);
 
 pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
-
-s->timestamps[s->ts_head] = frame->pts;
-s->ts_head = (s->ts_head + 1) % FF_ARRAY_ELEMS(s->timestamps);
 } else {
 flags |= ff_AMediaCodec_getBufferFlagEndOfStream(codec);
 s->eof_sent = 1;
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 6/7] avcodec/mediacodecenc: add max-bframes support

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/mediacodecenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index 4b0397d1ea..9378563fac 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -264,6 +264,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
 ff_AMediaFormat_setInt32(format, "level", s->level);
 }
+if (avctx->max_b_frames > 0)
+ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
 
 ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec);
 ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 3/7] avcodec/mediacodecenc: add level option

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/mediacodecenc.c | 143 -
 libavcodec/version.h   |   2 +-
 2 files changed, 142 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index c28cce56c6..d098880941 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -80,6 +80,7 @@ typedef struct MediaCodecEncContext {
 AVFrame *frame;
 
 int bitrate_mode;
+int level;
 } MediaCodecEncContext;
 
 enum {
@@ -233,6 +234,10 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
 ff_AMediaFormat_setInt32(format, "profile", ret);
 }
+if (s->level > 0) {
+av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
+ff_AMediaFormat_setInt32(format, "level", s->level);
+}
 
 ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec);
 ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
@@ -540,17 +545,151 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = 
{  \
 };  \
 
 #if CONFIG_H264_MEDIACODEC_ENCODER
+
+enum MediaCodecAvcLevel {
+AVCLevel1   = 0x01,
+AVCLevel1b  = 0x02,
+AVCLevel11  = 0x04,
+AVCLevel12  = 0x08,
+AVCLevel13  = 0x10,
+AVCLevel2   = 0x20,
+AVCLevel21  = 0x40,
+AVCLevel22  = 0x80,
+AVCLevel3   = 0x100,
+AVCLevel31  = 0x200,
+AVCLevel32  = 0x400,
+AVCLevel4   = 0x800,
+AVCLevel41  = 0x1000,
+AVCLevel42  = 0x2000,
+AVCLevel5   = 0x4000,
+AVCLevel51  = 0x8000,
+AVCLevel52  = 0x1,
+AVCLevel6   = 0x2,
+AVCLevel61  = 0x4,
+AVCLevel62  = 0x8,
+};
+
 static const AVOption h264_options[] = {
 COMMON_OPTION
+{ "level", "Specify level",
+OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, 
"level" },
+{ "1",  "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1  },  0, 0, VE, 
"level" },
+{ "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, 
"level" },
+{ "1.1","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, 
"level" },
+{ "1.2","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, 
"level" },
+{ "1.3","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, 
"level" },
+{ "2",  "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2  },  0, 0, VE, 
"level" },
+{ "2.1","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, 
"level" },
+{ "2.2","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, 
"level" },
+{ "3",  "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3  },  0, 0, VE, 
"level" },
+{ "3.1","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, 
"level" },
+{ "3.2","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, 
"level" },
+{ "4",  "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4  },  0, 0, VE, 
"level" },
+{ "4.1","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, 
"level" },
+{ "4.2","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, 
"level" },
+{ "5",  "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5  },  0, 0, VE, 
"level" },
+{ "5.1","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, 
"level" },
+{ "5.2","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, 
"level" },
+{ "6.0","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6  }, 0, 0, VE, 
"level" },
+{ "6.1","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, 
"level" },
+{ "6.2","", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, 
"level" },
 { NULL, }
 };
+
 DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
-#endif
+
+#endif  // CONFIG_H264_MEDIACODEC_ENCODER
 
 #if CONFIG_HEVC_MEDIACODEC_ENCODER
+
+enum MediaCodecHevcLevel {
+HEVCMainTierLevel1  = 0x1,
+HEVCHighTierLevel1  = 0x2,
+HEVCMainTierLevel2  = 0x4,
+HEVCHighTierLevel2  = 0x8,
+HEVCMainTierLevel21 = 0x10,
+HEVCHighTierLevel21 = 0x20,
+HEVCMainTierLevel3  = 0x40,
+HEVCHighTierLevel3  = 0x80,
+HEVCMainTierLevel31 = 0x100,
+HEVCHighTierLevel31 = 0x200,
+HEVCMainTierLevel4  = 0x400,
+HEVCHighTierLevel4  = 0x800,
+HEVCMainTierLevel41 = 0x1000,
+HEVCHighTierLevel41 = 0x2000,
+HEVCMainTierLevel5  = 0x4000,
+HEVCHighTierLevel5  = 0x8000,
+HEVCMainTierLevel51 = 0x1,
+HEVCHighTierLevel51 = 0x2,
+HEVCMainTierLevel52 = 0x4,
+HEVCHighTierLevel52 = 0x8,
+HEVCMainTierLevel6  = 0x10,
+HEVCHighTierLevel6  = 0x20,
+HEVCMainTierLevel61 = 0x40,
+HEVCHighTierLevel61 = 0x80,
+HEVCMainTierLevel62 = 0x100,
+HEVCHighTierLevel62 = 0x200,
+};
+
 static const AVOption hevc_options[] = {
 COMMON_OPTION
+

[FFmpeg-devel] [PATCH 1/7] avcodec/mediacodecenc: add bitrate_mode option

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/mediacodecenc.c | 25 +
 libavcodec/version.h   |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index 69246ad693..c8d8f84e46 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -39,6 +39,17 @@
 #define INPUT_DEQUEUE_TIMEOUT_US 8000
 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
 
+enum BitrateMode {
+/* Constant quality mode */
+BITRATE_MODE_CQ = 0,
+/* Variable bitrate mode */
+BITRATE_MODE_VBR = 1,
+/* Constant bitrate mode */
+BITRATE_MODE_CBR = 2,
+/* Constant bitrate mode with frame drops */
+BITRATE_MODE_CBR_FD = 3,
+};
+
 typedef struct MediaCodecEncContext {
 AVClass *avclass;
 FFAMediaCodec *codec;
@@ -67,6 +78,8 @@ typedef struct MediaCodecEncContext {
 int eof_sent;
 
 AVFrame *frame;
+
+int bitrate_mode;
 } MediaCodecEncContext;
 
 enum {
@@ -193,6 +206,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 
 if (avctx->bit_rate)
 ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
+if (s->bitrate_mode >= 0)
+ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
 // frame-rate and i-frame-interval are required to configure codec
 if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 
0) {
 s->fps = avctx->framerate.num / avctx->framerate.den;
@@ -485,6 +500,16 @@ static const AVOption common_options[] = {
 OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE },
 { "codec_name", "Select codec by name",
 OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
+{ "bitrate_mode", "Bitrate control method",
+OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
INT_MAX, VE, "bitrate_mode" },
+{ "cq", "Constant quality mode",
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, 
"bitrate_mode" },
+{ "vbr", "Variable bitrate mode",
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, 
"bitrate_mode" },
+{ "cbr", "Constant bitrate mode",
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, 
"bitrate_mode" },
+{ "cbr_fd", "Constant bitrate mode with frame drops",
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, 
VE, "bitrate_mode" },
 { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 9e66920593..527b4dbd0b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  54
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 2/7] avcodec/mediacodecenc: make each encoder has its own option

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/mediacodecenc.c | 42 ++
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index c8d8f84e46..c28cce56c6 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -495,29 +495,27 @@ static const AVCodecHWConfigInternal *const 
mediacodec_hw_configs[] = {
 
 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
-static const AVOption common_options[] = {
-{ "ndk_codec", "Use MediaCodec from NDK",
-OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE },
-{ "codec_name", "Select codec by name",
-OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
-{ "bitrate_mode", "Bitrate control method",
-OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
INT_MAX, VE, "bitrate_mode" },
-{ "cq", "Constant quality mode",
-0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, 
"bitrate_mode" },
-{ "vbr", "Variable bitrate mode",
-0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, 
"bitrate_mode" },
-{ "cbr", "Constant bitrate mode",
-0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, 
"bitrate_mode" },
-{ "cbr_fd", "Constant bitrate mode with frame drops",
-0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, 
VE, "bitrate_mode" },
-{ NULL },
-};
+#define COMMON_OPTION  
 \
+{ "ndk_codec", "Use MediaCodec from NDK",  
 \
+OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE },  \
+{ "codec_name", "Select codec by name",
 \
+OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, 
 \
+{ "bitrate_mode", "Bitrate control method",
 \
+OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
INT_MAX, VE, "bitrate_mode" },  \
+{ "cq", "Constant quality mode",   
 \
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, 
"bitrate_mode" }, \
+{ "vbr", "Variable bitrate mode",  
 \
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, 
"bitrate_mode" },\
+{ "cbr", "Constant bitrate mode",  
 \
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, 
"bitrate_mode" },\
+{ "cbr_fd", "Constant bitrate mode with frame drops",  
 \
+0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, 
VE, "bitrate_mode" }, \
 
 #define MEDIACODEC_ENCODER_CLASS(name)  \
 static const AVClass name ## _mediacodec_class = {  \
 .class_name = #name "_mediacodec",  \
 .item_name  = av_default_item_name, \
-.option = common_options,   \
+.option = name ## _options, \
 .version= LIBAVUTIL_VERSION_INT,\
 };  \
 
@@ -542,9 +540,17 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = { 
 \
 };  \
 
 #if CONFIG_H264_MEDIACODEC_ENCODER
+static const AVOption h264_options[] = {
+COMMON_OPTION
+{ NULL, }
+};
 DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
 #endif
 
 #if CONFIG_HEVC_MEDIACODEC_ENCODER
+static const AVOption hevc_options[] = {
+COMMON_OPTION
+{ NULL, }
+};
 DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
 #endif
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 7/7] avcodec/mediacodecenc: add pts_as_dts option

2022-12-04 Thread Zhao Zhili
From: Zhao Zhili 

It works since most of Android devices don't output B frames by
default. The behavior is documented by Android now, although there
is some exception in history, which should have been fixed now.
---
 libavcodec/mediacodecenc.c | 8 
 libavcodec/version.h   | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index 9378563fac..3893ca8dee 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -71,6 +71,7 @@ typedef struct MediaCodecEncContext {
 
 int bitrate_mode;
 int level;
+int pts_as_dts;
 } MediaCodecEncContext;
 
 enum {
@@ -266,6 +267,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 }
 if (avctx->max_b_frames > 0)
 ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
+if (s->pts_as_dts == -1)
+s->pts_as_dts = avctx->max_b_frames <= 0;
 
 ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec);
 ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
@@ -358,6 +361,8 @@ static int mediacodec_receive(AVCodecContext *avctx,
 }
 memcpy(pkt->data + extradata_size, out_buf + out_info.offset, 
out_info.size);
 pkt->pts = av_rescale_q(out_info.presentationTimeUs, AV_TIME_BASE_Q, 
avctx->time_base);
+if (s->pts_as_dts)
+pkt->dts = pkt->pts;
 if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
 pkt->flags |= AV_PKT_FLAG_KEY;
 ret = 0;
@@ -548,6 +553,9 @@ static const AVCodecHWConfigInternal *const 
mediacodec_hw_configs[] = {
 0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, 
"bitrate_mode" },\
 { "cbr_fd", "Constant bitrate mode with frame drops",  
 \
 0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, 
VE, "bitrate_mode" }, \
+{ "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx 
max_b_frames <= 0, "  \
+"since most of Android devices don't output B frames by 
default.", \
+OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, 
VE }, \
 
 #define MEDIACODEC_ENCODER_CLASS(name)  \
 static const AVClass name ## _mediacodec_class = {  \
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 61bdf5806b..dd90cd1335 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  54
-#define LIBAVCODEC_VERSION_MICRO 103
+#define LIBAVCODEC_VERSION_MICRO 104
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.25.1

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

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


Re: [FFmpeg-devel] [PATCH] lavc/videotoolbox: validate vt context in the decoder callback

2022-12-04 Thread Alessandro Di Nepi
On 4 Dec 2022, 17:01 +0200, FFmpeg development discussions and patches 
, wrote:
> When this happens, does it continue happening, or is it transient? My main
> concern is log spamming.
Good question: this is just a transient state, so that it won't continue 
happening.
To give you some context: when the decoding start, the value of `vtctx` is 
captured "too" early so that the first time the callback is called, it's still 
NULL.
The next time it will have a proper value.
___
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] AVX512 NUCs for FATE and development

2022-12-04 Thread Kieran Kunhya
Hello,

As discussed at the developer meeting it would be good to have an AVX-512
(ICL) FATE machine and also a development machine.
What I didn't realise until a few weeks ago is that 11th Generation NUCs
have AVX512ICL support.

I suggest buying:

2x
https://www.scan.co.uk/products/intel-nuc-bnuc11tnki7-rocket-lake-core-i7-1165g7-dual-ddr4-so-dimm-slots-intel-iris-xe-graphics
- £529 each
2x 2x 16GB RAM - 32GB in each (price TBC as I want to buy the right one,
RAM can be confusing)
2x M.2 NVMe SSDs -
https://www.amazon.co.uk/WD_BLACK-Internal-Gaming-Technology-speeds/dp/B08KFN1KT1

£1500 total I would estimate.

I am happy to host these (as with the M1s) but as these are NUCs anyone can
buy and host them easily.

Regards,
Kieran Kunhya
___
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] lavu/pixdesc: handle xv30be in av_[read|write]_image_line

2022-12-04 Thread Philip Langdale
xv30be is an obnoxious format that I shouldn't have included in the
first place. xv30 packs 3 10bit channels into 32bits and while our
byte-oriented logic can handle Little Endian correctly, it cannot
handle Big Endian. To avoid that, I marked xv30be as a bitstream
format, but while that didn't produce FATE errors, it turns out that
the existing read/write code silently produces incorrect results, which
can be revealed via ubsan.

In all likelyhood, the correct fix here is to remove the format. As
this format is only used by Intel vaapi, it's only going to show up
in LE form, so we could just drop the BE version. But I don't want to
deal with creating a hole in the pixfmt list and all the weirdness that
comes from that. Instead, I decided to write the correct read/write
code for it.

And that code isn't too bad, as long as it's specialised for this
format, as the channels are all bit-aligned inside a 32bit word.

Signed-off-by: Philip Langdale 
---
 libavutil/pixdesc.c | 70 -
 1 file changed, 50 insertions(+), 20 deletions(-)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index ca3e204a0b..62a2ae08d9 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -46,19 +46,35 @@ void av_read_image_line2(void *dst,
 uint32_t *dst32 = dst;
 
 if (flags & AV_PIX_FMT_FLAG_BITSTREAM) {
-int skip = x * step + comp.offset;
-const uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3);
-int shift = 8 - depth - (skip & 7);
+if (depth == 10) {
+// Assume all channels are packed into a 32bit value
+const uint8_t *byte_p = data[plane] + y * linesize[plane];
+const uint32_t *p = (uint32_t *)byte_p;
 
-while (w--) {
-int val = (*p >> shift) & mask;
-if (read_pal_component)
-val = data[1][4*val + c];
-shift -= step;
-p -= shift >> 3;
-shift &= 7;
-if (dst_element_size == 4) *dst32++ = val;
-else   *dst16++ = val;
+while (w--) {
+int val = AV_RB32(p);
+val = (val >> comp.offset) & mask;
+if (read_pal_component)
+val = data[1][4*val + c];
+if (dst_element_size == 4) *dst32++ = val;
+else   *dst16++ = val;
+p++;
+}
+} else {
+int skip = x * step + comp.offset;
+const uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3);
+int shift = 8 - depth - (skip & 7);
+
+while (w--) {
+int val = (*p >> shift) & mask;
+if (read_pal_component)
+val = data[1][4*val + c];
+shift -= step;
+p -= shift >> 3;
+shift &= 7;
+if (dst_element_size == 4) *dst32++ = val;
+else   *dst16++ = val;
+}
 }
 } else {
 const uint8_t *p = data[plane] + y * linesize[plane] +
@@ -109,15 +125,29 @@ void av_write_image_line2(const void *src,
 const uint16_t *src16 = src;
 
 if (flags & AV_PIX_FMT_FLAG_BITSTREAM) {
-int skip = x * step + comp.offset;
-uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3);
-int shift = 8 - depth - (skip & 7);
+if (depth == 10) {
+// Assume all channels are packed into a 32bit value
+const uint8_t *byte_p = data[plane] + y * linesize[plane];
+uint32_t *p = (uint32_t *)byte_p;
+int offset = comp.offset;
+uint32_t mask  = ((1ULL << depth) - 1) << offset;
 
-while (w--) {
-*p |= (src_element_size == 4 ? *src32++ : *src16++) << shift;
-shift -= step;
-p -= shift >> 3;
-shift &= 7;
+while (w--) {
+uint16_t val = src_element_size == 4 ? *src32++ : *src16++;
+AV_WB32(p, (AV_RB32(p) & ~mask) | (val << offset));
+p++;
+}
+} else {
+int skip = x * step + comp.offset;
+uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3);
+int shift = 8 - depth - (skip & 7);
+
+while (w--) {
+*p |= (src_element_size == 4 ? *src32++ : *src16++) << shift;
+shift -= step;
+p -= shift >> 3;
+shift &= 7;
+}
 }
 } else {
 int shift = comp.shift;
-- 
2.37.2

___
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 v5 0/4] swscale: rgbaf32 input/output support

2022-12-04 Thread Mark Reid
On Wed, Nov 23, 2022 at 11:35 AM  wrote:

> From: Mark Reid 
>
> This patch series adds swscale input/output support for the packed rgb
> float formats.
> A few of the filters also needed support the larger 96/128 bit packed
> pixel sizes.
>
> I also plan to eventually add lossless unscaled conversions between the
> planer and packed formats.
>
> changes since v4
> * added comment about refactoring input functions
> changes since v3
> * removed half uv path implementation
> changes since v2
> * add bias to rgbaf32 output to improve non overflowing range
> changes since v1
> * output correct alpha if src doesn't have alpha
>
>
> Mark Reid (4):
>   swscale/input: add rgbaf32 input support
>   avfilter/vf_hflip: add support for packed rgb float formats
>   avfilter/vf_transpose: add support for packed rgb float formats
>   swscale/output: add rgbaf32 output support
>
>  libavfilter/vf_hflip_init.h  |  25 +
>  libavfilter/vf_transpose.c   |  44 
>  libswscale/input.c   | 122 +++
>  libswscale/output.c  |  92 +
>  libswscale/swscale_unscaled.c|   4 +-
>  libswscale/tests/floatimg_cmp.c  |   4 +-
>  libswscale/utils.c   |  14 ++-
>  libswscale/yuv2rgb.c |   2 +
>  tests/ref/fate/filter-pixdesc-rgbaf32be  |   1 +
>  tests/ref/fate/filter-pixdesc-rgbaf32le  |   1 +
>  tests/ref/fate/filter-pixdesc-rgbf32be   |   1 +
>  tests/ref/fate/filter-pixdesc-rgbf32le   |   1 +
>  tests/ref/fate/filter-pixfmts-copy   |   4 +
>  tests/ref/fate/filter-pixfmts-crop   |   4 +
>  tests/ref/fate/filter-pixfmts-field  |   4 +
>  tests/ref/fate/filter-pixfmts-fieldorder |   4 +
>  tests/ref/fate/filter-pixfmts-hflip  |   4 +
>  tests/ref/fate/filter-pixfmts-il |   4 +
>  tests/ref/fate/filter-pixfmts-null   |   4 +
>  tests/ref/fate/filter-pixfmts-scale  |   4 +
>  tests/ref/fate/filter-pixfmts-transpose  |   4 +
>  tests/ref/fate/filter-pixfmts-vflip  |   4 +
>  tests/ref/fate/sws-floatimg-cmp  |  16 +++
>  23 files changed, 363 insertions(+), 4 deletions(-)
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32be
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32le
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32be
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32le
>
> --
> 2.31.1.windows.1
>
>
ping
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 1/5] avcodec/binkaudio: clear pts when returning more than one frame per input packet

2022-12-04 Thread James Almer
This will be needed for the following commit, after which ff_get_buffer() will
stop setting frame->pts to AV_NOPTS_VALUE.

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

diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index 046bf93207..f28ecba760 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -296,9 +296,10 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 {
 BinkAudioContext *s = avctx->priv_data;
 GetBitContext *gb = &s->gb;
-int ret;
+int new_pkt, ret;
 
 again:
+new_pkt = !s->pkt->data;
 if (!s->pkt->data) {
 ret = ff_decode_get_packet(avctx, s->pkt);
 if (ret < 0) {
@@ -325,6 +326,8 @@ again:
 frame->nb_samples = s->frame_len;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
+if (!new_pkt)
+frame->pts = AV_NOPTS_VALUE;
 }
 
 if (decode_block(s, (float **)frame->extended_data,
-- 
2.38.1

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

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


[FFmpeg-devel] [PATCH 2/5] Revert "avcodec/decode: use a packet list to store packet properties"

2022-12-04 Thread James Almer
The idea behind last_pkt_props was to store the properties of the last packet
fed to the decoder. Any sort of queueing required by decoders that consume
several packets before they start outputting frames should be done by the
decoders in question. An example of this is in the libdav1d wrapper.

This is required to maintain its contents during flush, and for the following
commits that will fix last_pkt_props in frame threading scenarios.

This revers commit 022a12b306ab2096e6ac9fc9b149828a849d65b2.

Signed-off-by: James Almer 
---
 libavcodec/avcodec.c| 10 -
 libavcodec/decode.c | 47 ++---
 libavcodec/internal.h   |  1 -
 tests/ref/fate/flcl1905 |  2 +-
 4 files changed, 8 insertions(+), 52 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a85d3c2309..efa76d2740 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -386,9 +386,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 av_frame_unref(avci->recon_frame);
 } else {
 av_packet_unref(avci->last_pkt_props);
-while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
-av_packet_unref(avci->last_pkt_props);
-
 av_packet_unref(avci->in_pkt);
 
 avctx->pts_correction_last_pts =
@@ -453,13 +450,6 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 av_freep(&avci->byte_buffer);
 av_frame_free(&avci->buffer_frame);
 av_packet_free(&avci->buffer_pkt);
-if (avci->pkt_props) {
-while (av_fifo_can_read(avci->pkt_props)) {
-av_packet_unref(avci->last_pkt_props);
-av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
-}
-av_fifo_freep2(&avci->pkt_props);
-}
 av_packet_free(&avci->last_pkt_props);
 
 av_packet_free(&avci->in_pkt);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..c94d9aa33c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -132,38 +132,16 @@ fail2:
 return 0;
 }
 
-#define IS_EMPTY(pkt) (!(pkt)->data)
-
-static int copy_packet_props(AVPacket *dst, const AVPacket *src)
-{
-int ret = av_packet_copy_props(dst, src);
-if (ret < 0)
-return ret;
-
-dst->size = src->size; // HACK: Needed for ff_decode_frame_props().
-dst->data = (void*)1;  // HACK: Needed for IS_EMPTY().
-
-return 0;
-}
-
 static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
 {
-AVPacket tmp = { 0 };
 int ret = 0;
 
-if (IS_EMPTY(avci->last_pkt_props)) {
-if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)
-return copy_packet_props(avci->last_pkt_props, pkt);
+av_packet_unref(avci->last_pkt_props);
+if (pkt) {
+ret = av_packet_copy_props(avci->last_pkt_props, pkt);
+if (!ret)
+avci->last_pkt_props->size = pkt->size; // HACK: Needed for 
ff_decode_frame_props().
 }
-
-ret = copy_packet_props(&tmp, pkt);
-if (ret < 0)
-return ret;
-
-ret = av_fifo_write(avci->pkt_props, &tmp, 1);
-if (ret < 0)
-av_packet_unref(&tmp);
-
 return ret;
 }
 
@@ -483,7 +461,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 if (ret >= pkt->size || ret < 0) {
 av_packet_unref(pkt);
-av_packet_unref(avci->last_pkt_props);
 } else {
 int consumed = ret;
 
@@ -578,8 +555,6 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 
 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
 ret = codec->cb.receive_frame(avctx, frame);
-if (ret != AVERROR(EAGAIN))
-av_packet_unref(avci->last_pkt_props);
 } else
 ret = decode_simple_receive_frame(avctx, frame);
 
@@ -593,12 +568,6 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 return ok;
 }
 
-if (!(codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
-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,
  frame->pts,
@@ -1293,7 +1262,7 @@ static int add_metadata_from_side_data(const AVPacket 
*avpkt, AVFrame *frame)
 
 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
 {
-AVPacket *pkt = avctx->internal->last_pkt_props;
+const AVPacket *pkt = avctx->internal->last_pkt_props;
 static const struct {
 enum AVPacketSideDataType packet;
 enum AVFrameSideDataType frame;
@@ -1651,9 +1620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 avci->in_pkt = av_packet_alloc();
 avci->last_pkt_props = av_packet_alloc();
-avci->pkt_props  = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
-  AV_FIFO_FLAG_AUTO_GROW);
- 

[FFmpeg-devel] [PATCH 3/5] avcodec/decode: don't set last_pkt_props->size

2022-12-04 Thread James Almer
Use the opaque field instead to store this value.

No functional change, but removes the hack that made the packet technically
invalid, allowing the safe usage of functions like av_packet_ref() on it
if required.

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

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index c94d9aa33c..b184c3f55b 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -140,7 +140,7 @@ static int extract_packet_props(AVCodecInternal *avci, 
const AVPacket *pkt)
 if (pkt) {
 ret = av_packet_copy_props(avci->last_pkt_props, pkt);
 if (!ret)
-avci->last_pkt_props->size = pkt->size; // HACK: Needed for 
ff_decode_frame_props().
+avci->last_pkt_props->opaque = (void *)(intptr_t)pkt->size; // 
Needed for ff_decode_frame_props().
 }
 return ret;
 }
@@ -469,7 +469,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 pkt->pts  = AV_NOPTS_VALUE;
 pkt->dts  = AV_NOPTS_VALUE;
 if (!(codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
-avci->last_pkt_props->size -= consumed; // See 
extract_packet_props() comment.
+// See extract_packet_props() comment.
+avci->last_pkt_props->opaque = (void 
*)((intptr_t)avci->last_pkt_props->opaque - consumed);
 avci->last_pkt_props->pts = AV_NOPTS_VALUE;
 avci->last_pkt_props->dts = AV_NOPTS_VALUE;
 }
@@ -1284,7 +1285,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 frame->pts = pkt->pts;
 frame->pkt_pos  = pkt->pos;
 frame->duration = pkt->duration;
-frame->pkt_size = pkt->size;
+frame->pkt_size = (int)(intptr_t)pkt->opaque;
 
 for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
 size_t size;
-- 
2.38.1

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

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


[FFmpeg-devel] [PATCH 4/5] avcodec/pthread_frame.c: keep the last_pkt_props from worker threads in sync with the user context

2022-12-04 Thread James Almer
Making it point to the input packet results in different behavior during flush,
where its contents will be that of an empty packet instead of containing the
props from the last input packet fed to the decoder.
After this change, decoding with more than one thread will shield the same
results as using a single thread.

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

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index df82a4125f..3397e0cc66 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -371,6 +371,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
  */
 static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
 {
+int err;
+
 dst->flags  = src->flags;
 
 dst->draw_horiz_band= src->draw_horiz_band;
@@ -406,6 +408,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
src->slice_count * sizeof(*dst->slice_offset));
 }
 dst->slice_count = src->slice_count;
+
+av_packet_unref(dst->internal->last_pkt_props);
+err = av_packet_copy_props(dst->internal->last_pkt_props, 
src->internal->last_pkt_props);
+if (err < 0)
+return err;
+
 return 0;
 }
 
@@ -775,6 +783,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int 
thread_count)
 av_freep(&ctx->slice_offset);
 
 av_buffer_unref(&ctx->internal->pool);
+av_packet_free(&ctx->internal->last_pkt_props);
 av_freep(&ctx->internal);
 av_buffer_unref(&ctx->hw_frames_ctx);
 }
@@ -846,9 +855,9 @@ static av_cold int init_thread(PerThreadContext *p, int 
*threads_to_free,
 return err;
 
 if (!(p->frame = av_frame_alloc()) ||
-!(p->avpkt = av_packet_alloc()))
+!(p->avpkt = av_packet_alloc()) ||
+!(copy->internal->last_pkt_props = av_packet_alloc()))
 return AVERROR(ENOMEM);
-copy->internal->last_pkt_props = p->avpkt;
 
 if (!first)
 copy->internal->is_copy = 1;
-- 
2.38.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 5/5] avcodec/mpeg4videodec: duplicate the last decoded frame when the last coded frame was skipped

2022-12-04 Thread James Almer
This ensures the video stream duration is not lost after decoding.

Signed-off-by: James Almer 
---
 libavcodec/h263dec.c   | 13 +
 libavcodec/mpegvideo.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index ac7a8521e5..0a2d7487a8 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -430,6 +430,18 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame 
*pict,
 return ret;
 s->next_picture_ptr = NULL;
 
+*got_frame = 1;
+} else if (s->skipped_last_frame && s->current_picture_ptr) {
+/* Output the last picture we decoded again if the stream ended 
with
+ * an NVOP */
+if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
+return ret;
+/* Copy props from the last input packet. Otherwise, props from 
the last
+ * returned picture would be reused */
+if ((ret = ff_decode_frame_props(avctx, pict)) < 0)
+return ret;
+s->current_picture_ptr = NULL;
+
 *got_frame = 1;
 }
 
@@ -500,6 +512,7 @@ retry:
 s->extradata_parsed = 1;
 }
 ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0, 0);
+s->skipped_last_frame = (ret == FRAME_SKIPPED);
 } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
 ret = ff_intel_h263_decode_picture_header(s);
 } else if (CONFIG_FLV_DECODER && s->h263_flv) {
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 6440b906b1..42275953b9 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -175,6 +175,7 @@ typedef struct MpegEncContext {
 Picture *last_picture_ptr; ///< pointer to the previous picture.
 Picture *next_picture_ptr; ///< pointer to the next picture (for bidir 
pred)
 Picture *current_picture_ptr;  ///< pointer to the current picture
+int skipped_last_frame;
 int last_dc[3];///< last DC values for MPEG-1
 int16_t *dc_val_base;
 int16_t *dc_val[3];///< used for MPEG-4 DC prediction, all 3 
arrays must be continuous
-- 
2.38.1

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

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


[FFmpeg-devel] [PATCH 1/2] avformat/mov: do not emit zero sized packets

2022-12-04 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/mov.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 29bd3103e3..935b2f8d9f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8772,6 +8772,10 @@ static int mov_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 goto retry;
 }
 
+/* Empty packet or corrupt index? */
+if (!sample->size)
+goto retry;
+
 if (st->codecpar->codec_id == AV_CODEC_ID_EIA_608 && sample->size > 8)
 ret = get_eia608_packet(sc->pb, pkt, sample->size);
 else
-- 
2.35.3

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

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


[FFmpeg-devel] [PATCH 2/2] avformat/mov: re-allow zero sample sizes if that is not the default

2022-12-04 Thread Marton Balint
Patch 03d81a044ad587ea83567f75dc36bc3d64278199 disallowed zero sample sizes,
but there are some files in the wild which have zero sized samples (e.g.
no audio in some part of a live recording).

Fix this by only disallowing zero sized samples if the size is coming from the
default sample size and not from the trun box. This approach fixes the original
timeout issue from fuzzed files differently.

Signed-off-by: Marton Balint 
---
 libavformat/mov.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 935b2f8d9f..9d3a2ab830 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5230,6 +5230,9 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (index_entry_pos > 0)
 prev_dts = sti->index_entries[index_entry_pos-1].timestamp;
 
+if (entries && !frag->size && !(flags & MOV_TRUN_SAMPLE_SIZE))
+return AVERROR_INVALIDDATA;
+
 for (i = 0; i < entries && !pb->eof_reached; i++) {
 unsigned sample_size = frag->size;
 int sample_flags = i ? frag->flags : first_sample_flags;
@@ -5293,8 +5296,6 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 distance++;
 if (av_sat_add64(dts, sample_duration) != dts + 
(uint64_t)sample_duration)
 return AVERROR_INVALIDDATA;
-if (!sample_size)
-return AVERROR_INVALIDDATA;
 dts += sample_duration;
 offset += sample_size;
 sc->data_size += sample_size;
-- 
2.35.3

___
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 v5 4/4] swscale/output: add rgbaf32 output support

2022-12-04 Thread Michael Niedermayer
On Wed, Nov 23, 2022 at 11:35:40AM -0800, mindm...@gmail.com wrote:
> From: Mark Reid 
> 
> ---
>  libswscale/output.c  | 92 
>  libswscale/swscale_unscaled.c|  4 +-
>  libswscale/tests/floatimg_cmp.c  |  4 +-
>  libswscale/utils.c   | 16 +++--
>  libswscale/yuv2rgb.c |  2 +
>  tests/ref/fate/filter-pixdesc-rgbaf32be  |  1 +
>  tests/ref/fate/filter-pixdesc-rgbaf32le  |  1 +
>  tests/ref/fate/filter-pixdesc-rgbf32be   |  1 +
>  tests/ref/fate/filter-pixdesc-rgbf32le   |  1 +
>  tests/ref/fate/filter-pixfmts-copy   |  4 ++
>  tests/ref/fate/filter-pixfmts-crop   |  4 ++
>  tests/ref/fate/filter-pixfmts-field  |  4 ++
>  tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
>  tests/ref/fate/filter-pixfmts-hflip  |  4 ++
>  tests/ref/fate/filter-pixfmts-il |  4 ++
>  tests/ref/fate/filter-pixfmts-null   |  4 ++
>  tests/ref/fate/filter-pixfmts-scale  |  4 ++
>  tests/ref/fate/filter-pixfmts-transpose  |  4 ++
>  tests/ref/fate/filter-pixfmts-vflip  |  4 ++
>  tests/ref/fate/sws-floatimg-cmp  | 16 +
>  20 files changed, 170 insertions(+), 8 deletions(-)
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32be
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32le
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32be
>  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32le
> 
> diff --git a/libswscale/output.c b/libswscale/output.c
> index 5c85bff971..1d86a244f9 100644
> --- a/libswscale/output.c
> +++ b/libswscale/output.c
> @@ -2471,6 +2471,92 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t 
> *lumFilter,
>  }
>  }
>  
> +static void
> +yuv2rgbaf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
> +const int16_t **lumSrcx, int lumFilterSize,
> +const int16_t *chrFilter, const int16_t **chrUSrcx,
> +const int16_t **chrVSrcx, int chrFilterSize,
> +const int16_t **alpSrcx, uint8_t *dest,
> +int dstW, int y)
> +{
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
> +int i;
> +int alpha = desc->flags & AV_PIX_FMT_FLAG_ALPHA;
> +int hasAlpha = alpha && alpSrcx;
> +int pixelStep = alpha ? 4 : 3;
> +uint32_t *dest32 = (uint32_t*)dest;
> +const int32_t **lumSrc  = (const int32_t**)lumSrcx;
> +const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
> +const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
> +const int32_t **alpSrc  = (const int32_t**)alpSrcx;
> +static const float float_mult = 1.0f / 65535.0f;
> +uint32_t a = av_float2int(1.0f);
> +
> +for (i = 0; i < dstW; i++) {
> +int j;
> +int Y = -0x4000;
> +int U = -(128 << 23);
> +int V = -(128 << 23);
> +int R, G, B, A;
> +
> +for (j = 0; j < lumFilterSize; j++)
> +Y += lumSrc[j][i] * (unsigned)lumFilter[j];
> +
> +for (j = 0; j < chrFilterSize; j++) {
> +U += chrUSrc[j][i] * (unsigned)chrFilter[j];
> +V += chrVSrc[j][i] * (unsigned)chrFilter[j];
> +}
> +
> +Y >>= 14;
> +Y += 0x1;
> +U >>= 14;
> +V >>= 14;
> +
> +if (hasAlpha) {
> +A = -0x4000;
> +
> +for (j = 0; j < lumFilterSize; j++)
> +A += alpSrc[j][i] * (unsigned)lumFilter[j];
> +
> +A >>= 1;
> +A += 0x20002000;
> +a = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 
> 14));
> +}
> +
> +Y -= c->yuv2rgb_y_offset;
> +Y *= c->yuv2rgb_y_coeff;
> +Y += (1 << 13) - (1 << 29);
> +R = V * c->yuv2rgb_v2r_coeff;
> +G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
> +B =U * c->yuv2rgb_u2b_coeff;
> +
> +R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
> +G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
> +B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
> +
> +dest32[0] = av_float2int(float_mult * (float)R);
> +dest32[1] = av_float2int(float_mult * (float)G);
> +dest32[2] = av_float2int(float_mult * (float)B);
> +if (alpha)
> +dest32[3] = a;

why is this using uint32_t with av_float2int() and not floats straight ?



> +
> +dest32 += pixelStep;
> +}
> +if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
> +dest32 = (uint32_t*)dest;
> +for (i = 0; i < dstW; i++) {
> +dest32[0] = av_bswap32(dest32[0]);
> +dest32[1] = av_bswap32(dest32[1]);
> +dest32[2] = av_bswap32(dest32[2]);
> +if (alpha)
> +dest32[3] = av_bswap32(dest32[3]);
> +
> +dest32 += pixelStep;
> +}
> +}

teh code in bswapdsp seems more efficient, that should be shared and
used ideally

thx

[...]
-- 
M

Re: [FFmpeg-devel] [PATCH] Revert "avformat/mov: disallow a zero sample size in trun atoms"

2022-12-04 Thread Marton Balint




On Fri, 2 Dec 2022, Gyan Doshi wrote:




On 2022-12-02 06:16 am, Chris Ribble wrote:

 On Thu, Dec 1, 2022 at 4:51 PM Marton Balint  wrote:

 Can you explain why those files are considered valid, or why it makes
 sense to generate such files?

 Thanks,
 Marton


 As far as I can tell, the file that a user provided with this problem
 was generated by an encoder (running FFmpeg 3.4) that started writing
 zero-sized samples when their video switcher + capture card stopped
 receiving audio input. I'm not arguing that it's good for files to be
 generated like this, but it's nice for FFmpeg to be able to process
 them all the same (i.e. the robustness principle).

 With this patch reverted, FFmpeg can accept an input file that is
 partially broken (with playback anomalies due to the presence of
 zero-sized samples) and produce a valid, working output mp4 (or DASH
 stream), just like it could in release 5.0 and older.

 One of the best things about FFmpeg is that it can fix invalid
 container metadata. I feel like losing that capability for this
 scenario is a regression.


FWIW, we don't discard regular MP4s with sample entries of 0 in stts, which 
is only permitted for the last solo sample in a track. So, I agree.


More strict enforcement of sample size was introduced to avoid DOS/Timeout 
with crafted (fuzzed) files and disallow emitting zero sized packets.


Invalid file support is not something that is always worth doing, there 
are other, more important factors, like limiting code complexity or 
improving resiliance against denial of service. The problem here is that I 
honestly don't know if a zero sample size is against spec, just stupid, or 
there is a legitimate use for it.


So I sent a 2 patch series which fixes the original issue differently. 
Please test and review them if you can.


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


Re: [FFmpeg-devel] [PATCH] Revert "avformat/mov: disallow a zero sample size in trun atoms"

2022-12-04 Thread Chris Ribble
> More strict enforcement of sample size was introduced to avoid DOS/Timeout
> with crafted (fuzzed) files and disallow emitting zero sized packets.
>
> Invalid file support is not something that is always worth doing, there
> are other, more important factors, like limiting code complexity or
> improving resiliance against denial of service. The problem here is that I
> honestly don't know if a zero sample size is against spec, just stupid, or
> there is a legitimate use for it.
>
> So I sent a 2 patch series which fixes the original issue differently.
> Please test and review them if you can.

Marton,

Thank you for looking into this further.

I tried your patch series and FFmpeg still generates an error
(AVERROR_INVALIDDATA) while processing the moof fragment with
zero-sized samples.

It seems like !(flags & MOV_TRUN_SAMPLE_SIZE) evaluates to true when
the flag is set (512 is "inverted" to 1). Is that what you had in
mind?

If I change it to this, things work as expected for my input mp4:
if (entries && !frag->size && (flags & MOV_TRUN_SAMPLE_SIZE !=
MOV_TRUN_SAMPLE_SIZE))
  return AVERROR_INVALIDDATA;

Sorry if I was supposed to provide this feedback on the patch series
itself; I'm happy to do so there as needed.

Thanks,
Chris
___
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] Del has_video for HLS_INDEPENDENT_SEGMENTS, it can be used with audio

2022-12-04 Thread Steven Liu
Xavier Laffargue  于2022年12月4日周日 02:38写道:
>
> Signed-off-by: Xavier Laffargue 
> ---
> libavformat/hlsenc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index a86fc8907f..92276084aa 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1598,7 +1598,7 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> avio_printf(byterange_mode ? hls->m3u8_out : vs->out, 
> "#EXT-X-DISCONTINUITY\n");
> vs->discontinuity_set = 1;
> }
> -if (vs->has_video && (hls->flags & HLS_INDEPENDENT_SEGMENTS)) {
> +if (hls->flags & HLS_INDEPENDENT_SEGMENTS) {
> avio_printf(byterange_mode ? hls->m3u8_out : vs->out, 
> "#EXT-X-INDEPENDENT-SEGMENTS\n");
> }
> for (en = vs->segments; en; en = en->next) {
> --
> 2.31.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".

Hi Xavier,

I cannot apply this patch, it will output message:

Applying: Del has_video for HLS_INDEPENDENT_SEGMENTS, it can be used with audio
error: patch failed: libavformat/hlsenc.c:1598
error: libavformat/hlsenc.c: patch does not apply
Patch failed at 0001 Del has_video for HLS_INDEPENDENT_SEGMENTS, it
can be used with audio
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".



BTW, the subject title should lead as avformat/hlsenc:


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

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


Re: [FFmpeg-devel] [PATCH 1/2] libavformat/hlsenc: Enable HTTP, persistent connections for hls_delete_file

2022-12-04 Thread Steven Liu
Basel Sayeh  于2022年11月29日周二 08:08写道:
>
> Please ignore this version and use the other one, as it was sent using
> the wrong email client and the patch is missed up.
Hi Basel,

Could you send a new version patchset name lead by "v2" ?

git format -patch -v 2



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

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


Re: [FFmpeg-devel] [PATCH] avformat/file: add fd protocol

2022-12-04 Thread zhilizhao(赵志立)



> On Nov 19, 2022, at 02:48, Zhao Zhili  wrote:
> 
> From: Zhao Zhili 
> 
> Unlike the pipe protocol, fd protocol has seek support if it
> corresponding to a regular file.
> ---
> Sometimes it's the only way to access files via file descriptor, e.g.,
> requesting a shared file on Android:
> https://developer.android.com/training/secure-file-sharing/request-file
> 
> doc/protocols.texi  | 24 +++
> libavformat/Makefile|  1 +
> libavformat/file.c  | 51 +
> libavformat/protocols.c |  1 +
> libavformat/version.h   |  4 ++--
> 5 files changed, 79 insertions(+), 2 deletions(-)
> 
> 

Ping for review.

___
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/7] avcodec/mediacodecenc: make each encoder has its own option

2022-12-04 Thread Steven Liu
Zhao Zhili  于2022年12月5日周一 01:13写道:
>
> From: Zhao Zhili 
>
> ---
>  libavcodec/mediacodecenc.c | 42 ++
>  1 file changed, 24 insertions(+), 18 deletions(-)
>
> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
> index c8d8f84e46..c28cce56c6 100644
> --- a/libavcodec/mediacodecenc.c
> +++ b/libavcodec/mediacodecenc.c
> @@ -495,29 +495,27 @@ static const AVCodecHWConfigInternal *const 
> mediacodec_hw_configs[] = {
>
>  #define OFFSET(x) offsetof(MediaCodecEncContext, x)
>  #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> -static const AVOption common_options[] = {
> -{ "ndk_codec", "Use MediaCodec from NDK",
> -OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, 
> -1, 1, VE },
> -{ "codec_name", "Select codec by name",
> -OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
> -{ "bitrate_mode", "Bitrate control method",
> -OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
> INT_MAX, VE, "bitrate_mode" },
> -{ "cq", "Constant quality mode",
> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, 
> VE, "bitrate_mode" },
> -{ "vbr", "Variable bitrate mode",
> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, 
> VE, "bitrate_mode" },
> -{ "cbr", "Constant bitrate mode",
> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, 
> VE, "bitrate_mode" },
> -{ "cbr_fd", "Constant bitrate mode with frame drops",
> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 
> 0, VE, "bitrate_mode" },
> -{ NULL },
> -};
> +#define COMMON_OPTION
>\
> +{ "ndk_codec", "Use MediaCodec from NDK",
>\
> +OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, 
> -1, 1, VE },  \
> +{ "codec_name", "Select codec by name",  
>\
> +OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },   
>\
> +{ "bitrate_mode", "Bitrate control method",  
>\
> +OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
> INT_MAX, VE, "bitrate_mode" },  \
> +{ "cq", "Constant quality mode", 
>\
> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, 
> VE, "bitrate_mode" }, \
> +{ "vbr", "Variable bitrate mode",
>\
> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, 
> VE, "bitrate_mode" },\
> +{ "cbr", "Constant bitrate mode",
>\
> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, 
> VE, "bitrate_mode" },\
> +{ "cbr_fd", "Constant bitrate mode with frame drops",
>\
> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 
> 0, VE, "bitrate_mode" }, \

Why don't merge 1/7 and 2/7 into one step?
>
>  #define MEDIACODEC_ENCODER_CLASS(name)  \
>  static const AVClass name ## _mediacodec_class = {  \
>  .class_name = #name "_mediacodec",  \
>  .item_name  = av_default_item_name, \
> -.option = common_options,   \
> +.option = name ## _options, \
>  .version= LIBAVUTIL_VERSION_INT,\
>  };  \
>
> @@ -542,9 +540,17 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = 
> {  \
>  };  \
>
>  #if CONFIG_H264_MEDIACODEC_ENCODER
> +static const AVOption h264_options[] = {
> +COMMON_OPTION
> +{ NULL, }
> +};
>  DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
>  #endif
>
>  #if CONFIG_HEVC_MEDIACODEC_ENCODER
> +static const AVOption hevc_options[] = {
> +COMMON_OPTION
> +{ NULL, }
> +};
>  DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
>  #endif
> --
> 2.25.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-req

Re: [FFmpeg-devel] [PATCH] lavu/hwcontext_vaapi: Skip 'vgem' driver

2022-12-04 Thread Xiang, Haihao
On Wed, 2022-11-23 at 13:54 -0800, Brian Norris wrote:
> There can be more than one available render node, and it's not
> guaranteed the first node we come across is the correct one. In
> particular, 'vgem' devices are common, and are
> never VAAPI-enabled and thus not valid here.
> 
> We have a 'kernel_driver' arg already for specifying a single driver we
> *do* want, but it doesn't support a negation, nor a list. It's easier
> just to automatically skip 'vgem' anyway, to avoid foisting this burden
> on users.
> 
> This has precedent in libva-utils already:
> 
>   bfb6b98ed62a exclude vgem node and invalid drm node in vainfo
>   
> https://github.com/intel/libva-utils/commit/bfb6b98ed62ac14a840ba62639ab902a23912258
> 
> Signed-off-by: Brian Norris 
> ---
> 
>  libavutil/hwcontext_vaapi.c | 28 +---
>  1 file changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index 4bcde74f6212..84b03b633251 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -1700,6 +1700,7 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
>  char path[64];
>  int n, max_devices = 8;
>  #if CONFIG_LIBDRM
> +drmVersion *info;
>  const AVDictionaryEntry *kernel_driver;
>  kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0);
>  #endif
> @@ -1713,9 +1714,15 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
>  break;
>  }
>  #if CONFIG_LIBDRM
> +info = drmGetVersion(priv->drm_fd);
> +if (!info) {
> +av_log(ctx, AV_LOG_VERBOSE,
> +   "Failed to get DRM version for device %d.\n", n);
> +close(priv->drm_fd);
> +priv->drm_fd = -1;
> +continue;
> +}
>  if (kernel_driver) {
> -drmVersion *info;
> -info = drmGetVersion(priv->drm_fd);
>  if (strcmp(kernel_driver->value, info->name)) {
>  av_log(ctx, AV_LOG_VERBOSE, "Ignoring device %d "
> "with non-matching kernel driver (%s).\n",
> @@ -1730,12 +1737,19 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
> "with matching kernel driver (%s).\n",
> n, info->name);
>  drmFreeVersion(info);
> -} else
> -#endif
> -{
> -av_log(ctx, AV_LOG_VERBOSE, "Trying to use "
> -   "DRM render node for device %d.\n", n);
> +break;
> +} else if (!strncmp(info->name, "vgem", 4)) {

The virtual GEM device is vgem, so better to use strcmp here. 

Thanks
Haihao

> +av_log(ctx, AV_LOG_VERBOSE,
> +   "Skipping vgem node for device %d.\n", n);
> +drmFreeVersion(info);
> +close(priv->drm_fd);
> +priv->drm_fd = -1;
> +continue;
>  }
> +drmFreeVersion(info);
> +#endif
> +av_log(ctx, AV_LOG_VERBOSE, "Trying to use "
> +   "DRM render node for device %d.\n", n);
>  break;
>  }
>  if (n >= max_devices)
___
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] [Internet]Re: [PATCH 2/7] avcodec/mediacodecenc: make each encoder has its own option

2022-12-04 Thread zhilizhao(赵志立)

> On Dec 5, 2022, at 12:23, Steven Liu  wrote:
> 
> Zhao Zhili  于2022年12月5日周一 01:13写道:
>> 
>> From: Zhao Zhili 
>> 
>> ---
>> libavcodec/mediacodecenc.c | 42 ++
>> 1 file changed, 24 insertions(+), 18 deletions(-)
>> 
>> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
>> index c8d8f84e46..c28cce56c6 100644
>> --- a/libavcodec/mediacodecenc.c
>> +++ b/libavcodec/mediacodecenc.c
>> @@ -495,29 +495,27 @@ static const AVCodecHWConfigInternal *const 
>> mediacodec_hw_configs[] = {
>> 
>> #define OFFSET(x) offsetof(MediaCodecEncContext, x)
>> #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
>> -static const AVOption common_options[] = {
>> -{ "ndk_codec", "Use MediaCodec from NDK",
>> -OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, 
>> -1, 1, VE },
>> -{ "codec_name", "Select codec by name",
>> -OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
>> -{ "bitrate_mode", "Bitrate control method",
>> -OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
>> INT_MAX, VE, "bitrate_mode" },
>> -{ "cq", "Constant quality mode",
>> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, 
>> VE, "bitrate_mode" },
>> -{ "vbr", "Variable bitrate mode",
>> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, 
>> VE, "bitrate_mode" },
>> -{ "cbr", "Constant bitrate mode",
>> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, 
>> VE, "bitrate_mode" },
>> -{ "cbr_fd", "Constant bitrate mode with frame drops",
>> -0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 
>> 0, VE, "bitrate_mode" },
>> -{ NULL },
>> -};
>> +#define COMMON_OPTION   
>> \
>> +{ "ndk_codec", "Use MediaCodec from NDK",   
>> \
>> +OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, 
>> -1, 1, VE },  \
>> +{ "codec_name", "Select codec by name", 
>> \
>> +OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },  
>> \
>> +{ "bitrate_mode", "Bitrate control method", 
>> \
>> +OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
>> INT_MAX, VE, "bitrate_mode" },  \
>> +{ "cq", "Constant quality mode",
>> \
>> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, 
>> VE, "bitrate_mode" }, \
>> +{ "vbr", "Variable bitrate mode",   
>> \
>> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, 
>> VE, "bitrate_mode" },\
>> +{ "cbr", "Constant bitrate mode",   
>> \
>> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, 
>> VE, "bitrate_mode" },\
>> +{ "cbr_fd", "Constant bitrate mode with frame drops",   
>> \
>> +0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 
>> 0, VE, "bitrate_mode" }, \
> 
> Why don't merge 1/7 and 2/7 into one step?

I’m waiting for someone to ask the question :)

Patch 3/7 can be simplified to passthrough an opaque int
value to MediaFormat, without those AV_OPT_TYPE_CONST,
enum MediaCodecAvcLevel and enum MediaCodecHevcLevel, then
patch 2/7 is unnecessary.

I’d like to ask: do you like to drop those AV_OPT_TYPE_CONST,
or keep them as patch 3/7 currently do?

After a second thought, patch 2/7 is future proof. I will
reorder patch 1/7 and 2/7.

>> 
>> #define MEDIACODEC_ENCODER_CLASS(name)  \
>> static const AVClass name ## _mediacodec_class = {  \
>> .class_name = #name "_mediacodec",  \
>> .item_name  = av_default_item_name, \
>> -.option = common_options,   \
>> +.option = name ## _options, \
>> .version= LIBAVUTIL_VERSION_INT,\
>> };  \
>> 
>> @@ -542,9 +540,17 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder 
>> = {  \
>> };  \
>> 
>> #if CONFIG_H264_MEDIACODEC_ENCODER
>> +static const AVOption h264_options[] = {
>> +COMMON_OPTION
>> +{ NULL, }
>> +};
>> DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
>> #endif
>> 
>> #if CONFIG_HEVC_MEDIACODEC_ENCODER
>> +static const AVOption hevc_options[] = {
>> +COMMON_OPTION
>> 

[FFmpeg-devel] [PATCH 2/2] libswscale: add AVBSwapDSPContext and use

2022-12-04 Thread mindmark
From: Mark Reid 

There are some places in input.c that could use it too
but they aren't currently being pass the SwsContext
---
 libswscale/output.c   | 36 +++
 libswscale/swscale_internal.h |  3 +++
 libswscale/swscale_unscaled.c | 26 +
 libswscale/utils.c|  2 ++
 4 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 5c85bff971..cd44081e3d 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2313,13 +2313,11 @@ yuv2gbrp_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 }
 }
 if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
-for (i = 0; i < dstW; i++) {
-dest16[0][i] = av_bswap16(dest16[0][i]);
-dest16[1][i] = av_bswap16(dest16[1][i]);
-dest16[2][i] = av_bswap16(dest16[2][i]);
-if (hasAlpha)
-dest16[3][i] = av_bswap16(dest16[3][i]);
-}
+c->bsdsp.bswap16_buf(dest16[0], dest16[0], dstW);
+c->bsdsp.bswap16_buf(dest16[1], dest16[1], dstW);
+c->bsdsp.bswap16_buf(dest16[2], dest16[2], dstW);
+if (hasAlpha)
+c->bsdsp.bswap16_buf(dest16[3], dest16[3], dstW);
 }
 }
 
@@ -2385,13 +2383,11 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
 }
 if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
-for (i = 0; i < dstW; i++) {
-dest16[0][i] = av_bswap16(dest16[0][i]);
-dest16[1][i] = av_bswap16(dest16[1][i]);
-dest16[2][i] = av_bswap16(dest16[2][i]);
-if (hasAlpha)
-dest16[3][i] = av_bswap16(dest16[3][i]);
-}
+c->bsdsp.bswap16_buf(dest16[0], dest16[0], dstW);
+c->bsdsp.bswap16_buf(dest16[1], dest16[1], dstW);
+c->bsdsp.bswap16_buf(dest16[2], dest16[2], dstW);
+if (hasAlpha)
+c->bsdsp.bswap16_buf(dest16[3], dest16[3], dstW);
 }
 }
 
@@ -2461,13 +2457,11 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 
30) >> 14));
 }
 if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
-for (i = 0; i < dstW; i++) {
-dest32[0][i] = av_bswap32(dest32[0][i]);
-dest32[1][i] = av_bswap32(dest32[1][i]);
-dest32[2][i] = av_bswap32(dest32[2][i]);
-if (hasAlpha)
-dest32[3][i] = av_bswap32(dest32[3][i]);
-}
+c->bsdsp.bswap32_buf(dest32[0], dest32[0], dstW);
+c->bsdsp.bswap32_buf(dest32[1], dest32[1], dstW);
+c->bsdsp.bswap32_buf(dest32[2], dest32[2], dstW);
+if (hasAlpha)
+c->bsdsp.bswap32_buf(dest32[3], dest32[3], dstW);
 }
 }
 
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index abeebbb002..400f0bc8ed 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #include "libavutil/avassert.h"
+#include "libavutil/bswapdsp.h"
 #include "libavutil/common.h"
 #include "libavutil/frame.h"
 #include "libavutil/intreadwrite.h"
@@ -682,6 +683,8 @@ typedef struct SwsContext {
 atomic_int   data_unaligned_warned;
 
 Half2FloatTables *h2f_tables;
+
+AVBSwapDSPContext bsdsp;
 } SwsContext;
 //FIXME check init (where 0)
 
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 9af2e7ecc3..0010ab24d1 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -468,7 +468,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *src[],
   int srcStride[], int srcSliceY, int srcSliceH,
   uint8_t *dst[], int dstStride[])
 {
-int i, j, p;
+int i, p;
 
 for (p = 0; p < 4; p++) {
 int srcstr = srcStride[p] / 2;
@@ -480,9 +480,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *src[],
 continue;
 dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
 for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
-for (j = 0; j < min_stride; j++) {
-dstPtr[j] = av_bswap16(srcPtr[j]);
-}
+c->bsdsp.bswap16_buf(dstPtr, srcPtr, min_stride);
 srcPtr += srcstr;
 dstPtr += dststr;
 }
@@ -495,7 +493,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *src[],
   int srcStride[], int srcSliceY, int srcSliceH,
   uint8_t *dst[], int dstStride[])
 {
-int i, j, p;
+int i, p;
 
 for (p = 0; p < 4; p++) {
 int srcstr = srcStride[p] / 4;
@@ -507,9 +505,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *src[],
 continue;
 dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
 for (i = 0; i < (srcSliceH >> c

[FFmpeg-devel] [PATCH 1/2] avutil: move bswapdsp from avcodec to avutil

2022-12-04 Thread mindmark
From: Mark Reid 

Also renamed bswap_buf to bswap32_buf
---
 configure | 56 ---
 libavcodec/4xm.c  | 14 ++---
 libavcodec/Makefile   |  1 -
 libavcodec/ac3dec.c   |  4 +-
 libavcodec/ac3dec.h   |  4 +-
 libavcodec/alsdec.c   | 12 ++--
 libavcodec/apedec.c   | 10 ++--
 libavcodec/asv.c  |  4 +-
 libavcodec/asv.h  |  4 +-
 libavcodec/asvdec.c   |  4 +-
 libavcodec/asvenc.c   |  4 +-
 libavcodec/cllc.c |  6 +-
 libavcodec/eamad.c|  6 +-
 libavcodec/eatqi.c| 10 ++--
 libavcodec/exr.c  |  6 +-
 libavcodec/flacenc.c  |  6 +-
 libavcodec/fraps.c| 10 ++--
 libavcodec/hevcdec.c  |  4 +-
 libavcodec/hevcdec.h  |  4 +-
 libavcodec/huffyuvdec.c   | 14 ++---
 libavcodec/huffyuvenc.c   |  8 +--
 libavcodec/imc.c  |  6 +-
 libavcodec/imm4.c | 12 ++--
 libavcodec/mdec.c |  6 +-
 libavcodec/mimic.c| 12 ++--
 libavcodec/mobiclip.c |  6 +-
 libavcodec/motionpixels.c | 10 ++--
 libavcodec/mpc.h  |  4 +-
 libavcodec/mpc7.c |  8 +--
 libavcodec/rawdec.c   |  8 +--
 libavcodec/riscv/Makefile |  3 -
 libavcodec/shorten.c  |  7 ++-
 libavcodec/truemotion2.c  | 11 ++--
 libavcodec/truespeech.c   |  8 +--
 libavcodec/utvideo.h  |  4 +-
 libavcodec/utvideodec.c   | 16 +++---
 libavcodec/utvideoenc.c   | 10 ++--
 libavcodec/x86/Makefile   |  2 -
 libavcodec/ylc.c  | 18 +++---
 libavutil/Makefile|  2 +
 {libavcodec => libavutil}/bswapdsp.c  | 17 +++---
 {libavcodec => libavutil}/bswapdsp.h  | 16 +++---
 libavutil/riscv/Makefile  |  7 ++-
 .../riscv/bswapdsp_init.c |  9 +--
 .../riscv/bswapdsp_rvb.S  |  0
 .../riscv/bswapdsp_rvv.S  |  0
 libavutil/version.h   |  2 +-
 libavutil/x86/Makefile|  8 ++-
 {libavcodec => libavutil}/x86/bswapdsp.asm|  2 +-
 {libavcodec => libavutil}/x86/bswapdsp_init.c | 17 +++---
 tests/checkasm/Makefile   |  2 +-
 tests/checkasm/bswapdsp.c |  8 +--
 tests/checkasm/checkasm.c |  4 +-
 53 files changed, 216 insertions(+), 220 deletions(-)
 rename {libavcodec => libavutil}/bswapdsp.c (80%)
 rename {libavcodec => libavutil}/bswapdsp.h (71%)
 rename {libavcodec => libavutil}/riscv/bswapdsp_init.c (85%)
 rename {libavcodec => libavutil}/riscv/bswapdsp_rvb.S (100%)
 rename {libavcodec => libavutil}/riscv/bswapdsp_rvv.S (100%)
 rename {libavcodec => libavutil}/x86/bswapdsp.asm (98%)
 rename {libavcodec => libavutil}/x86/bswapdsp_init.c (80%)

diff --git a/configure b/configure
index f4eedfc207..03b502ea37 100755
--- a/configure
+++ b/configure
@@ -2421,7 +2421,6 @@ CONFIG_EXTRA="
 audio_frame_queue
 audiodsp
 blockdsp
-bswapdsp
 cabac
 cbs
 cbs_av1
@@ -2749,8 +2748,8 @@ aac_decoder_select="adts_header mpeg4audio sinewin"
 aac_fixed_decoder_select="adts_header mpeg4audio"
 aac_encoder_select="audio_frame_queue iirfilter lpc sinewin"
 aac_latm_decoder_select="aac_decoder aac_latm_parser"
-ac3_decoder_select="ac3_parser ac3dsp bswapdsp fmtconvert"
-ac3_fixed_decoder_select="ac3_parser ac3dsp bswapdsp"
+ac3_decoder_select="ac3_parser ac3dsp fmtconvert"
+ac3_fixed_decoder_select="ac3_parser ac3dsp"
 ac3_encoder_select="ac3dsp audiodsp me_cmp"
 ac3_fixed_encoder_select="ac3dsp audiodsp me_cmp"
 acelp_kelvin_decoder_select="audiodsp"
@@ -2759,20 +2758,20 @@ adpcm_g722_encoder_select="g722dsp"
 agm_decoder_select="idctdsp"
 aic_decoder_select="golomb idctdsp"
 alac_encoder_select="lpc"
-als_decoder_select="bswapdsp mpeg4audio"
+als_decoder_select="mpeg4audio"
 amrnb_decoder_select="lsp"
 amrwb_decoder_select="lsp"
 amv_decoder_select="sp5x_decoder exif"
 amv_encoder_select="jpegtables mpegvideoenc"
-ape_decoder_select="bswapdsp llauddsp"
+ape_decoder_select="llauddsp"
 apng_decoder_select="inflate_wrapper"
 apng_encoder_select="deflate_wrapper llvidencdsp"
 aptx_encoder_select="audio_frame_queue"
 aptx_hd_encoder_select="audio_frame_queue"
-asv1_decoder_select="blockdsp bswapdsp idctdsp"
-asv1_enc

Re: [FFmpeg-devel] [PATCH v5 4/4] swscale/output: add rgbaf32 output support

2022-12-04 Thread Mark Reid
On Sun, Dec 4, 2022 at 4:05 PM Michael Niedermayer 
wrote:

> On Wed, Nov 23, 2022 at 11:35:40AM -0800, mindm...@gmail.com wrote:
> > From: Mark Reid 
> >
> > ---
> >  libswscale/output.c  | 92 
> >  libswscale/swscale_unscaled.c|  4 +-
> >  libswscale/tests/floatimg_cmp.c  |  4 +-
> >  libswscale/utils.c   | 16 +++--
> >  libswscale/yuv2rgb.c |  2 +
> >  tests/ref/fate/filter-pixdesc-rgbaf32be  |  1 +
> >  tests/ref/fate/filter-pixdesc-rgbaf32le  |  1 +
> >  tests/ref/fate/filter-pixdesc-rgbf32be   |  1 +
> >  tests/ref/fate/filter-pixdesc-rgbf32le   |  1 +
> >  tests/ref/fate/filter-pixfmts-copy   |  4 ++
> >  tests/ref/fate/filter-pixfmts-crop   |  4 ++
> >  tests/ref/fate/filter-pixfmts-field  |  4 ++
> >  tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
> >  tests/ref/fate/filter-pixfmts-hflip  |  4 ++
> >  tests/ref/fate/filter-pixfmts-il |  4 ++
> >  tests/ref/fate/filter-pixfmts-null   |  4 ++
> >  tests/ref/fate/filter-pixfmts-scale  |  4 ++
> >  tests/ref/fate/filter-pixfmts-transpose  |  4 ++
> >  tests/ref/fate/filter-pixfmts-vflip  |  4 ++
> >  tests/ref/fate/sws-floatimg-cmp  | 16 +
> >  20 files changed, 170 insertions(+), 8 deletions(-)
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32be
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32le
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32be
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32le
> >
> > diff --git a/libswscale/output.c b/libswscale/output.c
> > index 5c85bff971..1d86a244f9 100644
> > --- a/libswscale/output.c
> > +++ b/libswscale/output.c
> > @@ -2471,6 +2471,92 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t
> *lumFilter,
> >  }
> >  }
> >
> > +static void
> > +yuv2rgbaf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
> > +const int16_t **lumSrcx, int lumFilterSize,
> > +const int16_t *chrFilter, const int16_t **chrUSrcx,
> > +const int16_t **chrVSrcx, int chrFilterSize,
> > +const int16_t **alpSrcx, uint8_t *dest,
> > +int dstW, int y)
> > +{
> > +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
> > +int i;
> > +int alpha = desc->flags & AV_PIX_FMT_FLAG_ALPHA;
> > +int hasAlpha = alpha && alpSrcx;
> > +int pixelStep = alpha ? 4 : 3;
> > +uint32_t *dest32 = (uint32_t*)dest;
> > +const int32_t **lumSrc  = (const int32_t**)lumSrcx;
> > +const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
> > +const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
> > +const int32_t **alpSrc  = (const int32_t**)alpSrcx;
> > +static const float float_mult = 1.0f / 65535.0f;
> > +uint32_t a = av_float2int(1.0f);
> > +
> > +for (i = 0; i < dstW; i++) {
> > +int j;
> > +int Y = -0x4000;
> > +int U = -(128 << 23);
> > +int V = -(128 << 23);
> > +int R, G, B, A;
> > +
> > +for (j = 0; j < lumFilterSize; j++)
> > +Y += lumSrc[j][i] * (unsigned)lumFilter[j];
> > +
> > +for (j = 0; j < chrFilterSize; j++) {
> > +U += chrUSrc[j][i] * (unsigned)chrFilter[j];
> > +V += chrVSrc[j][i] * (unsigned)chrFilter[j];
> > +}
> > +
> > +Y >>= 14;
> > +Y += 0x1;
> > +U >>= 14;
> > +V >>= 14;
> > +
> > +if (hasAlpha) {
> > +A = -0x4000;
> > +
> > +for (j = 0; j < lumFilterSize; j++)
> > +A += alpSrc[j][i] * (unsigned)lumFilter[j];
> > +
> > +A >>= 1;
> > +A += 0x20002000;
> > +a = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30)
> >> 14));
> > +}
> > +
> > +Y -= c->yuv2rgb_y_offset;
> > +Y *= c->yuv2rgb_y_coeff;
> > +Y += (1 << 13) - (1 << 29);
> > +R = V * c->yuv2rgb_v2r_coeff;
> > +G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
> > +B =U * c->yuv2rgb_u2b_coeff;
> > +
> > +R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
> > +G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
> > +B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
> > +
> > +dest32[0] = av_float2int(float_mult * (float)R);
> > +dest32[1] = av_float2int(float_mult * (float)G);
> > +dest32[2] = av_float2int(float_mult * (float)B);
> > +if (alpha)
> > +dest32[3] = a;
>
> why is this using uint32_t with av_float2int() and not floats straight ?
>
>
It's this way because it is matching the planar f32 version, I will change
both.


>
>
> > +
> > +dest32 += pixelStep;
> > +}
> > +if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
> > +dest32 = (uint32_t*)dest;
> > +for (i = 0; i < dstW; i++) {
> > +dest32

Re: [FFmpeg-devel] [PATCH] libavcodec/qsvenc: enable Hyper Encode

2022-12-04 Thread Xiang, Haihao


> From dfa35dd22e9178971a47709065ed4e976f57f8ef Mon Sep 17 00:00:00 2001
> From: galinart 
> Date: Fri, 4 Nov 2022 11:10:52 +
> Subject: [PATCH] libavcodec/qsvenc: enable Hyper Encode
> 
> Hyper Encode uses Intel integrated and discrete graphics on one system
> to accelerate encoding of a single video stream.
> Depending on the selected parameters and codecs, performance gain on AlderLake
> iGPU + ARC Gfx up to 1.6x.
> 
> More information: 
> https://www.intel.co.uk/content/www/uk/en/architecture-and-technology/adaptix/deep-link.html
> Developer guide: 
> https://github.com/oneapi-src/oneVPL-intel-gpu/blob/main/doc/HyperEncode_FeatureDeveloperGuide.md
> 
> Hyper Encode is supported only on Windows and requires D3D11 and oneVPL.
> 
> To enable Hyper Encode need to specify:
> -Hyper Encode mode (-dual_gfx on or dual_gfx adaptive)
> -Encoder: h264_qsv or hevc_qsv
> -BRC: VBR, CQP or ICQ
> -Lowpower mode (-low_power 1)
> -Closed GOP for AVC or strict GOP for HEVC -idr_interval = 0 used by default
> 
> Depending on the encoding parameters, the following parameters may need
> to be adjusted:
> -g recommended >= 30 for better performance
> -async_depth recommended >= 30 for better performance
> -extra_hw_frames recommended equal to async_depth value
> -bf recommended = 0 for better performance
> 
> In the cases with fast encoding (-preset veryfast) there may be no
> performance gain due to the fact that the decode is slower than the encode.
> 
> Command line examples:
> 
> ffmpeg.exe -init_hw_device qsv:hw,child_device_type=d3d11va,child_device=0 -v
> verbose -y -hwaccel qsv -extra_hw_frames 60 -async_depth 60 -c:v h264_qsv -i
> bbb_sunflower_2160p_60fps_normal.mp4
> -async_depth 60 -c:v h264_qsv -preset medium -g 60 -low_power 1 -bf 0
> -dual_gfx on output.h265
> 
> Signed-off-by: galinart 
> ---
>  libavcodec/qsvenc.c  | 91 +++-
>  libavcodec/qsvenc.h  | 19 -
>  libavcodec/qsvenc_h264.c |  3 ++
>  libavcodec/qsvenc_hevc.c |  3 ++
>  4 files changed, 112 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index d5e9f2d420..96526d4579 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -169,6 +169,8 @@ do {\
>  }   \
>  } while (0) \
>  
> +#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
> +
>  static const char *print_ratecontrol(mfxU16 rc_mode)
>  {
>  int i;
> @@ -197,6 +199,10 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  mfxExtCodingOption2 *co2 = NULL;
>  mfxExtCodingOption3 *co3 = NULL;
>  mfxExtHEVCTiles *exthevctiles = NULL;
> +#if QSV_HAVE_HE
> +mfxExtHyperModeParam *exthypermodeparam = NULL;
> +#endif
> +
>  const char *tmp_str = NULL;
>  
>  if (q->co2_idx > 0)
> @@ -208,6 +214,11 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  if (q->exthevctiles_idx > 0)
>  exthevctiles = (mfxExtHEVCTiles *)coding_opts[q->exthevctiles_idx];
>  
> +#if QSV_HAVE_HE
> +if (q->exthypermodeparam_idx > 0)
> +exthypermodeparam = (mfxExtHyperModeParam *)coding_opts[q-
> >exthypermodeparam_idx];
> +#endif
> +
>  av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n",
> print_profile(avctx->codec_id, info->CodecProfile), info-
> >CodecLevel);
>  
> @@ -373,6 +384,21 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  av_log(avctx, AV_LOG_VERBOSE, "NumTileColumns: %"PRIu16";
> NumTileRows: %"PRIu16"\n",
> exthevctiles->NumTileColumns, exthevctiles->NumTileRows);
>  }
> +
> +#if QSV_HAVE_HE
> +if (exthypermodeparam) {
> +av_log(avctx, AV_LOG_VERBOSE, "HyperEncode: ");
> +
> +if (exthypermodeparam->Mode == MFX_HYPERMODE_OFF)
> +av_log(avctx, AV_LOG_VERBOSE, "OFF");
> +if (exthypermodeparam->Mode == MFX_HYPERMODE_ON)
> +av_log(avctx, AV_LOG_VERBOSE, "ON");
> +if (exthypermodeparam->Mode == MFX_HYPERMODE_ADAPTIVE)
> +av_log(avctx, AV_LOG_VERBOSE, "Adaptive");
> +
> +av_log(avctx, AV_LOG_VERBOSE, "\n");
> +}
> +#endif
>  }
>  
>  static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
> @@ -1154,6 +1180,54 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q-
> >extvsi;
>  }
>  
> +#if QSV_HAVE_HE
> +   if (q->dual_gfx) {
> +if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 4)) {
> +mfxIMPL impl;
> +MFXQueryIMPL(q->session, &impl);
> +
> +if (MFX_IMPL_VIA_MASK(impl) != MFX_IMPL_VIA_D3D11) {
> +av_log(avctx, AV_LOG_ERROR, "Dual GFX mode requires D3D11VA
> \n");
> +return AVERROR_UNKNOWN;
> +}
> +if (q->param.mfx.LowPower != MFX_CODINGOPTION_ON) {
> +av_log(

[FFmpeg-devel] [PATCH v2 01/13] lavc/hevc_ps: remove profile limitation of pps_range_extensions()

2022-12-04 Thread Fei Wang
Follow spec 7.3.2.3.1.

Signed-off-by: Fei Wang 
---
update:
1. fix uninitialized variable which may cause segment fault.

 libavcodec/hevc_ps.c |  2 +-
 tests/ref/fate/hevc-conformance-PS_A_VIDYO_3 | 50 ++--
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 5fe62ec35b..537a3ff99b 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1658,7 +1658,7 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, 
AVCodecContext *avctx,
 if (get_bits1(gb)) { // pps_extension_present_flag
 pps->pps_range_extensions_flag = get_bits1(gb);
 skip_bits(gb, 7); // pps_extension_7bits
-if (sps->ptl.general_ptl.profile_idc == FF_PROFILE_HEVC_REXT && 
pps->pps_range_extensions_flag) {
+if (pps->pps_range_extensions_flag) {
 if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0)
 goto err;
 }
diff --git a/tests/ref/fate/hevc-conformance-PS_A_VIDYO_3 
b/tests/ref/fate/hevc-conformance-PS_A_VIDYO_3
index 59b82b72bb..d1d86b2dc9 100644
--- a/tests/ref/fate/hevc-conformance-PS_A_VIDYO_3
+++ b/tests/ref/fate/hevc-conformance-PS_A_VIDYO_3
@@ -3,28 +3,28 @@
 #codec_id 0: rawvideo
 #dimensions 0: 416x240
 #sar 0: 0/1
-0,  0,  0,1,   149760, 0x88619f80
-0,  1,  1,1,   149760, 0x550bdaf0
-0,  2,  2,1,   149760, 0x4121f7a2
-0,  3,  3,1,   149760, 0x210b1d07
-0,  4,  4,1,   149760, 0x731b7758
-0,  5,  5,1,   149760, 0x17adb789
-0,  6,  6,1,   149760, 0x98b2f080
-0,  7,  7,1,   149760, 0xc0be1f2a
-0,  8,  8,1,   149760, 0xc01e387a
-0,  9,  9,1,   149760, 0xd932822b
-0, 10, 10,1,   149760, 0x16c0a1df
-0, 11, 11,1,   149760, 0x5aa6c005
-0, 12, 12,1,   149760, 0xd3aab602
-0, 13, 13,1,   149760, 0x4e6ecab1
-0, 14, 14,1,   149760, 0x8a86f1f2
-0, 15, 15,1,   149760, 0x2ed21e1b
-0, 16, 16,1,   149760, 0x80892f24
-0, 17, 17,1,   149760, 0xb8a952ef
-0, 18, 18,1,   149760, 0x557e57fb
-0, 19, 19,1,   149760, 0x2b825b2c
-0, 20, 20,1,   149760, 0x30b69b5e
-0, 21, 21,1,   149760, 0x802ebf08
-0, 22, 22,1,   149760, 0x95aadc8e
-0, 23, 23,1,   149760, 0x4d4c02b7
-0, 24, 24,1,   149760, 0x3fdd1762
+0,  0,  0,1,   149760, 0x5c4f70f4
+0,  1,  1,1,   149760, 0xf4628e59
+0,  2,  2,1,   149760, 0xa28e5bdc
+0,  3,  3,1,   149760, 0xda0e53d7
+0,  4,  4,1,   149760, 0x42dd334a
+0,  5,  5,1,   149760, 0x25ba9dfe
+0,  6,  6,1,   149760, 0x8854d8ca
+0,  7,  7,1,   149760, 0xc04505d4
+0,  8,  8,1,   149760, 0xd3fce146
+0,  9,  9,1,   149760, 0x8bfd88bd
+0, 10, 10,1,   149760, 0x33d965b2
+0, 11, 11,1,   149760, 0x12746b7a
+0, 12, 12,1,   149760, 0xb7642694
+0, 13, 13,1,   149760, 0x32b5035f
+0, 14, 14,1,   149760, 0x7bea0af1
+0, 15, 15,1,   149760, 0x577d4fc8
+0, 16, 16,1,   149760, 0x023a9c66
+0, 17, 17,1,   149760, 0x9abe76c4
+0, 18, 18,1,   149760, 0x2b14dba5
+0, 19, 19,1,   149760, 0x7b8affcf
+0, 20, 20,1,   149760, 0x21e4c323
+0, 21, 21,1,   149760, 0xf0b7d9cd
+0, 22, 22,1,   149760, 0x4db0c5bc
+0, 23, 23,1,   149760, 0xf455f752
+0, 24, 24,1,   149760, 0x569fec99
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 02/13] lavc/avcodec: Add HEVC Screen Content Coding Extensions profile

2022-12-04 Thread Fei Wang
From: Linjie Fu 

Described in HEVC spec A.3.7.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/avcodec.h  | 1 +
 libavcodec/hevc_ps.c  | 2 ++
 libavcodec/profiles.c | 1 +
 3 files changed, 4 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..79fad674df 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1639,6 +1639,7 @@ typedef struct AVCodecContext {
 #define FF_PROFILE_HEVC_MAIN_10 2
 #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE  3
 #define FF_PROFILE_HEVC_REXT4
+#define FF_PROFILE_HEVC_SCC 9
 
 #define FF_PROFILE_VVC_MAIN_10  1
 #define FF_PROFILE_VVC_MAIN_10_444 33
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 537a3ff99b..ad92b6bcbc 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -259,6 +259,8 @@ static int decode_profile_tier_level(GetBitContext *gb, 
AVCodecContext *avctx,
 av_log(avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n");
 else if (ptl->profile_idc == FF_PROFILE_HEVC_REXT)
 av_log(avctx, AV_LOG_DEBUG, "Range Extension profile bitstream\n");
+else if (ptl->profile_idc == FF_PROFILE_HEVC_SCC)
+av_log(avctx, AV_LOG_DEBUG, "Screen Content Coding Extension profile 
bitstream\n");
 else
 av_log(avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", 
ptl->profile_idc);
 
diff --git a/libavcodec/profiles.c b/libavcodec/profiles.c
index 7af7fbeb13..2230fc5415 100644
--- a/libavcodec/profiles.c
+++ b/libavcodec/profiles.c
@@ -85,6 +85,7 @@ const AVProfile ff_hevc_profiles[] = {
 { FF_PROFILE_HEVC_MAIN_10,  "Main 10" },
 { FF_PROFILE_HEVC_MAIN_STILL_PICTURE,   "Main Still Picture"  },
 { FF_PROFILE_HEVC_REXT, "Rext"},
+{ FF_PROFILE_HEVC_SCC,  "Scc" },
 { FF_PROFILE_UNKNOWN },
 };
 
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 03/13] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2022-12-04 Thread Fei Wang
From: Linjie Fu 

1. Add extension syntax according to 7.3.2.2.3/7.3.2.3.3 in T-REC-H.265-201911.
2. Keep using parsed PPS when bitstream overread for compatibility. For
example, the clip PS_A_VIDYO_3.bit in FATE test has incomplete extension
syntax which will be overread and un-decodable if without this change.
3. Format brace in pps_range_extensions().

Signed-off-by: Linjie Fu 
Signed-off-by: Haihao Xiang 
Signed-off-by: Fei Wang 
---
 libavcodec/hevc.h|   3 +
 libavcodec/hevc_ps.c | 288 +--
 libavcodec/hevc_ps.h |  69 +++
 3 files changed, 349 insertions(+), 11 deletions(-)

diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 1804755327..6b454a75c1 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -154,6 +154,9 @@ enum {
 // get near that, though, so set a lower limit here with the maximum
 // possible value for 4K video (at most 135 16x16 Ctb rows).
 HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
+
+// A.3.7: Screen content coding extensions
+HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
 };
 
 
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index ad92b6bcbc..3181962918 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -853,7 +853,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 HEVCWindow *ow;
 int ret = 0;
 int log2_diff_max_min_transform_block_size;
-int bit_depth_chroma, start, vui_present, sublayer_ordering_info;
+int bit_depth_chroma, start, vui_present, sublayer_ordering_info, 
num_comps;
 int i;
 
 // Coded parameters
@@ -1074,8 +1074,12 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 decode_vui(gb, avctx, apply_defdispwin, sps);
 
 if (get_bits1(gb)) { // sps_extension_flag
-sps->sps_range_extension_flag = get_bits1(gb);
-skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
+sps->sps_range_extension_flag  = get_bits1(gb);
+sps->sps_multilayer_extension_flag = get_bits1(gb);
+sps->sps_3d_extension_flag = get_bits1(gb);
+sps->sps_scc_extension_flag= get_bits1(gb);
+skip_bits(gb, 4); // sps_extension_4bits
+
 if (sps->sps_range_extension_flag) {
 sps->transform_skip_rotation_enabled_flag = get_bits1(gb);
 sps->transform_skip_context_enabled_flag  = get_bits1(gb);
@@ -1101,6 +1105,57 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 av_log(avctx, AV_LOG_WARNING,
"cabac_bypass_alignment_enabled_flag not yet 
implemented\n");
 }
+
+if (sps->sps_multilayer_extension_flag) {
+skip_bits1(gb); // inter_view_mv_vert_constraint_flag
+av_log(avctx, AV_LOG_WARNING,
+   "sps_multilayer_extension_flag not yet implemented\n");
+}
+
+if (sps->sps_3d_extension_flag) {
+for (i = 0; i <= 1; i++) {
+skip_bits1(gb); // iv_di_mc_enabled_flag
+skip_bits1(gb); // iv_mv_scal_enabled_flag
+if (i == 0) {
+get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
+skip_bits1(gb); // iv_res_pred_enabled_flag
+skip_bits1(gb); // depth_ref_enabled_flag
+skip_bits1(gb); // vsp_mc_enabled_flag
+skip_bits1(gb); // dbbp_enabled_flag
+} else {
+skip_bits1(gb); // tex_mc_enabled_flag
+get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
+skip_bits1(gb); // intra_contour_enabled_flag
+skip_bits1(gb); // intra_dc_only_wedge_enabled_flag
+skip_bits1(gb); // cqt_cu_part_pred_enabled_flag
+skip_bits1(gb); // inter_dc_only_enabled_flag
+skip_bits1(gb); // skip_intra_enabled_flag
+}
+}
+av_log(avctx, AV_LOG_WARNING,
+   "sps_3d_extension_flag not yet implemented\n");
+}
+
+if (sps->sps_scc_extension_flag) {
+sps->sps_curr_pic_ref_enabled_flag = get_bits1(gb);
+sps->palette_mode_enabled_flag = get_bits1(gb);
+if (sps->palette_mode_enabled_flag) {
+sps->palette_max_size = get_ue_golomb_long(gb);
+sps->delta_palette_max_predictor_size = get_ue_golomb_long(gb);
+sps->sps_palette_predictor_initializers_present_flag = 
get_bits1(gb);
+
+if (sps->sps_palette_predictor_initializers_present_flag) {
+sps->sps_num_palette_predictor_initializers_minus1 = 
get_ue_golomb_long(gb);
+num_comps = !sps->chroma_format_idc ? 1 : 3;
+for (int comp = 0; comp < num_comps; comp++)
+for (i = 0; i <= 
sps->sps_num_palette_predic

[FFmpeg-devel] [PATCH v2 04/13] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2022-12-04 Thread Fei Wang
From: Linjie Fu 

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/hevcdec.c | 6 ++
 libavcodec/hevcdec.h | 4 
 2 files changed, 10 insertions(+)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 567e8d81d4..f9a97ac7f5 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -856,6 +856,12 @@ static int hls_slice_header(HEVCContext *s)
 sh->slice_cr_qp_offset = 0;
 }
 
+if (s->ps.pps->pps_slice_act_qp_offsets_present_flag) {
+sh->slice_act_y_qp_offset  = get_se_golomb(gb);
+sh->slice_act_cb_qp_offset = get_se_golomb(gb);
+sh->slice_act_cr_qp_offset = get_se_golomb(gb);
+}
+
 if (s->ps.pps->chroma_qp_offset_list_enabled_flag)
 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
 else
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 9d3f4adbb3..7841ba8565 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -295,6 +295,10 @@ typedef struct SliceHeader {
 int slice_cb_qp_offset;
 int slice_cr_qp_offset;
 
+int slice_act_y_qp_offset;
+int slice_act_cb_qp_offset;
+int slice_act_cr_qp_offset;
+
 uint8_t cu_chroma_qp_offset_enabled_flag;
 
 int beta_offset;///< beta_offset_div2 * 2
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 05/13] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2022-12-04 Thread Fei Wang
From: Linjie Fu 

According to 7.3.6.1, use_integer_mv_flag should be parsed if
motion_vector_resolution_control_idc equals to 2. If not present, it
equals to motion_vector_resolution_control_idc.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/hevcdec.c | 8 
 libavcodec/hevcdec.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index f9a97ac7f5..52fa627133 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -839,6 +839,14 @@ static int hls_slice_header(HEVCContext *s)
sh->max_num_merge_cand);
 return AVERROR_INVALIDDATA;
 }
+
+// Syntax in 7.3.6.1
+if (s->ps.sps->motion_vector_resolution_control_idc == 2)
+sh->use_integer_mv_flag = get_bits1(gb);
+else
+// Inferred to be equal to 
motion_vector_resolution_control_idc if not present
+sh->use_integer_mv_flag = 
s->ps.sps->motion_vector_resolution_control_idc;
+
 }
 
 sh->slice_qp_delta = get_se_golomb(gb);
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 7841ba8565..a7fc669bcb 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -305,6 +305,7 @@ typedef struct SliceHeader {
 int tc_offset;  ///< tc_offset_div2 * 2
 
 unsigned int max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand
+uint8_t use_integer_mv_flag;
 
 unsigned *entry_point_offset;
 int * offset;
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 08/13] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2022-12-04 Thread Fei Wang
From: Linjie Fu 

Including sps/pps/slice parameters.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_hevc.c | 52 +
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 20fb36adfa..750738d36e 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -124,7 +124,7 @@ static int vaapi_hevc_start_frame(AVCodecContext  
*avctx,
 const HEVCPPS  *pps = h->ps.pps;
 
 const ScalingList *scaling_list = NULL;
-int pic_param_size, err, i;
+int pic_param_size, num_comps, pre_palette_size, err, i;
 
 VAPictureParameterBufferHEVC *pic_param = (VAPictureParameterBufferHEVC 
*)&pic->pic_param;
 
@@ -245,8 +245,46 @@ static int vaapi_hevc_start_frame(AVCodecContext  
*avctx,
 for (i = 0; i < 6; i++)
 pic->pic_param.rext.cr_qp_offset_list[i]= 
pps->cr_qp_offset_list[i];
 }
+
+pre_palette_size = pps->pps_palette_predictor_initializers_present_flag ?
+   pps->pps_num_palette_predictor_initializers :
+   (sps->sps_palette_predictor_initializers_present_flag ?
+   sps->sps_num_palette_predictor_initializers_minus1 + 1 :
+   0);
+
+if (avctx->profile == FF_PROFILE_HEVC_SCC) {
+pic->pic_param.scc = (VAPictureParameterBufferHEVCScc) {
+.screen_content_pic_fields.bits = {
+.pps_curr_pic_ref_enabled_flag  = 
pps->pps_curr_pic_ref_enabled_flag,
+.palette_mode_enabled_flag  = 
sps->palette_mode_enabled_flag,
+.motion_vector_resolution_control_idc   = 
sps->motion_vector_resolution_control_idc,
+.intra_boundary_filtering_disabled_flag = 
sps->intra_boundary_filtering_disabled_flag,
+.residual_adaptive_colour_transform_enabled_flag
+= 
pps->residual_adaptive_colour_transform_enabled_flag,
+.pps_slice_act_qp_offsets_present_flag  = 
pps->pps_slice_act_qp_offsets_present_flag,
+},
+.palette_max_size   = 
sps->palette_max_size,
+.delta_palette_max_predictor_size   = 
sps->delta_palette_max_predictor_size,
+.predictor_palette_size = pre_palette_size,
+.pps_act_y_qp_offset_plus5  = 
pps->residual_adaptive_colour_transform_enabled_flag ?
+  
pps->pps_act_y_qp_offset + 5 : 0,
+.pps_act_cb_qp_offset_plus5 = 
pps->residual_adaptive_colour_transform_enabled_flag ?
+  
pps->pps_act_cb_qp_offset + 5 : 0,
+.pps_act_cr_qp_offset_plus3 = 
pps->residual_adaptive_colour_transform_enabled_flag ?
+  
pps->pps_act_cr_qp_offset + 3 : 0,
+};
+
+num_comps = pps->monochrome_palette_flag ? 1 : 3;
+for (int comp = 0; comp < num_comps; comp++)
+for (i = 0; i < pre_palette_size; i++)
+pic->pic_param.scc.predictor_palette_entries[comp][i] =
+pps->pps_palette_predictor_initializers_present_flag ?
+pps->pps_palette_predictor_initializer[comp][i]:
+sps->sps_palette_predictor_initializer[comp][i];
+}
+
 #endif
-pic_param_size = avctx->profile == FF_PROFILE_HEVC_REXT ?
+pic_param_size = avctx->profile >= FF_PROFILE_HEVC_REXT ?
 sizeof(pic->pic_param) : 
sizeof(VAPictureParameterBufferHEVC);
 
 err = ff_vaapi_decode_make_param_buffer(avctx, &pic->pic,
@@ -299,7 +337,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
 VASliceParameterBufferHEVC *last_slice_param = (VASliceParameterBufferHEVC 
*)&pic->last_slice_param;
 int ret;
 
-int slice_param_size = avctx->profile == FF_PROFILE_HEVC_REXT ?
+int slice_param_size = avctx->profile >= FF_PROFILE_HEVC_REXT ?
 sizeof(pic->last_slice_param) : 
sizeof(VASliceParameterBufferHEVC);
 
 if (pic->last_size) {
@@ -413,7 +451,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 VAAPIDecodePictureHEVC *pic = h->ref->hwaccel_picture_private;
 VASliceParameterBufferHEVC *last_slice_param = (VASliceParameterBufferHEVC 
*)&pic->last_slice_param;
 
-int slice_param_size = avctx->profile == FF_PROFILE_HEVC_REXT ?
+int slice_param_size = avctx->profile >= FF_PROFILE_HEVC_REXT ?
 sizeof(pic->last_slice_param) : 
sizeof(VASliceParameterBufferHEVC);
 
 int nb_list = (sh->slice_type == HEVC_SLICE_B) ?
@@ -478,11 +516,15 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
  

[FFmpeg-devel] [PATCH v2 06/13] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2022-12-04 Thread Fei Wang
From: Linjie Fu 

uint8_t is big enough and keep consistent with the definition in
cbs_h265.h.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/hevcdec.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index a7fc669bcb..aab816791e 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -304,7 +304,7 @@ typedef struct SliceHeader {
 int beta_offset;///< beta_offset_div2 * 2
 int tc_offset;  ///< tc_offset_div2 * 2
 
-unsigned int max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand
+uint8_t max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand
 uint8_t use_integer_mv_flag;
 
 unsigned *entry_point_offset;
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 10/13] lavc/vaapi_hevc: Set correct rps type for scc

2022-12-04 Thread Fei Wang
From: Linjie Fu 

According to 8.1.3 and 8.3.2.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_hevc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 6ce1e17fa8..005d782819 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -71,6 +71,7 @@ static void fill_vaapi_pic(VAPictureHEVC *va_pic, const 
HEVCFrame *pic, int rps_
 static int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
 {
 VASurfaceID pic_surf = ff_vaapi_get_surface_id(pic->frame);
+const HEVCFrame *current_picture = h->ref;
 int i;
 
 for (i = 0; i < h->rps[ST_CURR_BEF].nb_refs; i++) {
@@ -88,6 +89,9 @@ static int find_frame_rps_type(const HEVCContext *h, const 
HEVCFrame *pic)
 return VA_PICTURE_HEVC_RPS_LT_CURR;
 }
 
+if (h->ps.pps->pps_curr_pic_ref_enabled_flag && current_picture->poc == 
pic->poc)
+return VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
+
 return 0;
 }
 
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 07/13] lavc/hevc: Update reference list for SCC

2022-12-04 Thread Fei Wang
From: Linjie Fu 

Screen Content Coding allows non-intra slice in an IRAP frame which can
reference the frame itself, and would mark the current decoded picture
as "used for long-term reference", no matter TwoVersionsOfCurrDecPicFlag(8.1.3),
hence some previous restricts are not suitable any more.

Constructe RefPicListTemp and RefPicList according to 8-8/9/10. Disable
slice decoding for SCC profile to avoid unexpected error in hevc native
decoder and patch welcome.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/hevc_refs.c | 21 -
 libavcodec/hevcdec.c   | 10 +-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 811e8feff8..96153a2459 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -322,7 +322,7 @@ int ff_hevc_slice_rpl(HEVCContext *s)
 return ret;
 
 if (!(s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs +
-  s->rps[LT_CURR].nb_refs)) {
+  s->rps[LT_CURR].nb_refs) && 
!s->ps.pps->pps_curr_pic_ref_enabled_flag) {
 av_log(s->avctx, AV_LOG_ERROR, "Zero refs in the frame RPS.\n");
 return AVERROR_INVALIDDATA;
 }
@@ -349,6 +349,13 @@ int ff_hevc_slice_rpl(HEVCContext *s)
 rpl_tmp.nb_refs++;
 }
 }
+// Construct RefPicList0, RefPicList1 (8-8, 8-10)
+if (s->ps.pps->pps_curr_pic_ref_enabled_flag) {
+rpl_tmp.list[rpl_tmp.nb_refs]   = s->ref->poc;
+rpl_tmp.ref[rpl_tmp.nb_refs]= s->ref;
+rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = 1;
+rpl_tmp.nb_refs++;
+}
 }
 
 /* reorder the references if necessary */
@@ -371,6 +378,14 @@ int ff_hevc_slice_rpl(HEVCContext *s)
 rpl->nb_refs = FFMIN(rpl->nb_refs, sh->nb_refs[list_idx]);
 }
 
+// 8-9
+if (s->ps.pps->pps_curr_pic_ref_enabled_flag &&
+!sh->rpl_modification_flag[list_idx] &&
+rpl_tmp.nb_refs > sh->nb_refs[L0]) {
+rpl->list[sh->nb_refs[L0] - 1] = s->ref->poc;
+rpl->ref[sh->nb_refs[L0] - 1]  = s->ref;
+}
+
 if (sh->collocated_list == list_idx &&
 sh->collocated_ref_idx < rpl->nb_refs)
 s->ref->collocated_ref = rpl->ref[sh->collocated_ref_idx];
@@ -541,5 +556,9 @@ int ff_hevc_frame_nb_refs(const HEVCContext *s)
 for (i = 0; i < long_rps->nb_refs; i++)
 ret += !!long_rps->used[i];
 }
+
+if (s->ps.pps->pps_curr_pic_ref_enabled_flag)
+ret++;
+
 return ret;
 }
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 52fa627133..121ceb4e75 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -668,7 +668,8 @@ static int hls_slice_header(HEVCContext *s)
sh->slice_type);
 return AVERROR_INVALIDDATA;
 }
-if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I) {
+if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
+!s->ps.pps->pps_curr_pic_ref_enabled_flag) {
 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
 return AVERROR_INVALIDDATA;
 }
@@ -3123,6 +3124,13 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 if (ret < 0)
 goto fail;
 } else {
+if (s->avctx->profile == FF_PROFILE_HEVC_SCC) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "SCC profile is not yet implemented in hevc native 
decoder.\n");
+ret = AVERROR_PATCHWELCOME;
+goto fail;
+}
+
 if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0)
 ctb_addr_ts = hls_slice_data_wpp(s, nal);
 else
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 11/13] lavc/vaapi_hevc: Loose the restricts for SCC decoding

2022-12-04 Thread Fei Wang
From: Linjie Fu 

Allow current picture as the reference picture.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_hevc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 005d782819..ca14052d56 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -104,7 +104,8 @@ static void fill_vaapi_reference_frames(const HEVCContext 
*h, VAPictureParameter
 const HEVCFrame *frame = NULL;
 
 while (!frame && j < FF_ARRAY_ELEMS(h->DPB)) {
-if (&h->DPB[j] != current_picture && (h->DPB[j].flags & 
(HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)))
+if ((&h->DPB[j] != current_picture || 
h->ps.pps->pps_curr_pic_ref_enabled_flag) &&
+(h->DPB[j].flags & (HEVC_FRAME_FLAG_LONG_REF | 
HEVC_FRAME_FLAG_SHORT_REF)))
 frame = &h->DPB[j];
 j++;
 }
@@ -222,7 +223,8 @@ static int vaapi_hevc_start_frame(AVCodecContext  
*avctx,
 }
 
 #if VA_CHECK_VERSION(1, 2, 0)
-if (avctx->profile == FF_PROFILE_HEVC_REXT) {
+if (avctx->profile == FF_PROFILE_HEVC_REXT ||
+avctx->profile == FF_PROFILE_HEVC_SCC) {
 pic->pic_param.rext = (VAPictureParameterBufferHEVCRext) {
 .range_extension_pic_fields.bits  = {
 .transform_skip_rotation_enabled_flag   = 
sps->transform_skip_rotation_enabled_flag,
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 12/13] avcodec/hevcdec: Replace number with enum

2022-12-04 Thread Fei Wang
Keep same style with IS_IDR()/IS_BLA().

Signed-off-by: Fei Wang 
---
 libavcodec/hevcdec.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index aab816791e..94609e4699 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -75,7 +75,7 @@
 #define IS_IDR(s) ((s)->nal_unit_type == HEVC_NAL_IDR_W_RADL || 
(s)->nal_unit_type == HEVC_NAL_IDR_N_LP)
 #define IS_BLA(s) ((s)->nal_unit_type == HEVC_NAL_BLA_W_RADL || 
(s)->nal_unit_type == HEVC_NAL_BLA_W_LP || \
(s)->nal_unit_type == HEVC_NAL_BLA_N_LP)
-#define IS_IRAP(s) ((s)->nal_unit_type >= 16 && (s)->nal_unit_type <= 23)
+#define IS_IRAP(s) ((s)->nal_unit_type >= HEVC_NAL_BLA_W_LP && 
(s)->nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23)
 
 enum RPSType {
 ST_CURR_BEF = 0,
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 13/13] lavc/vaapi_hevc: Remove duplicate code

2022-12-04 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_hevc.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index ca14052d56..b3ff2f7344 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -538,12 +538,6 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 pic->last_slice_param.rext.ChromaOffsetL0[i][1] = 
sh->chroma_offset_l0[i][1];
 }
 
-for (i = 0; i < 15 && i < sh->nb_refs[L0]; i++) {
-pic->last_slice_param.rext.luma_offset_l0[i] = 
sh->luma_offset_l0[i];
-pic->last_slice_param.rext.ChromaOffsetL0[i][0] = 
sh->chroma_offset_l0[i][0];
-pic->last_slice_param.rext.ChromaOffsetL0[i][1] = 
sh->chroma_offset_l0[i][1];
-}
-
 if (sh->slice_type == HEVC_SLICE_B) {
 for (i = 0; i < 15 && i < sh->nb_refs[L1]; i++) {
 pic->last_slice_param.rext.luma_offset_l1[i] = 
sh->luma_offset_l1[i];
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 09/13] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2022-12-04 Thread Fei Wang
From: Linjie Fu 

Note that Screen-Extended Main 4:4:4 and 4:4:4 10 supports
chroma_format_idc from 0, 1 or 3, hence both 420 and 444 are
supported.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_decode.c |  4 +++-
 libavcodec/vaapi_hevc.c   | 14 --
 libavcodec/vaapi_hevc.h   |  2 +-
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 134f10eca5..29ac439b36 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -410,7 +410,9 @@ static const struct {
 #endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
- ff_vaapi_parse_hevc_rext_profile ),
+ ff_vaapi_parse_hevc_profile ),
+MAP(HEVC,HEVC_SCC,None,
+ ff_vaapi_parse_hevc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 750738d36e..6ce1e17fa8 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -586,9 +586,9 @@ static int ptl_convert(const PTLCommon *general_ptl, 
H265RawProfileTierLevel *h2
 }
 
 /*
- * Find exact va_profile for HEVC Range Extension
+ * Find exact va_profile for HEVC Range Extension and Screen Content Coding 
Extension
  */
-VAProfile ff_vaapi_parse_hevc_rext_profile(AVCodecContext *avctx)
+VAProfile ff_vaapi_parse_hevc_profile(AVCodecContext *avctx)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
@@ -627,6 +627,16 @@ VAProfile ff_vaapi_parse_hevc_rext_profile(AVCodecContext 
*avctx)
 else if (!strcmp(profile->name, "Main 4:4:4 12") ||
  !strcmp(profile->name, "Main 4:4:4 12 Intra"))
 return VAProfileHEVCMain444_12;
+else if (!strcmp(profile->name, "Screen-Extended Main"))
+return VAProfileHEVCSccMain;
+else if (!strcmp(profile->name, "Screen-Extended Main 10"))
+return VAProfileHEVCSccMain10;
+else if (!strcmp(profile->name, "Screen-Extended Main 4:4:4"))
+return VAProfileHEVCSccMain444;
+#if VA_CHECK_VERSION(1, 8, 0)
+else if (!strcmp(profile->name, "Screen-Extended Main 4:4:4 10"))
+return VAProfileHEVCSccMain444_10;
+#endif
 #else
 av_log(avctx, AV_LOG_WARNING, "HEVC profile %s is "
"not supported with this VA version.\n", profile->name);
diff --git a/libavcodec/vaapi_hevc.h b/libavcodec/vaapi_hevc.h
index b3b0e6fc1e..7662dca510 100644
--- a/libavcodec/vaapi_hevc.h
+++ b/libavcodec/vaapi_hevc.h
@@ -22,6 +22,6 @@
 #include 
 #include "avcodec.h"
 
-VAProfile ff_vaapi_parse_hevc_rext_profile(AVCodecContext *avctx);
+VAProfile ff_vaapi_parse_hevc_profile(AVCodecContext *avctx);
 
 #endif /* AVCODEC_VAAPI_HEVC_H */
-- 
2.25.1

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

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


Re: [FFmpeg-devel] [PATCH v2] libavfilter/qsvvpp: Use different alignment for YUV420P format

2022-12-04 Thread Xiang, Haihao
On Do, 2022-12-01 at 10:48 +0800, wenbin.chen-at-intel@ffmpeg.org wrote:
> From: Wenbin Chen 
> 
> When process yuv420 frames, FFmpeg uses same alignment on Y/U/V
> planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
> pitch, which makes U/V planes 16-bytes aligned. We need to set
> a separate alignment to meet runtime's behaviour.
> 
> Now alignment is changed to 16 so that the linesizes of U/V planes
> meet the requirment of VPL/MSDK. Add get_buffer.video callback to
> qsv filters to change the default get_buffer behaviour.
> 
> Now the commandline works fine:
> ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 3082x1884 \
> -i ./3082x1884.yuv -vf 'vpp_qsv=w=2466:h=1508' -f rawvideo \
> -pix_fmt yuv420p 2466_1508.yuv
> 
> Signed-off-by: Wenbin Chen 
> ---
>  libavfilter/qsvvpp.c | 13 +
>  libavfilter/qsvvpp.h |  1 +
>  libavfilter/vf_deinterlace_qsv.c |  1 +
>  libavfilter/vf_overlay_qsv.c |  2 ++
>  libavfilter/vf_scale_qsv.c   |  1 +
>  libavfilter/vf_vpp_qsv.c |  1 +
>  6 files changed, 19 insertions(+)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 8428ee89ab..d5cfeab402 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -1003,3 +1003,16 @@ int ff_qsvvpp_create_mfx_session(void *ctx,
>  }
>  
>  #endif
> +
> +AVFrame *ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h)
> +{
> +/* When process YUV420 frames, FFmpeg uses same alignment on Y/U/V
> + * planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
> + * pitch, which makes U/V planes 16-bytes aligned. We need to set a
> + * separate alignment to meet runtime's behaviour.
> +*/
> +return ff_default_get_video_buffer2(inlink,
> +FFALIGN(inlink->w, 32),
> +FFALIGN(inlink->h, 32),
> +16);

It uses the same alignment for all formats, which is conflicted with the title. 

Thanks
Haihao


> +}
> diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
> index a8cfcc565a..6f7c9bfc15 100644
> --- a/libavfilter/qsvvpp.h
> +++ b/libavfilter/qsvvpp.h
> @@ -127,4 +127,5 @@ int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err,
>  int ff_qsvvpp_create_mfx_session(void *ctx, void *loader, mfxIMPL
> implementation,
>   mfxVersion *pver, mfxSession *psession);
>  
> +AVFrame *ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h);
>  #endif /* AVFILTER_QSVVPP_H */
> diff --git a/libavfilter/vf_deinterlace_qsv.c
> b/libavfilter/vf_deinterlace_qsv.c
> index 98ed7283ad..6c94923f02 100644
> --- a/libavfilter/vf_deinterlace_qsv.c
> +++ b/libavfilter/vf_deinterlace_qsv.c
> @@ -581,6 +581,7 @@ static const AVFilterPad qsvdeint_inputs[] = {
>  .name = "default",
>  .type = AVMEDIA_TYPE_VIDEO,
>  .filter_frame = qsvdeint_filter_frame,
> +.get_buffer.video = ff_qsvvpp_get_video_buffer,
>  },
>  };
>  
> diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> index d947a1faa1..1a2c1b1e96 100644
> --- a/libavfilter/vf_overlay_qsv.c
> +++ b/libavfilter/vf_overlay_qsv.c
> @@ -399,11 +399,13 @@ static const AVFilterPad overlay_qsv_inputs[] = {
>  .name  = "main",
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .config_props  = config_main_input,
> +.get_buffer.video = ff_qsvvpp_get_video_buffer,
>  },
>  {
>  .name  = "overlay",
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .config_props  = config_overlay_input,
> +.get_buffer.video = ff_qsvvpp_get_video_buffer,
>  },
>  };
>  
> diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> index 758e730f78..36d5f3a6ec 100644
> --- a/libavfilter/vf_scale_qsv.c
> +++ b/libavfilter/vf_scale_qsv.c
> @@ -641,6 +641,7 @@ static const AVFilterPad qsvscale_inputs[] = {
>  .name = "default",
>  .type = AVMEDIA_TYPE_VIDEO,
>  .filter_frame = qsvscale_filter_frame,
> +.get_buffer.video = ff_qsvvpp_get_video_buffer,
>  },
>  };
>  
> diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
> index 4a053f9145..b26d19c3bc 100644
> --- a/libavfilter/vf_vpp_qsv.c
> +++ b/libavfilter/vf_vpp_qsv.c
> @@ -634,6 +634,7 @@ static const AVFilterPad vpp_inputs[] = {
>  .name  = "default",
>  .type  = AVMEDIA_TYPE_VIDEO,
>  .config_props  = config_input,
> +.get_buffer.video = ff_qsvvpp_get_video_buffer,
>  },
>  };
>  
___
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 v1 03/13] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2022-12-04 Thread Wang, Fei W
On Thu, 2022-12-01 at 22:52 -0300, James Almer wrote:
> On 12/1/2022 5:13 AM, Fei Wang wrote:
> > +static void colour_mapping_octants(GetBitContext *gb, HEVCPPS
> > *pps, int inp_depth,
> > +   int idx_y, int idx_cb, int
> > idx_cr, int inp_length)
> > +{
> > +uint8_t split_octant_flag, coded_res_flag;
> > +uint16_t part_num_y, res_coeff_q, res_coeff_r;
> 
> Use int or unsigned for scalar values in stack.
> 
> > +int bit_depth_cm_input_y, bit_depth_cm_output_y, cm_res_bits;
> > +int k, m, n, c, i, j;
> 
> You can reduce the scope of almost all the above variables.
> 
> > +
> > +part_num_y = 1 << pps->cm_y_part_num_log2;
> > +
> > +if (inp_depth < pps->cm_octant_depth)
> > +split_octant_flag = get_bits1(gb);
> > +
> > +if (split_octant_flag)
> 
> split_octant_flag may be undefined here. It should be initialized to
> 0.
> This is probably the source of the issue Michael reported.
> 
> > +for (k = 0; k < 2; k++)
> 
> for (int k = 0...)
> 
> Same for the rest.

Fixed in V2.

Thanks
Fei

> 
> > +for (m = 0; m < 2; m++)
> > +for (n = 0; n < 2; n++)
> > +colour_mapping_octants(gb, pps, inp_depth + 1,
> > +   idx_y + part_num_y * k
> > * inp_length / 2,
> > +   idx_cb + m * inp_length
> > / 2,
> > +   idx_cr + n * inp_length
> > / 2,
> > +   inp_length / 2);
> > +else
> > +for (i = 0; i < part_num_y; i++) {
> > +for (j = 0; j < 4; j++) {
> > +coded_res_flag = get_bits1(gb);
> > +if (coded_res_flag)
> > +for (c = 0; c < 3; c++) {
> > +res_coeff_q = get_ue_golomb_long(gb);
> > +bit_depth_cm_input_y = 8 + pps-
> > >luma_bit_depth_cm_input_minus8;
> > +bit_depth_cm_output_y = 8 + pps-
> > >luma_bit_depth_cm_output_minus8;
> > +cm_res_bits = FFMAX(0, 10 +
> > bit_depth_cm_input_y - bit_depth_cm_output_y -
> > +pps->cm_res_quant_bits 
> > - (pps->cm_delta_flc_bits_minus1 + 1));
> > +res_coeff_r = get_bits(gb, cm_res_bits);
> > +if (res_coeff_q || res_coeff_r)
> > +skip_bits1(gb);
> > +}
> > +}
> > +}
> > +}
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2] libavfilter/qsvvpp: Use different alignment for YUV420P format

2022-12-04 Thread Chen, Wenbin
> On Do, 2022-12-01 at 10:48 +0800, wenbin.chen-at-intel@ffmpeg.org
> wrote:
> > From: Wenbin Chen 
> >
> > When process yuv420 frames, FFmpeg uses same alignment on Y/U/V
> > planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
> > pitch, which makes U/V planes 16-bytes aligned. We need to set
> > a separate alignment to meet runtime's behaviour.
> >
> > Now alignment is changed to 16 so that the linesizes of U/V planes
> > meet the requirment of VPL/MSDK. Add get_buffer.video callback to
> > qsv filters to change the default get_buffer behaviour.
> >
> > Now the commandline works fine:
> > ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 3082x1884 \
> > -i ./3082x1884.yuv -vf 'vpp_qsv=w=2466:h=1508' -f rawvideo \
> > -pix_fmt yuv420p 2466_1508.yuv
> >
> > Signed-off-by: Wenbin Chen 
> > ---
> >  libavfilter/qsvvpp.c | 13 +
> >  libavfilter/qsvvpp.h |  1 +
> >  libavfilter/vf_deinterlace_qsv.c |  1 +
> >  libavfilter/vf_overlay_qsv.c |  2 ++
> >  libavfilter/vf_scale_qsv.c   |  1 +
> >  libavfilter/vf_vpp_qsv.c |  1 +
> >  6 files changed, 19 insertions(+)
> >
> > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> > index 8428ee89ab..d5cfeab402 100644
> > --- a/libavfilter/qsvvpp.c
> > +++ b/libavfilter/qsvvpp.c
> > @@ -1003,3 +1003,16 @@ int ff_qsvvpp_create_mfx_session(void *ctx,
> >  }
> >
> >  #endif
> > +
> > +AVFrame *ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h)
> > +{
> > +/* When process YUV420 frames, FFmpeg uses same alignment on
> Y/U/V
> > + * planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
> > + * pitch, which makes U/V planes 16-bytes aligned. We need to set a
> > + * separate alignment to meet runtime's behaviour.
> > +*/
> > +return ff_default_get_video_buffer2(inlink,
> > +FFALIGN(inlink->w, 32),
> > +FFALIGN(inlink->h, 32),
> > +16);
> 
> It uses the same alignment for all formats, which is conflicted with the 
> title.
> 
> Thanks
> Haihao
> 
I will change the title and send the patch again.

Thanks
Wenbin
> 
> > +}
> > diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
> > index a8cfcc565a..6f7c9bfc15 100644
> > --- a/libavfilter/qsvvpp.h
> > +++ b/libavfilter/qsvvpp.h
> > @@ -127,4 +127,5 @@ int ff_qsvvpp_print_warning(void *log_ctx,
> mfxStatus err,
> >  int ff_qsvvpp_create_mfx_session(void *ctx, void *loader, mfxIMPL
> > implementation,
> >   mfxVersion *pver, mfxSession *psession);
> >
> > +AVFrame *ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h);
> >  #endif /* AVFILTER_QSVVPP_H */
> > diff --git a/libavfilter/vf_deinterlace_qsv.c
> > b/libavfilter/vf_deinterlace_qsv.c
> > index 98ed7283ad..6c94923f02 100644
> > --- a/libavfilter/vf_deinterlace_qsv.c
> > +++ b/libavfilter/vf_deinterlace_qsv.c
> > @@ -581,6 +581,7 @@ static const AVFilterPad qsvdeint_inputs[] = {
> >  .name = "default",
> >  .type = AVMEDIA_TYPE_VIDEO,
> >  .filter_frame = qsvdeint_filter_frame,
> > +.get_buffer.video = ff_qsvvpp_get_video_buffer,
> >  },
> >  };
> >
> > diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> > index d947a1faa1..1a2c1b1e96 100644
> > --- a/libavfilter/vf_overlay_qsv.c
> > +++ b/libavfilter/vf_overlay_qsv.c
> > @@ -399,11 +399,13 @@ static const AVFilterPad overlay_qsv_inputs[] = {
> >  .name  = "main",
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .config_props  = config_main_input,
> > +.get_buffer.video = ff_qsvvpp_get_video_buffer,
> >  },
> >  {
> >  .name  = "overlay",
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .config_props  = config_overlay_input,
> > +.get_buffer.video = ff_qsvvpp_get_video_buffer,
> >  },
> >  };
> >
> > diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> > index 758e730f78..36d5f3a6ec 100644
> > --- a/libavfilter/vf_scale_qsv.c
> > +++ b/libavfilter/vf_scale_qsv.c
> > @@ -641,6 +641,7 @@ static const AVFilterPad qsvscale_inputs[] = {
> >  .name = "default",
> >  .type = AVMEDIA_TYPE_VIDEO,
> >  .filter_frame = qsvscale_filter_frame,
> > +.get_buffer.video = ff_qsvvpp_get_video_buffer,
> >  },
> >  };
> >
> > diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
> > index 4a053f9145..b26d19c3bc 100644
> > --- a/libavfilter/vf_vpp_qsv.c
> > +++ b/libavfilter/vf_vpp_qsv.c
> > @@ -634,6 +634,7 @@ static const AVFilterPad vpp_inputs[] = {
> >  .name  = "default",
> >  .type  = AVMEDIA_TYPE_VIDEO,
> >  .config_props  = config_input,
> > +.get_buffer.video = ff_qsvvpp_get_video_buffer,
> >  },
> >  };
> >
___
ffmpeg-devel mailing list

Re: [FFmpeg-devel] [PATCH] avutil/tests/dict: Explicitly test av_dict_iterate()

2022-12-04 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> This commit tests it in a way that automatically checks
> that using av_dict_iterate() is equivalent to using
> av_dict_get() with key "" and AV_DICT_IGNORE_SUFFIX.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavutil/tests/dict.c | 30 +-
>  1 file changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/libavutil/tests/dict.c b/libavutil/tests/dict.c
> index 91567289c2..bececefb31 100644
> --- a/libavutil/tests/dict.c
> +++ b/libavutil/tests/dict.c
> @@ -20,10 +20,30 @@
>  
>  #include "libavutil/dict.c"
>  
> +static const AVDictionaryEntry *dict_iterate(const AVDictionary *m,
> + const AVDictionaryEntry *prev)
> +{
> +const AVDictionaryEntry *dict_get = av_dict_get(m, "", prev, 
> AV_DICT_IGNORE_SUFFIX);
> +const AVDictionaryEntry *dict_iterate = av_dict_iterate(m, prev);
> +
> +if (dict_get != dict_iterate) {
> +#define GET(entry, mem) ((entry) ? (entry)->mem : "N/A")
> +printf("Iterating with av_dict_iterate() yields a different result "
> +   "than iterating with av_dict_get() and AV_DICT_IGNORE_SUFFIX "
> +   "(prev: %p, key %s; av_dict_iterate() %p, key %s, value %s; "
> +   "av_dict_get() %p, key %s, value %s)\n",
> +   prev, GET(prev, key),
> +   dict_iterate, GET(dict_iterate, key), GET(dict_iterate, 
> value),
> +   dict_get, GET(dict_get, key), GET(dict_get, value));
> +#undef GET
> +}
> +return dict_iterate;
> +}
> +
>  static void print_dict(const AVDictionary *m)
>  {
> -AVDictionaryEntry *t = NULL;
> -while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
> +const AVDictionaryEntry *t = NULL;
> +while ((t = dict_iterate(m, t)))
>  printf("%s %s   ", t->key, t->value);
>  printf("\n");
>  }
> @@ -94,7 +114,7 @@ int main(void)
>  if (av_dict_get(dict, NULL, NULL, 0))
>  printf("av_dict_get() does not correctly handle NULL key.\n");
>  e = NULL;
> -while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
> +while ((e = dict_iterate(dict, e)))
>  printf("%s %s\n", e->key, e->value);
>  av_dict_free(&dict);
>  
> @@ -106,7 +126,7 @@ int main(void)
>  printf("av_dict_set does not correctly handle NULL key\n");
>  
>  e = NULL;
> -while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
> +while ((e = dict_iterate(dict, e)))
>  printf("'%s' '%s'\n", e->key, e->value);
>  av_dict_free(&dict);
>  
> @@ -122,7 +142,7 @@ int main(void)
>  av_dict_set_int(&dict, "12", 1, 0);
>  av_dict_set_int(&dict, "12", 2, AV_DICT_APPEND);
>  e = NULL;
> -while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
> +while ((e = dict_iterate(dict, e)))
>  printf("%s %s\n", e->key, e->value);
>  av_dict_free(&dict);
>  

Will apply this patch as well as the remaining one of Marvin's patches
(the one from #7: "avutil: use av_dict_iterate") tonight unless there
are objections.

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


[FFmpeg-devel] [PATCH] lavfi/vf_vpp_qsv: use macros for extra mfx parameter

2022-12-04 Thread Xiang, Haihao
From: Haihao Xiang 

Make it easy to add new extra mfx parameter buffer. No functional
change.

Signed-off-by: Haihao Xiang 
---
 libavfilter/vf_vpp_qsv.c | 86 
 1 file changed, 34 insertions(+), 52 deletions(-)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index a14b3de7b5..61ea0c4256 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -365,53 +365,44 @@ static int config_output(AVFilterLink *outlink)
 param.crop = &crop;
 }
 
-if (vpp->deinterlace) {
-memset(&vpp->deinterlace_conf, 0, sizeof(mfxExtVPPDeinterlacing));
-vpp->deinterlace_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
-vpp->deinterlace_conf.Header.BufferSz = sizeof(mfxExtVPPDeinterlacing);
-vpp->deinterlace_conf.Mode = vpp->deinterlace == 1 ?
- MFX_DEINTERLACING_BOB : 
MFX_DEINTERLACING_ADVANCED;
+#define INIT_MFX_EXTBUF(extbuf, id) do { \
+memset(&vpp->extbuf, 0, sizeof(vpp->extbuf)); \
+vpp->extbuf.Header.BufferId = id; \
+vpp->extbuf.Header.BufferSz = sizeof(vpp->extbuf); \
+param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->extbuf; \
+} while (0)
+
+#define SET_MFX_PARAM_FIELD(extbuf, field, value) do { \
+vpp->extbuf.field = value; \
+} while (0)
 
-param.ext_buf[param.num_ext_buf++] = 
(mfxExtBuffer*)&vpp->deinterlace_conf;
+if (vpp->deinterlace) {
+INIT_MFX_EXTBUF(deinterlace_conf, MFX_EXTBUFF_VPP_DEINTERLACING);
+SET_MFX_PARAM_FIELD(deinterlace_conf, Mode, (vpp->deinterlace == 1 ?
+MFX_DEINTERLACING_BOB : 
MFX_DEINTERLACING_ADVANCED));
 }
 
 if (vpp->use_frc) {
-memset(&vpp->frc_conf, 0, sizeof(mfxExtVPPFrameRateConversion));
-vpp->frc_conf.Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
-vpp->frc_conf.Header.BufferSz = sizeof(mfxExtVPPFrameRateConversion);
-vpp->frc_conf.Algorithm = MFX_FRCALGM_DISTRIBUTED_TIMESTAMP;
-
-param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->frc_conf;
+INIT_MFX_EXTBUF(frc_conf, MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION);
+SET_MFX_PARAM_FIELD(frc_conf, Algorithm, 
MFX_FRCALGM_DISTRIBUTED_TIMESTAMP);
 }
 
 if (vpp->denoise) {
-memset(&vpp->denoise_conf, 0, sizeof(mfxExtVPPDenoise));
-vpp->denoise_conf.Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
-vpp->denoise_conf.Header.BufferSz = sizeof(mfxExtVPPDenoise);
-vpp->denoise_conf.DenoiseFactor   = vpp->denoise;
-
-param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->denoise_conf;
+INIT_MFX_EXTBUF(denoise_conf, MFX_EXTBUFF_VPP_DENOISE);
+SET_MFX_PARAM_FIELD(denoise_conf, DenoiseFactor, vpp->denoise);
 }
 
 if (vpp->detail) {
-memset(&vpp->detail_conf, 0, sizeof(mfxExtVPPDetail));
-vpp->detail_conf.Header.BufferId  = MFX_EXTBUFF_VPP_DETAIL;
-vpp->detail_conf.Header.BufferSz  = sizeof(mfxExtVPPDetail);
-vpp->detail_conf.DetailFactor = vpp->detail;
-
-param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->detail_conf;
+INIT_MFX_EXTBUF(detail_conf, MFX_EXTBUFF_VPP_DETAIL);
+SET_MFX_PARAM_FIELD(detail_conf, DetailFactor, vpp->detail);
 }
 
 if (vpp->procamp) {
-memset(&vpp->procamp_conf, 0, sizeof(mfxExtVPPProcAmp));
-vpp->procamp_conf.Header.BufferId  = MFX_EXTBUFF_VPP_PROCAMP;
-vpp->procamp_conf.Header.BufferSz  = sizeof(mfxExtVPPProcAmp);
-vpp->procamp_conf.Hue  = vpp->hue;
-vpp->procamp_conf.Saturation   = vpp->saturation;
-vpp->procamp_conf.Contrast = vpp->contrast;
-vpp->procamp_conf.Brightness   = vpp->brightness;
-
-param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->procamp_conf;
+INIT_MFX_EXTBUF(procamp_conf, MFX_EXTBUFF_VPP_PROCAMP);
+SET_MFX_PARAM_FIELD(procamp_conf, Hue, vpp->hue);
+SET_MFX_PARAM_FIELD(procamp_conf, Saturation, vpp->saturation);
+SET_MFX_PARAM_FIELD(procamp_conf, Contrast, vpp->contrast);
+SET_MFX_PARAM_FIELD(procamp_conf, Brightness, vpp->brightness);
 }
 
 if (vpp->transpose >= 0) {
@@ -458,18 +449,14 @@ static int config_output(AVFilterLink *outlink)
 
 if (vpp->rotate) {
 if (QSV_RUNTIME_VERSION_ATLEAST(mfx_version, 1, 17)) {
-memset(&vpp->rotation_conf, 0, sizeof(mfxExtVPPRotation));
-vpp->rotation_conf.Header.BufferId  = MFX_EXTBUFF_VPP_ROTATION;
-vpp->rotation_conf.Header.BufferSz  = sizeof(mfxExtVPPRotation);
-vpp->rotation_conf.Angle = vpp->rotate;
+INIT_MFX_EXTBUF(rotation_conf, MFX_EXTBUFF_VPP_ROTATION);
+SET_MFX_PARAM_FIELD(rotation_conf, Angle, vpp->rotate);
 
 if (MFX_ANGLE_90 == vpp->rotate || MFX_ANGLE_270 == vpp->rotate) {
 FFSWAP(int, vpp->out_width, vpp->out_height);
   

[FFmpeg-devel] [PATCH v3] libavfilter/qsvvpp: Change the alignment to meet the requirement of YUV420P format

2022-12-04 Thread wenbin . chen-at-intel . com
From: Wenbin Chen 

When process yuv420 frames, FFmpeg uses same alignment on Y/U/V
planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
pitch, which makes U/V planes 16-bytes aligned. We need to set
a separate alignment to meet runtime's behaviour.

Now alignment is changed to 16 so that the linesizes of U/V planes
meet the requirment of VPL/MSDK. Add get_buffer.video callback to
qsv filters to change the default get_buffer behaviour.

Now the commandline works fine:
ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 3082x1884 \
-i ./3082x1884.yuv -vf 'vpp_qsv=w=2466:h=1508' -f rawvideo \
-pix_fmt yuv420p 2466_1508.yuv

Signed-off-by: Wenbin Chen 
---
 libavfilter/qsvvpp.c | 13 +
 libavfilter/qsvvpp.h |  1 +
 libavfilter/vf_deinterlace_qsv.c |  1 +
 libavfilter/vf_overlay_qsv.c |  2 ++
 libavfilter/vf_scale_qsv.c   |  1 +
 libavfilter/vf_vpp_qsv.c |  1 +
 6 files changed, 19 insertions(+)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8428ee89ab..d5cfeab402 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -1003,3 +1003,16 @@ int ff_qsvvpp_create_mfx_session(void *ctx,
 }
 
 #endif
+
+AVFrame *ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h)
+{
+/* When process YUV420 frames, FFmpeg uses same alignment on Y/U/V
+ * planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
+ * pitch, which makes U/V planes 16-bytes aligned. We need to set a
+ * separate alignment to meet runtime's behaviour.
+*/
+return ff_default_get_video_buffer2(inlink,
+FFALIGN(inlink->w, 32),
+FFALIGN(inlink->h, 32),
+16);
+}
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index a8cfcc565a..6f7c9bfc15 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -127,4 +127,5 @@ int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err,
 int ff_qsvvpp_create_mfx_session(void *ctx, void *loader, mfxIMPL 
implementation,
  mfxVersion *pver, mfxSession *psession);
 
+AVFrame *ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h);
 #endif /* AVFILTER_QSVVPP_H */
diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index 98ed7283ad..6c94923f02 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -581,6 +581,7 @@ static const AVFilterPad qsvdeint_inputs[] = {
 .name = "default",
 .type = AVMEDIA_TYPE_VIDEO,
 .filter_frame = qsvdeint_filter_frame,
+.get_buffer.video = ff_qsvvpp_get_video_buffer,
 },
 };
 
diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
index d947a1faa1..1a2c1b1e96 100644
--- a/libavfilter/vf_overlay_qsv.c
+++ b/libavfilter/vf_overlay_qsv.c
@@ -399,11 +399,13 @@ static const AVFilterPad overlay_qsv_inputs[] = {
 .name  = "main",
 .type  = AVMEDIA_TYPE_VIDEO,
 .config_props  = config_main_input,
+.get_buffer.video = ff_qsvvpp_get_video_buffer,
 },
 {
 .name  = "overlay",
 .type  = AVMEDIA_TYPE_VIDEO,
 .config_props  = config_overlay_input,
+.get_buffer.video = ff_qsvvpp_get_video_buffer,
 },
 };
 
diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 758e730f78..36d5f3a6ec 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -641,6 +641,7 @@ static const AVFilterPad qsvscale_inputs[] = {
 .name = "default",
 .type = AVMEDIA_TYPE_VIDEO,
 .filter_frame = qsvscale_filter_frame,
+.get_buffer.video = ff_qsvvpp_get_video_buffer,
 },
 };
 
diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 4a053f9145..b26d19c3bc 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -634,6 +634,7 @@ static const AVFilterPad vpp_inputs[] = {
 .name  = "default",
 .type  = AVMEDIA_TYPE_VIDEO,
 .config_props  = config_input,
+.get_buffer.video = ff_qsvvpp_get_video_buffer,
 },
 };
 
-- 
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".