diff mbox series

[FFmpeg-devel] lavc: replace AVCodecInternal.allocate_progress with an internal cap

Message ID 20200316081530.1706-1-anton@khirnov.net
State Accepted
Headers show
Series [FFmpeg-devel] lavc: replace AVCodecInternal.allocate_progress with an internal cap
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Anton Khirnov March 16, 2020, 8:15 a.m. UTC
This is a constant codec property, so a capability flag is more appropriate.
---
Updated for wavpack changes
---
 doc/multithreading.txt     |  5 +++--
 libavcodec/ffv1dec.c       |  4 +---
 libavcodec/h264dec.c       |  5 ++---
 libavcodec/hevcdec.c       |  5 ++---
 libavcodec/internal.h      | 20 +++++---------------
 libavcodec/mimic.c         |  3 +--
 libavcodec/mpeg4videodec.c |  4 ++--
 libavcodec/pngdec.c        | 10 ++++++----
 libavcodec/pthread_frame.c |  4 ++--
 libavcodec/rv30.c          |  1 +
 libavcodec/rv34.c          |  2 --
 libavcodec/rv40.c          |  1 +
 libavcodec/vp3.c           |  6 +++---
 libavcodec/vp8.c           |  2 +-
 libavcodec/vp9.c           |  4 ++--
 libavcodec/wavpack.c       |  5 ++---
 16 files changed, 34 insertions(+), 47 deletions(-)
diff mbox series

Patch

diff --git a/doc/multithreading.txt b/doc/multithreading.txt
index 83849deacc..5b9dcb0bfc 100644
--- a/doc/multithreading.txt
+++ b/doc/multithreading.txt
@@ -58,9 +58,10 @@  Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very lit
 speed gain at this point but it should work.
 
 If there are inter-frame dependencies, so the codec calls
-ff_thread_report/await_progress(), set AVCodecInternal.allocate_progress. The
+ff_thread_report/await_progress(), set FF_CODEC_CAP_ALLOCATE_PROGRESS in
+AVCodec.caps_internal and use ff_thread_get_buffer() to allocate frames. The
 frames must then be freed with ff_thread_release_buffer().
-Otherwise leave it at zero and decode directly into the user-supplied frames.
+Otherwise decode directly into the user-supplied frames.
 
 Call ff_thread_report_progress() after some part of the current picture has decoded.
 A good place to put this is where draw_horiz_band() is called - add this if it isn't
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index ca1286f413..2ffd3ef991 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -826,8 +826,6 @@  static av_cold int decode_init(AVCodecContext *avctx)
     if ((ret = ff_ffv1_init_slice_contexts(f)) < 0)
         return ret;
 
-    avctx->internal->allocate_progress = 1;
-
     return 0;
 }
 
@@ -1094,5 +1092,5 @@  AVCodec ff_ffv1_decoder = {
     .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
     .capabilities   = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |
                       AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8a2a8a7b41..67c50f9fbd 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -426,8 +426,6 @@  static av_cold int h264_decode_init(AVCodecContext *avctx)
         h->avctx->has_b_frames = h->ps.sps->num_reorder_frames;
     }
 
-    avctx->internal->allocate_progress = 1;
-
     ff_h264_flush_change(h);
 
     if (h->enable_er < 0 && (avctx->active_thread_type & FF_THREAD_SLICE))
@@ -1082,7 +1080,8 @@  AVCodec ff_h264_decoder = {
 #endif
                                NULL
                            },
-    .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING,
+    .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING |
+                             FF_CODEC_CAP_ALLOCATE_PROGRESS,
     .flush                 = flush_dpb,
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context),
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 7448be482c..58689a4370 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3491,8 +3491,6 @@  static av_cold int hevc_decode_init(AVCodecContext *avctx)
     HEVCContext *s = avctx->priv_data;
     int ret;
 
-    avctx->internal->allocate_progress = 1;
-
     ret = hevc_init_context(avctx);
     if (ret < 0)
         return ret;
@@ -3582,7 +3580,8 @@  AVCodec ff_hevc_decoder = {
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(hevc_init_thread_copy),
     .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
                              AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
-    .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING,
+    .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING |
+                             FF_CODEC_CAP_ALLOCATE_PROGRESS,
     .profiles              = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
     .hw_configs            = (const AVCodecHWConfigInternal*[]) {
 #if CONFIG_HEVC_DXVA2_HWACCEL
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index bccd9222d4..700807cd75 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -68,6 +68,11 @@ 
  * Codec initializes slice-based threading with a main function
  */
 #define FF_CODEC_CAP_SLICE_THREAD_HAS_MF    (1 << 5)
+/*
+ * The codec supports frame threading and has inter-frame dependencies, so it
+ * uses ff_thread_report/await_progress().
+ */
+#define FF_CODEC_CAP_ALLOCATE_PROGRESS      (1 << 6)
 
 /**
  * AVCodec.codec_tags termination value
@@ -141,21 +146,6 @@  typedef struct AVCodecInternal {
      */
     int is_copy;
 
-    /**
-     * Whether to allocate progress for frame threading.
-     *
-     * The codec must set it to 1 if it uses ff_thread_await/report_progress(),
-     * then progress will be allocated in ff_thread_get_buffer(). The frames
-     * then MUST be freed with ff_thread_release_buffer().
-     *
-     * If the codec does not need to call the progress functions (there are no
-     * dependencies between the frames), it should leave this at 0. Then it can
-     * decode straight to the user-provided frames (which the user will then
-     * free with av_frame_unref()), there is no need to call
-     * ff_thread_release_buffer().
-     */
-    int allocate_progress;
-
     /**
      * An audio frame with less than required samples has been submitted and
      * padded with silence. Reject all subsequent frames.
diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index 1d463e9962..8e3a77a334 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -139,8 +139,6 @@  static av_cold int mimic_decode_init(AVCodecContext *avctx)
     MimicContext *ctx = avctx->priv_data;
     int ret, i;
 
-    avctx->internal->allocate_progress = 1;
-
     ctx->prev_index = 0;
     ctx->cur_index  = 15;
 
@@ -481,4 +479,5 @@  AVCodec ff_mimic_decoder = {
     .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
     .update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context),
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(mimic_init_thread_copy),
+    .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index a51985d51b..b985484b93 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3549,7 +3549,6 @@  static av_cold int decode_init(AVCodecContext *avctx)
     ctx->time_increment_bits = 4; /* default value for broken headers */
 
     avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
-    avctx->internal->allocate_progress = 1;
 
     return 0;
 }
@@ -3595,7 +3594,8 @@  AVCodec ff_mpeg4_decoder = {
     .capabilities          = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
                              AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |
                              AV_CODEC_CAP_FRAME_THREADS,
-    .caps_internal         = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
+    .caps_internal         = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
+                             FF_CODEC_CAP_ALLOCATE_PROGRESS,
     .flush                 = ff_mpeg_flush,
     .max_lowres            = 3,
     .pix_fmts              = ff_h263_hwaccel_pixfmt_list_420,
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 3ce980fc15..af8608b23b 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1772,7 +1772,6 @@  static av_cold int png_dec_init(AVCodecContext *avctx)
     }
 
     if (!avctx->internal->is_copy) {
-        avctx->internal->allocate_progress = 1;
         ff_pngdsp_init(&s->dsp);
     }
 
@@ -1812,7 +1811,8 @@  AVCodec ff_apng_decoder = {
     .init_thread_copy = ONLY_IF_THREADS_ENABLED(png_dec_init),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
-    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE |
+                      FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 #endif
 
@@ -1829,7 +1829,8 @@  AVCodec ff_png_decoder = {
     .init_thread_copy = ONLY_IF_THREADS_ENABLED(png_dec_init),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
-    .caps_internal  = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE,
+    .caps_internal  = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE |
+                      FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 #endif
 
@@ -1845,6 +1846,7 @@  AVCodec ff_lscr_decoder = {
     .decode         = decode_frame_lscr,
     .flush          = decode_flush,
     .capabilities   = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
-    .caps_internal  = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE,
+    .caps_internal  = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE |
+                      FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 #endif
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index b5bd494474..6f122d98e2 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -201,7 +201,7 @@  static attribute_align_arg void *frame_worker_thread(void *arg)
         p->result = codec->decode(avctx, p->frame, &p->got_frame, &p->avpkt);
 
         if ((p->result < 0 || !p->got_frame) && p->frame->buf[0]) {
-            if (avctx->internal->allocate_progress)
+            if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS)
                 av_log(avctx, AV_LOG_ERROR, "A frame threaded decoder did not "
                        "free the frame on failure. This is a bug, please report it.\n");
             av_frame_unref(p->frame);
@@ -896,7 +896,7 @@  static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int
         return -1;
     }
 
-    if (avctx->internal->allocate_progress) {
+    if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) {
         atomic_int *progress;
         f->progress = av_buffer_alloc(2 * sizeof(*progress));
         if (!f->progress) {
diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c
index ddaaac651c..0a63352e6b 100644
--- a/libavcodec/rv30.c
+++ b/libavcodec/rv30.c
@@ -306,4 +306,5 @@  AVCodec ff_rv30_decoder = {
     },
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context),
+    .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index d171e6e1bd..f877258db6 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1526,8 +1526,6 @@  av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
     if(!intra_vlcs[0].cbppattern[0].bits)
         rv34_init_tables();
 
-    avctx->internal->allocate_progress = 1;
-
     return 0;
 }
 
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index dfeebda838..ad15044ee3 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -585,4 +585,5 @@  AVCodec ff_rv40_decoder = {
     },
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context),
+    .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 903871e93d..5057137430 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -2330,8 +2330,6 @@  static av_cold int vp3_decode_init(AVCodecContext *avctx)
     if (ret < 0)
         return ret;
 
-    avctx->internal->allocate_progress = 1;
-
     if (avctx->codec_tag == MKTAG('V', 'P', '4', '0'))
         s->version = 3;
     else if (avctx->codec_tag == MKTAG('V', 'P', '3', '0'))
@@ -3268,7 +3266,7 @@  AVCodec ff_theora_decoder = {
     .flush                 = vp3_decode_flush,
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
-    .caps_internal         = FF_CODEC_CAP_EXPORTS_CROPPING,
+    .caps_internal         = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 #endif
 
@@ -3286,6 +3284,7 @@  AVCodec ff_vp3_decoder = {
     .flush                 = vp3_decode_flush,
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
+    .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 
 #if CONFIG_VP4_DECODER
@@ -3303,5 +3302,6 @@  AVCodec ff_vp4_decoder = {
     .flush                 = vp3_decode_flush,
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
+    .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 #endif
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index b4deb3ed67..81da0422be 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2853,7 +2853,6 @@  int vp78_decode_init(AVCodecContext *avctx, int is_vp7)
     s->vp7   = avctx->codec->id == AV_CODEC_ID_VP7;
     s->pix_fmt = AV_PIX_FMT_NONE;
     avctx->pix_fmt = AV_PIX_FMT_YUV420P;
-    avctx->internal->allocate_progress = 1;
 
     ff_videodsp_init(&s->vdsp, 8);
 
@@ -2988,5 +2987,6 @@  AVCodec ff_vp8_decoder = {
 #endif
                                NULL
                            },
+    .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
 #endif /* CONFIG_VP7_DECODER */
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7aaae9b792..f4d3a56580 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1730,7 +1730,6 @@  static av_cold int vp9_decode_init(AVCodecContext *avctx)
 {
     VP9Context *s = avctx->priv_data;
 
-    avctx->internal->allocate_progress = 1;
     s->last_bpp = 0;
     s->s.h.filter.sharpness = -1;
 
@@ -1799,7 +1798,8 @@  AVCodec ff_vp9_decoder = {
     .close                 = vp9_decode_free,
     .decode                = vp9_decode_frame,
     .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
-    .caps_internal         = FF_CODEC_CAP_SLICE_THREAD_HAS_MF,
+    .caps_internal         = FF_CODEC_CAP_SLICE_THREAD_HAS_MF |
+                             FF_CODEC_CAP_ALLOCATE_PROGRESS,
     .flush                 = vp9_decode_flush,
     .init_thread_copy      = ONLY_IF_THREADS_ENABLED(vp9_decode_init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(vp9_decode_update_thread_context),
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index b27262b94e..2a2a2b7690 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1020,8 +1020,6 @@  static av_cold int wavpack_decode_init(AVCodecContext *avctx)
 
     s->fdec_num = 0;
 
-    avctx->internal->allocate_progress = 1;
-
     s->curr_frame.f = av_frame_alloc();
     s->prev_frame.f = av_frame_alloc();
 
@@ -1661,5 +1659,6 @@  AVCodec ff_wavpack_decoder = {
     .init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
-                      AV_CODEC_CAP_SLICE_THREADS
+                      AV_CODEC_CAP_SLICE_THREADS,
+    .caps_internal  = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };