Skip to content

Commit

Permalink
ffmpeg >= 5.1 fix (thx Hendi48)
Browse files Browse the repository at this point in the history
  • Loading branch information
BPanther committed Aug 4, 2024
1 parent 99f0806 commit 155e6d5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/driver/audiodec/ffmpegdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State *state,
}

mSampleRate = samplerate;
mChannels = av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO);
mChannels = 2; // AV_CHANNEL_LAYOUT_STEREO.nb_channels

#if !HAVE_ARM_HARDWARE
audioDecoder->PrepareClipPlay(mChannels, mSampleRate, 16, 1);
Expand All @@ -304,12 +304,22 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State *state,
AVFrame *frame = NULL;
AVPacket rpacket;
av_init_packet(&rpacket);
#if LIBSWRESAMPLE_VERSION_INT < AV_VERSION_INT(4, 5, 100)
c->channel_layout = c->channel_layout ? c->channel_layout : AV_CH_LAYOUT_STEREO;

av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0);
//av_opt_set_int(swr, "out_channel_layout", c->channel_layout, 0);
av_opt_set_int(swr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
av_opt_set_int(swr, "in_sample_rate", c->sample_rate, 0);
#else
if (!c->ch_layout.nb_channels) // Is this even possible?
c->ch_layout = AV_CHANNEL_LAYOUT_STEREO;

av_opt_set_chlayout(swr, "in_chlayout", &c->ch_layout, 0);
//av_opt_set_int(swr, "out_chlayout", c->ch_layout, 0);
AVChannelLayout out_chlayout = AV_CHANNEL_LAYOUT_STEREO;
av_opt_set_chlayout(swr, "out_chlayout", &out_chlayout, 0);
#endif
av_opt_set_int(swr, "out_sample_rate", c->sample_rate, 0);
av_opt_set_sample_fmt(swr, "in_sample_fmt", c->sample_fmt, 0);
av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
Expand Down Expand Up @@ -579,7 +589,11 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData *m, bool save_cover)
if (!codec)
codec = avcodec_find_decoder(avc->streams[best_stream]->codecpar->codec_id);
samplerate = avc->streams[best_stream]->codecpar->sample_rate;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
mChannels = av_get_channel_layout_nb_channels(avc->streams[best_stream]->codecpar->channel_layout);
#else
mChannels = avc->streams[best_stream]->codecpar->ch_layout.nb_channels;
#endif
#endif
std::stringstream ss;

Expand Down

0 comments on commit 155e6d5

Please sign in to comment.