make neutrino compatible with new ffmpeg

This commit is contained in:
Jacek Jendrzej
2017-03-07 15:00:17 +01:00
parent d3c3d3760c
commit bfa589eb08
6 changed files with 184 additions and 24 deletions

View File

@@ -47,6 +47,11 @@ extern "C" {
#define av_frame_unref avcodec_get_frame_defaults
#define av_frame_free avcodec_free_frame
#endif
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57, 8, 0 ))
#define av_packet_unref av_free_packet
#endif
#include <OpenThreads/ScopedLock>
#include <driver/netfile.h>
@@ -218,9 +223,16 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state,
Status=DATA_ERR;
return Status;
}
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 ))
AVCodecContext *c = avc->streams[best_stream]->codec;
#else
AVCodecContext *c = avcodec_alloc_context3(codec);
if(avcodec_parameters_to_context(c,avc->streams[best_stream]->codecpar) < 0){
DeInit();
Status=DATA_ERR;
return Status;
}
#endif
mutex.lock();
int r = avcodec_open2(c, codec, NULL);
mutex.unlock();
@@ -326,9 +338,10 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state,
Status=DATA_ERR;
break;
}
} else
} else{
av_frame_unref(frame);
}
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100)
int len = avcodec_decode_audio4(c, frame, &got_frame, &packet);
if (len < 0) {
// skip frame
@@ -340,6 +353,27 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state,
mutex.unlock();
continue;
}
packet.size -= len;
packet.data += len;
#else
int ret = avcodec_send_packet(c, &packet);
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF){
break;
}
if (ret >= 0){
packet.size = 0;
}
ret = avcodec_receive_frame(c, frame);
if (ret < 0){
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF){
break;
}
else{
continue;
}
}
got_frame = 1;
#endif
if (got_frame && *state!=PAUSE) {
int out_samples;
outsamples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + frame->nb_samples,
@@ -368,8 +402,6 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state,
if (!start_pts)
start_pts = pts;
}
packet.size -= len;
packet.data += len;
}
if (time_played && avc->streams[best_stream]->time_base.den)
*time_played = (pts - start_pts) * avc->streams[best_stream]->time_base.num / avc->streams[best_stream]->time_base.den;
@@ -428,7 +460,11 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover)
if (!is_stream) {
GetMeta(avc->metadata);
for(unsigned int i = 0; i < avc->nb_streams; i++) {
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 ))
if (avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
#else
if (avc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
#endif
GetMeta(avc->streams[i]->metadata);
}
}
@@ -445,12 +481,17 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover)
DeInit();
return false;
}
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 ))
if (!codec)
codec = avcodec_find_decoder(avc->streams[best_stream]->codec->codec_id);
samplerate = avc->streams[best_stream]->codec->sample_rate;
mChannels = av_get_channel_layout_nb_channels(avc->streams[best_stream]->codec->channel_layout);
#else
if (!codec)
codec = avcodec_find_decoder(avc->streams[best_stream]->codecpar->codec_id);
samplerate = avc->streams[best_stream]->codecpar->sample_rate;
mChannels = av_get_channel_layout_nb_channels(avc->streams[best_stream]->codecpar->channel_layout);
#endif
std::stringstream ss;
if (codec && codec->long_name != NULL)
@@ -470,8 +511,13 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover)
printf("CFfmpegDec: format %s (%s) duration %ld\n", avc->iformat->name, type_info.c_str(), total_time);
for(unsigned int i = 0; i < avc->nb_streams; i++) {
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 ))
if (avc->streams[i]->codec->bit_rate > 0)
bitrate += avc->streams[i]->codec->bit_rate;
#else
if (avc->streams[i]->codecpar->bit_rate > 0)
bitrate += avc->streams[i]->codecpar->bit_rate;
#endif
if (save_cover && (avc->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
mkdir(COVERDIR, 0755);
std::string cover(COVERDIR);