diff mbox series

[FFmpeg-devel,3/4] avcodec/nvenc: Add single slice intra refresh support

Message ID 1630579138-6145-3-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/nvenc: make number of slices per frame configurable | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Lance Wang Sept. 2, 2021, 10:38 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/nvenc.c      | 23 +++++++++++++++++++++++
 libavcodec/nvenc.h      |  2 ++
 libavcodec/nvenc_h264.c |  2 ++
 libavcodec/nvenc_hevc.c |  2 ++
 4 files changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index e739f8b..79f3253 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -529,6 +529,23 @@  static int nvenc_check_capabilities(AVCodecContext *avctx)
     }
 #endif
 
+#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
+    ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH);
+    if(ctx->single_slice_intra_refresh && ret <= 0) {
+        av_log(avctx, AV_LOG_WARNING, "Single slice intra refresh not supported by the device\n");
+        return AVERROR(ENOSYS);
+    }
+#else
+    if(ctx->single_slice_intra_refresh) {
+        av_log(avctx, AV_LOG_WARNING, "Single slice intra refresh need SDK 11.1 at build time\n");
+        return AVERROR(ENOSYS);
+    }
+#endif
+
+    /* force to enable intra refresh */
+    if(ctx->single_slice_intra_refresh)
+        ctx->intra_refresh = 1;
+
     ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_INTRA_REFRESH);
     if(ctx->intra_refresh && ret <= 0) {
         av_log(avctx, AV_LOG_WARNING, "Intra refresh not supported by the device\n");
@@ -1086,6 +1103,9 @@  static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
         h264->enableIntraRefresh = 1;
         h264->intraRefreshPeriod = avctx->gop_size;
         h264->intraRefreshCnt = avctx->gop_size - 1;
+#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
+        h264->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
+#endif
     }
 
     h264->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
@@ -1189,6 +1209,9 @@  static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
         hevc->enableIntraRefresh = 1;
         hevc->intraRefreshPeriod = avctx->gop_size;
         hevc->intraRefreshCnt = avctx->gop_size - 1;
+#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
+        hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
+#endif
     }
 
     hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index e7cc0e6..1e756a6 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -73,6 +73,7 @@  typedef void ID3D11Device;
 // SDK 11.1 compile time feature checks
 #if NVENCAPI_CHECK_VERSION(11, 1)
 #define NVENC_HAVE_QP_CHROMA_OFFSETS
+#define NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
 #endif
 
 typedef struct NvencSurface
@@ -231,6 +232,7 @@  typedef struct NvencContext
     int ldkfs;
     int extra_sei;
     int intra_refresh;
+    int single_slice_intra_refresh;
 } NvencContext;
 
 int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index 532dff3..1a46e70 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -190,6 +190,8 @@  static const AVOption options[] = {
                                                             OFFSET(extra_sei),    AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0, 1, VE },
     { "intra_refresh", "Use Periodic Intra Refresh instead of IDR frames.",
                                                             OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
+    { "single_slice_intra_refresh", "Use single slice intra refresh.",
+                                                            OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { NULL }
 };
 
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index 6814fe1..8c89d6e 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -171,6 +171,8 @@  static const AVOption options[] = {
                                                             OFFSET(extra_sei),    AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0, 1, VE },
     { "intra_refresh", "Use Periodic Intra Refresh instead of IDR frames.",
                                                             OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
+    { "single_slice_intra_refresh", "Use single slice intra refresh.",
+                                                            OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { NULL }
 };