From patchwork Sat Dec 24 17:41:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 1909 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp383466vsb; Sat, 24 Dec 2016 09:42:38 -0800 (PST) X-Received: by 10.28.227.215 with SMTP id a206mr21663366wmh.84.1482601358457; Sat, 24 Dec 2016 09:42:38 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id aq9si40000186wjc.48.2016.12.24.09.42.37; Sat, 24 Dec 2016 09:42:38 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ECF7F689BD0; Sat, 24 Dec 2016 19:42:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D3306899BE for ; Sat, 24 Dec 2016 19:42:02 +0200 (EET) Received: from phare.normalesup.org (archicubes.ens.fr [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id uBOHg33d095777 for ; Sat, 24 Dec 2016 18:42:03 +0100 (CET) Received: by phare.normalesup.org (Postfix, from userid 1001) id 1101CE0087; Sat, 24 Dec 2016 18:42:03 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Dec 2016 18:41:35 +0100 Message-Id: <20161224174149.8995-4-george@nsup.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161224174149.8995-1-george@nsup.org> References: <20161224174149.8995-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Sat, 24 Dec 2016 18:42:03 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 03/17] lavfi: implement ff_link_make_frame_writable(). 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Unlike av_frame_is_writable(), it uses the link's alloc callback, making direct rendering possible. The code comes from ff_filter_frame_framed(), moved with mostly trivial changes. Signed-off-by: Nicolas George --- libavfilter/avfilter.c | 94 ++++++++++++++++++++++++++++---------------------- libavfilter/internal.h | 7 ++++ 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 191554eb6d..2de5a0ea78 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1106,49 +1106,12 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) if (!(filter_frame = dst->filter_frame)) filter_frame = default_filter_frame; - /* copy the frame if needed */ - if (dst->needs_writable && !av_frame_is_writable(frame)) { - av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n"); - - switch (link->type) { - case AVMEDIA_TYPE_VIDEO: - out = ff_get_video_buffer(link, link->w, link->h); - break; - case AVMEDIA_TYPE_AUDIO: - out = ff_get_audio_buffer(link, frame->nb_samples); - break; - default: - ret = AVERROR(EINVAL); - goto fail; - } - if (!out) { - ret = AVERROR(ENOMEM); - goto fail; - } - - ret = av_frame_copy_props(out, frame); + if (dst->needs_writable) { + ret = ff_link_make_frame_writable(link, &frame); if (ret < 0) goto fail; - - switch (link->type) { - case AVMEDIA_TYPE_VIDEO: - av_image_copy(out->data, out->linesize, (const uint8_t **)frame->data, frame->linesize, - frame->format, frame->width, frame->height); - break; - case AVMEDIA_TYPE_AUDIO: - av_samples_copy(out->extended_data, frame->extended_data, - 0, 0, frame->nb_samples, - av_frame_get_channels(frame), - frame->format); - break; - default: - ret = AVERROR(EINVAL); - goto fail; - } - - av_frame_free(&frame); - } else - out = frame; + } + out = frame; /* TODO rename */ while(cmd && cmd->time <= out->pts * av_q2d(link->time_base)){ av_log(link->dst, AV_LOG_DEBUG, @@ -1556,6 +1519,55 @@ int ff_link_acknowledge_status(AVFilterLink *link) return 1; } +int ff_link_make_frame_writable(AVFilterLink *link, AVFrame **rframe) +{ + AVFrame *frame = *rframe; + AVFrame *out; + int ret; + + if (av_frame_is_writable(frame)) + return 0; + av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n"); + + switch (link->type) { + case AVMEDIA_TYPE_VIDEO: + out = ff_get_video_buffer(link, link->w, link->h); + break; + case AVMEDIA_TYPE_AUDIO: + out = ff_get_audio_buffer(link, frame->nb_samples); + break; + default: + return AVERROR(EINVAL); + } + if (!out) + return AVERROR(ENOMEM); + + ret = av_frame_copy_props(out, frame); + if (ret < 0) { + av_frame_free(&out); + return ret; + } + + switch (link->type) { + case AVMEDIA_TYPE_VIDEO: + av_image_copy(out->data, out->linesize, (const uint8_t **)frame->data, frame->linesize, + frame->format, frame->width, frame->height); + break; + case AVMEDIA_TYPE_AUDIO: + av_samples_copy(out->extended_data, frame->extended_data, + 0, 0, frame->nb_samples, + av_frame_get_channels(frame), + frame->format); + break; + default: + av_assert0(!"reached"); + } + + av_frame_free(&frame); + *rframe = out; + return 0; +} + const AVClass *avfilter_get_class(void) { return &avfilter_class; diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 3c09032610..422363477b 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -624,4 +624,11 @@ void ff_filter_set_ready(AVFilterContext *filter, unsigned priority); */ int ff_link_acknowledge_status(AVFilterLink *link); +/** + * Make sure a frame is writable. + * This is similar to av_frame_make_writable() except it uses the link's + * buffer allocation callback, and therefore allows direct rendering. + */ +int ff_link_make_frame_writable(AVFilterLink *link, AVFrame **rframe); + #endif /* AVFILTER_INTERNAL_H */