Skip to content

Commit

Permalink
ffmpeg: disable deprecated avcodec iterator/register
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 8, 2018
1 parent 3f9f6a2 commit 01f81df
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -326,7 326,9 @@ AVDemuxer::AVDemuxer(QObject *parent)
class AVInitializer {
public:
AVInitializer() {
#if !AVCODEC_STATIC_REGISTER
avcodec_register_all();
#endif
#if QTAV_HAVE(AVDEVICE)
avdevice_register_all();
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/QtAV/private/AVCompat.h
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
solve the version problem and diffirent api in FFmpeg and libav
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -61,6 61,8 @@ extern "C"
#include <libavutil/avstring.h>
#include <libavfilter/version.h>

#define AVCODEC_STATIC_REGISTER FFMPEG_MODULE_CHECK(LIBAVCODEC, 58, 10, 100)

#if !FFMPEG_MODULE_CHECK(LIBAVUTIL, 51, 73, 101)
#include <libavutil/channel_layout.h>
#endif
Expand Down
13 changes: 9 additions & 4 deletions src/QtAV_Global.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -190,7 190,7 @@ QString aboutQtAV_HTML()
{
static QString about = QString::fromLatin1("<img src='qrc:/QtAV.svg'><h3>QtAV " QTAV_VERSION_STR_LONG "</h3>\n"
"<p>%1</p><p>%2</p><p>%3 </p>"
"<p>Copyright (C) 2012-2017 Wang Bin (aka. Lucas Wang) <a href='mailto:[email protected]'>[email protected]</a></p>\n"
"<p>Copyright (C) 2012-2018 Wang Bin (aka. Lucas Wang) <a href='mailto:[email protected]'>[email protected]</a></p>\n"
"<p>%4: <a href='http://qtav.org/donate.html'>http://qtav.org/donate.html</a></p>\n"
"<p>%5: <a href='https://github.com/wang-bin/QtAV'>https://github.com/wang-bin/QtAV</a></p>\n"
"<p>%6: <a href='http://qtav.org'>http://qtav.org</a></p>"
Expand Down Expand Up @@ -305,9 305,14 @@ QString avcodecOptions()
void* obj = const_cast<void*>(reinterpret_cast<const void*>(avcodec_get_class()));
opts = Internal::optionsToString((void*)&obj);
opts.append(ushort('\n'));
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
AVCodec* c = NULL;
while ((c=av_codec_next(c))) {
while ((c = av_codec_next(c))) {
#endif
QString opt(Internal::optionsToString((void*)&c->priv_class).trimmed());
if (opt.isEmpty())
continue;
Expand Down
4 changes: 3 additions & 1 deletion src/codec/AVDecoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -47,7 47,9 @@ static AVCodec* get_codec(const QString &name, const QString& hwa, AVCodecID cid
AVDecoder::AVDecoder(AVDecoderPrivate &d)
:DPTR_INIT(&d)
{
#if !AVCODEC_STATIC_REGISTER
avcodec_register_all(); // avcodec_find_decoder will always be used
#endif
}

AVDecoder::~AVDecoder()
Expand Down
11 changes: 8 additions & 3 deletions src/codec/audio/AudioDecoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -43,9 43,14 @@ QStringList AudioDecoder::supportedCodecs()
static QStringList codecs;
if (!codecs.isEmpty())
return codecs;
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
AVCodec* c = NULL;
while ((c=av_codec_next(c))) {
while ((c = av_codec_next(c))) {
#endif
if (!av_codec_is_decoder(c) || c->type != AVMEDIA_TYPE_AUDIO)
continue;
codecs.append(QString::fromLatin1(c->name));
Expand Down
4 changes: 3 additions & 1 deletion src/codec/audio/AudioDecoderFFmpeg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -63,7 63,9 @@ class AudioDecoderFFmpegPrivate Q_DECL_FINAL: public AudioDecoderPrivate
: AudioDecoderPrivate()
, frame(av_frame_alloc())
{
#if !AVCODEC_STATIC_REGISTER
avcodec_register_all();
#endif
}
~AudioDecoderFFmpegPrivate() {
if (frame) {
Expand Down
11 changes: 8 additions & 3 deletions src/codec/audio/AudioEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2015)
Expand Down Expand Up @@ -45,9 45,14 @@ QStringList AudioEncoder::supportedCodecs()
static QStringList codecs;
if (!codecs.isEmpty())
return codecs;
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
AVCodec* c = NULL;
while ((c=av_codec_next(c))) {
while ((c = av_codec_next(c))) {
#endif
if (!av_codec_is_encoder(c) || c->type != AVMEDIA_TYPE_AUDIO)
continue;
codecs.append(QString::fromLatin1(c->name));
Expand Down
11 changes: 8 additions & 3 deletions src/codec/video/VideoDecoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -93,9 93,14 @@ QStringList VideoDecoder::supportedCodecs()
static QStringList codecs;
if (!codecs.isEmpty())
return codecs;
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
AVCodec* c = NULL;
while ((c=av_codec_next(c))) {
while ((c = av_codec_next(c))) {
#endif
if (!av_codec_is_decoder(c) || c->type != AVMEDIA_TYPE_VIDEO)
continue;
codecs.append(QString::fromLatin1(c->name));
Expand Down
4 changes: 3 additions & 1 deletion src/codec/video/VideoDecoderD3D.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2016)
Expand Down Expand Up @@ -34,7 34,9 @@ namespace QtAV {

static bool check_ffmpeg_hevc_dxva2()
{
#if !AVCODEC_STATIC_REGISTER
avcodec_register_all();
#endif
AVHWAccel *hwa = av_hwaccel_next(0);
while (hwa) {
if (strncmp("hevc_dxva2", hwa->name, 10) == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/codec/video/VideoDecoderFFmpegBase.h
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand Down Expand Up @@ -51,7 51,9 @@ class VideoDecoderFFmpegBasePrivate : public VideoDecoderPrivate
, width(0)
, height(0)
{
#if !AVCODEC_STATIC_REGISTER
avcodec_register_all();
#endif
frame = av_frame_alloc();
}
virtual ~VideoDecoderFFmpegBasePrivate() {
Expand Down
11 changes: 8 additions & 3 deletions src/codec/video/VideoEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2015)
Expand Down Expand Up @@ -46,9 46,14 @@ QStringList VideoEncoder::supportedCodecs()
static QStringList codecs;
if (!codecs.isEmpty())
return codecs;
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
AVCodec* c = NULL;
while ((c=av_codec_next(c))) {
while ((c = av_codec_next(c))) {
#endif
if (!av_codec_is_encoder(c) || c->type != AVMEDIA_TYPE_VIDEO)
continue;
codecs.append(QString::fromLatin1(c->name));
Expand Down
4 changes: 3 additions & 1 deletion src/codec/video/VideoEncoderFFmpeg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2015)
Expand Down Expand Up @@ -90,7 90,9 @@ class VideoEncoderFFmpegPrivate Q_DECL_FINAL: public VideoEncoderPrivate
: VideoEncoderPrivate()
, nb_encoded(0)
{
#if !AVCODEC_STATIC_REGISTER
avcodec_register_all();
#endif
// NULL: codec-specific defaults won't be initialized, which may result in suboptimal default settings (this is important mainly for encoders, e.g. libx264).
avctx = avcodec_alloc_context3(NULL);
}
Expand Down
23 changes: 16 additions & 7 deletions src/subtitle/SubtitleProcessorFFmpeg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand Down Expand Up @@ -80,12 80,16 @@ QString SubtitleProcessorFFmpeg::name() const
QStringList ffmpeg_supported_sub_extensions_by_codec()
{
QStringList exts;
AVCodec *c = av_codec_next(NULL);
while (c) {
if (c->type != AVMEDIA_TYPE_SUBTITLE) {
c = av_codec_next(c);
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
while ((c = av_codec_next(c))) {
#endif
if (c->type != AVMEDIA_TYPE_SUBTITLE)
continue;
}
qDebug("sub codec: %s", c->name);
AVInputFormat *i = av_iformat_next(NULL);
while (i) {
Expand All @@ -105,7 109,6 @@ QStringList ffmpeg_supported_sub_extensions_by_codec()
//qDebug("codec name '%s' is not found in AVInputFormat, just append codec name", c->name);
//exts.append(c->name);
}
c = av_codec_next(c);
}
return exts;
}
Expand All @@ -127,7 130,13 @@ QStringList ffmpeg_supported_sub_extensions()
// AVCodecDescriptor.name and AVCodec.name may be different. avcodec_get_name() use AVCodecDescriptor if possible
QStringList codecs;
const AVCodec* c = NULL;
#if AVCODEC_STATIC_REGISTER
void* it = NULL;
while ((c = av_codec_iterate(&it))) {
#else
avcodec_register_all();
while ((c = av_codec_next(c))) {
#endif
if (c->type == AVMEDIA_TYPE_SUBTITLE)
codecs.append(QString::fromLatin1(c->name));
}
Expand Down

0 comments on commit 01f81df

Please sign in to comment.