[FFmpeg-devel] libaomdec: add row_mt option

Submitted by Tristan Matthews on Sept. 26, 2018, 12:21 p.m.

Details

Message ID 20180926122138.8471-1-tmatth@videolan.org
State New
Headers show

Commit Message

Tristan Matthews Sept. 26, 2018, 12:21 p.m.
Partially fixes #7456
---
 libavcodec/libaomdec.c | 62 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

Comments

Hendrik Leppkes Sept. 26, 2018, 1:35 p.m.
On Wed, Sep 26, 2018 at 2:27 PM Tristan Matthews <tmatth@videolan.org> wrote:
>
> Partially fixes #7456
> ---

row-mt is enabled by default in recent libaom versions, and they even
removed the option for it from aomdec, so do we really need that
option?

- Hendrik
Tristan Matthews Sept. 26, 2018, 5:22 p.m.
On Wed, Sep 26, 2018 at 9:43 AM Hendrik Leppkes <h.leppkes@gmail.com> wrote:

> On Wed, Sep 26, 2018 at 2:27 PM Tristan Matthews <tmatth@videolan.org>
> wrote:
> >
> > Partially fixes #7456
> > ---
>
> row-mt is enabled by default in recent libaom versions, and they even
> removed the option for it from aomdec, so do we really need that
> option?
>

I'm fine with dropping the option (unless someone has a good reason for
wanting to disable row_mt), but I'd still suggest doing the explicit codec
control call.

Best,
Tristan


> - Hendrik
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Patch hide | download patch | download mbox

diff --git a/libavcodec/libaomdec.c b/libavcodec/libaomdec.c
index 2530c9f76b..6740f98be1 100644
--- a/libavcodec/libaomdec.c
+++ b/libavcodec/libaomdec.c
@@ -23,20 +23,63 @@ 
  * AV1 decoder support via libaom
  */
 
+#define AOM_DISABLE_CTRL_TYPECHECKS 1
 #include <aom/aom_decoder.h>
 #include <aom/aomdx.h>
 
 #include "libavutil/common.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
 
 #include "avcodec.h"
 #include "internal.h"
 #include "profiles.h"
 
 typedef struct AV1DecodeContext {
+    AVClass *class;
     struct aom_codec_ctx decoder;
+    int row_mt;
 } AV1DecodeContext;
 
+static const char *const ctlidstr[] = {
+    [AV1D_SET_ROW_MT]          = "AV1D_SET_ROW_MT",
+};
+
+
+static av_cold void log_decoder_error(AVCodecContext *avctx, const char *desc)
+{
+    AV1DecodeContext *ctx    = avctx->priv_data;
+    const char *error  = aom_codec_error(&ctx->decoder);
+    const char *detail = aom_codec_error_detail(&ctx->decoder);
+
+    av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
+    if (detail)
+        av_log(avctx, AV_LOG_ERROR, "  Additional information: %s\n", detail);
+}
+
+static av_cold int codecctl_int(AVCodecContext *avctx,
+                                enum aom_dec_control_id id, int val)
+{
+    AV1DecodeContext *ctx = avctx->priv_data;
+    char buf[80];
+    int width = -30;
+    int res;
+
+    snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
+    av_log(avctx, AV_LOG_DEBUG, "  %*s%d\n", width, buf, val);
+
+    res = aom_codec_control(&ctx->decoder, id, val);
+    if (res != AOM_CODEC_OK) {
+        snprintf(buf, sizeof(buf), "Failed to set %s codec control",
+                 ctlidstr[id]);
+        log_decoder_error(avctx, buf);
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
+}
+
+
 static av_cold int aom_init(AVCodecContext *avctx,
                             const struct aom_codec_iface *iface)
 {
@@ -56,6 +99,10 @@  static av_cold int aom_init(AVCodecContext *avctx,
         return AVERROR(EINVAL);
     }
 
+    // codec control failures are currently treated only as warnings
+    av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
+    codecctl_int(avctx, AV1D_SET_ROW_MT, ctx->row_mt);
+
     return 0;
 }
 
@@ -220,6 +267,20 @@  static av_cold int av1_init(AVCodecContext *avctx)
     return aom_init(avctx, &aom_codec_av1_dx_algo);
 }
 
+#define OFFSET(x) offsetof(AV1DecodeContext, x)
+#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+    { "row-mt", "Enable row-based multithreading", OFFSET(row_mt), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VD},
+    { NULL },
+};
+
+static const AVClass class_aom = {
+    .class_name = "libaom-av1 decoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_libaom_av1_decoder = {
     .name           = "libaom-av1",
     .long_name      = NULL_IF_CONFIG_SMALL("libaom AV1"),
@@ -231,5 +292,6 @@  AVCodec ff_libaom_av1_decoder = {
     .decode         = aom_decode,
     .capabilities   = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1,
     .profiles       = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
+    .priv_class     = &class_aom,
     .wrapper_name   = "libaom",
 };