From patchwork Thu Jul 28 16:18:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sebechlebskyjan@gmail.com X-Patchwork-Id: 20 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp886474vsd; Thu, 28 Jul 2016 09:32:18 -0700 (PDT) X-Received: by 10.194.7.100 with SMTP id i4mr37802993wja.154.1469723538628; Thu, 28 Jul 2016 09:32:18 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ej2si13887485wjd.174.2016.07.28.09.32.18; Thu, 28 Jul 2016 09:32:18 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3B9B368A519; Thu, 28 Jul 2016 19:32:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0997D68A235 for ; Thu, 28 Jul 2016 19:32:06 +0300 (EEST) Received: by mail-wm0-f65.google.com with SMTP id x83so11929102wma.3 for ; Thu, 28 Jul 2016 09:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X5clzV4j+L5O6So8AuFpWXpER345T9kgL24UrTAy8Zo=; b=KejHzU3rKXOzFfA+J+Ohxs+lFHr3xXSS5KqBw0HbXnY/V/+0/GDB1HIc2NeDaSIpHN B+79upWZ7/0Ke78+iVhxrLdxD3SJ49WwhEcS1GRK/ozwzrpLjoyIUSPk0xtTzqZh6DrH kGf13n02umQdYx3u+mhKv3JE/YFO4WEqkxV7Nz1MubyEdQu6QRAzRKDL1wesjdbf19OC bJ22mP7n8+H/KqhbuOqtnDnHdYLp7duAie+moTAfvCMxZAGFOjnfRN2Dowvw9gHGcSWs G3zh8ZMMZNdnjtJLl5vHgvAW9iBD1szDfEab1vVxunGx3LbBVlpbzV+IM6yXyzvntRx8 hADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X5clzV4j+L5O6So8AuFpWXpER345T9kgL24UrTAy8Zo=; b=eaw2Z+cpo1KW1CPJFlITH661PLTcGQNTlCkMuZBXhszbiMa5Dls07tlBp4E6jYgZcx ex8kQ3BIdiNsOs3+vZCVuXuHrtRyY6aEkge1kkT3ur/ZCO329GdZJ/b6aPTuTmNI+FWF jg/SD+zJKx8avJy8f8KdFXc9PK8u99Gk8bdJTxGwpyVmJqTZLXU3GltlP10eAySawKnm Xlqc0bwU1f6cb4nh0BbvOppiUr9dBJa5QLhj4fdSEKwwQceqbwrtA6CP+Kw0rndmpjEd dG7UngNbYhS0nnapztWGQUlD7kQyLHQfCFzQTXPHZ3r8f2jLQQ4U/NqHm2LaTqk2hZMM QGCA== X-Gm-Message-State: ALyK8tJGLl1zldM3iioFWRuzzm+FEpJVGLCD7UmQEIP8ujzq8XcZH00+lAhc/yO+W60xJg== X-Received: by 10.28.58.7 with SMTP id h7mr57897664wma.35.1469722713926; Thu, 28 Jul 2016 09:18:33 -0700 (PDT) Received: from localhost.localdomain (157.174.broadband3.iol.cz. [85.70.174.157]) by smtp.gmail.com with ESMTPSA id i80sm12961969wmf.11.2016.07.28.09.18.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jul 2016 09:18:33 -0700 (PDT) From: sebechlebskyjan@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Jul 2016 18:18:13 +0200 Message-Id: <1469722696-2018-2-git-send-email-sebechlebskyjan@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469722696-2018-1-git-send-email-sebechlebskyjan@gmail.com> References: <1469722696-2018-1-git-send-email-sebechlebskyjan@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/5] avcodec/bsf: Add ff_bsf_get_packet_ref() function 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: Jan Sebechlebsky MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Sebechlebsky Use of this function can save unnecessary malloc operation in bitstream filter. Signed-off-by: Jan Sebechlebsky --- libavcodec/bsf.c | 16 ++++++++++++++++ libavcodec/bsf.h | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c index 8e36861..40fc925 100644 --- a/libavcodec/bsf.c +++ b/libavcodec/bsf.c @@ -220,3 +220,19 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt) return 0; } + +int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt) +{ + AVBSFInternal *in = ctx->internal; + + if (in->eof) + return AVERROR_EOF; + + if (!ctx->internal->buffer_pkt->data && + !ctx->internal->buffer_pkt->side_data_elems) + return AVERROR(EAGAIN); + + av_packet_move_ref(pkt, ctx->internal->buffer_pkt); + + return 0; +} diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h index 3435df5..af035ee 100644 --- a/libavcodec/bsf.h +++ b/libavcodec/bsf.h @@ -28,6 +28,17 @@ */ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt); +/** + * Called by bitstream filters to get packet for filtering. + * The reference to packet is moved to provided packet structure. + * + * @param ctx pointer to AVBSFContext of filter + * @param pkt pointer to packet to move reference to + * + * @return 0>= on success, negative AVERROR in case of failure + */ +int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt); + const AVClass *ff_bsf_child_class_next(const AVClass *prev); #endif /* AVCODEC_BSF_H */