[FFmpeg-devel] [PATCH v2 6/6] lavc/vaapi_encode: Add VAAPI AV1 encoder

2023-07-17 Thread Fei Wang
Signed-off-by: Fei Wang 
---
update
1. set color_range in sequence header.

 Changelog |1 +
 configure |3 +
 doc/encoders.texi |   13 +
 libavcodec/Makefile   |1 +
 libavcodec/allcodecs.c|1 +
 libavcodec/vaapi_encode.c |  125 +++-
 libavcodec/vaapi_encode.h |   12 +
 libavcodec/vaapi_encode_av1.c | 1229 +
 8 files changed, 1367 insertions(+), 18 deletions(-)
 create mode 100644 libavcodec/vaapi_encode_av1.c

diff --git a/Changelog b/Changelog
index 3876082844..7ae9b85d52 100644
--- a/Changelog
+++ b/Changelog
@@ -25,6 +25,7 @@ version :
 - Raw VVC bitstream parser, muxer and demuxer
 - Bitstream filter for editing metadata in VVC streams
 - Bitstream filter for converting VVC from MP4 to Annex B
+- VAAPI AV1 encoder
 
 version 6.0:
 - Radiance HDR image support
diff --git a/configure b/configure
index b018abf139..fbc729b5c6 100755
--- a/configure
+++ b/configure
@@ -3323,6 +3323,8 @@ av1_qsv_decoder_select="qsvdec"
 av1_qsv_encoder_select="qsvenc"
 av1_qsv_encoder_deps="libvpl"
 av1_amf_encoder_deps="amf"
+av1_vaapi_encoder_deps="VAEncPictureParameterBufferAV1"
+av1_vaapi_encoder_select="cbs_av1 vaapi_encode"
 
 # parsers
 aac_parser_select="adts_header mpeg4audio"
@@ -7104,6 +7106,7 @@ if enabled vaapi; then
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
 check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
+check_type "va/va.h va/va_enc_av1.h"  "VAEncPictureParameterBufferAV1"
 fi
 
 if enabled_all opencl libdrm ; then
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 25d6b7f09e..fb331ebd8e 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3991,6 +3991,19 @@ Average variable bitrate.
 Each encoder also has its own specific options:
 @table @option
 
+@item av1_vaapi
+@option{profile} sets the value of @emph{seq_profile}.
+@option{tier} sets the value of @emph{seq_tier}.
+@option{level} sets the value of @emph{seq_level_idx}.
+
+@table @option
+@item tiles
+Set the number of tiles to encode the input video with, as columns x rows.
+(default is 1x1).
+@item tile_groups
+Set tile groups number (default is 1).
+@end table
+
 @item h264_vaapi
 @option{profile} sets the value of @emph{profile_idc} and the 
@emph{constraint_set*_flag}s.
 @option{level} sets the value of @emph{level_idc}.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3cd5997e64..fe1e6aa99d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -259,6 +259,7 @@ OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER)  += mediacodecenc.o
 OBJS-$(CONFIG_AV1_NVENC_ENCODER)   += nvenc_av1.o nvenc.o
 OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
+OBJS-$(CONFIG_AV1_VAAPI_ENCODER)   += vaapi_encode_av1.o 
av1_profile_level.o
 OBJS-$(CONFIG_AVRN_DECODER)+= avrndec.o
 OBJS-$(CONFIG_AVRP_DECODER)+= r210dec.o
 OBJS-$(CONFIG_AVRP_ENCODER)+= r210enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8775d15a4f..c43c1d7b48 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -844,6 +844,7 @@ extern const FFCodec ff_av1_nvenc_encoder;
 extern const FFCodec ff_av1_qsv_decoder;
 extern const FFCodec ff_av1_qsv_encoder;
 extern const FFCodec ff_av1_amf_encoder;
+extern const FFCodec ff_av1_vaapi_encoder;
 extern const FFCodec ff_libopenh264_encoder;
 extern const FFCodec ff_libopenh264_decoder;
 extern const FFCodec ff_h264_amf_encoder;
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2604f12b9e..2907e159fb 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -669,6 +669,15 @@ static int 
vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 
+// AV1 packs P frame and next B frame into one pkt, and uses the other
+// repeat frame header pkt at the display order position of the P frame
+// to indicate its frame index. Each frame has a corresponding pkt in its
+// display order position. So don't need to consider delay for AV1 
timestamp.
+if (avctx->codec_id == AV_CODEC_ID_AV1) {
+pkt->dts = pkt->pts - ctx->dts_pts_diff;
+return 0;
+}
+
 if (ctx->output_delay == 0) {
 pkt->dts = pkt->pts;
 } else if (pic->encode_order < ctx->decode_delay) {
@@ -689,9 +698,10 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VACodedBufferSegment *buf_list, *buf;
-VAStatus vas;
+AVPacket *pkt_ptr = pkt;
 int total_size = 0;
 uint8_t *ptr;
+VAS

[FFmpeg-devel] [PATCH v2 5/6] lavc/vaapi_encode: Separate reference frame into previous/future list

2023-07-17 Thread Fei Wang
To support more reference frames from different directions.

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c   | 112 +---
 libavcodec/vaapi_encode.h   |  15 +++--
 libavcodec/vaapi_encode_h264.c  |  94 +--
 libavcodec/vaapi_encode_h265.c  |  76 +-
 libavcodec/vaapi_encode_mpeg2.c |   6 +-
 libavcodec/vaapi_encode_vp8.c   |   6 +-
 libavcodec/vaapi_encode_vp9.c   |  26 
 7 files changed, 208 insertions(+), 127 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index c8545cd8db..2604f12b9e 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -276,21 +276,34 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_DEBUG, "Issuing encode for pic %"PRId64"/%"PRId64" "
"as type %s.\n", pic->display_order, pic->encode_order,
picture_type_name[pic->type]);
-if (pic->nb_refs == 0) {
+if (pic->nb_refs[0] == 0 && pic->nb_refs[1] == 0) {
 av_log(avctx, AV_LOG_DEBUG, "No reference pictures.\n");
 } else {
-av_log(avctx, AV_LOG_DEBUG, "Refers to:");
-for (i = 0; i < pic->nb_refs; i++) {
+av_log(avctx, AV_LOG_DEBUG, "L0 refers to");
+for (i = 0; i < pic->nb_refs[0]; i++) {
 av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64,
-   pic->refs[i]->display_order, pic->refs[i]->encode_order);
+   pic->refs[0][i]->display_order, 
pic->refs[0][i]->encode_order);
 }
 av_log(avctx, AV_LOG_DEBUG, ".\n");
+
+if (pic->nb_refs[1]) {
+av_log(avctx, AV_LOG_DEBUG, "L1 refers to");
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64,
+   pic->refs[1][i]->display_order, 
pic->refs[1][i]->encode_order);
+}
+av_log(avctx, AV_LOG_DEBUG, ".\n");
+}
 }
 
 av_assert0(!pic->encode_issued);
-for (i = 0; i < pic->nb_refs; i++) {
-av_assert0(pic->refs[i]);
-av_assert0(pic->refs[i]->encode_issued);
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+av_assert0(pic->refs[0][i]->encode_issued);
+}
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+av_assert0(pic->refs[1][i]->encode_issued);
 }
 
 av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n", pic->input_surface);
@@ -832,8 +845,12 @@ static void vaapi_encode_add_ref(AVCodecContext *avctx,
 
 if (is_ref) {
 av_assert0(pic != target);
-av_assert0(pic->nb_refs < MAX_PICTURE_REFERENCES);
-pic->refs[pic->nb_refs++] = target;
+av_assert0(pic->nb_refs[0] < MAX_PICTURE_REFERENCES &&
+   pic->nb_refs[1] < MAX_PICTURE_REFERENCES);
+if (target->display_order < pic->display_order)
+pic->refs[0][pic->nb_refs[0]++] = target;
+else
+pic->refs[1][pic->nb_refs[1]++] = target;
 ++refs;
 }
 
@@ -862,10 +879,16 @@ static void vaapi_encode_remove_refs(AVCodecContext 
*avctx,
 if (pic->ref_removed[level])
 return;
 
-for (i = 0; i < pic->nb_refs; i++) {
-av_assert0(pic->refs[i]);
---pic->refs[i]->ref_count[level];
-av_assert0(pic->refs[i]->ref_count[level] >= 0);
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+--pic->refs[0][i]->ref_count[level];
+av_assert0(pic->refs[0][i]->ref_count[level] >= 0);
+}
+
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+--pic->refs[1][i]->ref_count[level];
+av_assert0(pic->refs[1][i]->ref_count[level] >= 0);
 }
 
 for (i = 0; i < pic->nb_dpb_pics; i++) {
@@ -910,7 +933,7 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 vaapi_encode_add_ref(avctx, pic, end,   1, 1, 0);
 vaapi_encode_add_ref(avctx, pic, prev,  0, 0, 1);
 
-for (ref = end->refs[1]; ref; ref = ref->refs[1])
+for (ref = end->refs[1][0]; ref; ref = ref->refs[1][0])
 vaapi_encode_add_ref(avctx, pic, ref, 0, 1, 0);
 }
 *last = prev;
@@ -933,7 +956,7 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 vaapi_encode_add_ref(avctx, pic, end,   1, 1, 0);
 vaapi_encode_add_ref(avctx, pic, prev,  0, 0, 1);
 
-for (ref = end->refs[1]; ref; ref = ref->refs[1])

[FFmpeg-devel] [PATCH v2 4/6] lavc/vaapi_encode: Extract set output pkt timestamp function

2023-07-17 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c | 37 -
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 8c9f14df66..c8545cd8db 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -650,6 +650,27 @@ fail_at_end:
 return err;
 }
 
+static int vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
+ VAAPIEncodePicture *pic,
+ AVPacket *pkt)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+
+if (ctx->output_delay == 0) {
+pkt->dts = pkt->pts;
+} else if (pic->encode_order < ctx->decode_delay) {
+if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
+pkt->dts = INT64_MIN;
+else
+pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
+} else {
+pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
+(3 * ctx->output_delay + ctx->async_depth)];
+}
+
+return 0;
+}
+
 static int vaapi_encode_output(AVCodecContext *avctx,
VAAPIEncodePicture *pic, AVPacket *pkt)
 {
@@ -1273,19 +1294,9 @@ int ff_vaapi_encode_receive_packet(AVCodecContext 
*avctx, AVPacket *pkt)
 return err;
 }
 
-if (ctx->output_delay == 0) {
-pkt->dts = pkt->pts;
-} else if (pic->encode_order < ctx->decode_delay) {
-if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
-pkt->dts = INT64_MIN;
-else
-pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
-} else {
-pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
-(3 * ctx->output_delay + ctx->async_depth)];
-}
-av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" dts 
%"PRId64".\n",
-   pkt->pts, pkt->dts);
+vaapi_encode_set_output_timestamp(avctx, pic, pkt);
+av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64", dts %"PRId64", "
+   "size %u bytes.\n", pkt->pts, pkt->dts, pkt->size);
 
 ctx->output_order = pic->encode_order;
 vaapi_encode_clear_old(avctx);
-- 
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 3/6] lavc/vaapi_encode: Init pic at the beginning of API

2023-07-17 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index bfca315a7a..8c9f14df66 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1205,7 +1205,7 @@ fail:
 int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodePicture *pic;
+VAAPIEncodePicture *pic = NULL;
 AVFrame *frame = ctx->frame;
 int err;
 
@@ -1228,8 +1228,6 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 }
 
 if (ctx->has_sync_buffer_func) {
-pic = NULL;
-
 if (av_fifo_can_write(ctx->encode_fifo)) {
 err = vaapi_encode_pick_next(avctx, &pic);
 if (!err) {
@@ -1255,7 +1253,6 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 av_fifo_read(ctx->encode_fifo, &pic, 1);
 ctx->encode_order = pic->encode_order + 1;
 } else {
-pic = NULL;
 err = vaapi_encode_pick_next(avctx, &pic);
 if (err < 0)
 return err;
-- 
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 2/6] lavc/av1: Add common code and unit test for level handling

2023-07-17 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/Makefile|   4 +-
 libavcodec/av1_profile_level.c |  91 
 libavcodec/av1_profile_level.h |  58 +++
 libavcodec/tests/.gitignore|   1 +
 libavcodec/tests/av1_levels.c  | 124 +
 tests/fate/libavcodec.mak  |   5 ++
 6 files changed, 282 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/av1_profile_level.c
 create mode 100644 libavcodec/av1_profile_level.h
 create mode 100644 libavcodec/tests/av1_levels.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1b0226c089..3cd5997e64 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -30,6 +30,7 @@ HEADERS = ac3_parser.h
  \
 OBJS = ac3_parser.o \
adts_parser.o\
allcodecs.o  \
+   av1_profile_level.o  \
avcodec.o\
avdct.o  \
avpacket.o   \
@@ -1308,7 +1309,8 @@ SKIPHEADERS-$(CONFIG_VULKAN)   += vulkan.h 
vulkan_video.h vulkan_decode.
 SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h 
v4l2_m2m.h
 SKIPHEADERS-$(CONFIG_ZLIB) += zlib_wrapper.h
 
-TESTPROGS = avcodec \
+TESTPROGS = av1_levels  \
+avcodec \
 avpacket\
 bitstream_be\
 bitstream_le\
diff --git a/libavcodec/av1_profile_level.c b/libavcodec/av1_profile_level.c
new file mode 100644
index 00..5aacf6ddb0
--- /dev/null
+++ b/libavcodec/av1_profile_level.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2023 Intel Corporation
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "av1_profile_level.h"
+
+/** ignore entries which named in spec but no details. Like level 2.2 and 7.0. 
*/
+static const AV1LevelDescriptor av1_levels[] = {
+// Name  MaxVSize   MainMbps   
   MaxTiles
+// |  level_idx | MaxDisplayRate| 
HighMbps | MaxTileCols
+// |  |   MaxPicSize|   | MaxDecodeRate || 
  MainCR|   |
+// |  | |MaxHSize   |   |   | MaxHeaderRate || 
| HighCR|   |
+// |  | ||  |   |   |   |   || 
|  ||   |
+{ "2.0",  0,   147456,  2048, 1152,   4423680, 5529600, 150,   1.5,
 0, 2, 0,   8,  4 },
+{ "2.1",  1,   278784,  2816, 1584,   8363520,10454400, 150,   3.0,
 0, 2, 0,   8,  4 },
+{ "3.0",  4,   665856,  4352, 2448,  19975680,24969600, 150,   6.0,
 0, 2, 0,  16,  6 },
+{ "3.1",  5,  1065024,  5504, 3096,  31950720,39938400, 150,  10.0,
 0, 2, 0,  16,  6 },
+{ "4.0",  8,  2359296,  6144, 3456,  70778880,77856768, 300,  12.0,  
30.0, 4, 4,  32,  8 },
+{ "4.1",  9,  2359296,  6144, 3456,  141557760,  155713536, 300,  20.0,  
50.0, 4, 4,  32,  8 },
+{ "5.0", 12,  8912896,  8192, 4352,  267386880,  273715200, 300,  30.0, 
100.0, 6, 4,  64,  8 },
+{ "5.1", 13,  8912896,  8192, 4352,  534773760,  547430400, 300,  40.0, 
160.0, 8, 4,  64,  8 },
+{ "5.2", 14,  8912896,  8192, 4352, 1069547520, 1094860800, 300,  60.0, 
240.0, 8, 4,  64,  8 },
+{ "5.3", 15,  8912896,  8192, 4352, 1069547520, 1176502272, 300,  60.0, 
240.0, 8, 4,  64,  8 },
+{ "6.0", 16, 35651584, 16384, 8704, 1069547520, 1176502272, 300,  60.0, 
240.0, 8, 4, 128, 16 },
+{ &quo

[FFmpeg-devel] [PATCH v2 1/6] avcodec/cbs_av1: Add tx mode enum values

2023-07-17 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/av1.h | 7 +++
 libavcodec/cbs_av1_syntax_template.c | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/av1.h b/libavcodec/av1.h
index 384f7cddc7..8704bc41c1 100644
--- a/libavcodec/av1.h
+++ b/libavcodec/av1.h
@@ -175,6 +175,13 @@ enum {
 AV1_RESTORE_SWITCHABLE = 3,
 };
 
+// TX mode (section 6.8.21)
+enum {
+AV1_ONLY_4X4= 0,
+AV1_TX_MODE_LARGEST = 1,
+AV1_TX_MODE_SELECT  = 2,
+};
+
 // Sequence Headers are actually unbounded because one can use
 // an arbitrary number of leading zeroes when encoding via uvlc.
 // The following estimate is based around using the lowest number
diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index a747e17784..3a5cafbfb7 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1028,9 +1028,9 @@ static int FUNC(read_tx_mode)(CodedBitstreamContext *ctx, 
RWContext *rw,
 int err;
 
 if (priv->coded_lossless)
-infer(tx_mode, 0);
+infer(tx_mode, AV1_ONLY_4X4);
 else
-increment(tx_mode, 1, 2);
+increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT);
 
 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 v1 6/6] lavc/vaapi_encode: Add VAAPI AV1 encoder

2023-07-10 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 Changelog |1 +
 configure |3 +
 doc/encoders.texi |   13 +
 libavcodec/Makefile   |1 +
 libavcodec/allcodecs.c|1 +
 libavcodec/vaapi_encode.c |  125 +++-
 libavcodec/vaapi_encode.h |   12 +
 libavcodec/vaapi_encode_av1.c | 1228 +
 8 files changed, 1366 insertions(+), 18 deletions(-)
 create mode 100644 libavcodec/vaapi_encode_av1.c

diff --git a/Changelog b/Changelog
index 3876082844..7ae9b85d52 100644
--- a/Changelog
+++ b/Changelog
@@ -25,6 +25,7 @@ version :
 - Raw VVC bitstream parser, muxer and demuxer
 - Bitstream filter for editing metadata in VVC streams
 - Bitstream filter for converting VVC from MP4 to Annex B
+- VAAPI AV1 encoder
 
 version 6.0:
 - Radiance HDR image support
diff --git a/configure b/configure
index 0ab0761011..6a1a30aaec 100755
--- a/configure
+++ b/configure
@@ -3323,6 +3323,8 @@ av1_qsv_decoder_select="qsvdec"
 av1_qsv_encoder_select="qsvenc"
 av1_qsv_encoder_deps="libvpl"
 av1_amf_encoder_deps="amf"
+av1_vaapi_encoder_deps="VAEncPictureParameterBufferAV1"
+av1_vaapi_encoder_select="cbs_av1 vaapi_encode"
 
 # parsers
 aac_parser_select="adts_header mpeg4audio"
@@ -7106,6 +7108,7 @@ if enabled vaapi; then
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
 check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
+check_type "va/va.h va/va_enc_av1.h"  "VAEncPictureParameterBufferAV1"
 fi
 
 if enabled_all opencl libdrm ; then
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 25d6b7f09e..fb331ebd8e 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3991,6 +3991,19 @@ Average variable bitrate.
 Each encoder also has its own specific options:
 @table @option
 
+@item av1_vaapi
+@option{profile} sets the value of @emph{seq_profile}.
+@option{tier} sets the value of @emph{seq_tier}.
+@option{level} sets the value of @emph{seq_level_idx}.
+
+@table @option
+@item tiles
+Set the number of tiles to encode the input video with, as columns x rows.
+(default is 1x1).
+@item tile_groups
+Set tile groups number (default is 1).
+@end table
+
 @item h264_vaapi
 @option{profile} sets the value of @emph{profile_idc} and the 
@emph{constraint_set*_flag}s.
 @option{level} sets the value of @emph{level_idc}.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3cd5997e64..fe1e6aa99d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -259,6 +259,7 @@ OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER)  += mediacodecenc.o
 OBJS-$(CONFIG_AV1_NVENC_ENCODER)   += nvenc_av1.o nvenc.o
 OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
+OBJS-$(CONFIG_AV1_VAAPI_ENCODER)   += vaapi_encode_av1.o 
av1_profile_level.o
 OBJS-$(CONFIG_AVRN_DECODER)+= avrndec.o
 OBJS-$(CONFIG_AVRP_DECODER)+= r210dec.o
 OBJS-$(CONFIG_AVRP_ENCODER)+= r210enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8775d15a4f..c43c1d7b48 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -844,6 +844,7 @@ extern const FFCodec ff_av1_nvenc_encoder;
 extern const FFCodec ff_av1_qsv_decoder;
 extern const FFCodec ff_av1_qsv_encoder;
 extern const FFCodec ff_av1_amf_encoder;
+extern const FFCodec ff_av1_vaapi_encoder;
 extern const FFCodec ff_libopenh264_encoder;
 extern const FFCodec ff_libopenh264_decoder;
 extern const FFCodec ff_h264_amf_encoder;
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2604f12b9e..2907e159fb 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -669,6 +669,15 @@ static int 
vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 
+// AV1 packs P frame and next B frame into one pkt, and uses the other
+// repeat frame header pkt at the display order position of the P frame
+// to indicate its frame index. Each frame has a corresponding pkt in its
+// display order position. So don't need to consider delay for AV1 
timestamp.
+if (avctx->codec_id == AV_CODEC_ID_AV1) {
+pkt->dts = pkt->pts - ctx->dts_pts_diff;
+return 0;
+}
+
 if (ctx->output_delay == 0) {
 pkt->dts = pkt->pts;
 } else if (pic->encode_order < ctx->decode_delay) {
@@ -689,9 +698,10 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VACodedBufferSegment *buf_list, *buf;
-VAStatus vas;
+AVPacket *pkt_ptr = pkt;
 int total_size = 0;
 uint8_t *ptr;
+VAStatus vas;
 int err;
 
 err = vaapi_en

[FFmpeg-devel] [PATCH v1 5/6] lavc/vaapi_encode: Separate reference frame into previous/future list

2023-07-10 Thread Fei Wang
To support more reference frames from different directions.

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c   | 112 +---
 libavcodec/vaapi_encode.h   |  15 +++--
 libavcodec/vaapi_encode_h264.c  |  94 +--
 libavcodec/vaapi_encode_h265.c  |  76 +-
 libavcodec/vaapi_encode_mpeg2.c |   6 +-
 libavcodec/vaapi_encode_vp8.c   |   6 +-
 libavcodec/vaapi_encode_vp9.c   |  26 
 7 files changed, 208 insertions(+), 127 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index c8545cd8db..2604f12b9e 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -276,21 +276,34 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_DEBUG, "Issuing encode for pic %"PRId64"/%"PRId64" "
"as type %s.\n", pic->display_order, pic->encode_order,
picture_type_name[pic->type]);
-if (pic->nb_refs == 0) {
+if (pic->nb_refs[0] == 0 && pic->nb_refs[1] == 0) {
 av_log(avctx, AV_LOG_DEBUG, "No reference pictures.\n");
 } else {
-av_log(avctx, AV_LOG_DEBUG, "Refers to:");
-for (i = 0; i < pic->nb_refs; i++) {
+av_log(avctx, AV_LOG_DEBUG, "L0 refers to");
+for (i = 0; i < pic->nb_refs[0]; i++) {
 av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64,
-   pic->refs[i]->display_order, pic->refs[i]->encode_order);
+   pic->refs[0][i]->display_order, 
pic->refs[0][i]->encode_order);
 }
 av_log(avctx, AV_LOG_DEBUG, ".\n");
+
+if (pic->nb_refs[1]) {
+av_log(avctx, AV_LOG_DEBUG, "L1 refers to");
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64,
+   pic->refs[1][i]->display_order, 
pic->refs[1][i]->encode_order);
+}
+av_log(avctx, AV_LOG_DEBUG, ".\n");
+}
 }
 
 av_assert0(!pic->encode_issued);
-for (i = 0; i < pic->nb_refs; i++) {
-av_assert0(pic->refs[i]);
-av_assert0(pic->refs[i]->encode_issued);
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+av_assert0(pic->refs[0][i]->encode_issued);
+}
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+av_assert0(pic->refs[1][i]->encode_issued);
 }
 
 av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n", pic->input_surface);
@@ -832,8 +845,12 @@ static void vaapi_encode_add_ref(AVCodecContext *avctx,
 
 if (is_ref) {
 av_assert0(pic != target);
-av_assert0(pic->nb_refs < MAX_PICTURE_REFERENCES);
-pic->refs[pic->nb_refs++] = target;
+av_assert0(pic->nb_refs[0] < MAX_PICTURE_REFERENCES &&
+   pic->nb_refs[1] < MAX_PICTURE_REFERENCES);
+if (target->display_order < pic->display_order)
+pic->refs[0][pic->nb_refs[0]++] = target;
+else
+pic->refs[1][pic->nb_refs[1]++] = target;
 ++refs;
 }
 
@@ -862,10 +879,16 @@ static void vaapi_encode_remove_refs(AVCodecContext 
*avctx,
 if (pic->ref_removed[level])
 return;
 
-for (i = 0; i < pic->nb_refs; i++) {
-av_assert0(pic->refs[i]);
---pic->refs[i]->ref_count[level];
-av_assert0(pic->refs[i]->ref_count[level] >= 0);
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+--pic->refs[0][i]->ref_count[level];
+av_assert0(pic->refs[0][i]->ref_count[level] >= 0);
+}
+
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+--pic->refs[1][i]->ref_count[level];
+av_assert0(pic->refs[1][i]->ref_count[level] >= 0);
 }
 
 for (i = 0; i < pic->nb_dpb_pics; i++) {
@@ -910,7 +933,7 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 vaapi_encode_add_ref(avctx, pic, end,   1, 1, 0);
 vaapi_encode_add_ref(avctx, pic, prev,  0, 0, 1);
 
-for (ref = end->refs[1]; ref; ref = ref->refs[1])
+for (ref = end->refs[1][0]; ref; ref = ref->refs[1][0])
 vaapi_encode_add_ref(avctx, pic, ref, 0, 1, 0);
 }
 *last = prev;
@@ -933,7 +956,7 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 vaapi_encode_add_ref(avctx, pic, end,   1, 1, 0);
 vaapi_encode_add_ref(avctx, pic, prev,  0, 0, 1);
 
-for (ref = end->refs[1]; ref; ref = ref->refs[1])

[FFmpeg-devel] [PATCH v1 4/6] lavc/vaapi_encode: Extract set output pkt timestamp function

2023-07-10 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c | 37 -
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 8c9f14df66..c8545cd8db 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -650,6 +650,27 @@ fail_at_end:
 return err;
 }
 
+static int vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
+ VAAPIEncodePicture *pic,
+ AVPacket *pkt)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+
+if (ctx->output_delay == 0) {
+pkt->dts = pkt->pts;
+} else if (pic->encode_order < ctx->decode_delay) {
+if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
+pkt->dts = INT64_MIN;
+else
+pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
+} else {
+pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
+(3 * ctx->output_delay + ctx->async_depth)];
+}
+
+return 0;
+}
+
 static int vaapi_encode_output(AVCodecContext *avctx,
VAAPIEncodePicture *pic, AVPacket *pkt)
 {
@@ -1273,19 +1294,9 @@ int ff_vaapi_encode_receive_packet(AVCodecContext 
*avctx, AVPacket *pkt)
 return err;
 }
 
-if (ctx->output_delay == 0) {
-pkt->dts = pkt->pts;
-} else if (pic->encode_order < ctx->decode_delay) {
-if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
-pkt->dts = INT64_MIN;
-else
-pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
-} else {
-pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
-(3 * ctx->output_delay + ctx->async_depth)];
-}
-av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" dts 
%"PRId64".\n",
-   pkt->pts, pkt->dts);
+vaapi_encode_set_output_timestamp(avctx, pic, pkt);
+av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64", dts %"PRId64", "
+   "size %u bytes.\n", pkt->pts, pkt->dts, pkt->size);
 
 ctx->output_order = pic->encode_order;
 vaapi_encode_clear_old(avctx);
-- 
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 v1 3/6] lavc/vaapi_encode: Init pic at the beginning of API

2023-07-10 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index bfca315a7a..8c9f14df66 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1205,7 +1205,7 @@ fail:
 int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodePicture *pic;
+VAAPIEncodePicture *pic = NULL;
 AVFrame *frame = ctx->frame;
 int err;
 
@@ -1228,8 +1228,6 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 }
 
 if (ctx->has_sync_buffer_func) {
-pic = NULL;
-
 if (av_fifo_can_write(ctx->encode_fifo)) {
 err = vaapi_encode_pick_next(avctx, &pic);
 if (!err) {
@@ -1255,7 +1253,6 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 av_fifo_read(ctx->encode_fifo, &pic, 1);
 ctx->encode_order = pic->encode_order + 1;
 } else {
-pic = NULL;
 err = vaapi_encode_pick_next(avctx, &pic);
 if (err < 0)
 return err;
-- 
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 v1 2/6] lavc/av1: Add common code and unit test for level handling

2023-07-10 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/Makefile|   4 +-
 libavcodec/av1_profile_level.c |  91 
 libavcodec/av1_profile_level.h |  58 +++
 libavcodec/tests/.gitignore|   1 +
 libavcodec/tests/av1_levels.c  | 124 +
 tests/fate/libavcodec.mak  |   5 ++
 6 files changed, 282 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/av1_profile_level.c
 create mode 100644 libavcodec/av1_profile_level.h
 create mode 100644 libavcodec/tests/av1_levels.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1b0226c089..3cd5997e64 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -30,6 +30,7 @@ HEADERS = ac3_parser.h
  \
 OBJS = ac3_parser.o \
adts_parser.o\
allcodecs.o  \
+   av1_profile_level.o  \
avcodec.o\
avdct.o  \
avpacket.o   \
@@ -1308,7 +1309,8 @@ SKIPHEADERS-$(CONFIG_VULKAN)   += vulkan.h 
vulkan_video.h vulkan_decode.
 SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h 
v4l2_m2m.h
 SKIPHEADERS-$(CONFIG_ZLIB) += zlib_wrapper.h
 
-TESTPROGS = avcodec \
+TESTPROGS = av1_levels  \
+avcodec \
 avpacket\
 bitstream_be\
 bitstream_le\
diff --git a/libavcodec/av1_profile_level.c b/libavcodec/av1_profile_level.c
new file mode 100644
index 00..5aacf6ddb0
--- /dev/null
+++ b/libavcodec/av1_profile_level.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2023 Intel Corporation
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "av1_profile_level.h"
+
+/** ignore entries which named in spec but no details. Like level 2.2 and 7.0. 
*/
+static const AV1LevelDescriptor av1_levels[] = {
+// Name  MaxVSize   MainMbps   
   MaxTiles
+// |  level_idx | MaxDisplayRate| 
HighMbps | MaxTileCols
+// |  |   MaxPicSize|   | MaxDecodeRate || 
  MainCR|   |
+// |  | |MaxHSize   |   |   | MaxHeaderRate || 
| HighCR|   |
+// |  | ||  |   |   |   |   || 
|  ||   |
+{ "2.0",  0,   147456,  2048, 1152,   4423680, 5529600, 150,   1.5,
 0, 2, 0,   8,  4 },
+{ "2.1",  1,   278784,  2816, 1584,   8363520,10454400, 150,   3.0,
 0, 2, 0,   8,  4 },
+{ "3.0",  4,   665856,  4352, 2448,  19975680,24969600, 150,   6.0,
 0, 2, 0,  16,  6 },
+{ "3.1",  5,  1065024,  5504, 3096,  31950720,39938400, 150,  10.0,
 0, 2, 0,  16,  6 },
+{ "4.0",  8,  2359296,  6144, 3456,  70778880,77856768, 300,  12.0,  
30.0, 4, 4,  32,  8 },
+{ "4.1",  9,  2359296,  6144, 3456,  141557760,  155713536, 300,  20.0,  
50.0, 4, 4,  32,  8 },
+{ "5.0", 12,  8912896,  8192, 4352,  267386880,  273715200, 300,  30.0, 
100.0, 6, 4,  64,  8 },
+{ "5.1", 13,  8912896,  8192, 4352,  534773760,  547430400, 300,  40.0, 
160.0, 8, 4,  64,  8 },
+{ "5.2", 14,  8912896,  8192, 4352, 1069547520, 1094860800, 300,  60.0, 
240.0, 8, 4,  64,  8 },
+{ "5.3", 15,  8912896,  8192, 4352, 1069547520, 1176502272, 300,  60.0, 
240.0, 8, 4,  64,  8 },
+{ "6.0", 16, 35651584, 16384, 8704, 1069547520, 1176502272, 300,  60.0, 
240.0, 8, 4, 128, 16 },
+{ &quo

[FFmpeg-devel] [PATCH v1 1/6] avcodec/cbs_av1: Add tx mode enum values

2023-07-10 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/av1.h | 7 +++
 libavcodec/cbs_av1_syntax_template.c | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/av1.h b/libavcodec/av1.h
index 384f7cddc7..8704bc41c1 100644
--- a/libavcodec/av1.h
+++ b/libavcodec/av1.h
@@ -175,6 +175,13 @@ enum {
 AV1_RESTORE_SWITCHABLE = 3,
 };
 
+// TX mode (section 6.8.21)
+enum {
+AV1_ONLY_4X4= 0,
+AV1_TX_MODE_LARGEST = 1,
+AV1_TX_MODE_SELECT  = 2,
+};
+
 // Sequence Headers are actually unbounded because one can use
 // an arbitrary number of leading zeroes when encoding via uvlc.
 // The following estimate is based around using the lowest number
diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index a747e17784..3a5cafbfb7 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1028,9 +1028,9 @@ static int FUNC(read_tx_mode)(CodedBitstreamContext *ctx, 
RWContext *rw,
 int err;
 
 if (priv->coded_lossless)
-infer(tx_mode, 0);
+infer(tx_mode, AV1_ONLY_4X4);
 else
-increment(tx_mode, 1, 2);
+increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT);
 
 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] fftools/ffmpeg_dec: Don't keep sending frame to filters in flushing

2023-06-26 Thread Fei Wang
Filter may has a limited frame pool size. Do not always send frame to
filters without reaping.

Fix the regression of commit 5fa00b38e6.

Example cmd:
$ ffmpeg -threads 20 -init_hw_device vaapi=hw:/dev/dri/renderD128   \
-hwaccel_output_format vaapi -hwaccel vaapi -i avc_1080P.mp4\
-vf 'scale_vaapi=w=720:h=480' -f null -

Signed-off-by: Fei Wang 
---
Change:
1. rebase to master.

 fftools/ffmpeg_dec.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 85bf8dc536..a7ae51fed2 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -803,6 +803,12 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int 
no_eof)
 av_frame_unref(d->frame);
 if (ret < 0)
 goto finish;
+
+// During flushing, break out to reap filter once send a frame to 
filters to
+// avoid drain out filter's output frame pool. Especially for HW 
filters which
+// always have a limited frame pool size.
+if (!pkt)
+return 0;
 }
 
 finish:
-- 
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 3/3] lavfi/{denoise, procamp, scale, sharpness}_vaapi: Add passthrough mode

2023-06-15 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavfilter/vaapi_vpp.c| 15 ---
 libavfilter/vaapi_vpp.h|  2 ++
 libavfilter/vf_misc_vaapi.c|  9 +
 libavfilter/vf_procamp_vaapi.c | 10 ++
 libavfilter/vf_scale_vaapi.c   | 13 +
 5 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 4de19564e9..cf2592e068 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -95,6 +95,7 @@ int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
 int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 {
 AVFilterContext *avctx = outlink->src;
+AVFilterLink   *inlink = avctx->inputs[0];
 VAAPIVPPContext *ctx   = avctx->priv;
 AVVAAPIHWConfig *hwconfig = NULL;
 AVHWFramesConstraints *constraints = NULL;
@@ -111,6 +112,17 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 if (!ctx->output_height)
 ctx->output_height = avctx->inputs[0]->h;
 
+outlink->w = ctx->output_width;
+outlink->h = ctx->output_height;
+
+if (ctx->passthrough) {
+if (inlink->hw_frames_ctx)
+outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
+av_log(ctx, AV_LOG_VERBOSE, "Using VAAPI filter passthrough mode.\n");
+
+return 0;
+}
+
 av_assert0(ctx->input_frames);
 ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
 if (!ctx->device_ref) {
@@ -214,9 +226,6 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 return AVERROR(EIO);
 }
 
-outlink->w = ctx->output_width;
-outlink->h = ctx->output_height;
-
 if (ctx->build_filter_params) {
 err = ctx->build_filter_params(avctx);
 if (err < 0)
diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h
index cc845b854c..6764ab0c39 100644
--- a/libavfilter/vaapi_vpp.h
+++ b/libavfilter/vaapi_vpp.h
@@ -56,6 +56,8 @@ typedef struct VAAPIVPPContext {
 VABufferID filter_buffers[VAProcFilterCount];
 intnb_filter_buffers;
 
+int passthrough;
+
 int (*build_filter_params)(AVFilterContext *avctx);
 
 void (*pipeline_uninit)(AVFilterContext *avctx);
diff --git a/libavfilter/vf_misc_vaapi.c b/libavfilter/vf_misc_vaapi.c
index db3e69679a..71bc5e3c34 100644
--- a/libavfilter/vf_misc_vaapi.c
+++ b/libavfilter/vf_misc_vaapi.c
@@ -131,6 +131,9 @@ static int misc_vaapi_filter_frame(AVFilterLink *inlink, 
AVFrame *input_frame)
av_get_pix_fmt_name(input_frame->format),
input_frame->width, input_frame->height, input_frame->pts);
 
+if (vpp_ctx->passthrough)
+return ff_filter_frame(outlink, input_frame);
+
 if (vpp_ctx->va_context == VA_INVALID_ID)
 return AVERROR(EINVAL);
 
@@ -176,11 +179,14 @@ fail:
 static av_cold int denoise_vaapi_init(AVFilterContext *avctx)
 {
 VAAPIVPPContext *vpp_ctx = avctx->priv;
+DenoiseVAAPIContext *ctx = avctx->priv;
 
 ff_vaapi_vpp_ctx_init(avctx);
 vpp_ctx->pipeline_uninit = ff_vaapi_vpp_pipeline_uninit;
 vpp_ctx->build_filter_params = denoise_vaapi_build_filter_params;
 vpp_ctx->output_format   = AV_PIX_FMT_NONE;
+if (ctx->denoise == DENOISE_DEFAULT)
+vpp_ctx->passthrough = 1;
 
 return 0;
 }
@@ -188,11 +194,14 @@ static av_cold int denoise_vaapi_init(AVFilterContext 
*avctx)
 static av_cold int sharpness_vaapi_init(AVFilterContext *avctx)
 {
 VAAPIVPPContext *vpp_ctx = avctx->priv;
+SharpnessVAAPIContext *ctx = avctx->priv;
 
 ff_vaapi_vpp_ctx_init(avctx);
 vpp_ctx->pipeline_uninit = ff_vaapi_vpp_pipeline_uninit;
 vpp_ctx->build_filter_params = sharpness_vaapi_build_filter_params;
 vpp_ctx->output_format   = AV_PIX_FMT_NONE;
+if (ctx->sharpness == SHARPNESS_DEFAULT)
+vpp_ctx->passthrough = 1;
 
 return 0;
 }
diff --git a/libavfilter/vf_procamp_vaapi.c b/libavfilter/vf_procamp_vaapi.c
index 4a3b9d0766..acfc72947c 100644
--- a/libavfilter/vf_procamp_vaapi.c
+++ b/libavfilter/vf_procamp_vaapi.c
@@ -136,6 +136,9 @@ static int procamp_vaapi_filter_frame(AVFilterLink *inlink, 
AVFrame *input_frame
av_get_pix_fmt_name(input_frame->format),
input_frame->width, input_frame->height, input_frame->pts);
 
+if (vpp_ctx->passthrough)
+return ff_filter_frame(outlink, input_frame);
+
 if (vpp_ctx->va_context == VA_INVALID_ID)
 return AVERROR(EINVAL);
 
@@ -179,11 +182,18 @@ fail:
 static av_cold int procamp_vaapi_init(AVFilterContext *avctx)
 {
 VAAPIVPPContext *vpp_ctx = avctx->priv;
+ProcampVAAPIContext *ctx = avctx->priv;
+float eps = 1.0e-10f;
 
 ff_vaapi_vpp_ctx_init(avctx);
 vpp_ctx->pipeline_uninit = ff_vaapi_vpp_pipeline_uninit;
 vpp_ctx->build_filter_params = procamp_vaapi_build_f

[FFmpeg-devel] [PATCH v2 2/3] lavfi/vaapi: Add some debug message

2023-06-15 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavfilter/vaapi_vpp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 10d31977c6..4de19564e9 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -554,6 +554,10 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
 if (err < 0)
 return err;
 
+av_log(avctx, AV_LOG_DEBUG, "Filter frame from surface %#x to %#x.\n",
+   ff_vaapi_vpp_get_surface_id(input_frame),
+   ff_vaapi_vpp_get_surface_id(output_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 v2 1/3] lavfi/vaapi: Add function to get surface ID from AVFrame

2023-06-15 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavfilter/vaapi_vpp.c | 10 ++
 libavfilter/vaapi_vpp.h |  5 +
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index a323dab8b8..10d31977c6 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -518,7 +518,6 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
  AVFrame *output_frame)
 {
 VAAPIVPPContext *ctx = avctx->priv;
-VASurfaceID input_surface;
 int err;
 
 ctx->input_region = (VARectangle) {
@@ -534,10 +533,8 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
 output_frame->crop_left   = 0;
 output_frame->crop_right  = 0;
 
-input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3],
-
 *params = (VAProcPipelineParameterBuffer) {
-.surface = input_surface,
+.surface = ff_vaapi_vpp_get_surface_id(input_frame),
 .surface_region  = &ctx->input_region,
 .output_region   = NULL,
 .output_background_color = VAAPI_VPP_BACKGROUND_BLACK,
@@ -623,7 +620,6 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
  AVFrame *output_frame)
 {
 VAAPIVPPContext *ctx = avctx->priv;
-VASurfaceID output_surface;
 VABufferID *params_ids;
 VAStatus vas;
 int err;
@@ -635,10 +631,8 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
 for (int i = 0; i < cout; i++)
 params_ids[i] = VA_INVALID_ID;
 
-output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3];
-
 vas = vaBeginPicture(ctx->hwctx->display,
- ctx->va_context, output_surface);
+ ctx->va_context, 
ff_vaapi_vpp_get_surface_id(output_frame));
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to attach new picture: "
"%d (%s).\n", vas, vaErrorStr(vas));
diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h
index ead07036dc..cc845b854c 100644
--- a/libavfilter/vaapi_vpp.h
+++ b/libavfilter/vaapi_vpp.h
@@ -27,6 +27,11 @@
 
 #include "avfilter.h"
 
+static inline VASurfaceID ff_vaapi_vpp_get_surface_id(const AVFrame *frame)
+{
+return (uintptr_t)frame->data[3];
+}
+
 // ARGB black, for VAProcPipelineParameterBuffer.output_background_color.
 #define VAAPI_VPP_BACKGROUND_BLACK 0xff00
 
-- 
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 v1] fftools/ffmpeg_dec: Don't keep sending frame to filters in flushing

2023-06-11 Thread Fei Wang
Filter may has a limited frame pool size. Do not always send frame to
filters without reaping.

Fix the regression of commit 5fa00b38e6.

Example cmd:
$ ffmpeg -threads 20 -init_hw_device vaapi=hw:/dev/dri/renderD128   \
-hwaccel_output_format vaapi -hwaccel vaapi -i avc_1080P.mp4\
-vf 'scale_vaapi=w=720:h=480' -f null -

Signed-off-by: Fei Wang 
---
 fftools/ffmpeg_dec.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 799be63215..d6b34402f8 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -531,6 +531,12 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int 
no_eof)
 av_frame_unref(frame);
 if (ret < 0)
 exit_program(1);
+
+// During flushing, break out to reap filter once send a frame to 
filters to
+// avoid drain out filter's output frame pool. Especially for HW 
filters which
+// always have a limited frame pool size.
+if (!pkt)
+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 v1 3/3] lavfi/{denoise, procamp, scale, sharpness}_vaapi: Add passthrough mode

2023-05-29 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavfilter/vaapi_vpp.c| 15 ---
 libavfilter/vaapi_vpp.h|  2 ++
 libavfilter/vf_misc_vaapi.c|  9 +
 libavfilter/vf_procamp_vaapi.c | 10 ++
 libavfilter/vf_scale_vaapi.c   |  9 +
 5 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 4de19564e9..cf2592e068 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -95,6 +95,7 @@ int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
 int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 {
 AVFilterContext *avctx = outlink->src;
+AVFilterLink   *inlink = avctx->inputs[0];
 VAAPIVPPContext *ctx   = avctx->priv;
 AVVAAPIHWConfig *hwconfig = NULL;
 AVHWFramesConstraints *constraints = NULL;
@@ -111,6 +112,17 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 if (!ctx->output_height)
 ctx->output_height = avctx->inputs[0]->h;
 
+outlink->w = ctx->output_width;
+outlink->h = ctx->output_height;
+
+if (ctx->passthrough) {
+if (inlink->hw_frames_ctx)
+outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
+av_log(ctx, AV_LOG_VERBOSE, "Using VAAPI filter passthrough mode.\n");
+
+return 0;
+}
+
 av_assert0(ctx->input_frames);
 ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
 if (!ctx->device_ref) {
@@ -214,9 +226,6 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 return AVERROR(EIO);
 }
 
-outlink->w = ctx->output_width;
-outlink->h = ctx->output_height;
-
 if (ctx->build_filter_params) {
 err = ctx->build_filter_params(avctx);
 if (err < 0)
diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h
index cc845b854c..6764ab0c39 100644
--- a/libavfilter/vaapi_vpp.h
+++ b/libavfilter/vaapi_vpp.h
@@ -56,6 +56,8 @@ typedef struct VAAPIVPPContext {
 VABufferID filter_buffers[VAProcFilterCount];
 intnb_filter_buffers;
 
+int passthrough;
+
 int (*build_filter_params)(AVFilterContext *avctx);
 
 void (*pipeline_uninit)(AVFilterContext *avctx);
diff --git a/libavfilter/vf_misc_vaapi.c b/libavfilter/vf_misc_vaapi.c
index db3e69679a..0a4c174ab9 100644
--- a/libavfilter/vf_misc_vaapi.c
+++ b/libavfilter/vf_misc_vaapi.c
@@ -131,6 +131,9 @@ static int misc_vaapi_filter_frame(AVFilterLink *inlink, 
AVFrame *input_frame)
av_get_pix_fmt_name(input_frame->format),
input_frame->width, input_frame->height, input_frame->pts);
 
+if (vpp_ctx->passthrough)
+return ff_filter_frame(outlink, input_frame);
+
 if (vpp_ctx->va_context == VA_INVALID_ID)
 return AVERROR(EINVAL);
 
@@ -176,11 +179,14 @@ fail:
 static av_cold int denoise_vaapi_init(AVFilterContext *avctx)
 {
 VAAPIVPPContext *vpp_ctx = avctx->priv;
+DenoiseVAAPIContext *ctx = avctx->priv;
 
 ff_vaapi_vpp_ctx_init(avctx);
 vpp_ctx->pipeline_uninit = ff_vaapi_vpp_pipeline_uninit;
 vpp_ctx->build_filter_params = denoise_vaapi_build_filter_params;
 vpp_ctx->output_format   = AV_PIX_FMT_NONE;
+if (!ctx->denoise)
+vpp_ctx->passthrough = 1;
 
 return 0;
 }
@@ -188,11 +194,14 @@ static av_cold int denoise_vaapi_init(AVFilterContext 
*avctx)
 static av_cold int sharpness_vaapi_init(AVFilterContext *avctx)
 {
 VAAPIVPPContext *vpp_ctx = avctx->priv;
+SharpnessVAAPIContext *ctx = avctx->priv;
 
 ff_vaapi_vpp_ctx_init(avctx);
 vpp_ctx->pipeline_uninit = ff_vaapi_vpp_pipeline_uninit;
 vpp_ctx->build_filter_params = sharpness_vaapi_build_filter_params;
 vpp_ctx->output_format   = AV_PIX_FMT_NONE;
+if (!ctx->sharpness)
+vpp_ctx->passthrough = 1;
 
 return 0;
 }
diff --git a/libavfilter/vf_procamp_vaapi.c b/libavfilter/vf_procamp_vaapi.c
index 4a3b9d0766..82c446dc76 100644
--- a/libavfilter/vf_procamp_vaapi.c
+++ b/libavfilter/vf_procamp_vaapi.c
@@ -136,6 +136,9 @@ static int procamp_vaapi_filter_frame(AVFilterLink *inlink, 
AVFrame *input_frame
av_get_pix_fmt_name(input_frame->format),
input_frame->width, input_frame->height, input_frame->pts);
 
+if (vpp_ctx->passthrough)
+return ff_filter_frame(outlink, input_frame);
+
 if (vpp_ctx->va_context == VA_INVALID_ID)
 return AVERROR(EINVAL);
 
@@ -179,11 +182,18 @@ fail:
 static av_cold int procamp_vaapi_init(AVFilterContext *avctx)
 {
 VAAPIVPPContext *vpp_ctx = avctx->priv;
+ProcampVAAPIContext *ctx = avctx->priv;
+float eps = 0.0001;
 
 ff_vaapi_vpp_ctx_init(avctx);
 vpp_ctx->pipeline_uninit = ff_vaapi_vpp_pipeline_uninit;
 vpp_ctx->build_filter_params = procamp_vaapi_build_filter_params;
 vpp_ctx->output_format  

[FFmpeg-devel] [PATCH v1 2/3] lavfi/vaapi: Add some debug message

2023-05-29 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavfilter/vaapi_vpp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 10d31977c6..4de19564e9 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -554,6 +554,10 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
 if (err < 0)
 return err;
 
+av_log(avctx, AV_LOG_DEBUG, "Filter frame from surface %#x to %#x.\n",
+   ff_vaapi_vpp_get_surface_id(input_frame),
+   ff_vaapi_vpp_get_surface_id(output_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 v1 1/3] lavfi/vaapi: Add function to get surface ID from AVFrame

2023-05-29 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavfilter/vaapi_vpp.c | 10 ++
 libavfilter/vaapi_vpp.h |  5 +
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index a323dab8b8..10d31977c6 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -518,7 +518,6 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
  AVFrame *output_frame)
 {
 VAAPIVPPContext *ctx = avctx->priv;
-VASurfaceID input_surface;
 int err;
 
 ctx->input_region = (VARectangle) {
@@ -534,10 +533,8 @@ int ff_vaapi_vpp_init_params(AVFilterContext *avctx,
 output_frame->crop_left   = 0;
 output_frame->crop_right  = 0;
 
-input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3],
-
 *params = (VAProcPipelineParameterBuffer) {
-.surface = input_surface,
+.surface = ff_vaapi_vpp_get_surface_id(input_frame),
 .surface_region  = &ctx->input_region,
 .output_region   = NULL,
 .output_background_color = VAAPI_VPP_BACKGROUND_BLACK,
@@ -623,7 +620,6 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
  AVFrame *output_frame)
 {
 VAAPIVPPContext *ctx = avctx->priv;
-VASurfaceID output_surface;
 VABufferID *params_ids;
 VAStatus vas;
 int err;
@@ -635,10 +631,8 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
 for (int i = 0; i < cout; i++)
 params_ids[i] = VA_INVALID_ID;
 
-output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3];
-
 vas = vaBeginPicture(ctx->hwctx->display,
- ctx->va_context, output_surface);
+ ctx->va_context, 
ff_vaapi_vpp_get_surface_id(output_frame));
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to attach new picture: "
"%d (%s).\n", vas, vaErrorStr(vas));
diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h
index ead07036dc..cc845b854c 100644
--- a/libavfilter/vaapi_vpp.h
+++ b/libavfilter/vaapi_vpp.h
@@ -27,6 +27,11 @@
 
 #include "avfilter.h"
 
+static inline VASurfaceID ff_vaapi_vpp_get_surface_id(const AVFrame *frame)
+{
+return (uintptr_t)frame->data[3];
+}
+
 // ARGB black, for VAProcPipelineParameterBuffer.output_background_color.
 #define VAAPI_VPP_BACKGROUND_BLACK 0xff00
 
-- 
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 v1] lavc/vp9: Add RGB* formats for VAAPI hwaccel

2023-02-27 Thread Fei Wang
Signed-off-by: Fei Wang 
---
 libavcodec/vp9.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7c0a246446..7ff387faf4 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -239,6 +239,13 @@ static int update_size(AVCodecContext *avctx, int w, int h)
 case AV_PIX_FMT_YUV444P12:
 #if CONFIG_VP9_VAAPI_HWACCEL
 *fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+break;
+case AV_PIX_FMT_GBRP:
+case AV_PIX_FMT_GBRP10:
+case AV_PIX_FMT_GBRP12:
+#if CONFIG_VP9_VAAPI_HWACCEL
+*fmtp++ = AV_PIX_FMT_VAAPI;
 #endif
 break;
 }
-- 
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 v1] lavu/hwcontext_vaapi: sync surface before export its DRM handle

2023-02-23 Thread Fei Wang
According to description of vaExportSurfaceHandle in libva, vaSyncSurface
must be called if the contents of the surface will be read.

Fixes ticket #9967.

Signed-off-by: Fei Wang 
---
 libavutil/hwcontext_vaapi.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 938bd5447d..90c2c191d9 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1319,8 +1319,17 @@ static int vaapi_map_to_drm_esh(AVHWFramesContext *hwfc, 
AVFrame *dst,
 surface_id = (VASurfaceID)(uintptr_t)src->data[3];
 
 export_flags = VA_EXPORT_SURFACE_SEPARATE_LAYERS;
-if (flags & AV_HWFRAME_MAP_READ)
+if (flags & AV_HWFRAME_MAP_READ) {
 export_flags |= VA_EXPORT_SURFACE_READ_ONLY;
+
+vas = vaSyncSurface(hwctx->display, surface_id);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(hwfc, AV_LOG_ERROR, "Failed to sync surface "
+   "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
+return AVERROR(EIO);
+}
+}
+
 if (flags & AV_HWFRAME_MAP_WRITE)
 export_flags |= VA_EXPORT_SURFACE_WRITE_ONLY;
 
-- 
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 v7 08/10] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2023-02-15 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..ab8c12e364 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_rext_scc_profile ),
+MAP(HEVC,HEVC_SCC,None,
+ ff_vaapi_parse_hevc_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index a7b541750c..1cf43bd4dc 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -591,9 +591,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_rext_scc_profile(AVCodecContext *avctx)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
@@ -632,6 +632,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..449635d0d7 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_rext_scc_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".


[FFmpeg-devel] [PATCH v7 07/10] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2023-02-15 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 | 57 +
 1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 20fb36adfa..a7b541750c 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -126,6 +126,10 @@ static int vaapi_hevc_start_frame(AVCodecContext  
*avctx,
 const ScalingList *scaling_list = NULL;
 int pic_param_size, err, i;
 
+#if VA_CHECK_VERSION(1, 2, 0)
+int num_comps, pre_palette_size;
+#endif
+
 VAPictureParameterBufferHEVC *pic_param = (VAPictureParameterBufferHEVC 
*)&pic->pic_param;
 
 pic->pic.output_surface = ff_vaapi_get_surface_id(h->ref->frame);
@@ -218,7 +222,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,
@@ -245,8 +250,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 (int j = 0; j < pre_palette_size; j++)
+pic->pic_param.scc.predictor_palette_entries[comp][j] =
+pps->pps_palette_predictor_initializers_present_flag ?
+pps->pps_palette_predictor_initializer[comp][j]:
+sps->sps_palette_predictor_initializer[comp][j];
+}
+
 #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 +342,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->las

[FFmpeg-devel] [PATCH v7 10/10] lavc/vaapi_hevc: Loose the restricts for SCC decoding

2023-02-15 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index a06785f7a6..0e5da15e53 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++;
 }
-- 
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 v7 09/10] lavc/vaapi_hevc: Set correct rps type for scc

2023-02-15 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 1cf43bd4dc..a06785f7a6 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 v7 06/10] lavc/hevc: Update reference list for SCC

2023-02-15 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 v7 05/10] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2023-02-15 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 v7 04/10] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2023-02-15 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 v7 02/10] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2023-02-15 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 | 289 +--
 libavcodec/hevc_ps.h |  69 +++
 3 files changed, 349 insertions(+), 12 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 4aa5b76d5f..348e4d8de2 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;
+  

[FFmpeg-devel] [PATCH v7 03/10] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2023-02-15 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 v7 01/10] lavc/avcodec: Add HEVC Screen Content Coding Extensions profile

2023-02-15 Thread Fei Wang
From: Linjie Fu 

Described in HEVC spec A.3.7. Bump minor version and add APIchanges
entry for new added profile.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
1. fix warning of patchwork report for V6.

 doc/APIchanges| 3 +++
 libavcodec/avcodec.h  | 1 +
 libavcodec/hevc_ps.c  | 2 ++
 libavcodec/profiles.c | 1 +
 libavcodec/version.h  | 2 +-
 5 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 29161e30bf..196f681730 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-02-16 - xx - lavc 60.3.100 - avcodec.h
+  Add FF_PROFILE_HEVC_SCC.
+
 2023-02-16 - xx - lavf 60.2.100 - avformat.h
   Deprecate AVFormatContext io_close callback.
   The superior io_close2 callback should be used instead.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 39881a1d2b..9a0fe97cad 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1654,6 +1654,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 5fe62ec35b..4aa5b76d5f 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 },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 0550d7b0d8..43794ea588 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR   2
+#define LIBAVCODEC_VERSION_MINOR   3
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
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 v6 08/10] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2023-02-15 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..ab8c12e364 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_rext_scc_profile ),
+MAP(HEVC,HEVC_SCC,None,
+ ff_vaapi_parse_hevc_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index a7b541750c..1cf43bd4dc 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -591,9 +591,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_rext_scc_profile(AVCodecContext *avctx)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
@@ -632,6 +632,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..449635d0d7 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_rext_scc_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".


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

2023-02-15 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 1cf43bd4dc..a06785f7a6 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 v6 10/10] lavc/vaapi_hevc: Loose the restricts for SCC decoding

2023-02-15 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index a06785f7a6..0e5da15e53 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++;
 }
-- 
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 v6 07/10] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2023-02-15 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 | 57 +
 1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 20fb36adfa..a7b541750c 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -126,6 +126,10 @@ static int vaapi_hevc_start_frame(AVCodecContext  
*avctx,
 const ScalingList *scaling_list = NULL;
 int pic_param_size, err, i;
 
+#if VA_CHECK_VERSION(1, 2, 0)
+int num_comps, pre_palette_size;
+#endif
+
 VAPictureParameterBufferHEVC *pic_param = (VAPictureParameterBufferHEVC 
*)&pic->pic_param;
 
 pic->pic.output_surface = ff_vaapi_get_surface_id(h->ref->frame);
@@ -218,7 +222,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,
@@ -245,8 +250,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 (int j = 0; j < pre_palette_size; j++)
+pic->pic_param.scc.predictor_palette_entries[comp][j] =
+pps->pps_palette_predictor_initializers_present_flag ?
+pps->pps_palette_predictor_initializer[comp][j]:
+sps->sps_palette_predictor_initializer[comp][j];
+}
+
 #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 +342,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->las

[FFmpeg-devel] [PATCH v6 06/10] lavc/hevc: Update reference list for SCC

2023-02-15 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 v6 05/10] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2023-02-15 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 v6 04/10] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2023-02-15 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 v6 03/10] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2023-02-15 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 v6 02/10] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2023-02-15 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 | 289 +--
 libavcodec/hevc_ps.h |  69 +++
 3 files changed, 349 insertions(+), 12 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 4aa5b76d5f..348e4d8de2 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;
+  

[FFmpeg-devel] [PATCH v6 01/10] lavc/avcodec: Add HEVC Screen Content Coding Extensions profile

2023-02-15 Thread Fei Wang
From: Linjie Fu 

Described in HEVC spec A.3.7. Bump minor version and add APIchanges
entry for new added profile.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
update:
1. bump minor version and add APIchanges entry for new profile.

 doc/APIchanges| 3 +++
 libavcodec/avcodec.h  | 1 +
 libavcodec/hevc_ps.c  | 2 ++
 libavcodec/profiles.c | 1 +
 libavcodec/version.h  | 2 +-
 5 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 3ca724724b..5ab4a9c94f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-02-14 - xx - lavc 60.3.100 - avcodec.h
+  Add FF_PROFILE_HEVC_SCC.
+
 2023-02-13 - xx - lavu 58.1.100 - frame.h
   Deprecate AVFrame.coded_picture_number and display_picture_number.
   Their usefulness is questionable and very few decoders set them.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 39881a1d2b..9a0fe97cad 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1654,6 +1654,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 5fe62ec35b..4aa5b76d5f 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 },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 0550d7b0d8..43794ea588 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR   2
+#define LIBAVCODEC_VERSION_MINOR   3
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
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 v5 08/10] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2023-02-05 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..ab8c12e364 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_rext_scc_profile ),
+MAP(HEVC,HEVC_SCC,None,
+ ff_vaapi_parse_hevc_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index a7b541750c..1cf43bd4dc 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -591,9 +591,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_rext_scc_profile(AVCodecContext *avctx)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
@@ -632,6 +632,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..449635d0d7 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_rext_scc_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".


[FFmpeg-devel] [PATCH v5 10/10] lavc/vaapi_hevc: Loose the restricts for SCC decoding

2023-02-05 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index a06785f7a6..0e5da15e53 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++;
 }
-- 
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 v5 07/10] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2023-02-05 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 | 57 +
 1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 20fb36adfa..a7b541750c 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -126,6 +126,10 @@ static int vaapi_hevc_start_frame(AVCodecContext  
*avctx,
 const ScalingList *scaling_list = NULL;
 int pic_param_size, err, i;
 
+#if VA_CHECK_VERSION(1, 2, 0)
+int num_comps, pre_palette_size;
+#endif
+
 VAPictureParameterBufferHEVC *pic_param = (VAPictureParameterBufferHEVC 
*)&pic->pic_param;
 
 pic->pic.output_surface = ff_vaapi_get_surface_id(h->ref->frame);
@@ -218,7 +222,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,
@@ -245,8 +250,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 (int j = 0; j < pre_palette_size; j++)
+pic->pic_param.scc.predictor_palette_entries[comp][j] =
+pps->pps_palette_predictor_initializers_present_flag ?
+pps->pps_palette_predictor_initializer[comp][j]:
+sps->sps_palette_predictor_initializer[comp][j];
+}
+
 #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 +342,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->las

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

2023-02-05 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 1cf43bd4dc..a06785f7a6 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 v5 06/10] lavc/hevc: Update reference list for SCC

2023-02-05 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 v5 05/10] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2023-02-05 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 v5 04/10] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2023-02-05 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 v5 03/10] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2023-02-05 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 v5 02/10] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2023-02-05 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 | 289 +--
 libavcodec/hevc_ps.h |  69 +++
 3 files changed, 349 insertions(+), 12 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 4aa5b76d5f..348e4d8de2 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;
+  

[FFmpeg-devel] [PATCH v5 01/10] lavc/avcodec: Add HEVC Screen Content Coding Extensions profile

2023-02-05 Thread Fei Wang
From: Linjie Fu 

Described in HEVC spec A.3.7.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
1. fix compile warning with VAAPI version less than 1.2.0

 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 90b437ccbe..9e36d2402a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1672,6 +1672,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 5fe62ec35b..4aa5b76d5f 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 v4 07/10] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2023-02-02 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..73a8f5b4ce 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 (int j = 0; j < pre_palette_size; j++)
+pic->pic_param.scc.predictor_palette_entries[comp][j] =
+pps->pps_palette_predictor_initializers_present_flag ?
+pps->pps_palette_predictor_initializer[comp][j]:
+sps->sps_palette_predictor_initializer[comp][j];
+}
+
 #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) 

[FFmpeg-devel] [PATCH v4 10/10] lavc/vaapi_hevc: Loose the restricts for SCC decoding

2023-02-02 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 29c75e88f0..42e1b62fc3 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 v4 09/10] lavc/vaapi_hevc: Set correct rps type for scc

2023-02-02 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 c10617a81a..29c75e88f0 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 v4 06/10] lavc/hevc: Update reference list for SCC

2023-02-02 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 v4 08/10] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2023-02-02 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..ab8c12e364 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_rext_scc_profile ),
+MAP(HEVC,HEVC_SCC,None,
+ ff_vaapi_parse_hevc_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 73a8f5b4ce..c10617a81a 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_rext_scc_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..449635d0d7 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_rext_scc_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".


[FFmpeg-devel] [PATCH v4 05/10] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2023-02-02 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 v4 04/10] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2023-02-02 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 v4 03/10] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2023-02-02 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 v4 02/10] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2023-02-02 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 | 289 +--
 libavcodec/hevc_ps.h |  69 +++
 3 files changed, 349 insertions(+), 12 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 4aa5b76d5f..348e4d8de2 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;
+  

[FFmpeg-devel] [PATCH v4 01/10] lavc/avcodec: Add HEVC Screen Content Coding Extensions profile

2023-02-02 Thread Fei Wang
From: Linjie Fu 

Described in HEVC spec A.3.7.

Signed-off-by: Linjie Fu 
Signed-off-by: Fei Wang 
---
update: fix accidential fail in FATE.

 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 90b437ccbe..9e36d2402a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1672,6 +1672,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 5fe62ec35b..4aa5b76d5f 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 v3 08/11] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2023-01-03 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..73a8f5b4ce 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 (int j = 0; j < pre_palette_size; j++)
+pic->pic_param.scc.predictor_palette_entries[comp][j] =
+pps->pps_palette_predictor_initializers_present_flag ?
+pps->pps_palette_predictor_initializer[comp][j]:
+sps->sps_palette_predictor_initializer[comp][j];
+}
+
 #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) 

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

2023-01-03 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 29c75e88f0..42e1b62fc3 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 v3 07/11] lavc/hevc: Update reference list for SCC

2023-01-03 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 v3 10/11] lavc/vaapi_hevc: Set correct rps type for scc

2023-01-03 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 c10617a81a..29c75e88f0 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 v3 09/11] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2023-01-03 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..ab8c12e364 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_rext_scc_profile ),
+MAP(HEVC,HEVC_SCC,None,
+ ff_vaapi_parse_hevc_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 73a8f5b4ce..c10617a81a 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_rext_scc_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..449635d0d7 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_rext_scc_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".


[FFmpeg-devel] [PATCH v3 06/11] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2023-01-03 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 v3 05/11] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2023-01-03 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 v3 04/11] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2023-01-03 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 v3 03/11] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2023-01-03 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 | 287 +--
 libavcodec/hevc_ps.h |  69 +++
 3 files changed, 348 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..0672acb706 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;
+  

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

2023-01-03 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 0ac581d660..8d77b05ba0 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 v3 01/11] lavc/hevc_ps: remove profile limitation of pps_range_extensions()

2023-01-03 Thread Fei Wang
Follow spec 7.3.2.3.1.

Signed-off-by: Fei Wang 
---
update:
1. fix some code style.
2. seperate patchset into 2.

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


[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 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 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 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 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 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 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) : 
size

[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 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 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;
+  

[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 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 v1 13/13] lavc/vaapi_hevc: Remove duplicate code

2022-12-01 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 v1 12/13] avcodec/hevcdec: Replace number with enum

2022-12-01 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 v1 08/13] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2022-12-01 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) : 
size

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

2022-12-01 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 v1 10/13] lavc/vaapi_hevc: Set correct rps type for scc

2022-12-01 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 v1 09/13] lavc/vaapi_hevc: Add vaapi profile parse support for SCC

2022-12-01 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".


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

2022-12-01 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 50e7fd4465..bd8199d1dd 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -669,7 +669,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;
 }
@@ -3256,6 +3257,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 v1 06/13] lavc/hevcdec: Set max_num_merge_cand to uint8_t

2022-12-01 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 v1 05/13] lavc/hevcdec: Fix the parsing for use_integer_mv_flag

2022-12-01 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 edf3a2b134..50e7fd4465 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -840,6 +840,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 v1 04/13] lavc/hevcdec: Add slice parse support for HEVC SCC extension

2022-12-01 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 fb44d8d3f2..edf3a2b134 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -857,6 +857,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 v1 03/13] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

2022-12-01 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 | 293 +--
 libavcodec/hevc_ps.h |  69 ++
 3 files changed, 357 insertions(+), 8 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 3052f58779..086b1d4002 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -910,7 +910,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
@@ -1131,8 +1131,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);
@@ -1158,6 +1162,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;
+  

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

2022-12-01 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 b7ba24a72d..3052f58779 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -278,6 +278,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 v1 01/13] lavc/hevc_ps: remove profile limitation of pps_range_extensions()

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

Signed-off-by: Fei Wang 
---
 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 f665d8053c..b7ba24a72d 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1715,7 +1715,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 v5 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT

2022-11-13 Thread Fei Wang
This can fix vp9 decode image corruption when the frame size is change,
but the pervious frames still be referenced.

Surfaces don't need to be bound to vaContext only after VAAPI 1.0.0:
https://github.com/intel/libva/commit/492b692005ccd0d8da190209d5b3ae7b7825f4b8

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_decode.c | 11 ---
 libavcodec/vaapi_decode.h |  1 +
 libavcodec/vaapi_vp9.c|  4 
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 134f10eca5..d950471b6d 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -658,9 +658,6 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
 VAStatus vas;
 int err;
 
-ctx->va_config  = VA_INVALID_ID;
-ctx->va_context = VA_INVALID_ID;
-
 err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VAAPI);
 if (err < 0)
 goto fail;
@@ -670,6 +667,12 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
 ctx->device = ctx->frames->device_ctx;
 ctx->hwctx  = ctx->device->hwctx;
 
+if (ctx->inited)
+return 0;
+
+ctx->va_config  = VA_INVALID_ID;
+ctx->va_context = VA_INVALID_ID;
+
 err = vaapi_decode_make_config(avctx, ctx->frames->device_ref,
&ctx->va_config, NULL);
 if (err)
@@ -691,6 +694,8 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: "
"%#x/%#x.\n", ctx->va_config, ctx->va_context);
 
+ctx->inited = 1;
+
 return 0;
 
 fail:
diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
index 6beda14e52..62a4f37ed9 100644
--- a/libavcodec/vaapi_decode.h
+++ b/libavcodec/vaapi_decode.h
@@ -61,6 +61,7 @@ typedef struct VAAPIDecodeContext {
 int   surface_count;
 
 VASurfaceAttrib   pixel_format_attribute;
+int   inited;
 } VAAPIDecodeContext;
 
 
diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c
index 776382f683..245b7a1b3a 100644
--- a/libavcodec/vaapi_vp9.c
+++ b/libavcodec/vaapi_vp9.c
@@ -181,5 +181,9 @@ const AVHWAccel ff_vp9_vaapi_hwaccel = {
 .uninit   = ff_vaapi_decode_uninit,
 .frame_params = ff_vaapi_common_frame_params,
 .priv_data_size   = sizeof(VAAPIDecodeContext),
+#if VA_CHECK_VERSION(1, 0, 0)
+.caps_internal= HWACCEL_CAP_ASYNC_SAFE | 
HWACCEL_CAP_RESET_WITHOUT_UNINIT,
+#else
 .caps_internal= HWACCEL_CAP_ASYNC_SAFE,
+#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".


  1   2   3   >