From patchwork Tue Jan 14 03:13:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17338 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 0B77B44BB86 for ; Tue, 14 Jan 2020 05:14:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA9E068B0C2; Tue, 14 Jan 2020 05:14:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0381568A898 for ; Tue, 14 Jan 2020 05:14:01 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id p9so12105507wmc.2 for ; Mon, 13 Jan 2020 19:14:00 -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=XrOknFAUUVHlThSiNzzSubt5UsrhqwF0q0epZQTeIbw=; b=rSzQi25O9qD6/nyzuZ5vou3k3DyBg6n7V3UZoUdYrLKczZIT5wif5SPsR5J9h+zqRl AZOzDD0MaVWBZtMjkrWORaVm9H3SoC7EzSwG1Q5N4qqrqomz1UKYmcqR/1dbhlEekRqS uH3Jc8qWyDwjRfilWXs3HTrbq77m+UYlmaFnFZgcquIOsGcK0uHaMbgfnC/nfaYN2Tvc CisM5PQvnp8V5e0mehQ5BIU11VL+OLL2Vvyla52xPrRK53J8refZ6998dBGrfZlVXlgS wFg+M1C869a/oS0pyRyXUYJ+CnLGwWwEQ7EXPQaH7ESsugGLhsvyShzyn8tNzRu+03Yb CVew== 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=XrOknFAUUVHlThSiNzzSubt5UsrhqwF0q0epZQTeIbw=; b=WQ59FF9HK7j4tZyrabyUgBlhWo8kcEFvGftvT+cDrv01zXjQ7CD+QkpVRkjTMX9VKf wYNyyBBbCkDYJYqBbVffkYpSbxyvH9a5/3ve62HCvZLS5zHnJVuBK+81vM5akz1XTXAF iV2CWS5SgB3BUPU1srhiUdBfu2ja53eGpkTGPWsmXWQevChMN0qrFIbvXsdj+h55Cs+j vvJpao1Fg8rs4QOLEeFsTrm0hVZOJBxjiyR4N1o6hMMmRpJohr438Uyl+uxMqE45/2Hl rLSpHMblKqmFBLepY+EOKcVWaBTrFGHkK0+r2QPKafIhGT2ywjQdv91cjJ3DmOxhbT5O SGVg== X-Gm-Message-State: APjAAAVZEu1r9mabyjOqu3Ogp1hvx2j9RxUblONYXSLQbN5ZgSwpDNPY yNNrjEm2imkSJ1DPsxZRt7X7mpDx X-Google-Smtp-Source: APXvYqxIzBFrP1Id7B4PxEy7nWWYFm3x/I2cJ4wtdC7GLsltStKTHCjonsNRNoFAsQFvPhN1u3zxXg== X-Received: by 2002:a1c:bbc3:: with SMTP id l186mr24227948wmf.101.1578971640317; Mon, 13 Jan 2020 19:14:00 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id w20sm16588476wmk.34.2020.01.13.19.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 19:13:59 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jan 2020 04:13:35 +0100 Message-Id: <20200114031336.24096-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114031336.24096-1-andreas.rheinhardt@gmail.com> References: <20200114031336.24096-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avformat/segafilmenc: Combine several checks 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" by moving them around. Signed-off-by: Andreas Rheinhardt --- libavformat/segafilmenc.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c index 4f881f4f2f..137f153331 100644 --- a/libavformat/segafilmenc.c +++ b/libavformat/segafilmenc.c @@ -155,7 +155,6 @@ static int get_audio_codec_id(enum AVCodecID codec_id) static int film_init(AVFormatContext *format_context) { - AVStream *audio = NULL; FILMOutputContext *film = format_context->priv_data; film->audio_index = -1; film->video_index = -1; @@ -171,8 +170,12 @@ static int film_init(AVFormatContext *format_context) av_log(format_context, AV_LOG_ERROR, "Sega FILM allows a maximum of one audio stream.\n"); return AVERROR(EINVAL); } + if (get_audio_codec_id(st->codecpar->codec_id) < 0) { + av_log(format_context, AV_LOG_ERROR, + "Incompatible audio stream format.\n"); + return AVERROR(EINVAL); + } film->audio_index = i; - audio = st; } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -200,11 +203,6 @@ static int film_init(AVFormatContext *format_context) return AVERROR(EINVAL); } - if (audio != NULL && get_audio_codec_id(audio->codecpar->codec_id) < 0) { - av_log(format_context, AV_LOG_ERROR, "Incompatible audio stream format.\n"); - return AVERROR(EINVAL); - } - return 0; } @@ -269,11 +267,9 @@ static int film_write_header(AVFormatContext *format_context) { int ret = 0; int64_t sample_table_size, stabsize, headersize; - int8_t audio_codec; AVIOContext *pb = format_context->pb; FILMOutputContext *film = format_context->priv_data; FILMPacket *prev, *packet; - AVStream *audio = NULL; AVStream *video = NULL; /* Calculate how much we need to reserve for the header; @@ -290,13 +286,6 @@ static int film_write_header(AVFormatContext *format_context) /* Seek back to the beginning to start writing the header now */ avio_seek(pb, 0, SEEK_SET); - if (film->audio_index > -1) - audio = format_context->streams[film->audio_index]; - - if (audio != NULL) { - audio_codec = get_audio_codec_id(audio->codecpar->codec_id); - } - /* First, write the FILM header; this is very simple */ ffio_wfourcc(pb, "FILM"); @@ -327,7 +316,10 @@ static int film_write_header(AVFormatContext *format_context) avio_wb32(pb, video->codecpar->width); avio_w8(pb, 24); /* Bits per pixel - observed to always be 24 */ - if (audio != NULL) { + if (film->audio_index > -1) { + AVStream *audio = format_context->streams[film->audio_index]; + int audio_codec = get_audio_codec_id(audio->codecpar->codec_id); + avio_w8(pb, audio->codecpar->channels); /* Audio channels */ avio_w8(pb, audio->codecpar->bits_per_coded_sample); /* Audio bit depth */ avio_w8(pb, audio_codec); /* Compression - 0 is PCM, 2 is ADX */