mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
ffmpeg: Remove code to support deprecated versions
See previous commit; now that we're enforcing explicit minimums, any code to support anything older than those minimums is trivially dead.
This commit is contained in:
parent
a19e9aea63
commit
148010c5f0
@ -63,11 +63,7 @@ FfmpegAudioCursor(FfmpegAudio *src) :
|
|||||||
_format_ctx = _ffvfile.get_format_context();
|
_format_ctx = _ffvfile.get_format_context();
|
||||||
nassertv(_format_ctx != NULL);
|
nassertv(_format_ctx != NULL);
|
||||||
|
|
||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
|
|
||||||
if (avformat_find_stream_info(_format_ctx, NULL) < 0) {
|
if (avformat_find_stream_info(_format_ctx, NULL) < 0) {
|
||||||
#else
|
|
||||||
if (av_find_stream_info(_format_ctx) < 0) {
|
|
||||||
#endif
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -94,31 +90,20 @@ FfmpegAudioCursor(FfmpegAudio *src) :
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
|
|
||||||
AVDictionary *opts = NULL;
|
AVDictionary *opts = NULL;
|
||||||
av_dict_set(&opts, "request_sample_fmt", "s16", 0);
|
av_dict_set(&opts, "request_sample_fmt", "s16", 0);
|
||||||
if (avcodec_open2(_audio_ctx, pAudioCodec, NULL) < 0) {
|
if (avcodec_open2(_audio_ctx, pAudioCodec, NULL) < 0) {
|
||||||
#else
|
|
||||||
if (avcodec_open(_audio_ctx, pAudioCodec) < 0) {
|
|
||||||
#endif
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
|
|
||||||
av_dict_free(&opts);
|
av_dict_free(&opts);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set up the resample context if necessary.
|
// Set up the resample context if necessary.
|
||||||
if (_audio_ctx->sample_fmt != AV_SAMPLE_FMT_S16) {
|
if (_audio_ctx->sample_fmt != AV_SAMPLE_FMT_S16) {
|
||||||
#ifdef HAVE_SWRESAMPLE
|
#ifdef HAVE_SWRESAMPLE
|
||||||
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 25, 0)
|
|
||||||
ffmpeg_cat.error()
|
|
||||||
<< "Codec does not use signed 16-bit sample format. Upgrade libavcodec to 53.25.0 or higher.\n";
|
|
||||||
#else
|
|
||||||
ffmpeg_cat.debug()
|
ffmpeg_cat.debug()
|
||||||
<< "Codec does not use signed 16-bit sample format. Setting up swresample context.\n";
|
<< "Codec does not use signed 16-bit sample format. Setting up swresample context.\n";
|
||||||
#endif
|
|
||||||
|
|
||||||
_resample_ctx = swr_alloc();
|
_resample_ctx = swr_alloc();
|
||||||
av_opt_set_int(_resample_ctx, "in_channel_layout", _audio_ctx->channel_layout, 0);
|
av_opt_set_int(_resample_ctx, "in_channel_layout", _audio_ctx->channel_layout, 0);
|
||||||
@ -191,10 +176,8 @@ cleanup() {
|
|||||||
if (_frame) {
|
if (_frame) {
|
||||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 45, 101)
|
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 45, 101)
|
||||||
av_frame_free(&_frame);
|
av_frame_free(&_frame);
|
||||||
#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 59, 100)
|
|
||||||
avcodec_free_frame(&_frame);
|
|
||||||
#else
|
#else
|
||||||
av_free(&_frame);
|
avcodec_free_frame(&_frame);
|
||||||
#endif
|
#endif
|
||||||
_frame = NULL;
|
_frame = NULL;
|
||||||
}
|
}
|
||||||
@ -284,25 +267,6 @@ reload_buffer() {
|
|||||||
return true;
|
return true;
|
||||||
} else if (_packet_size > 0) {
|
} else if (_packet_size > 0) {
|
||||||
int bufsize = _buffer_size * 2;
|
int bufsize = _buffer_size * 2;
|
||||||
#if LIBAVCODEC_VERSION_INT < 3349504
|
|
||||||
int len = avcodec_decode_audio(_audio_ctx, _buffer, &bufsize,
|
|
||||||
_packet_data, _packet_size);
|
|
||||||
movies_debug("avcodec_decode_audio returned " << len);
|
|
||||||
#elif LIBAVCODEC_VERSION_INT < 3414272
|
|
||||||
int len = avcodec_decode_audio2(_audio_ctx, _buffer, &bufsize,
|
|
||||||
_packet_data, _packet_size);
|
|
||||||
movies_debug("avcodec_decode_audio2 returned " << len);
|
|
||||||
#elif LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 25, 0)
|
|
||||||
// We should technically also consider resampling in this case, but
|
|
||||||
// whatever. Just upgrade your ffmpeg version if you get garbage.
|
|
||||||
AVPacket pkt;
|
|
||||||
av_init_packet(&pkt);
|
|
||||||
pkt.data = _packet_data;
|
|
||||||
pkt.size = _packet_size;
|
|
||||||
int len = avcodec_decode_audio3(_audio_ctx, _buffer, &bufsize, &pkt);
|
|
||||||
movies_debug("avcodec_decode_audio3 returned " << len);
|
|
||||||
av_free_packet(&pkt);
|
|
||||||
#else
|
|
||||||
int got_frame;
|
int got_frame;
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
av_init_packet(&pkt);
|
av_init_packet(&pkt);
|
||||||
@ -332,7 +296,6 @@ reload_buffer() {
|
|||||||
}
|
}
|
||||||
#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(52, 19, 100)
|
#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(52, 19, 100)
|
||||||
av_frame_unref(_frame);
|
av_frame_unref(_frame);
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@ -376,11 +339,7 @@ seek(double t) {
|
|||||||
cleanup();
|
cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
|
|
||||||
if (avcodec_open2(_audio_ctx, pAudioCodec, NULL) < 0) {
|
if (avcodec_open2(_audio_ctx, pAudioCodec, NULL) < 0) {
|
||||||
#else
|
|
||||||
if (avcodec_open(_audio_ctx, pAudioCodec) < 0) {
|
|
||||||
#endif
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -36,21 +36,10 @@ PStatCollector FfmpegVideoCursor::_fetch_buffer_pcollector("*:FFMPEG Video Decod
|
|||||||
PStatCollector FfmpegVideoCursor::_seek_pcollector("*:FFMPEG Video Decoding:Seek");
|
PStatCollector FfmpegVideoCursor::_seek_pcollector("*:FFMPEG Video Decoding:Seek");
|
||||||
PStatCollector FfmpegVideoCursor::_export_frame_pcollector("*:FFMPEG Convert Video to BGR");
|
PStatCollector FfmpegVideoCursor::_export_frame_pcollector("*:FFMPEG Convert Video to BGR");
|
||||||
|
|
||||||
#if LIBAVFORMAT_VERSION_MAJOR < 53
|
|
||||||
#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LIBAVCODEC_VERSION_MAJOR < 54
|
#if LIBAVCODEC_VERSION_MAJOR < 54
|
||||||
#define AV_CODEC_ID_VP8 CODEC_ID_VP8
|
#define AV_CODEC_ID_VP8 CODEC_ID_VP8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51, 74, 100)
|
|
||||||
#define AV_PIX_FMT_NONE PIX_FMT_NONE
|
|
||||||
#define AV_PIX_FMT_BGR24 PIX_FMT_BGR24
|
|
||||||
#define AV_PIX_FMT_BGRA PIX_FMT_BGRA
|
|
||||||
typedef PixelFormat AVPixelFormat;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52, 32, 100)
|
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52, 32, 100)
|
||||||
#define AV_PIX_FMT_FLAG_ALPHA PIX_FMT_ALPHA
|
#define AV_PIX_FMT_FLAG_ALPHA PIX_FMT_ALPHA
|
||||||
#endif
|
#endif
|
||||||
@ -120,7 +109,6 @@ init_from(FfmpegVideo *source) {
|
|||||||
_eof_known = false;
|
_eof_known = false;
|
||||||
_eof_frame = 0;
|
_eof_frame = 0;
|
||||||
|
|
||||||
#if LIBAVUTIL_VERSION_MAJOR >= 52
|
|
||||||
// Check if we got an alpha format. Please note that some video codecs
|
// Check if we got an alpha format. Please note that some video codecs
|
||||||
// (eg. libvpx) change the pix_fmt after decoding the first frame, which is
|
// (eg. libvpx) change the pix_fmt after decoding the first frame, which is
|
||||||
// why we didn't do this earlier.
|
// why we didn't do this earlier.
|
||||||
@ -128,9 +116,7 @@ init_from(FfmpegVideo *source) {
|
|||||||
if (desc && (desc->flags & AV_PIX_FMT_FLAG_ALPHA) != 0) {
|
if (desc && (desc->flags & AV_PIX_FMT_FLAG_ALPHA) != 0) {
|
||||||
_num_components = 4;
|
_num_components = 4;
|
||||||
_pixel_format = (int)AV_PIX_FMT_BGRA;
|
_pixel_format = (int)AV_PIX_FMT_BGRA;
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
{
|
|
||||||
_num_components = 3;
|
_num_components = 3;
|
||||||
_pixel_format = (int)AV_PIX_FMT_BGR24;
|
_pixel_format = (int)AV_PIX_FMT_BGR24;
|
||||||
}
|
}
|
||||||
@ -493,11 +479,7 @@ open_stream() {
|
|||||||
_format_ctx = _ffvfile.get_format_context();
|
_format_ctx = _ffvfile.get_format_context();
|
||||||
nassertr(_format_ctx != NULL, false);
|
nassertr(_format_ctx != NULL, false);
|
||||||
|
|
||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
|
|
||||||
if (avformat_find_stream_info(_format_ctx, NULL) < 0) {
|
if (avformat_find_stream_info(_format_ctx, NULL) < 0) {
|
||||||
#else
|
|
||||||
if (av_find_stream_info(_format_ctx) < 0) {
|
|
||||||
#endif
|
|
||||||
ffmpeg_cat.info()
|
ffmpeg_cat.info()
|
||||||
<< "Couldn't find stream info\n";
|
<< "Couldn't find stream info\n";
|
||||||
close_stream();
|
close_stream();
|
||||||
@ -539,11 +521,7 @@ open_stream() {
|
|||||||
close_stream();
|
close_stream();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
|
|
||||||
if (avcodec_open2(_video_ctx, pVideoCodec, NULL) < 0) {
|
if (avcodec_open2(_video_ctx, pVideoCodec, NULL) < 0) {
|
||||||
#else
|
|
||||||
if (avcodec_open(_video_ctx, pVideoCodec) < 0) {
|
|
||||||
#endif
|
|
||||||
ffmpeg_cat.info()
|
ffmpeg_cat.info()
|
||||||
<< "Couldn't open codec\n";
|
<< "Couldn't open codec\n";
|
||||||
close_stream();
|
close_stream();
|
||||||
@ -883,12 +861,7 @@ decode_frame(int &finished) {
|
|||||||
*/
|
*/
|
||||||
void FfmpegVideoCursor::
|
void FfmpegVideoCursor::
|
||||||
do_decode_frame(int &finished) {
|
do_decode_frame(int &finished) {
|
||||||
#if LIBAVCODEC_VERSION_INT < 3414272
|
|
||||||
avcodec_decode_video(_video_ctx, _frame,
|
|
||||||
&finished, _packet->data, _packet->size);
|
|
||||||
#else
|
|
||||||
avcodec_decode_video2(_video_ctx, _frame, &finished, _packet);
|
avcodec_decode_video2(_video_ctx, _frame, &finished, _packet);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,11 +107,7 @@ open_vfs(const Filename &filename) {
|
|||||||
|
|
||||||
// Now we can open the stream.
|
// Now we can open the stream.
|
||||||
int result =
|
int result =
|
||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 4, 0)
|
|
||||||
avformat_open_input(&_format_context, "", NULL, NULL);
|
avformat_open_input(&_format_context, "", NULL, NULL);
|
||||||
#else
|
|
||||||
av_open_input_file(&_format_context, "", NULL, 0, NULL);
|
|
||||||
#endif
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
@ -159,11 +155,7 @@ open_subfile(const SubfileInfo &info) {
|
|||||||
|
|
||||||
// Now we can open the stream.
|
// Now we can open the stream.
|
||||||
int result =
|
int result =
|
||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 4, 0)
|
|
||||||
avformat_open_input(&_format_context, fname.c_str(), NULL, NULL);
|
avformat_open_input(&_format_context, fname.c_str(), NULL, NULL);
|
||||||
#else
|
|
||||||
av_open_input_file(&_format_context, fname.c_str(), NULL, 0, NULL);
|
|
||||||
#endif
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
@ -179,12 +171,7 @@ open_subfile(const SubfileInfo &info) {
|
|||||||
void FfmpegVirtualFile::
|
void FfmpegVirtualFile::
|
||||||
close() {
|
close() {
|
||||||
if (_format_context != NULL) {
|
if (_format_context != NULL) {
|
||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
|
|
||||||
avformat_close_input(&_format_context);
|
avformat_close_input(&_format_context);
|
||||||
#else
|
|
||||||
av_close_input_file(_format_context);
|
|
||||||
_format_context = NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_io_context != NULL) {
|
if (_io_context != NULL) {
|
||||||
@ -218,9 +205,7 @@ register_protocol() {
|
|||||||
av_register_all();
|
av_register_all();
|
||||||
|
|
||||||
// And this one.
|
// And this one.
|
||||||
#if LIBAVFORMAT_VERSION_INT >= 0x351400
|
|
||||||
avformat_network_init();
|
avformat_network_init();
|
||||||
#endif
|
|
||||||
|
|
||||||
// Let's also register the logging to Panda's notify callback.
|
// Let's also register the logging to Panda's notify callback.
|
||||||
av_log_set_callback(&log_callback);
|
av_log_set_callback(&log_callback);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user