Skip to content

Commit

Permalink
Merge pull request #14332 from FernetMenta/ffmpeg
Browse files Browse the repository at this point in the history
AE: adapt to new ffmpeg api - kills warning
  • Loading branch information
FernetMenta committed Aug 21, 2018
2 parents a52449f + 1079fb5 commit 033b897
Showing 1 changed file with 46 additions and 27 deletions.
73 changes: 46 additions & 27 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp
Expand Up @@ -2933,19 +2933,19 @@ bool CActiveAE::CompareFormat(AEAudioFormat &lhs, AEAudioFormat &rhs)

IAESound *CActiveAE::MakeSound(const std::string& file)
{
AVFormatContext *fmt_ctx = NULL;
AVCodecContext *dec_ctx = NULL;
AVFormatContext *fmt_ctx = nullptr;
AVCodecContext *dec_ctx = nullptr;
AVIOContext *io_ctx;
AVInputFormat *io_fmt = NULL;
AVCodec *dec = NULL;
CActiveAESound *sound = NULL;
AVInputFormat *io_fmt = nullptr;
AVCodec *dec = nullptr;
CActiveAESound *sound = nullptr;
SampleConfig config;

sound = new CActiveAESound(file, this);
if (!sound->Prepare())
{
delete sound;
return NULL;
return nullptr;
}
int fileSize = sound->GetFileSize();

Expand All @@ -2961,15 +2961,15 @@ IAESound *CActiveAE::MakeSound(const std::string& file)

io_ctx->max_packet_size = bufferSize;

if(!sound->IsSeekPossible())
if (!sound->IsSeekPossible())
{
io_ctx->seekable = 0;
io_ctx->max_packet_size = 0;
}

fmt_ctx->pb = io_ctx;

av_probe_input_buffer(io_ctx, &io_fmt, file.c_str(), NULL, 0, 0);
av_probe_input_buffer(io_ctx, &io_fmt, file.c_str(), nullptr, 0, 0);
if (!io_fmt)
{
avformat_close_input(&fmt_ctx);
Expand All @@ -2983,10 +2983,10 @@ IAESound *CActiveAE::MakeSound(const std::string& file)
}

// find decoder
if (avformat_open_input(&fmt_ctx, file.c_str(), NULL, NULL) == 0)
if (avformat_open_input(&fmt_ctx, file.c_str(), nullptr, nullptr) == 0)
{
fmt_ctx->flags |= AVFMT_FLAG_NOPARSE;
if (avformat_find_stream_info(fmt_ctx, NULL) >= 0)
if (avformat_find_stream_info(fmt_ctx, nullptr) >= 0)
{
AVCodecID codecId = fmt_ctx->streams[0]->codecpar->codec_id;
dec = avcodec_find_decoder(codecId);
Expand Down Expand Up @@ -3017,32 +3017,25 @@ IAESound *CActiveAE::MakeSound(const std::string& file)
AVPacket avpkt;
AVFrame *decoded_frame = NULL;
decoded_frame = av_frame_alloc();
bool error = false;

if (avcodec_open2(dec_ctx, dec, NULL) >= 0)
if (avcodec_open2(dec_ctx, dec, nullptr) >= 0)
{
bool init = false;

// decode until eof
av_init_packet(&avpkt);
int len;
while (av_read_frame(fmt_ctx, &avpkt) >= 0)
int ret;
while (av_read_frame(fmt_ctx, &avpkt) >= 0 && !error)
{
int got_frame = 0;
len = avcodec_decode_audio4(dec_ctx, decoded_frame, &got_frame, &avpkt);
if (len < 0)
ret = avcodec_send_packet(dec_ctx, &avpkt);
if (ret < 0)
{
av_frame_free(&decoded_frame);
avcodec_free_context(&dec_ctx);
avformat_close_input(&fmt_ctx);
if (io_ctx)
{
av_freep(&io_ctx->buffer);
av_freep(&io_ctx);
}
delete sound;
return NULL;
error = true;
break;
}
if (got_frame)

while ((ret = avcodec_receive_frame(dec_ctx, decoded_frame)) == 0)
{
if (!init)
{
Expand All @@ -3056,6 +3049,26 @@ IAESound *CActiveAE::MakeSound(const std::string& file)
decoded_frame->nb_samples, decoded_frame->linesize[0]);
}
av_packet_unref(&avpkt);

if (ret < 0 && ret != AVERROR(EAGAIN))
{
error = true;
break;
}
}
ret = avcodec_send_packet(dec_ctx, nullptr);
while ((ret = avcodec_receive_frame(dec_ctx, decoded_frame)) != AVERROR_EOF)
{
if (ret == 0)
{
sound->StoreSound(true, decoded_frame->extended_data,
decoded_frame->nb_samples, decoded_frame->linesize[0]);
}
else
{
error = true;
break;
}
}
}

Expand All @@ -3068,6 +3081,12 @@ IAESound *CActiveAE::MakeSound(const std::string& file)
av_freep(&io_ctx);
}

if (error)
{
delete sound;
return nullptr;
}

sound->Finish();

// register sound
Expand Down

0 comments on commit 033b897

Please sign in to comment.