From patchwork Fri Oct 18 10:22:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Semashev X-Patchwork-Id: 15839 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6FB6E44A75D for ; Fri, 18 Oct 2019 13:22:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F85668AD3D; Fri, 18 Oct 2019 13:22:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED90C68AD18 for ; Fri, 18 Oct 2019 13:22:29 +0300 (EEST) Received: by mail-lj1-f193.google.com with SMTP id j19so5671321lja.1 for ; Fri, 18 Oct 2019 03:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YBAqAlzSCQZdlmXyjYYjUW76vZNQAdBd7NBlE9iwXaM=; b=P72PlVYqBQbAInhMP1Cztnn25ExfFAVnEM97OVkv3wBeCzo6Cx0WZmn7vQRzkYTpNe 8h5b6kJ/jHfvKfdnc8iJbtt7TsJJm3GFnqsbP7ww62x1vJhObcYNm2Hq4fvJQzWuutCK jrkQV9kA3V/Q7MYPD+TxyGH/bib+j7MXH9PLkmXzHsTC2yJcxfWpppxlDvnYCm4P/uod g5iVbZM7WnSFK/ZXSDA/T0M8hFHHqC7mRjOv7QHDQ+Y59Kex1U2jTZ5ixea6NwgHT8A0 5yOgzs/VAMKCG0eZ7J0MC6CYd6cc8zs9Iw1rS00ysw2ZtB8EkvRGEkit647T/YKXWdYx A6OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YBAqAlzSCQZdlmXyjYYjUW76vZNQAdBd7NBlE9iwXaM=; b=f1nqGuMX2SylQN0ct9FdPDMRhsZFR2PsmI3Pc9IFibrYMv+YoNu5ug6oJ/1+cOilWW GPz/+cBByVhYGxJU+fAzb5FD9Wt+/2fK2+/XA1RHjmDizC0CZIi5GPLTv4513RJgO/65 y/IGWy0UEk6R8Xfu3q7UyPP1VJUH+My8JXI5nUmZXWuqnd79deBjm3gE8dpi250CMeHW yET5zyUood2F/AbabMaf1HNdRwJyvmpyfmmREs7ZIgbHb2T3I1NZcYKa/X9n51bSH3sj NoLz1MfGKeRPxFL16Ql9tAbJob/PGfrjelAthURcgwWOj8RidXFhSlXbaTwD3gD19kaq s8Yw== X-Gm-Message-State: APjAAAVCaYJ20V+gf+JxeJBXcSX3KG1huFkNKHCKqNWXmucFMKKwKmjV JDH0fXO0QcS2eohhKpqF2IyvXCWH X-Google-Smtp-Source: APXvYqwTy6qvlC4sIOv0MiU+9G22A2o0h5sqj2NnhklFoi4FGugXv09vjUho4QWjR8PW4+J+3zRaSw== X-Received: by 2002:a2e:9151:: with SMTP id q17mr2652553ljg.115.1571394148448; Fri, 18 Oct 2019 03:22:28 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-154-226.ip.moscow.rt.ru. [37.110.154.226]) by smtp.gmail.com with ESMTPSA id h5sm4050183ljf.83.2019.10.18.03.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2019 03:22:26 -0700 (PDT) From: Andrey Semashev To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Oct 2019 13:22:16 +0300 Message-Id: <20191018102216.509-1-andrey.semashev@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/libdav1d: fix setting AVFrame reordered_opaque X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andrey Semashev , James Almer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Actually reorder the values. Should effectively fix ticket #8300. Signed-off-by: James Almer Updated to avoid extra memory allocations on 64-bit platforms. Signed-off-by: Andrey Semashev --- libavcodec/libdav1d.c | 46 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 8aa248e6cd..ff94310b40 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -19,12 +19,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include "libavutil/avassert.h" #include "libavutil/mastering_display_metadata.h" #include "libavutil/imgutils.h" #include "libavutil/opt.h" +#include "libavutil/mem.h" #include "avcodec.h" #include "decode.h" @@ -164,6 +166,12 @@ static void libdav1d_data_free(const uint8_t *data, void *opaque) { av_buffer_unref(&buf); } +static void libdav1d_user_data_free(const uint8_t *data, void *opaque) { +#if UINTPTR_MAX < UINT64_MAX + av_free((void *)data); +#endif +} + static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) { Libdav1dContext *dav1d = c->priv_data; @@ -191,6 +199,35 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) pkt.buf = NULL; av_packet_unref(&pkt); + +#if UINTPTR_MAX >= UINT64_MAX + if (c->reordered_opaque != (int64_t)(intptr_t)(const uint8_t *)NULL) { + res = dav1d_data_wrap_user_data(data, (const uint8_t *)(intptr_t)c->reordered_opaque, + libdav1d_user_data_free, NULL); + if (res < 0) { + dav1d_data_unref(data); + return res; + } + } +#else + if (c->reordered_opaque != AV_NOPTS_VALUE) { + int64_t *reordered_opaque = av_malloc(sizeof(int64_t)); + + if (!reordered_opaque) { + dav1d_data_unref(data); + return AVERROR(ENOMEM); + } + + *reordered_opaque = c->reordered_opaque; + res = dav1d_data_wrap_user_data(data, (const uint8_t *)reordered_opaque, + libdav1d_user_data_free, NULL); + if (res < 0) { + av_free(reordered_opaque); + dav1d_data_unref(data); + return res; + } + } +#endif } } @@ -260,7 +297,14 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) else frame->format = c->pix_fmt = pix_fmt[p->p.layout][p->seq_hdr->hbd]; - frame->reordered_opaque = c->reordered_opaque; +#if UINTPTR_MAX >= UINT64_MAX + frame->reordered_opaque = (int64_t)(intptr_t)p->m.user_data.data; +#else + if (p->m.user_data.data) + memcpy(&frame->reordered_opaque, p->m.user_data.data, sizeof(frame->reordered_opaque)); + else + frame->reordered_opaque = AV_NOPTS_VALUE; +#endif // match timestamps and packet size frame->pts = frame->best_effort_timestamp = p->m.timestamp;