From patchwork Fri Sep 4 11:03:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22088 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 B301C44940C for ; Fri, 4 Sep 2020 14:04:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8FD4768AA90; Fri, 4 Sep 2020 14:04:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B91EB6883C9 for ; Fri, 4 Sep 2020 14:04:01 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id l9so5681445wme.3 for ; Fri, 04 Sep 2020 04:04:01 -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=y0UygscdYCOqVBYxiW14/6B7T4DNgE/j4e9f9EUhU5o=; b=cOZF4Jk5Tiag268LfeKkfLNntY+GQXTYw371GISP1YSyufHxprBT0HQSy4hvieG0rS Lg0A2zqHbyTvAutAnKHcQN3OAIxHP0aeeh9jxyHFSO21ORWMf8CUxMJe+iC/rzpjyhZ+ On+BlMYvcRMoSuwJBKG1w2vtv5jsNyHHifSW71q97Zyr+gXXA/FhCPO8OHDHOO7+wFik AofeEkk8RKvizeiK98EwpjuN8VHA8BgD0wCnM7+F5aa3PToT8E3IE1SinSJchem9MVnW x38weL3cbvTglOIsDLestNU8KeSxXWwYSjn7823ktwuTW2YC6YUYG/Fvm7DRixjOt4TI 3K/A== 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=y0UygscdYCOqVBYxiW14/6B7T4DNgE/j4e9f9EUhU5o=; b=SNb+NcOssmFb63qUNKvcxq+/ScaQs5RGcbvpRQIVCxttOsJuVJPOWxkHJDhnWEnh4t VRJBtmoWy91D9uL4t5KX+3zaL4qtZkO04XUzxJGC7GjB70xkZxeB5KMZfPvgjh//4MT9 +nUbjeQ8/vQXOoNrf+KXePHOwmJ19rP+rjr9NZFXlSyH2wOSHOWWk/KaxviBkc+1K9ZG 25VeFD6+9A7BYzw6LHig3FfBaanVtvIKWVicMp1sLaB9R4vh1fMDnKJm7xsH1HpB+54H f3H8wpWLSi7yf6H1vBVSDaf+jWjsOcFEVYWO4bvXnjyeaOYsdhXmhjfUGkg3ZhhFL/3M eW/w== X-Gm-Message-State: AOAM532xwLNW4UVGB9+fuXdhJh4HVNm5t0HmpESCEDnKT/yiGkbFuJmS VH8F/faP1WXVAM8XX3FE9Yuq6pSZ0Gs= X-Google-Smtp-Source: ABdhPJzk5taO9U4fhYW+aiF/uWCVjJ0OPOLCYeJV/IHvLyKEmCJ6En9NW6Ho1o6kfcVvqF9CXrL38g== X-Received: by 2002:a05:600c:414b:: with SMTP id h11mr5434807wmm.20.1599217440803; Fri, 04 Sep 2020 04:04:00 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id n4sm10404643wrp.61.2020.09.04.04.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 04:04:00 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 4 Sep 2020 13:03:53 +0200 Message-Id: <20200904110354.10100-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/yuv4mpegenc: Simplify writing global and packet headers 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" YUV4MPEG writes a string as header for both the file itself as well as for every frame; these strings contain magic strings and these were up until now included in the string to write via %s. Yet they are compile time constants, so one can use the compile-time string concatentation instead of inserting these strings at runtime. Furthermore, the global header has been written via snprintf() to a local buffer first before writing it. This can be simplified by using avio_printf(). Signed-off-by: Andreas Rheinhardt --- That snprintf() call was weird: The buffer used had a size of Y4M_LINE_MAX + 1, yet snprintf has been told that the size was Y4M_LINE_MAX, despite snprintf always adding a trailing zero (i.e. it writes at most Y4M_LINE_MAX - 1 chars and then adds a zero). Furthermore, snprintf only returns something negative on format errors, not if the buffer is too small (this can be checked via the return value). And returning AVERROR(EIO) for this error is strange, too. libavformat/yuv4mpegenc.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c index c4781042bd..fdd020e13b 100644 --- a/libavformat/yuv4mpegenc.c +++ b/libavformat/yuv4mpegenc.c @@ -24,18 +24,15 @@ #include "internal.h" #include "yuv4mpeg.h" -#define Y4M_LINE_MAX 256 - static int yuv4_write_header(AVFormatContext *s) { AVStream *st; AVIOContext *pb = s->pb; int width, height; - int raten, rated, aspectn, aspectd, n; + int raten, rated, aspectn, aspectd, ret; char inter; const char *colorspace = ""; const char *colorrange = ""; - char buf[Y4M_LINE_MAX + 1]; int field_order; st = s->streams[0]; @@ -170,19 +167,15 @@ static int yuv4_write_header(AVFormatContext *s) break; } - /* construct stream header, if this is the first frame */ - n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s%s\n", - Y4M_MAGIC, width, height, raten, rated, inter, - aspectn, aspectd, colorspace, colorrange); - - if (n < 0) { + ret = avio_printf(pb, Y4M_MAGIC " W%d H%d F%d:%d I%c A%d:%d%s%s\n", + width, height, raten, rated, inter, + aspectn, aspectd, colorspace, colorrange); + if (ret < 0) { av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n"); - return AVERROR(EIO); + return ret; } - avio_write(pb, buf, strlen(buf)); - return 0; } @@ -200,7 +193,7 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) /* construct frame header */ - avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC); + avio_printf(s->pb, Y4M_FRAME_MAGIC "\n"); width = st->codecpar->width; height = st->codecpar->height; From patchwork Fri Sep 4 11:03:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22089 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 C7DB144940C for ; Fri, 4 Sep 2020 14:04:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AEB4868B01D; Fri, 4 Sep 2020 14:04:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2CC52689F05 for ; Fri, 4 Sep 2020 14:04:30 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id a65so5666974wme.5 for ; Fri, 04 Sep 2020 04:04:30 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=BrEh3oq29IlLXGGsVXAtAGDAiIfcxNzpJ1Oyh9YUnNU=; b=he1TipTy5QVZtTVOSa3ZSM6Pze6QZrc3yqFEQrYxPWb9Ixvku3PPtsi9AB3xqHU7QL LTO3l/K2h7UiNtgEnzkr6Ed1027BhAKv8tH8jg+ShxlmfbLoxVHs9hXQfISj1H5ydLFK xa24wqx8xoakkcKbvM2zTpLJuHKIE18ycCXaIwKIzQbytthen1nVgYcRWxt2CbSl/Wol ZS1h/u5k8sQcrLeqUZF36WivJA5Ii53xlPkj/wwZL6eqOgEzSypY8+Vf++z2RypOKFaa jQx/WE3I77QrvjZXeaDOy00uBu4kbgLWIn25QvAZoh0QuFhREl2Ub4ibzgcbKyhHdbX+ 6HEQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=BrEh3oq29IlLXGGsVXAtAGDAiIfcxNzpJ1Oyh9YUnNU=; b=tzKVt692YBz2EjoKIGbq2IQnBqHDiYxdvbNtXGKQV3UauJwlD7M+5vC1S/XqIl3njM 9d6UMAjGbnEwRaDZC1BySmzBzQjWjK2b1b/LUfc1YyGRKsQwS39dBnnREhSCeuuPZRIg 7GPNdMN1QC9DS9hsu9GR3upf3Xc+cETv0tCrl+FjzzzC5hnma32DtuRDRy/JAnI8BB+R LMa/hV8tt3a5kCDuzYiHEoFfFQTPlFcJKld/WdIOm9eyzLyT0BvCPpD3Wa2Czvmmyhjz 8OU2wl55Z3FaKhZ/kNhM75p+rVmXPIhHSqh1NgZm3I1n0wWPEMPNvbuWm1qu8WAG1f+S kxqQ== X-Gm-Message-State: AOAM530LG0pyI+pzLxGxYtiHRbuszX/14UMrw/ap/s0aE72Z/vd5bNAX 1/RiiEJZSX4wWVWNfrqTKeDH4bu9QhE= X-Google-Smtp-Source: ABdhPJwVHnM8R1gLKbYS/RRXdS9i1K8vK5GKcggv6SChPR939MqPUFEKtyf0kvy7ThWckaAyh7v1Dw== X-Received: by 2002:a7b:c768:: with SMTP id x8mr7552348wmk.189.1599217469398; Fri, 04 Sep 2020 04:04:29 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id n4sm10404643wrp.61.2020.09.04.04.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 04:04:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 4 Sep 2020 13:03:54 +0200 Message-Id: <20200904110354.10100-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200904110354.10100-1-andreas.rheinhardt@gmail.com> References: <20200904110354.10100-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/yuv4mpegenc: Add const where appropriate 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavformat/yuv4mpegenc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c index fdd020e13b..6b53780ba0 100644 --- a/libavformat/yuv4mpegenc.c +++ b/libavformat/yuv4mpegenc.c @@ -184,12 +184,10 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[pkt->stream_index]; AVIOContext *pb = s->pb; - AVFrame *frame; + const AVFrame *frame = (const AVFrame *)pkt->data; int width, height, h_chroma_shift, v_chroma_shift; int i; - uint8_t *ptr, *ptr1, *ptr2; - - frame = (AVFrame *)pkt->data; + const uint8_t *ptr, *ptr1, *ptr2; /* construct frame header */