Skip to content

Commit

Permalink
avformat/segafilmenc: Combine several checks
Browse files Browse the repository at this point in the history
by moving them around.

Signed-off-by: Andreas Rheinhardt <[email protected]>
Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
mkver authored and michaelni committed Feb 25, 2020
1 parent ba2581a commit ab44f0a
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions libavformat/segafilmenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit ab44f0a

Please sign in to comment.