From patchwork Tue Jan 8 15:10:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 11680 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 2ADD844DB91 for ; Tue, 8 Jan 2019 17:10:54 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C90C568A63F; Tue, 8 Jan 2019 17:10:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 45A6968A429 for ; Tue, 8 Jan 2019 17:10:44 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id p17so4683726qtl.5 for ; Tue, 08 Jan 2019 07:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=BQnuRsV+sx1bavmpI7OTJNism00E2ovOG/JPfXKCLQc=; b=tD0Ee/pIcnEy8oauJpcin4egk51+wwRRJZvCnZLwNqKdZBoApmkzMkeyHEVJu7neYK CcBO3Vwukrw2wMkK7K/H5RzWYy5rNst7XqmrSNZ6Ef3g8sHXnCFDJbzCJyNHPmfyvLwk EObfVxgGzLbAttx1mwP0aHcg1IOjLcTrMmiTwGBvjCC4/t/9DEnGWYcehwuCWixRnAUZ ogEp0WgKgIAaHe/PSbYXpX/SEFBL0FySBK2oVal1NKVClMrbuoZ15eIfcWjycaAKpNwX HDw/rv1T5CS3hZmWFncWmCASEL1k8iEwTpiGs8LVbinhA+Onc/1VdTYLyLbJ3r2rm9tb YoYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=BQnuRsV+sx1bavmpI7OTJNism00E2ovOG/JPfXKCLQc=; b=It2oTIK+YbiOhdGU0CE6oEN+eG9zHdow8If6bjxC5ygnRvMn78oujGf8abAFGbM+uW /DrnSekT+aql7EgoPNnVRHEE7u21/L7HKaiw+/8MIPtDEbFqFiH+9JVOCzJW5ydToSGA AAfiS4D89Yd+Ls7zphWVUa6QVX4/E3oAdFttznR3Iocnrtqzt3dqhsc4h+MMEBKmvG2h qbHX7/1PH/y6jTy3Y5v7v5jn3M2pM0lsBjOhrgWfAJNdIP5b/I/snTZrjKc+ELhQi5Yu i7GCRucBcO/iQltY/LzlZwHb3DFtwg+15PmtyJhbSZNRxovFqgj2CsATTUn9dyA4HiBy q1qw== X-Gm-Message-State: AJcUukeSreoRB/RBZd20/4rJu0KMgPZLrwzZ9ucrtWS0El2Rshzct8PH vTsyElHCc7m0W1s8mrv1WTygvN9/ X-Google-Smtp-Source: ALg8bN5wA715HqXsCOX7xIl2HScMthM75Ye7g1ksn/cp59Rf7YTfoksqMYNTGIspBR6Ebgjetpd/zg== X-Received: by 2002:ac8:35eb:: with SMTP id l40mr2063810qtb.165.1546960254070; Tue, 08 Jan 2019 07:10:54 -0800 (PST) Received: from localhost.localdomain ([179.38.137.223]) by smtp.gmail.com with ESMTPSA id r5sm30356416qke.33.2019.01.08.07.10.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 07:10:53 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jan 2019 12:10:35 -0300 Message-Id: <20190108151035.4336-1-jamrial@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/libdav1d: properly free all output picture references 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Dav1dPictures contain more than one buffer reference, so we're forced to use the API properly to free them all. Signed-off-by: James Almer --- libavcodec/libdav1d.c | 75 +++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 7f0b96e0cd..ed02da4ebf 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -72,11 +72,10 @@ static void libdav1d_data_free(const uint8_t *data, void *opaque) { } static void libdav1d_frame_free(void *opaque, uint8_t *data) { - Dav1dPicture p = { 0 }; + Dav1dPicture *p = opaque; - p.ref = opaque; - p.data[0] = (void *) 0x1; // this has to be non-NULL - dav1d_picture_unref(&p); + dav1d_picture_unref(p); + av_free(p); } static const enum AVPixelFormat pix_fmt[][3] = { @@ -90,7 +89,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) { Libdav1dContext *dav1d = c->priv_data; Dav1dData *data = &dav1d->data; - Dav1dPicture p = { 0 }; + Dav1dPicture *p; int res; if (!data->sz) { @@ -124,43 +123,49 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) return res; } - res = dav1d_get_picture(dav1d->c, &p); + p = av_mallocz(sizeof(*p)); + if (!p) + return AVERROR(ENOMEM); + + res = dav1d_get_picture(dav1d->c, p); if (res < 0) { if (res == -EINVAL) res = AVERROR_INVALIDDATA; else if (res == -EAGAIN && c->internal->draining) res = AVERROR_EOF; + av_free(p); return res; } - av_assert0(p.data[0] != NULL); + av_assert0(p->data[0] != NULL); frame->buf[0] = av_buffer_create(NULL, 0, libdav1d_frame_free, - p.ref, AV_BUFFER_FLAG_READONLY); + p, AV_BUFFER_FLAG_READONLY); if (!frame->buf[0]) { - dav1d_picture_unref(&p); + dav1d_picture_unref(p); + av_free(p); return AVERROR(ENOMEM); } - frame->data[0] = p.data[0]; - frame->data[1] = p.data[1]; - frame->data[2] = p.data[2]; - frame->linesize[0] = p.stride[0]; - frame->linesize[1] = p.stride[1]; - frame->linesize[2] = p.stride[1]; - - c->profile = p.seq_hdr->profile; - frame->format = c->pix_fmt = pix_fmt[p.p.layout][p.seq_hdr->hbd]; - frame->width = p.p.w; - frame->height = p.p.h; - if (c->width != p.p.w || c->height != p.p.h) { - res = ff_set_dimensions(c, p.p.w, p.p.h); + frame->data[0] = p->data[0]; + frame->data[1] = p->data[1]; + frame->data[2] = p->data[2]; + frame->linesize[0] = p->stride[0]; + frame->linesize[1] = p->stride[1]; + frame->linesize[2] = p->stride[1]; + + c->profile = p->seq_hdr->profile; + frame->format = c->pix_fmt = pix_fmt[p->p.layout][p->seq_hdr->hbd]; + frame->width = p->p.w; + frame->height = p->p.h; + if (c->width != p->p.w || c->height != p->p.h) { + res = ff_set_dimensions(c, p->p.w, p->p.h); if (res < 0) return res; } - switch (p.seq_hdr->chr) { + switch (p->seq_hdr->chr) { case DAV1D_CHR_VERTICAL: frame->chroma_location = c->chroma_sample_location = AVCHROMA_LOC_LEFT; break; @@ -168,25 +173,25 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) frame->chroma_location = c->chroma_sample_location = AVCHROMA_LOC_TOPLEFT; break; } - frame->colorspace = c->colorspace = (enum AVColorSpace) p.seq_hdr->mtrx; - frame->color_primaries = c->color_primaries = (enum AVColorPrimaries) p.seq_hdr->pri; - frame->color_trc = c->color_trc = (enum AVColorTransferCharacteristic) p.seq_hdr->trc; - frame->color_range = c->color_range = p.seq_hdr->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; + frame->colorspace = c->colorspace = (enum AVColorSpace) p->seq_hdr->mtrx; + frame->color_primaries = c->color_primaries = (enum AVColorPrimaries) p->seq_hdr->pri; + frame->color_trc = c->color_trc = (enum AVColorTransferCharacteristic) p->seq_hdr->trc; + frame->color_range = c->color_range = p->seq_hdr->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; // match timestamps and packet size - frame->pts = frame->best_effort_timestamp = p.m.timestamp; + frame->pts = frame->best_effort_timestamp = p->m.timestamp; #if FF_API_PKT_PTS FF_DISABLE_DEPRECATION_WARNINGS - frame->pkt_pts = p.m.timestamp; + frame->pkt_pts = p->m.timestamp; FF_ENABLE_DEPRECATION_WARNINGS #endif - frame->pkt_dts = p.m.timestamp; - frame->pkt_pos = p.m.offset; - frame->pkt_size = p.m.size; - frame->pkt_duration = p.m.duration; - frame->key_frame = p.frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY; + frame->pkt_dts = p->m.timestamp; + frame->pkt_pos = p->m.offset; + frame->pkt_size = p->m.size; + frame->pkt_duration = p->m.duration; + frame->key_frame = p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY; - switch (p.frame_hdr->frame_type) { + switch (p->frame_hdr->frame_type) { case DAV1D_FRAME_TYPE_KEY: case DAV1D_FRAME_TYPE_INTRA: frame->pict_type = AV_PICTURE_TYPE_I;