From patchwork Sat Dec 14 22:19:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16796 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 EADA6449C5F for ; Sun, 15 Dec 2019 00:33:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C64EE689767; Sun, 15 Dec 2019 00:33:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74AC1688200 for ; Sun, 15 Dec 2019 00:33:34 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id y17so2763775wrh.5 for ; Sat, 14 Dec 2019 14:33:34 -0800 (PST) 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=fCdoHV8fUQEr6wZyWYwmxMCXPiL3bLko8Wkgmqh5h1k=; b=p+ixrNBGBw1h+O/XeZcBOnnIh49LnkvWS5R1s1NAIiGToGcfgQD6Ga1QdsfuZqB5aS jkJkQpm4pY7jxGmVLJVSNxoG0LHN4eB1Ga0RH+HOWwu5ysK+rloWrsDECGlJcNonYZbM buZgEPbGvPnzQAkwpuhpHLYYLe7BhgqNAXHCFcPzwhSx62xG0kc1lH7egYIVivS0IXmR zTuvBDjtr734609qBmuXX+MIS89t57NWSXgYl1lR5t6GfFm6Fz/hnDzrx18nA/zkdVkC 6aCHTeBakOoqU7dqFZ+F9NjblGNy7MtciC7/SGW3nPntJxIwlRBeegmfgqV9B6elG1C7 8sQw== 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=fCdoHV8fUQEr6wZyWYwmxMCXPiL3bLko8Wkgmqh5h1k=; b=jNV1rRj6WwS9MXOvD6NDoEOwAz4+tu9So7JE0GRu2PLU9rxllZZCQB8Aayafo3g+zN CemZ3sG3wtm6IaAXtdL/XvFc1pa4H+jwcRSivRiLFu1dY5ryk2Dmb2HiYWbvLg0JH9s0 3bN+DcUGJ0xzysYd9mBMC1+t0kM3Duo4zJomBmGO0tpZcJbKNC9fFDtLHWjXuudQXNfT KFqPb8eoa1xeSEmE9EczOnG/ydcUz/khu0WNwfvX+qwB05r5CEvcs2NtzKenbiRiwKne nvRreQaSZioAbExsR+ctgE/pHy0304TqP3wfRxZ4b8yA/ntaKp3leF7t7gtdJWhOxN4K LrBQ== X-Gm-Message-State: APjAAAWXSwVMI2Hi8nhS/E2p100j2ItFzZEKSQRfR9oqFVor0idNzZmi zvCZqTGwBi9iDlB/W4b4Q2R+qCB3 X-Google-Smtp-Source: APXvYqysxnXQC/phSuj2bQVelbKl5vt+OICLx/zgLujRv+piHc42sdQmvbGpVNq627q+U7RCFlSJBA== X-Received: by 2002:adf:f20b:: with SMTP id p11mr20399392wro.195.1576362355562; Sat, 14 Dec 2019 14:25:55 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id v3sm15063771wml.47.2019.12.14.14.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2019 14:25:55 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 14 Dec 2019 23:19:25 +0100 Message-Id: <20191214221926.16074-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191214221926.16074-1-andreas.rheinhardt@gmail.com> References: <20191214221926.16074-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 13/14] h264_mp4toannexb: Cosmetics 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" Mainly reindentation, but some variables were also put into a smaller scope. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_mp4toannexb_bsf.c | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 8b3a39fa03..0150f97a1a 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -49,13 +49,13 @@ static void count_or_copy(uint8_t **out, uint64_t *out_size, if (copy) { memcpy(*out + start_code_size, in, in_size); - if (start_code_size == 4) { + if (start_code_size == 4) { AV_WB32(*out, 1); - } else if (start_code_size) { + } else if (start_code_size) { (*out)[0] = (*out)[1] = 0; (*out)[2] = 1; - } + } *out += start_code_size + in_size; } *out_size += start_code_size + in_size; @@ -168,15 +168,13 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx) static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) { H264BSFContext *s = ctx->priv_data; - AVPacket *in; uint8_t unit_type, new_idr, sps_seen, pps_seen; - uint32_t nal_size; const uint8_t *buf; const uint8_t *buf_end; uint8_t *out; uint64_t out_size; - int ret = 0, i; + int ret; ret = ff_bsf_get_packet(ctx, &in); if (ret < 0) @@ -201,12 +199,14 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) pps_seen = s->idr_pps_seen; out_size = 0; - do { + do { + uint32_t nal_size = 0; + /* possible overread ok due to padding */ - for (nal_size = 0, i = 0; ilength_size; i++) - nal_size = (nal_size << 8) | buf[i]; + for (int i = 0; i < s->length_size; i++) + nal_size = (nal_size << 8) | buf[i]; - buf += s->length_size; + buf += s->length_size; /* This check requires the cast as the right side might * otherwise be promoted to an unsigned value. */ @@ -220,41 +220,41 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) unit_type = *buf & 0x1f; - if (unit_type == H264_NAL_SPS) + if (unit_type == H264_NAL_SPS) { sps_seen = new_idr = 1; - else if (unit_type == H264_NAL_PPS) { + } else if (unit_type == H264_NAL_PPS) { pps_seen = new_idr = 1; - /* if SPS has not been seen yet, prepend the AVCC one to PPS */ + /* if SPS has not been seen yet, prepend the AVCC one to PPS */ if (!sps_seen) { - if (!s->sps_size) + if (!s->sps_size) { LOG_ONCE(ctx, AV_LOG_WARNING, "SPS not present in the stream, nor in AVCC, stream may be unreadable\n"); - else { + } else { count_or_copy(&out, &out_size, s->sps, s->sps_size, -1, j); sps_seen = 1; + } } } - } - /* if this is a new IDR picture following an IDR picture, reset the idr flag. - * Just check first_mb_in_slice to be 0 as this is the simplest solution. - * This could be checking idr_pic_id instead, but would complexify the parsing. */ + /* If this is a new IDR picture following an IDR picture, reset the idr flag. + * Just check first_mb_in_slice to be 0 as this is the simplest solution. + * This could be checking idr_pic_id instead, but would complexify the parsing. */ if (!new_idr && unit_type == H264_NAL_IDR_SLICE && (buf[1] & 0x80)) new_idr = 1; - /* prepend only to the first type 5 NAL unit of an IDR picture, if no sps/pps are already present */ + /* prepend only to the first type 5 NAL unit of an IDR picture, if no sps/pps are already present */ if (new_idr && unit_type == H264_NAL_IDR_SLICE && !sps_seen && !pps_seen) { if (ctx->par_out->extradata) count_or_copy(&out, &out_size, ctx->par_out->extradata, ctx->par_out->extradata_size, -1, j); new_idr = 0; - /* if only SPS has been seen, also insert PPS */ + /* if only SPS has been seen, also insert PPS */ } else if (new_idr && unit_type == H264_NAL_IDR_SLICE && sps_seen && !pps_seen) { - if (!s->pps_size) { + if (!s->pps_size) { LOG_ONCE(ctx, AV_LOG_WARNING, "PPS not present in the stream, nor in AVCC, stream may be unreadable\n"); } else { count_or_copy(&out, &out_size, s->pps, s->pps_size, -1, j); } - } + } count_or_copy(&out, &out_size, buf, nal_size, unit_type == H264_NAL_SPS || unit_type == H264_NAL_PPS, j); @@ -264,8 +264,8 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) pps_seen = 0; } - buf += nal_size; - } while (buf < buf_end); + buf += nal_size; + } while (buf < buf_end); if (!j) { if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {