correct fix for ddef88f0

Check that codec is not a NULL pointer right after it's first set, this
is done later after configuring the ctx anyway.
This commit is contained in:
Rafael Kitover 2016-12-31 04:07:12 -08:00
parent 57adfaf24e
commit 281e73eee0
1 changed files with 9 additions and 3 deletions

View File

@ -126,11 +126,17 @@ MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fm
AVCodec *codec = avcodec_find_encoder(fmt->audio_codec);
if (!codec) {
avformat_free_context(oc);
oc = NULL;
return MRET_ERR_NOCODEC;
}
ctx = aud_st->codec;
ctx->codec_id = fmt->audio_codec;
ctx->codec_type = AVMEDIA_TYPE_AUDIO;
// Some encoders don't like int16_t (SAMPLE_FMT_S16)
if(!codec) ctx->sample_fmt = codec->sample_fmts[0];
ctx->sample_fmt = codec->sample_fmts[0];
// This was changed in the initial ffmpeg 3.0 update,
// but shouldn't (as far as I'm aware) cause problems with older versions
ctx->bit_rate = 128000; // arbitrary; in case we're generating mp3
@ -142,9 +148,9 @@ MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fm
ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,6,0)
if(!codec || avcodec_open(ctx, codec)) {
if(avcodec_open(ctx, codec)) {
#else
if(!codec || avcodec_open2(ctx, codec, NULL)) {
if(avcodec_open2(ctx, codec, NULL)) {
#endif
avformat_free_context(oc);
oc = NULL;