From patchwork Thu Oct 17 08:29:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15804 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 E74D5449FA2 for ; Thu, 17 Oct 2019 11:30:53 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D18A668A7AD; Thu, 17 Oct 2019 11:30:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DFCB68A718 for ; Thu, 17 Oct 2019 11:30:47 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id o18so1249830wrv.13 for ; Thu, 17 Oct 2019 01:30:47 -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=e6dmiGuN+FCZqOs1b+4vNXmwKk/AbOMJUZjZ0HHq3vM=; b=Rclay5D86OXrG6hb3IRM7AsRfmox1/GSCMBfQA+N8beC+VtA0uE1eioywQrazBfiwr JZMdAA4mFwMwm+k87egxZ5hWujD0jG8HGJLZqbUllvMyRv29nbT2iKhbY0+Hux/wDckJ Kaq+yhezJ+jXDWz8+dPndsNGYFwjlNtVF4vnrfE6b0AAL1sWYMZMdKIaRUP8MAKEhD8A i60Ell2lgVxN46ZV7DnnimtLdbPnsulS3mVrBRsGkc3aKPoU7a9f5mO2xhhx0yxl7Ye7 EDPCqvY6OlLQo8K+vrLi3ya8w8OdxsuwXHddO4edkU7LTFD1AoXPH+D1xeWFC8chN769 ukTw== 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=e6dmiGuN+FCZqOs1b+4vNXmwKk/AbOMJUZjZ0HHq3vM=; b=UX2MvqN+9gCyBqk4bx1lbdG6qenI0f5pV1aQtLlmOMlHqfhW6WhtgNLzrzPN2C/HZP HejkKG36qK1I/4KSw8RIXi8mgqanIW3rdD+VbJfGp/IjahoYClKK7aSGwceZSGhOeEqg dlZYaCJFns1saWRTJF5xBvwbgab3md9VHf6q8yJbbNbd3sXfOU1SaUKBFbFOCsE7vm9q KJ1RB+6zNMhIB/RUfCBT6TkNgPIgZRWE0MC0QhqspsfZXA905G3OA6Ck93cApMdnBrsh icj2aQLi00kc7z5ao4iL0LudX0U5iJe8+QGBv4/Vg031gQ9VpP7TN6VXL/nM7skUYU65 lUhA== X-Gm-Message-State: APjAAAVmKDNK+h6r+BpwQMUpH8KWhWakNugHUFrss2xbg/wWcXHhWYLS C6UYDAb6Dz3V5L31/fhRSr9gNGDL X-Google-Smtp-Source: APXvYqzJF1QPKt8/hCclKSB5tcsezRvXGBcoy4Y+v9BoJGvv3/hwqcawkbvJm2TPs1T++zNoCWHixA== X-Received: by 2002:adf:ecd0:: with SMTP id s16mr1861451wro.65.1571301047202; Thu, 17 Oct 2019 01:30:47 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id l7sm1369273wrv.77.2019.10.17.01.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 01:30:46 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Oct 2019 10:29:43 +0200 Message-Id: <20191017082945.13534-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017082945.13534-1-andreas.rheinhardt@gmail.com> References: <20191017082945.13534-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/15] 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 | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index d00c4553c3..063dc411c0 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,13 +199,15 @@ 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; - unit_type = *buf & 0x1f; + buf += s->length_size; + unit_type = *buf & 0x1f; /* This check requires the cast as the right side might * otherwise be promoted to an unsigned value. */ @@ -216,41 +216,41 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) goto fail; } - 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); @@ -260,8 +260,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) {