diff mbox series

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

Message ID 20200114031336.24096-6-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/7] avformat/segafilmenc: Fix undefined left shift of 1 by 31 places
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 14, 2020, 3:13 a.m. UTC
by moving them around.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/segafilmenc.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
diff mbox series

Patch

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 */