From patchwork Tue Dec 3 21:29:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 16573 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 9F0F944A60C for ; Tue, 3 Dec 2019 23:30:49 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81EDD68B1D5; Tue, 3 Dec 2019 23:30:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D5E4568A8FA for ; Tue, 3 Dec 2019 23:30:42 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BCC2AE35ED; Tue, 3 Dec 2019 22:30:42 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NAoz4HGWwnOE; Tue, 3 Dec 2019 22:30:41 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C7A27E1E39; Tue, 3 Dec 2019 22:30:40 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Dec 2019 22:29:52 +0100 Message-Id: <20191203212952.28418-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: wrap non-shm image replies in a buffer ref 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This avoids a memcpy improving performance if SHM is not used. Signed-off-by: Marton Balint --- libavdevice/xcbgrab.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c index 063fecf838..440361c8fa 100644 --- a/libavdevice/xcbgrab.c +++ b/libavdevice/xcbgrab.c @@ -146,6 +146,11 @@ static int xcbgrab_reposition(AVFormatContext *s, return 0; } +static void xcbgrab_image_reply_free(void *opaque, uint8_t *data) +{ + free(opaque); +} + static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt) { XCBGrabContext *c = s->priv_data; @@ -154,7 +159,7 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt) xcb_drawable_t drawable = c->screen->root; xcb_generic_error_t *e = NULL; uint8_t *data; - int length, ret; + int length; iq = xcb_get_image(c->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable, c->x, c->y, c->width, c->height, ~0); @@ -178,14 +183,17 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt) data = xcb_get_image_data(img); length = xcb_get_image_data_length(img); - ret = av_new_packet(pkt, length); + av_init_packet(pkt); + pkt->data = data; + pkt->size = length; + pkt->buf = av_buffer_create(pkt->data, pkt->size, xcbgrab_image_reply_free, img, 0); - if (!ret) - memcpy(pkt->data, data, length); - - free(img); + if (!pkt->buf) { + free(img); + return AVERROR(ENOMEM); + } - return ret; + return 0; } static void wait_frame(AVFormatContext *s, AVPacket *pkt)