[FFmpeg-devel] [PATCH 6/7] avformat/segafilmenc: Combine several checks

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Tue Jan 14 05:13:35 EET 2020


by moving them around.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 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 */
-- 
2.20.1



More information about the ffmpeg-devel mailing list