From 0fb334dde992babe5e7a72cff70655c3c08915a2 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 6 Feb 2023 13:51:12 +0800 Subject: [PATCH 01/10] QtAV-1.13.0-ffmpeg-5.0.patch --- src/AVCompat.cpp | 2 +- src/AVDemuxer.cpp | 40 +++++++++++++++- src/AVMuxer.cpp | 26 +++++++++-- src/AVPlayerPrivate.cpp | 54 ++++++++++++++++++++++ src/AVPlayerPrivate.h | 8 ++++ src/CMakeLists.txt | 9 +++- src/QtAV/AVDemuxer.h | 10 ++++ src/QtAV/private/AVDecoder_p.h | 2 +- src/VideoFormat.cpp | 4 ++ src/VideoFrameExtractor.cpp | 4 ++ src/codec/AVDecoder.cpp | 23 +++++++-- src/codec/AVEncoder.cpp | 6 +++ src/codec/audio/AudioDecoderFFmpeg.cpp | 28 +++++++++++ src/codec/audio/AudioEncoderFFmpeg.cpp | 12 ++++- src/codec/video/VideoDecoderFFmpegBase.cpp | 25 ++++++++++ src/codec/video/VideoDecoderFFmpegHW.cpp | 4 ++ src/codec/video/VideoDecoderVAAPI.cpp | 4 +- src/codec/video/VideoEncoderFFmpeg.cpp | 12 +++-- src/filter/LibAVFilter.cpp | 11 +++++ src/libQtAV.pro | 4 +- src/subtitle/SubtitleProcessorFFmpeg.cpp | 11 ++++- 21 files changed, 276 insertions(+), 23 deletions(-) diff --git a/src/AVCompat.cpp b/src/AVCompat.cpp index befb3cd9f..cf113f038 100644 --- a/src/AVCompat.cpp +++ b/src/AVCompat.cpp @@ -391,7 +391,7 @@ const char *get_codec_long_name(enum AVCodecID id) if (cd) return cd->long_name; av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id); - AVCodec *codec = avcodec_find_decoder(id); + const AVCodec *codec = avcodec_find_decoder(id); if (codec) return codec->long_name; codec = avcodec_find_encoder(id); diff --git a/src/AVDemuxer.cpp b/src/AVDemuxer.cpp index e81ef79fa..7be82c7e4 100644 --- a/src/AVDemuxer.cpp +++ b/src/AVDemuxer.cpp @@ -291,7 +291,7 @@ class AVDemuxer::Private //copy the info, not parse the file when constructed, then need member vars QString file; QString file_orig; - AVInputFormat *input_format; + const AVInputFormat *input_format; QString format_forced; MediaIO *input; @@ -311,7 +311,11 @@ class AVDemuxer::Private // wanted_stream is REQUIRED. e.g. always set -1 to indicate the default stream, -2 to disable int stream, wanted_stream; // -1 default, selected by ff int index, wanted_index; // index in a kind of streams +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx; +#else + AVCodecParameters *avctx; +#endif } StreamInfo; StreamInfo astream, vstream, sstream; @@ -623,12 +627,14 @@ bool AVDemuxer::seek(qint64 pos) if (upos <= startTime()) { qDebug("************seek to beginning. started = false"); d->started = false; //??? +#if LIBAVCODEC_VERSION_MAJOR < 59 if (d->astream.avctx) d->astream.avctx->frame_number = 0; if (d->vstream.avctx) d->vstream.avctx->frame_number = 0; //TODO: why frame_number not changed after seek? if (d->sstream.avctx) d->sstream.avctx->frame_number = 0; +#endif } return true; } @@ -1071,37 +1077,61 @@ QList AVDemuxer::subtitleStreams() const return d->subtitle_streams; } +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext* AVDemuxer::audioCodecContext(int stream) const +#else +AVCodecParameters* AVDemuxer::audioCodecContext(int stream) const +#endif { if (stream < 0) return d->astream.avctx; if (stream > (int)d->format_ctx->nb_streams) return 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = d->format_ctx->streams[stream]->codec; +#else + AVCodecParameters *avctx = d->format_ctx->streams[stream]->codecpar; +#endif if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) return avctx; return 0; } +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext* AVDemuxer::videoCodecContext(int stream) const +#else +AVCodecParameters* AVDemuxer::videoCodecContext(int stream) const +#endif { if (stream < 0) return d->vstream.avctx; if (stream > (int)d->format_ctx->nb_streams) return 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = d->format_ctx->streams[stream]->codec; +#else + AVCodecParameters *avctx = d->format_ctx->streams[stream]->codecpar; +#endif if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) return avctx; return 0; } +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext* AVDemuxer::subtitleCodecContext(int stream) const +#else +AVCodecParameters* AVDemuxer::subtitleCodecContext(int stream) const +#endif { if (stream < 0) return d->sstream.avctx; if (stream > (int)d->format_ctx->nb_streams) return 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = d->format_ctx->streams[stream]->codec; +#else + AVCodecParameters *avctx = d->format_ctx->streams[stream]->codecpar; +#endif if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) return avctx; return 0; @@ -1298,7 +1328,11 @@ bool AVDemuxer::Private::setStream(AVDemuxer::StreamType st, int streamValue) // don't touch wanted index si->stream = s; si->wanted_stream = streamValue; +#if LIBAVCODEC_VERSION_MAJOR < 59 si->avctx = format_ctx->streams[s]->codec; +#else + si->avctx = format_ctx->streams[s]->codecpar; +#endif has_attached_pic = !!(format_ctx->streams[s]->disposition & AV_DISPOSITION_ATTACHED_PIC); return true; } @@ -1311,7 +1345,11 @@ bool AVDemuxer::Private::prepareStreams() return false; AVMediaType type = AVMEDIA_TYPE_UNKNOWN; for (unsigned int i = 0; i < format_ctx->nb_streams; ++i) { +#if LIBAVCODEC_VERSION_MAJOR < 59 type = format_ctx->streams[i]->codec->codec_type; +#else + type = format_ctx->streams[i]->codecpar->codec_type; +#endif if (type == AVMEDIA_TYPE_VIDEO) { video_streams.push_back(i); } else if (type == AVMEDIA_TYPE_AUDIO) { diff --git a/src/AVMuxer.cpp b/src/AVMuxer.cpp index 8ee692cc0..39e2a9496 100644 --- a/src/AVMuxer.cpp +++ b/src/AVMuxer.cpp @@ -81,7 +81,7 @@ class AVMuxer::Private //copy the info, not parse the file when constructed, then need member vars QString file; QString file_orig; - AVOutputFormat *format; + const AVOutputFormat *format; QString format_forced; MediaIO *io; @@ -94,7 +94,7 @@ class AVMuxer::Private AVStream *AVMuxer::Private::addStream(AVFormatContext* ctx, const QString &codecName, AVCodecID codecId) { - AVCodec *codec = NULL; + const AVCodec *codec = NULL; if (!codecName.isEmpty()) { codec = avcodec_find_encoder_by_name(codecName.toUtf8().constData()); if (!codec) { @@ -120,7 +120,8 @@ AVStream *AVMuxer::Private::addStream(AVFormatContext* ctx, const QString &codec // set by avformat if unset s->id = ctx->nb_streams - 1; s->time_base = kTB; - AVCodecContext *c = s->codec; +#if LIBAVCODEC_VERSION_MAJOR < 59 + AVCodec *c = s->codec; c->codec_id = codec->id; // Using codec->time_base is deprecated, but needed for older lavf. c->time_base = s->time_base; @@ -129,6 +130,7 @@ AVStream *AVMuxer::Private::addStream(AVFormatContext* ctx, const QString &codec c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; // expose avctx to encoder and set properties in encoder? // list codecs for a given format in ui +#endif return s; } @@ -137,16 +139,24 @@ bool AVMuxer::Private::prepareStreams() audio_streams.clear(); video_streams.clear(); subtitle_streams.clear(); - AVOutputFormat* fmt = format_ctx->oformat; + const AVOutputFormat* fmt = format_ctx->oformat; if (venc) { AVStream *s = addStream(format_ctx, venc->codecName(), fmt->video_codec); if (s) { +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *c = s->codec; +#else + AVCodecParameters *c = s->codecpar; +#endif c->bit_rate = venc->bitRate(); c->width = venc->width(); c->height = venc->height(); /// MUST set after encoder is open to ensure format is valid and the same +#if LIBAVCODEC_VERSION_MAJOR < 59 c->pix_fmt = (AVPixelFormat)VideoFormat::pixelFormatToFFmpeg(venc->pixelFormat()); +#else + c->format = (AVPixelFormat)VideoFormat::pixelFormatToFFmpeg(venc->pixelFormat()); +#endif // Set avg_frame_rate based on encoder frame_rate s->avg_frame_rate = av_d2q(venc->frameRate(), venc->frameRate()*1001.0+2); @@ -157,11 +167,19 @@ bool AVMuxer::Private::prepareStreams() if (aenc) { AVStream *s = addStream(format_ctx, aenc->codecName(), fmt->audio_codec); if (s) { +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *c = s->codec; +#else + AVCodecParameters *c = s->codecpar; +#endif c->bit_rate = aenc->bitRate(); /// MUST set after encoder is open to ensure format is valid and the same c->sample_rate = aenc->audioFormat().sampleRate(); +#if LIBAVCODEC_VERSION_MAJOR < 59 c->sample_fmt = (AVSampleFormat)aenc->audioFormat().sampleFormatFFmpeg(); +#else + c->format = (AVSampleFormat)aenc->audioFormat().sampleFormatFFmpeg(); +#endif c->channel_layout = aenc->audioFormat().channelLayoutFFmpeg(); c->channels = aenc->audioFormat().channels(); c->bits_per_raw_sample = aenc->audioFormat().bytesPerSample()*8; // need?? diff --git a/src/AVPlayerPrivate.cpp b/src/AVPlayerPrivate.cpp index 79eeff186..2c94fbc41 100644 --- a/src/AVPlayerPrivate.cpp +++ b/src/AVPlayerPrivate.cpp @@ -55,7 +55,11 @@ int computeNotifyPrecision(qint64 durati } } // namespace Internal +#if LIBAVCODEC_VERSION_MAJOR < 59 static bool correct_audio_channels(AVCodecContext *ctx) { +#else +static bool correct_audio_channels(AVCodecParameters *ctx) { +#endif if (ctx->channels <= 0) { if (ctx->channel_layout) { ctx->channels = av_get_channel_layout_nb_channels(ctx->channel_layout); @@ -251,7 +255,11 @@ void AVPlayer::Private::initBaseStatisti updateNotifyInterval(); } +#if LIBAVCODEC_VERSION_MAJOR < 59 void AVPlayer::Private::initCommonStatistics(int s, Statistics::Common *st, AVCodecContext *avctx) +#else +void AVPlayer::Private::initCommonStatistics(int s, Statistics::Common *st, AVCodecParameters *avctx) +#endif { AVFormatContext *fmt_ctx = demuxer.formatContext(); if (!fmt_ctx) { @@ -288,7 +296,11 @@ void AVPlayer::Private::initCommonStatis void AVPlayer::Private::initAudioStatistics(int s) { +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = demuxer.audioCodecContext(); +#else + AVCodecParameters *avctx = demuxer.audioCodecContext(); +#endif statistics.audio = Statistics::Common(); statistics.audio_only = Statistics::AudioOnly(); if (!avctx) @@ -306,14 +318,22 @@ void AVPlayer::Private::initAudioStatist // nb_channels -1: will use av_get_channel_layout_nb_channels av_get_channel_layout_string(cl, sizeof(cl), avctx->channels, avctx->channel_layout); statistics.audio_only.channel_layout = QLatin1String(cl); +#if LIBAVCODEC_VERSION_MAJOR < 59 statistics.audio_only.sample_fmt = QLatin1String(av_get_sample_fmt_name(avctx->sample_fmt)); +#else + statistics.audio_only.sample_fmt = QLatin1String(av_get_sample_fmt_name(static_cast(avctx->format))); +#endif statistics.audio_only.frame_size = avctx->frame_size; statistics.audio_only.sample_rate = avctx->sample_rate; } void AVPlayer::Private::initVideoStatistics(int s) { +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = demuxer.videoCodecContext(); +#else + AVCodecParameters *avctx = demuxer.videoCodecContext(); +#endif statistics.video = Statistics::Common(); statistics.video_only = Statistics::VideoOnly(); if (!avctx) @@ -324,10 +344,20 @@ void AVPlayer::Private::initVideoStatist statistics.video.decoder = vdec->name(); statistics.video.decoder_detail = vdec->description(); } +#if LIBAVCODEC_VERSION_MAJOR < 59 statistics.video_only.coded_height = avctx->coded_height; statistics.video_only.coded_width = avctx->coded_width; statistics.video_only.gop_size = avctx->gop_size; statistics.video_only.pix_fmt = QLatin1String(av_get_pix_fmt_name(avctx->pix_fmt)); +#else + // FIXME we can't really get coded_height, coded_width and gop_size from Parameters + // At some point we should make an effort to get the real codec context; in the mean + // time, this should be close enough... + statistics.video_only.coded_height = avctx->height; + statistics.video_only.coded_width = avctx->width; + statistics.video_only.gop_size = 0; + statistics.video_only.pix_fmt = QLatin1String(av_get_pix_fmt_name(static_cast(avctx->format))); +#endif statistics.video_only.height = avctx->height; statistics.video_only.width = avctx->width; statistics.video_only.rotate = 0; @@ -354,7 +384,11 @@ bool AVPlayer::Private::setupAudioThread athread->setDecoder(0); athread->setOutput(0); } +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = ademuxer->audioCodecContext(); +#else + AVCodecParameters *avctx = ademuxer->audioCodecContext(); +#endif if (!avctx) { // TODO: close ao? //TODO: check pulseaudio perapp control if closed return false; @@ -384,7 +418,11 @@ bool AVPlayer::Private::setupAudioThread correct_audio_channels(avctx); AudioFormat af; af.setSampleRate(avctx->sample_rate); +#if LIBAVCODEC_VERSION_MAJOR < 59 af.setSampleFormatFFmpeg(avctx->sample_fmt); +#else + af.setSampleFormatFFmpeg(avctx->format); +#endif af.setChannelLayoutFFmpeg(avctx->channel_layout); if (!af.isValid()) { qWarning("invalid audio format. audio stream will be disabled"); @@ -466,7 +504,11 @@ QVariantList AVPlayer::Private::getTrack t[QStringLiteral("stream_index")] = QVariant(s); AVStream *stream = demuxer->formatContext()->streams[s]; +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *ctx = stream->codec; +#else + AVCodecParameters *ctx = stream->codecpar; +#endif if (ctx) { t[QStringLiteral("codec")] = QByteArray(avcodec_descriptor_get(ctx->codec_id)->name); if (ctx->extradata) @@ -494,7 +536,11 @@ bool AVPlayer::Private::applySubtitleStr { if (!demuxer.setStreamIndex(AVDemuxer::SubtitleStream, n)) return false; +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *ctx = demuxer.subtitleCodecContext(); +#else + AVCodecParameters *ctx = demuxer.subtitleCodecContext(); +#endif if (!ctx) return false; // FIXME: AVCodecDescriptor.name and AVCodec.name are different! @@ -512,7 +558,11 @@ bool AVPlayer::Private::tryApplyDecoderP // TODO: add an option to apply the new decoder even if not available qint64 pos = player->position(); VideoDecoder *vd = NULL; +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = demuxer.videoCodecContext(); +#else + AVCodecParameters *avctx = demuxer.videoCodecContext(); +#endif foreach(VideoDecoderId vid, vc_ids) { qDebug("**********trying video decoder: %s...", VideoDecoder::name(vid)); vd = VideoDecoder::create(vid); @@ -560,7 +610,11 @@ bool AVPlayer::Private::setupVideoThread vthread->packetQueue()->clear(); vthread->setDecoder(0); } +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *avctx = demuxer.videoCodecContext(); +#else + AVCodecParameters *avctx = demuxer.videoCodecContext(); +#endif if (!avctx) { return false; } diff --git a/src/AVPlayerPrivate.h b/src/AVPlayerPrivate.h index 77e45f06a..15f114490 100644 --- a/src/AVPlayerPrivate.h +++ b/src/AVPlayerPrivate.h @@ -29,6 +29,10 @@ #include "AVDemuxThread.h" #include "utils/Logger.h" +extern "C" { +#include +} + namespace QtAV { static const qint64 kInvalidPosition = std::numeric_limits::max(); @@ -43,7 +47,11 @@ class AVPlayer::Private void applyFrameRate(); void initStatistics(); void initBaseStatistics(); +#if LIBAVCODEC_VERSION_MAJOR < 59 void initCommonStatistics(int s, Statistics::Common* st, AVCodecContext* avctx); +#else + void initCommonStatistics(int s, Statistics::Common* st, AVCodecParameters* avctx); +#endif void initAudioStatistics(int s); void initVideoStatistics(int s); void initSubtitleStatistics(int s); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7781fd632..a0613862d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -438,7 +438,10 @@ if(HAVE_OPENSL) list(APPEND EXTRA_DEFS -DQTAV_HAVE_OPENSL=1) list(APPEND EXTRA_LIBS OpenSLES) endif() -check_library_exists(va vaInitialize "" HAVE_VAAPI) +#check_library_exists(va vaInitialize "" HAVE_VAAPI) +# FIXME does VAAPI still need special attention or does +# ffmpeg 5.0 take care of it by itself? +set(HAVE_VAAPI OFF) if(HAVE_VAAPI) list(APPEND SOURCES vaapi/vaapi_helper.cpp @@ -449,7 +452,9 @@ if(HAVE_VAAPI) list(APPEND EXTRA_LIBS va X11) endif() -if(NOT APPLE) +# FIXME at some point, this should be ported to ffmpeg 5.0 +# But for now... NaziVidia sucks anyway. +if(NOT APPLE AND FALSE) list(APPEND EXTRA_DEFS -DQTAV_HAVE_CUDA=1) list(APPEND EXTRA_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cuda) list(APPEND SOURCES diff --git a/src/QtAV/AVDemuxer.h b/src/QtAV/AVDemuxer.h index 3b720f5d2..688c82f9c 100644 --- a/src/QtAV/AVDemuxer.h +++ b/src/QtAV/AVDemuxer.h @@ -28,6 +28,10 @@ #include #include +extern "C" { +#include +} + struct AVFormatContext; struct AVCodecContext; QT_BEGIN_NAMESPACE @@ -151,9 +155,15 @@ class Q_AV_EXPORT AVDemuxer : public QObject int subtitleStream() const; QList subtitleStreams() const; //codec. stream < 0: the stream going to play (or the stream set by setStreamIndex()) +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext* audioCodecContext(int stream = -1) const; AVCodecContext* videoCodecContext(int stream = -1) const; AVCodecContext* subtitleCodecContext(int stream = -1) const; +#else + AVCodecParameters* audioCodecContext(int stream = -1) const; + AVCodecParameters* videoCodecContext(int stream = -1) const; + AVCodecParameters* subtitleCodecContext(int stream = -1) const; +#endif /** * @brief getInterruptTimeout return the interrupt timeout */ diff --git a/src/QtAV/private/AVDecoder_p.h b/src/QtAV/private/AVDecoder_p.h index 2382974e2..5e952ea84 100644 --- a/src/QtAV/private/AVDecoder_p.h +++ b/src/QtAV/private/AVDecoder_p.h @@ -78,7 +78,7 @@ class Q_AV_PRIVATE_EXPORT AVDecoderPrivate : public DPtrPrivate { public: static const char* getProfileName(AVCodecID id, int profile) { - AVCodec *c = avcodec_find_decoder(id); + const AVCodec *c = avcodec_find_decoder(id); if (!c) return "Unknow"; return av_get_profile_name(c, profile); diff --git a/src/VideoFormat.cpp b/src/VideoFormat.cpp index b9c7b4f0a..5e7901f1d 100644 --- a/src/VideoFormat.cpp +++ b/src/VideoFormat.cpp @@ -702,7 +702,11 @@ bool VideoFormat::hasPalette() const bool VideoFormat::isPseudoPaletted() const { +#if LIBAVCODEC_VERSION_MAJOR < 59 return (d->flags() & AV_PIX_FMT_FLAG_PSEUDOPAL) == AV_PIX_FMT_FLAG_PSEUDOPAL; +#else + return hasPalette(); +#endif } bool VideoFormat::isBitStream() const diff --git a/src/VideoFrameExtractor.cpp b/src/VideoFrameExtractor.cpp index 60a1540f3..086d3fee9 100644 --- a/src/VideoFrameExtractor.cpp +++ b/src/VideoFrameExtractor.cpp @@ -192,7 +192,11 @@ class VideoFrameExtractorPrivate : public DPtrPrivate if (!vd) continue; decoder.reset(vd); +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *cctx = demuxer.videoCodecContext(); +#else + AVCodecParameters *cctx = demuxer.videoCodecContext(); +#endif if (cctx) decoder->setCodecContext(demuxer.videoCodecContext()); if (!cctx || !decoder->open()) { decoder.reset(0); diff --git a/src/codec/AVDecoder.cpp b/src/codec/AVDecoder.cpp index 440504d01..bc9cc278a 100644 --- a/src/codec/AVDecoder.cpp +++ b/src/codec/AVDecoder.cpp @@ -27,7 +27,7 @@ namespace QtAV { -static AVCodec* get_codec(const QString &name, const QString& hwa, AVCodecID cid) +static const AVCodec* get_codec(const QString &name, const QString& hwa, AVCodecID cid) { QString fullname(name); if (name.isEmpty()) { @@ -35,7 +35,7 @@ static AVCodec* get_codec(const QString &name, const QString& hwa, AVCodecID cid return avcodec_find_decoder(cid); fullname = QString("%1_%2").arg(avcodec_get_name(cid)).arg(hwa); } - AVCodec *codec = avcodec_find_decoder_by_name(fullname.toUtf8().constData()); + const AVCodec *codec = avcodec_find_decoder_by_name(fullname.toUtf8().constData()); if (codec) return codec; const AVCodecDescriptor* cd = avcodec_descriptor_get_by_name(fullname.toUtf8().constData()); @@ -76,7 +76,7 @@ bool AVDecoder::open() return false; } const QString hwa = property("hwaccel").toString(); - AVCodec* codec = get_codec(codecName(), hwa, d.codec_ctx->codec_id); + const AVCodec* codec = get_codec(codecName(), hwa, d.codec_ctx->codec_id); if (!codec) { // TODO: can be null for none-ffmpeg based decoders QString es(tr("No codec could be found for '%1'")); if (d.codec_name.isEmpty()) { @@ -153,6 +153,8 @@ void AVDecoder::flush() avcodec_flush_buffers(d_func().codec_ctx); } +static QMap ccs; + /* * do nothing if equal * close the old one. the codec context can not be shared in more than 1 decoder. @@ -160,9 +162,17 @@ void AVDecoder::flush() void AVDecoder::setCodecContext(void *codecCtx) { DPTR_D(AVDecoder); +#if LIBAVCODEC_VERSION_MAJOR < 59 AVCodecContext *ctx = (AVCodecContext*)codecCtx; - if (d.codec_ctx == ctx) + if (d.codec_ctx == codecCtx) return; +#else + AVCodecParameters *ctx = (AVCodecParameters*)codecCtx; + if(ccs.contains(ctx)) { + d.codec_ctx = ccs.value(ctx); + return; + } +#endif if (isOpen()) { qWarning("Can not copy codec properties when it's open"); close(); // @@ -180,7 +190,12 @@ void AVDecoder::setCodecContext(void *codecCtx) qWarning("avcodec_alloc_context3 failed"); return; } + ccs.insert(ctx, d.codec_ctx); +#if LIBAVCODEC_VERSION_MAJOR < 59 AV_ENSURE_OK(avcodec_copy_context(d.codec_ctx, ctx)); +#else + AV_ENSURE_OK(avcodec_parameters_to_context(d.codec_ctx, ctx)); +#endif } //TODO: reset other parameters? diff --git a/src/codec/AVEncoder.cpp b/src/codec/AVEncoder.cpp index 455539c78..5be64db2b 100644 --- a/src/codec/AVEncoder.cpp +++ b/src/codec/AVEncoder.cpp @@ -146,7 +146,13 @@ void AVEncoder::copyAVCodecContext(void* ctx) AVCodecContext* c = static_cast(ctx); if (d.avctx) { // dest should be avcodec_alloc_context3(NULL) +#if LIBAVCODEC_VERSION_MAJOR < 59 AV_ENSURE_OK(avcodec_copy_context(d.avctx, c)); +#else + AVCodecParameters *par; + avcodec_parameters_from_context(par, c); + AV_ENSURE_OK(avcodec_parameters_to_context(d.avctx, par)); +#endif d.is_open = false; return; } diff --git a/src/codec/audio/AudioDecoderFFmpeg.cpp b/src/codec/audio/AudioDecoderFFmpeg.cpp index d783588ae..7c5188fc8 100644 --- a/src/codec/audio/AudioDecoderFFmpeg.cpp +++ b/src/codec/audio/AudioDecoderFFmpeg.cpp @@ -100,10 +100,34 @@ bool AudioDecoderFFmpeg::decode(const Packet &packet) av_init_packet(&eofpkt); eofpkt.data = NULL; eofpkt.size = 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 ret = avcodec_decode_audio4(d.codec_ctx, d.frame, &got_frame_ptr, &eofpkt); +#else + ret = avcodec_receive_frame(d.codec_ctx, d.frame); + if (ret == AVERROR(EAGAIN)) + return false; + else if (ret < 0) { + qWarning("[AudioDecoder] %s", av_err2str(ret)); + return false; + } + got_frame_ptr = (ret == 0); + ret = avcodec_send_packet(d.codec_ctx, &eofpkt); +#endif } else { // const AVPacket*: ffmpeg >= 1.0. no libav +#if LIBAVCODEC_VERSION_MAJOR < 59 ret = avcodec_decode_audio4(d.codec_ctx, d.frame, &got_frame_ptr, (AVPacket*)packet.asAVPacket()); +#else + ret = avcodec_receive_frame(d.codec_ctx, d.frame); + if (ret == AVERROR(EAGAIN)) + return false; + else if (ret < 0) { + qWarning("[AudioDecoder] %s", av_err2str(ret)); + return false; + } + got_frame_ptr = (ret == 0); + ret = avcodec_send_packet(d.codec_ctx, (AVPacket*)packet.asAVPacket()); +#endif } d.undecoded_size = qMin(packet.data.size() - ret, packet.data.size()); if (ret == AVERROR(EAGAIN)) { @@ -145,7 +169,11 @@ AudioFrame AudioDecoderFFmpeg::frame() f.setBytesPerLine(d.frame->linesize[0], 0); // for correct alignment f.setSamplesPerChannel(d.frame->nb_samples); // TODO: ffplay check AVFrame.pts, pkt_pts, last_pts+nb_samples. move to AudioFrame::from(AVFrame*) +#if LIBAVCODEC_VERSION_MAJOR < 59 f.setTimestamp((double)d.frame->pkt_pts/1000.0); +#else + f.setTimestamp((double)d.frame->pts/1000.0); +#endif f.setAudioResampler(d.resampler); // TODO: remove. it's not safe if frame is shared. use a pool or detach if ref >1 return f; } diff --git a/src/codec/audio/AudioEncoderFFmpeg.cpp b/src/codec/audio/AudioEncoderFFmpeg.cpp index 3811e11a6..c338aae33 100644 --- a/src/codec/audio/AudioEncoderFFmpeg.cpp +++ b/src/codec/audio/AudioEncoderFFmpeg.cpp @@ -54,7 +54,9 @@ class AudioEncoderFFmpegPrivate Q_DECL_FINAL: public AudioEncoderPrivate AudioEncoderFFmpegPrivate() : AudioEncoderPrivate() { +#if LIBAVCODEC_VERSION_MAJOR < 59 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); } @@ -68,11 +70,11 @@ bool AudioEncoderFFmpegPrivate::open() { if (codec_name.isEmpty()) { // copy ctx from muxer by copyAVCodecContext - AVCodec *codec = avcodec_find_encoder(avctx->codec_id); + const AVCodec *codec = avcodec_find_encoder(avctx->codec_id); AV_ENSURE_OK(avcodec_open2(avctx, codec, &dict), false); return true; } - AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData()); + const AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData()); if (!codec) { const AVCodecDescriptor* cd = avcodec_descriptor_get_by_name(codec_name.toUtf8().constData()); if (cd) { @@ -204,7 +206,13 @@ bool AudioEncoderFFmpeg::encode(const AudioFrame &frame) pkt.data = (uint8_t*)d.buffer.constData(); //NULL pkt.size = d.buffer.size(); //0 int got_packet = 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 int ret = avcodec_encode_audio2(d.avctx, &pkt, f, &got_packet); +#else + int ret = avcodec_send_frame(d.avctx, f); + got_packet = (ret == 0); + ret = avcodec_receive_packet(d.avctx, &pkt); +#endif av_frame_free(&f); if (ret < 0) { //qWarning("error avcodec_encode_audio2: %s" ,av_err2str(ret)); diff --git a/src/codec/video/VideoDecoderFFmpegBase.cpp b/src/codec/video/VideoDecoderFFmpegBase.cpp index e344c5cbc..49cebb948 100644 --- a/src/codec/video/VideoDecoderFFmpegBase.cpp +++ b/src/codec/video/VideoDecoderFFmpegBase.cpp @@ -30,12 +30,21 @@ extern ColorRange colorRangeFromFFmpeg(AVColorRange cr); static void SetColorDetailsByFFmpeg(VideoFrame *f, AVFrame* frame, AVCodecContext* codec_ctx) { +#if LIBAVCODEC_VERSION_MAJOR < 59 ColorSpace cs = colorSpaceFromFFmpeg(av_frame_get_colorspace(frame)); if (cs == ColorSpace_Unknown) +#else + ColorSpace +#endif cs = colorSpaceFromFFmpeg(codec_ctx->colorspace); f->setColorSpace(cs); +#if LIBAVCODEC_VERSION_MAJOR < 59 ColorRange cr = colorRangeFromFFmpeg(av_frame_get_color_range(frame)); if (cr == ColorRange_Unknown) { +#else + ColorRange cr; + if (1) { +#endif // check yuvj format. TODO: deprecated, check only for old ffmpeg? const AVPixelFormat pixfmt = (AVPixelFormat)frame->format; switch (pixfmt) { @@ -125,9 +134,21 @@ bool VideoDecoderFFmpegBase::decode(const Packet &packet) av_init_packet(&eofpkt); eofpkt.data = NULL; eofpkt.size = 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 ret = avcodec_decode_video2(d.codec_ctx, d.frame, &got_frame_ptr, &eofpkt); +#else + ret = avcodec_receive_frame(d.codec_ctx, d.frame); + got_frame_ptr = (ret == 0); + ret = avcodec_send_packet(d.codec_ctx, &eofpkt); +#endif } else { +#if LIBAVCODEC_VERSION_MAJOR < 59 ret = avcodec_decode_video2(d.codec_ctx, d.frame, &got_frame_ptr, (AVPacket*)packet.asAVPacket()); +#else + ret = avcodec_receive_frame(d.codec_ctx, d.frame); + got_frame_ptr = (ret == 0); + ret = avcodec_send_packet(d.codec_ctx, (AVPacket*)packet.asAVPacket()); +#endif } //qDebug("pic_type=%c", av_get_picture_type_char(d.frame->pict_type)); d.undecoded_size = qMin(packet.data.size() - ret, packet.data.size()); @@ -159,7 +180,11 @@ VideoFrame VideoDecoderFFmpegBase::frame() frame.setBits(d.frame->data); frame.setBytesPerLine(d.frame->linesize); // in s. TODO: what about AVFrame.pts? av_frame_get_best_effort_timestamp? move to VideoFrame::from(AVFrame*) +#if LIBAVCODEC_VERSION_MAJOR < 59 frame.setTimestamp((double)d.frame->pkt_pts/1000.0); +#else + frame.setTimestamp((double)d.frame->pts/1000.0); +#endif frame.setMetaData(QStringLiteral("avbuf"), QVariant::fromValue(AVFrameBuffersRef(new AVFrameBuffers(d.frame)))); d.updateColorDetails(&frame); if (frame.format().hasPalette()) { diff --git a/src/codec/video/VideoDecoderFFmpegHW.cpp b/src/codec/video/VideoDecoderFFmpegHW.cpp index c17c8b28b..17d663e6b 100644 --- a/src/codec/video/VideoDecoderFFmpegHW.cpp +++ b/src/codec/video/VideoDecoderFFmpegHW.cpp @@ -328,7 +328,11 @@ VideoFrame VideoDecoderFFmpegHW::copyToFrame(const VideoFormat& fmt, int surface // TODO: buffer pool and create VideoFrame when needed to avoid copy? also for other va frame = frame.clone(); } +#if LIBAVCODEC_VERSION_MAJOR < 59 frame.setTimestamp(double(d.frame->pkt_pts)/1000.0); +#else + frame.setTimestamp(double(d.frame->pts)/1000.0); +#endif frame.setDisplayAspectRatio(d.getDAR(d.frame)); d.updateColorDetails(&frame); return frame; diff --git a/src/codec/video/VideoDecoderVAAPI.cpp b/src/codec/video/VideoDecoderVAAPI.cpp index a91caf92d..0c8ce0162 100644 --- a/src/codec/video/VideoDecoderVAAPI.cpp +++ b/src/codec/video/VideoDecoderVAAPI.cpp @@ -27,9 +27,11 @@ #include #include #include +#if LIBAVCODEC_VERSION_MAJOR < 59 extern "C" { #include } +#endif #include "QtAV/private/AVCompat.h" #include "QtAV/private/factory.h" #include "vaapi/SurfaceInteropVAAPI.h" @@ -84,7 +86,7 @@ FACTORY_REGISTER(VideoDecoder, VAAPI, "VAAPI") const char* getProfileName(AVCodecID id, int profile) { - AVCodec *c = avcodec_find_decoder(id); + const AVCodec *c = avcodec_find_decoder(id); if (!c) return "Unknow"; return av_get_profile_name(c, profile); diff --git a/src/codec/video/VideoEncoderFFmpeg.cpp b/src/codec/video/VideoEncoderFFmpeg.cpp index c0c902cb0..a352c533c 100644 --- a/src/codec/video/VideoEncoderFFmpeg.cpp +++ b/src/codec/video/VideoEncoderFFmpeg.cpp @@ -116,11 +116,11 @@ bool VideoEncoderFFmpegPrivate::open() nb_encoded = 0LL; if (codec_name.isEmpty()) { // copy ctx from muxer by copyAVCodecContext - AVCodec *codec = avcodec_find_encoder(avctx->codec_id); + const AVCodec *codec = avcodec_find_encoder(avctx->codec_id); AV_ENSURE_OK(avcodec_open2(avctx, codec, &dict), false); return true; } - AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData()); + const AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData()); if (!codec) { const AVCodecDescriptor* cd = avcodec_descriptor_get_by_name(codec_name.toUtf8().constData()); if (cd) { @@ -247,7 +247,7 @@ bool VideoEncoderFFmpegPrivate::open() applyOptionsForContext(); AV_ENSURE_OK(avcodec_open2(avctx, codec, &dict), false); // from mpv ao_lavc - const int buffer_size = qMax(qMax(width*height*6+200, AV_INPUT_BUFFER_MIN_SIZE), sizeof(AVPicture));//?? + const int buffer_size = qMax(qMax(width*height*6+200, AV_INPUT_BUFFER_MIN_SIZE), av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1));//?? buffer.resize(buffer_size); return true; } @@ -373,7 +373,13 @@ bool VideoEncoderFFmpeg::encode(const VideoFrame &frame) pkt.data = (uint8_t*)d.buffer.constData(); pkt.size = d.buffer.size(); int got_packet = 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 int ret = avcodec_encode_video2(d.avctx, &pkt, f.data(), &got_packet); +#else + int ret = avcodec_send_frame(d.avctx, f.data()); + got_packet = (ret == 0); + ret = avcodec_receive_packet(d.avctx, &pkt); +#endif if (ret < 0) { qWarning("error avcodec_encode_video2: %s" ,av_err2str(ret)); return false; //false diff --git a/src/filter/LibAVFilter.cpp b/src/filter/LibAVFilter.cpp index 8993a91f7..d770ddc33 100644 --- a/src/filter/LibAVFilter.cpp +++ b/src/filter/LibAVFilter.cpp @@ -84,7 +84,9 @@ class LibAVFilter::Private filter_graph = 0; in_filter_ctx = 0; out_filter_ctx = 0; +#if LIBAVCODEC_VERSION_MAJOR < 59 avfilter_register_all(); +#endif #endif //QTAV_HAVE(AVFILTER) } ~Private() { @@ -204,7 +206,9 @@ QString LibAVFilter::filterDescription(const QString &filterName) { QString s; #if QTAV_HAVE(AVFILTER) +#if LIBAVCODEC_VERSION_MAJOR < 59 avfilter_register_all(); +#endif const AVFilter *f = avfilter_get_by_name(filterName.toUtf8().constData()); if (!f) return s; @@ -283,11 +287,18 @@ QStringList LibAVFilter::registeredFilters(int type) { QStringList filters; #if QTAV_HAVE(AVFILTER) +#if LIBAVCODEC_VERSION_MAJOR < 59 avfilter_register_all(); +#endif const AVFilter* f = NULL; AVFilterPad* fp = NULL; // no const in avfilter_pad_get_name() for ffmpeg<=1.2 libav<=9 #if AV_MODULE_CHECK(LIBAVFILTER, 3, 8, 0, 53, 100) +#if LIBAVCODEC_VERSION_MAJOR < 59 while ((f = avfilter_next(f))) { +#else + void** ff = NULL; + while (f = av_filter_iterate(ff)) { +#endif #else AVFilter** ff = NULL; while ((ff = av_filter_next(ff)) && *ff) { diff --git a/src/libQtAV.pro b/src/libQtAV.pro index c6cbcc374..e68a3998e 100644 --- a/src/libQtAV.pro +++ b/src/libQtAV.pro @@ -244,7 +244,7 @@ config_pulseaudio { DEFINES *= QTAV_HAVE_PULSEAUDIO=1 LIBS += -lpulse } -CONFIG += config_cuda +!no-cuda: CONFIG *= config_cuda #CONFIG += config_cuda_link config_cuda { DEFINES += QTAV_HAVE_CUDA=1 @@ -287,7 +287,7 @@ config_d3d11va { } winrt: LIBS *= -ld3d11 } -win32:!winrt { +win32:!winrt:d3dva { HEADERS += directx/SurfaceInteropD3D9.h SOURCES += directx/SurfaceInteropD3D9.cpp enable_egl { diff --git a/src/subtitle/SubtitleProcessorFFmpeg.cpp b/src/subtitle/SubtitleProcessorFFmpeg.cpp index 8d4a94154..d2163e937 100644 --- a/src/subtitle/SubtitleProcessorFFmpeg.cpp +++ b/src/subtitle/SubtitleProcessorFFmpeg.cpp @@ -250,7 +250,7 @@ bool SubtitleProcessorFFmpeg::processHeader(const QByteArray &codec, const QByte if (codec_ctx) { avcodec_free_context(&codec_ctx); } - AVCodec *c = avcodec_find_decoder_by_name(codec.constData()); + const AVCodec *c = avcodec_find_decoder_by_name(codec.constData()); if (!c) { qDebug("subtitle avcodec_descriptor_get_by_name %s", codec.constData()); const AVCodecDescriptor *desc = avcodec_descriptor_get_by_name(codec.constData()); @@ -371,8 +371,15 @@ bool SubtitleProcessorFFmpeg::processSubtitle() qWarning("no subtitle stream found"); return false; } +#if LIBAVCODEC_VERSION_MAJOR < 59 codec_ctx = m_reader.subtitleCodecContext(); - AVCodec *dec = avcodec_find_decoder(codec_ctx->codec_id); + const AVCodec *dec = avcodec_find_decoder(codec_ctx->codec_id); +#else + AVCodecParameters *par = m_reader.subtitleCodecContext(); + const AVCodec *dec = avcodec_find_decoder(par->codec_id); + codec_ctx = avcodec_alloc_context3(dec); + avcodec_parameters_to_context(codec_ctx, par); +#endif const AVCodecDescriptor *dec_desc = avcodec_descriptor_get(codec_ctx->codec_id); if (!dec) { if (dec_desc) From 1cffff01b53fb04be7d4c1e9412a3ba5df88b09d Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 6 Feb 2023 13:11:29 +0800 Subject: [PATCH 02/10] FIX: remove msvc compat --- src/compat/msvc/changelog.txt | 138 --------------- src/compat/msvc/inttypes.h | 305 ---------------------------------- src/compat/msvc/stdint.h | 247 --------------------------- 3 files changed, 690 deletions(-) delete mode 100644 src/compat/msvc/changelog.txt delete mode 100644 src/compat/msvc/inttypes.h delete mode 100644 src/compat/msvc/stdint.h diff --git a/src/compat/msvc/changelog.txt b/src/compat/msvc/changelog.txt deleted file mode 100644 index e13b87e5c..000000000 --- a/src/compat/msvc/changelog.txt +++ /dev/null @@ -1,138 +0,0 @@ ------------------------------------------------------------------------- -r26 | 2009-10-02 13:36:47 +0400 | 2 lines - -[Issue 5] Change to "stdint.h" to let compiler search for it in local directory. - ------------------------------------------------------------------------- -r25 | 2009-09-17 23:46:49 +0400 | 2 lines - -[Issue 4] Fix incorrect int8_t behaviour if compiled with /J flag. - ------------------------------------------------------------------------- -r24 | 2009-05-13 14:53:48 +0400 | 2 lines - -Forgot about #ifdef __cplusplus guard around 'extern "C"', so inclusion to C files has been broken. - ------------------------------------------------------------------------- -r23 | 2009-05-12 01:27:45 +0400 | 3 lines - -[Issue 2] Always wrap is included. - ------------------------------------------------------------------------- -r19 | 2007-07-04 02:14:40 +0400 | 3 lines - -Explicitly cast to appropriate type INT8_MIN, INT16_MIN, INT32_MIN and INT64_MIN constants. -Due to their unusual definition in Visual Studio headers (-_Ix_MAX-1) they are propagated to int and thus do not have expected type, causing VS6 strict compiler to claim about type inconsistency. - ------------------------------------------------------------------------- -r18 | 2007-06-26 16:53:23 +0400 | 2 lines - -Better handling of (U)INTx_C macros - now they generate constants of exact width. - ------------------------------------------------------------------------- -r17 | 2007-03-29 20:16:14 +0400 | 2 lines - -Fix typo: Miscrosoft -> Microsoft. - ------------------------------------------------------------------------- -r16 | 2007-02-24 17:32:58 +0300 | 4 lines - -Remove include, as it is not present in Visual Studio 2005 Epxress Edition and required only for INT_PTR and UINT_PTR types. - -'intptr_t' and 'uintptr_t' types now defined explicitly with #ifdef _WIN64. - ------------------------------------------------------------------------- -r15 | 2007-02-11 20:53:05 +0300 | 2 lines - -More correct fix for compilation under VS6. - ------------------------------------------------------------------------- -r14 | 2007-02-11 20:04:32 +0300 | 2 lines - -Bugfix: fix compiling under VS6, when stdint.h enclosed in 'extern "C" {}'. - ------------------------------------------------------------------------- -r13 | 2006-12-13 16:53:11 +0300 | 2 lines - -Make _inline modifier for imaxdiv default option. Use STATIC_IMAXDIV to make it static. - ------------------------------------------------------------------------- -r12 | 2006-12-13 16:42:24 +0300 | 2 lines - -Error message changed: VC6 supported from now. - ------------------------------------------------------------------------- -r11 | 2006-12-13 16:39:33 +0300 | 2 lines - -All (U)INT* types changed to (unsigned) __int*. This should make stdint.h compatible with VC6. - ------------------------------------------------------------------------- -r10 | 2006-12-13 16:20:57 +0300 | 3 lines - -Added INLINE_IMAXDIV define switch. -If INLINE_IMAXDIV is defined imaxdiv() have static modifier. If not - it is _inline. - ------------------------------------------------------------------------- -r9 | 2006-12-13 15:53:52 +0300 | 2 lines - -Error message for non-MSC compiler changed. - ------------------------------------------------------------------------- -r8 | 2006-12-13 12:47:48 +0300 | 2 lines - -Added #ifndef for SIZE_MAX (it is defined in limits.h on MSVSC 8). - ------------------------------------------------------------------------- -r7 | 2006-12-13 01:08:02 +0300 | 2 lines - -License chaged to BSD-derivative. - ------------------------------------------------------------------------- -r6 | 2006-12-13 00:53:20 +0300 | 2 lines - -Added include to avoid warnings when it is included after stdint.h. - ------------------------------------------------------------------------- -r5 | 2006-12-12 00:58:05 +0300 | 2 lines - -BUGFIX: Definitions of INTPTR_MIN, INTPTR_MAX and UINTPTR_MAX for WIN32 and WIN64 was mixed up. - ------------------------------------------------------------------------- -r4 | 2006-12-12 00:51:55 +0300 | 2 lines - -Rise #error if _MSC_VER is not defined. I.e. compiler other then Microsoft Visual C++ is used. - ------------------------------------------------------------------------- -r3 | 2006-12-11 22:54:14 +0300 | 2 lines - -Added include to stdint.h. - ------------------------------------------------------------------------- -r2 | 2006-12-11 21:39:27 +0300 | 2 lines - -Initial check in. - ------------------------------------------------------------------------- -r1 | 2006-12-11 21:30:23 +0300 | 1 line - -Initial directory structure. ------------------------------------------------------------------------- diff --git a/src/compat/msvc/inttypes.h b/src/compat/msvc/inttypes.h deleted file mode 100644 index 4b3828a21..000000000 --- a/src/compat/msvc/inttypes.h +++ /dev/null @@ -1,305 +0,0 @@ -// ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The name of the author may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_INTTYPES_H_ // [ -#define _MSC_INTTYPES_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include "stdint.h" - -// 7.8 Format conversion of integer types - -typedef struct { - intmax_t quot; - intmax_t rem; -} imaxdiv_t; - -// 7.8.1 Macros for format specifiers - -#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 - -// The fprintf macros for signed integers are: -#define PRId8 "d" -#define PRIi8 "i" -#define PRIdLEAST8 "d" -#define PRIiLEAST8 "i" -#define PRIdFAST8 "d" -#define PRIiFAST8 "i" - -#define PRId16 "hd" -#define PRIi16 "hi" -#define PRIdLEAST16 "hd" -#define PRIiLEAST16 "hi" -#define PRIdFAST16 "hd" -#define PRIiFAST16 "hi" - -#define PRId32 "I32d" -#define PRIi32 "I32i" -#define PRIdLEAST32 "I32d" -#define PRIiLEAST32 "I32i" -#define PRIdFAST32 "I32d" -#define PRIiFAST32 "I32i" - -#define PRId64 "I64d" -#define PRIi64 "I64i" -#define PRIdLEAST64 "I64d" -#define PRIiLEAST64 "I64i" -#define PRIdFAST64 "I64d" -#define PRIiFAST64 "I64i" - -#define PRIdMAX "I64d" -#define PRIiMAX "I64i" - -#define PRIdPTR "Id" -#define PRIiPTR "Ii" - -// The fprintf macros for unsigned integers are: -#define PRIo8 "o" -#define PRIu8 "u" -#define PRIx8 "x" -#define PRIX8 "X" -#define PRIoLEAST8 "o" -#define PRIuLEAST8 "u" -#define PRIxLEAST8 "x" -#define PRIXLEAST8 "X" -#define PRIoFAST8 "o" -#define PRIuFAST8 "u" -#define PRIxFAST8 "x" -#define PRIXFAST8 "X" - -#define PRIo16 "ho" -#define PRIu16 "hu" -#define PRIx16 "hx" -#define PRIX16 "hX" -#define PRIoLEAST16 "ho" -#define PRIuLEAST16 "hu" -#define PRIxLEAST16 "hx" -#define PRIXLEAST16 "hX" -#define PRIoFAST16 "ho" -#define PRIuFAST16 "hu" -#define PRIxFAST16 "hx" -#define PRIXFAST16 "hX" - -#define PRIo32 "I32o" -#define PRIu32 "I32u" -#define PRIx32 "I32x" -#define PRIX32 "I32X" -#define PRIoLEAST32 "I32o" -#define PRIuLEAST32 "I32u" -#define PRIxLEAST32 "I32x" -#define PRIXLEAST32 "I32X" -#define PRIoFAST32 "I32o" -#define PRIuFAST32 "I32u" -#define PRIxFAST32 "I32x" -#define PRIXFAST32 "I32X" - -#define PRIo64 "I64o" -#define PRIu64 "I64u" -#define PRIx64 "I64x" -#define PRIX64 "I64X" -#define PRIoLEAST64 "I64o" -#define PRIuLEAST64 "I64u" -#define PRIxLEAST64 "I64x" -#define PRIXLEAST64 "I64X" -#define PRIoFAST64 "I64o" -#define PRIuFAST64 "I64u" -#define PRIxFAST64 "I64x" -#define PRIXFAST64 "I64X" - -#define PRIoMAX "I64o" -#define PRIuMAX "I64u" -#define PRIxMAX "I64x" -#define PRIXMAX "I64X" - -#define PRIoPTR "Io" -#define PRIuPTR "Iu" -#define PRIxPTR "Ix" -#define PRIXPTR "IX" - -// The fscanf macros for signed integers are: -#define SCNd8 "d" -#define SCNi8 "i" -#define SCNdLEAST8 "d" -#define SCNiLEAST8 "i" -#define SCNdFAST8 "d" -#define SCNiFAST8 "i" - -#define SCNd16 "hd" -#define SCNi16 "hi" -#define SCNdLEAST16 "hd" -#define SCNiLEAST16 "hi" -#define SCNdFAST16 "hd" -#define SCNiFAST16 "hi" - -#define SCNd32 "ld" -#define SCNi32 "li" -#define SCNdLEAST32 "ld" -#define SCNiLEAST32 "li" -#define SCNdFAST32 "ld" -#define SCNiFAST32 "li" - -#define SCNd64 "I64d" -#define SCNi64 "I64i" -#define SCNdLEAST64 "I64d" -#define SCNiLEAST64 "I64i" -#define SCNdFAST64 "I64d" -#define SCNiFAST64 "I64i" - -#define SCNdMAX "I64d" -#define SCNiMAX "I64i" - -#ifdef _WIN64 // [ -# define SCNdPTR "I64d" -# define SCNiPTR "I64i" -#else // _WIN64 ][ -# define SCNdPTR "ld" -# define SCNiPTR "li" -#endif // _WIN64 ] - -// The fscanf macros for unsigned integers are: -#define SCNo8 "o" -#define SCNu8 "u" -#define SCNx8 "x" -#define SCNX8 "X" -#define SCNoLEAST8 "o" -#define SCNuLEAST8 "u" -#define SCNxLEAST8 "x" -#define SCNXLEAST8 "X" -#define SCNoFAST8 "o" -#define SCNuFAST8 "u" -#define SCNxFAST8 "x" -#define SCNXFAST8 "X" - -#define SCNo16 "ho" -#define SCNu16 "hu" -#define SCNx16 "hx" -#define SCNX16 "hX" -#define SCNoLEAST16 "ho" -#define SCNuLEAST16 "hu" -#define SCNxLEAST16 "hx" -#define SCNXLEAST16 "hX" -#define SCNoFAST16 "ho" -#define SCNuFAST16 "hu" -#define SCNxFAST16 "hx" -#define SCNXFAST16 "hX" - -#define SCNo32 "lo" -#define SCNu32 "lu" -#define SCNx32 "lx" -#define SCNX32 "lX" -#define SCNoLEAST32 "lo" -#define SCNuLEAST32 "lu" -#define SCNxLEAST32 "lx" -#define SCNXLEAST32 "lX" -#define SCNoFAST32 "lo" -#define SCNuFAST32 "lu" -#define SCNxFAST32 "lx" -#define SCNXFAST32 "lX" - -#define SCNo64 "I64o" -#define SCNu64 "I64u" -#define SCNx64 "I64x" -#define SCNX64 "I64X" -#define SCNoLEAST64 "I64o" -#define SCNuLEAST64 "I64u" -#define SCNxLEAST64 "I64x" -#define SCNXLEAST64 "I64X" -#define SCNoFAST64 "I64o" -#define SCNuFAST64 "I64u" -#define SCNxFAST64 "I64x" -#define SCNXFAST64 "I64X" - -#define SCNoMAX "I64o" -#define SCNuMAX "I64u" -#define SCNxMAX "I64x" -#define SCNXMAX "I64X" - -#ifdef _WIN64 // [ -# define SCNoPTR "I64o" -# define SCNuPTR "I64u" -# define SCNxPTR "I64x" -# define SCNXPTR "I64X" -#else // _WIN64 ][ -# define SCNoPTR "lo" -# define SCNuPTR "lu" -# define SCNxPTR "lx" -# define SCNXPTR "lX" -#endif // _WIN64 ] - -#endif // __STDC_FORMAT_MACROS ] - -// 7.8.2 Functions for greatest-width integer types - -// 7.8.2.1 The imaxabs function -#define imaxabs _abs64 - -// 7.8.2.2 The imaxdiv function - -// This is modified version of div() function from Microsoft's div.c found -// in %MSVC.NET%\crt\src\div.c -#ifdef STATIC_IMAXDIV // [ -static -#else // STATIC_IMAXDIV ][ -_inline -#endif // STATIC_IMAXDIV ] -imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) -{ - imaxdiv_t result; - - result.quot = numer / denom; - result.rem = numer % denom; - - if (numer < 0 && result.rem > 0) { - // did division wrong; must fix up - ++result.quot; - result.rem -= denom; - } - - return result; -} - -// 7.8.2.3 The strtoimax and strtoumax functions -#define strtoimax _strtoi64 -#define strtoumax _strtoui64 - -// 7.8.2.4 The wcstoimax and wcstoumax functions -#define wcstoimax _wcstoi64 -#define wcstoumax _wcstoui64 - - -#endif // _MSC_INTTYPES_H_ ] diff --git a/src/compat/msvc/stdint.h b/src/compat/msvc/stdint.h deleted file mode 100644 index d02608a59..000000000 --- a/src/compat/msvc/stdint.h +++ /dev/null @@ -1,247 +0,0 @@ -// ISO C9x compliant stdint.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006-2008 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The name of the author may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_STDINT_H_ // [ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include - -// For Visual Studio 6 in C++ mode and for many Visual Studio versions when -// compiling for ARM we should wrap include with 'extern "C++" {}' -// or compiler give many errors like this: -// error C2733: second C linkage of overloaded function 'wmemchr' not allowed -#ifdef __cplusplus -extern "C" { -#endif -# include -#ifdef __cplusplus -} -#endif - -// Define _W64 macros to mark types changing their size, like intptr_t. -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -// 7.18.1 Integer types - -// 7.18.1.1 Exact-width integer types - -// Visual Studio 6 and Embedded Visual C++ 4 doesn't -// realize that, e.g. char has the same size as __int8 -// so we give up on __intX for them. -#if (_MSC_VER < 1300) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef signed __int8 int8_t; - typedef signed __int16 int16_t; - typedef signed __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - - -// 7.18.1.2 Minimum-width integer types -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -// 7.18.1.3 Fastest minimum-width integer types -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -// 7.18.1.4 Integer types capable of holding object pointers -#ifdef _WIN64 // [ - typedef signed __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else // _WIN64 ][ - typedef _W64 signed int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif // _WIN64 ] - -// 7.18.1.5 Greatest-width integer types -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -// 7.18.2 Limits of specified-width integer types - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 - -// 7.18.2.1 Limits of exact-width integer types -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -// 7.18.2.2 Limits of minimum-width integer types -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -// 7.18.2.3 Limits of fastest minimum-width integer types -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -// 7.18.2.4 Limits of integer types capable of holding object pointers -#ifdef _WIN64 // [ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else // _WIN64 ][ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif // _WIN64 ] - -// 7.18.2.5 Limits of greatest-width integer types -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -// 7.18.3 Limits of other integer types - -#ifdef _WIN64 // [ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else // _WIN64 ][ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif // _WIN64 ] - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX // [ -# ifdef _WIN64 // [ -# define SIZE_MAX _UI64_MAX -# else // _WIN64 ][ -# define SIZE_MAX _UI32_MAX -# endif // _WIN64 ] -#endif // SIZE_MAX ] - -// WCHAR_MIN and WCHAR_MAX are also defined in -#ifndef WCHAR_MIN // [ -# define WCHAR_MIN 0 -#endif // WCHAR_MIN ] -#ifndef WCHAR_MAX // [ -# define WCHAR_MAX _UI16_MAX -#endif // WCHAR_MAX ] - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif // __STDC_LIMIT_MACROS ] - - -// 7.18.4 Limits of other integer types - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 - -// 7.18.4.1 Macros for minimum-width integer constants - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -// 7.18.4.2 Macros for greatest-width integer constants -#define INTMAX_C INT64_C -#define UINTMAX_C UINT64_C - -#endif // __STDC_CONSTANT_MACROS ] - - -#endif // _MSC_STDINT_H_ ] From 57840a56bf04687879de02d8f8158c3d88e09f48 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 6 Feb 2023 18:34:30 +0800 Subject: [PATCH 03/10] FIX: avcodec_send_packet not return bytes send --- src/codec/audio/AudioDecoderFFmpeg.cpp | 4 +++- src/codec/video/VideoDecoderD3D11.cpp | 2 +- src/codec/video/VideoDecoderDXVA.cpp | 2 +- src/codec/video/VideoDecoderFFmpegBase.cpp | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/codec/audio/AudioDecoderFFmpeg.cpp b/src/codec/audio/AudioDecoderFFmpeg.cpp index 7c5188fc8..3b8492236 100644 --- a/src/codec/audio/AudioDecoderFFmpeg.cpp +++ b/src/codec/audio/AudioDecoderFFmpeg.cpp @@ -120,13 +120,15 @@ bool AudioDecoderFFmpeg::decode(const Packet &packet) #else ret = avcodec_receive_frame(d.codec_ctx, d.frame); if (ret == AVERROR(EAGAIN)) - return false; + ; else if (ret < 0) { qWarning("[AudioDecoder] %s", av_err2str(ret)); return false; } got_frame_ptr = (ret == 0); ret = avcodec_send_packet(d.codec_ctx, (AVPacket*)packet.asAVPacket()); + if (ret == 0) + ret = packet.data.size(); #endif } d.undecoded_size = qMin(packet.data.size() - ret, packet.data.size()); diff --git a/src/codec/video/VideoDecoderD3D11.cpp b/src/codec/video/VideoDecoderD3D11.cpp index 6c416fd36..628f79846 100644 --- a/src/codec/video/VideoDecoderD3D11.cpp +++ b/src/codec/video/VideoDecoderD3D11.cpp @@ -187,7 +187,7 @@ VideoFrame VideoDecoderD3D11::frame() f.setBytesPerLine(fmt.bytesPerLine(d.width, i), i); //used by gl to compute texture size } f.setMetaData(QStringLiteral("surface_interop"), QVariant::fromValue(VideoSurfaceInteropPtr(interop))); - f.setTimestamp(d.frame->pkt_pts/1000.0); + f.setTimestamp(d.frame->pts/1000.0); f.setDisplayAspectRatio(d.getDAR(d.frame)); return f; } diff --git a/src/codec/video/VideoDecoderDXVA.cpp b/src/codec/video/VideoDecoderDXVA.cpp index 64b12f33d..48e3cef26 100644 --- a/src/codec/video/VideoDecoderDXVA.cpp +++ b/src/codec/video/VideoDecoderDXVA.cpp @@ -189,7 +189,7 @@ VideoFrame VideoDecoderDXVA::frame() VideoFrame f(d.width, d.height, VideoFormat::Format_RGB32); f.setBytesPerLine(d.width * 4); //used by gl to compute texture size f.setMetaData(QStringLiteral("surface_interop"), QVariant::fromValue(VideoSurfaceInteropPtr(interop))); - f.setTimestamp(d.frame->pkt_pts/1000.0); + f.setTimestamp(d.frame->pts/1000.0); f.setDisplayAspectRatio(d.getDAR(d.frame)); return f; } diff --git a/src/codec/video/VideoDecoderFFmpegBase.cpp b/src/codec/video/VideoDecoderFFmpegBase.cpp index 49cebb948..bc7cc41de 100644 --- a/src/codec/video/VideoDecoderFFmpegBase.cpp +++ b/src/codec/video/VideoDecoderFFmpegBase.cpp @@ -148,12 +148,14 @@ bool VideoDecoderFFmpegBase::decode(const Packet &packet) ret = avcodec_receive_frame(d.codec_ctx, d.frame); got_frame_ptr = (ret == 0); ret = avcodec_send_packet(d.codec_ctx, (AVPacket*)packet.asAVPacket()); + if (ret == 0) + ret = packet.data.size(); #endif } //qDebug("pic_type=%c", av_get_picture_type_char(d.frame->pict_type)); d.undecoded_size = qMin(packet.data.size() - ret, packet.data.size()); if (ret < 0) { - //qWarning("[VideoDecoderFFmpegBase] %s", av_err2str(ret)); + qWarning("[VideoDecoderFFmpegBase] %s", av_err2str(ret)); return false; } if (!got_frame_ptr) { From 16ea31c8bc400bc5482947338a163561c01fb74f Mon Sep 17 00:00:00 2001 From: guochunmao Date: Mon, 6 Feb 2023 22:24:59 +0800 Subject: [PATCH 04/10] FIX: config QtAV --- .qmake.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.qmake.conf b/.qmake.conf index ef57faf62..e48873742 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -12,3 +12,7 @@ macx:isEqual(QT_MAJOR_VERSION,5):greaterThan(QT_MINOR_VERSION, 3): CONFIG *= c++ android: CONFIG*=c++11 QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8 QMAKE_IOS_DEPLOYMENT_TARGET = 6.0 + +INCLUDEPATH += $$PWD/../ffmpeg-n5.1-latest-win64-lgpl-shared-5.1/include +LIBS += -L$$PWD/../ffmpeg-n5.1-latest-win64-lgpl-shared-5.1/lib +CONFIG += no-d3d11va no-dxva no-cuda From b7fc3c9e437dd1a6fbce5bee7f4f1e25b7875b13 Mon Sep 17 00:00:00 2001 From: guochunmao Date: Tue, 7 Feb 2023 23:04:07 +0800 Subject: [PATCH 05/10] qt 6 compatible --- examples/examples.pro | 13 +++++++------ examples/videographicsitem/videoplayer.cpp | 3 +++ src/opengl/gl_api.cpp | 2 +- widgets/Direct2DRenderer.cpp | 2 +- widgets/GDIRenderer.cpp | 6 +++++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/examples.pro b/examples/examples.pro index 4a11c79ad..a5b950f92 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -8,13 +8,14 @@ SUBDIRS = common sharedoutput \ simpletranscode \ simpleplayer \ - player \ filters \ framereader \ - videocapture \ + videocapture +lessThan(QT_MAJOR_VERSION,6): SUBDIRS += \ + videowall \ videographicsitem \ - videogroup \ - videowall + player \ + videogroup contains(QT_CONFIG, opengl): SUBDIRS += \ shader \ glslfilter @@ -30,12 +31,12 @@ contains(QT_CONFIG, opengl): SUBDIRS += \ } greaterThan(QT_MAJOR_VERSION, 4) { - isEqual(QT_MAJOR_VERSION,5):greaterThan(QT_MINOR_VERSION,3)|greaterThan(QT_MAJOR_VERSION,5) { + isEqual(QT_MAJOR_VERSION,5):greaterThan(QT_MINOR_VERSION,3) { contains(QT_CONFIG, opengl):!winrt:!ios:!android: SUBDIRS += window } # qtHaveModule does not exist in Qt5.0 isEqual(QT_MINOR_VERSION, 0)|qtHaveModule(quick) { - SUBDIRS += QMLPlayer + lessThan(QT_MAJOR_VERSION,6): SUBDIRS += QMLPlayer QMLPlayer.depends += common sdk_build: SUBDIRS *= QMLPlayer/QMLPlayer_sdk.pro } diff --git a/src/opengl/gl_api.cpp b/src/opengl/gl_api.cpp index 9caeba8b4..3186158fb 100644 --- a/src/opengl/gl_api.cpp +++ b/src/opengl/gl_api.cpp @@ -31,7 +31,7 @@ void* GetProcAddress_Qt(const char *name) return 0; void* p = (void*)QOpenGLContext::currentContext()->getProcAddress(QByteArray((const char*)name)); if (!p) { -#if defined(Q_OS_WIN) && defined(QT_OPENGL_DYNAMIC) +#if defined(Q_OS_WIN) && defined(QT_OPENGL_DYNAMIC) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) HMODULE handle = (HMODULE)QOpenGLContext::openGLModuleHandle(); if (handle) p = (void*)GetProcAddress(handle, name); diff --git a/widgets/Direct2DRenderer.cpp b/widgets/Direct2DRenderer.cpp index 9e63febb4..13a60c620 100644 --- a/widgets/Direct2DRenderer.cpp +++ b/widgets/Direct2DRenderer.cpp @@ -55,7 +55,7 @@ class Direct2DRenderer : public QWidget, public VideoRenderer Q_OBJECT DPTR_DECLARE_PRIVATE(Direct2DRenderer) public: - Direct2DRenderer(QWidget* parent = 0, Qt::WindowFlags f = 0); + Direct2DRenderer(QWidget* parent = 0, Qt::WindowFlags f = {}); VideoRendererId id() const Q_DECL_OVERRIDE; bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE; diff --git a/widgets/GDIRenderer.cpp b/widgets/GDIRenderer.cpp index af20c869f..6e1507f7e 100644 --- a/widgets/GDIRenderer.cpp +++ b/widgets/GDIRenderer.cpp @@ -41,7 +41,7 @@ class GDIRenderer : public QWidget, public VideoRenderer Q_OBJECT DPTR_DECLARE_PRIVATE(GDIRenderer) public: - GDIRenderer(QWidget* parent = 0, Qt::WindowFlags f = 0); //offscreen? + GDIRenderer(QWidget* parent = 0, Qt::WindowFlags f = {}); //offscreen? VideoRendererId id() const Q_DECL_OVERRIDE; bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE; /* WA_PaintOnScreen: To render outside of Qt's paint system, e.g. If you require @@ -238,7 +238,11 @@ void GDIRenderer::drawBackground() //HDC hdc = d.device_context; Graphics g(d.device_context); SolidBrush brush(Color(bc.alpha(), bc.red(), bc.green(), bc.blue())); //argb +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const QVector bg(bgRegion.rects()); +#else + const QVector bg(bgRegion.begin(), bgRegion.end()); +#endif foreach (const QRect& r, bg) { g.FillRectangle(&brush, r.x(), r.y(), r.width(), r.height()); } From b94430f1f8b73a76caa15bf1d14cb09fa614317f Mon Sep 17 00:00:00 2001 From: guochunmao Date: Mon, 6 Feb 2023 22:24:59 +0800 Subject: [PATCH 06/10] FIX: config QtAV --- .qmake.conf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.qmake.conf b/.qmake.conf index e48873742..c9a0eee13 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -13,6 +13,8 @@ android: CONFIG*=c++11 QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8 QMAKE_IOS_DEPLOYMENT_TARGET = 6.0 -INCLUDEPATH += $$PWD/../ffmpeg-n5.1-latest-win64-lgpl-shared-5.1/include -LIBS += -L$$PWD/../ffmpeg-n5.1-latest-win64-lgpl-shared-5.1/lib +win32: { +INCLUDEPATH += $$PWD/../avbuild/sdk-mingw--gcc/include +LIBS += -L$$PWD/../avbuild/sdk-mingw--gcc/lib +} CONFIG += no-d3d11va no-dxva no-cuda From b3ea724208a40edfa72de273ecd7b66b8073f7c0 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Wed, 8 Feb 2023 13:38:32 +0800 Subject: [PATCH 07/10] use custom build ffmpeg --- .qmake.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/.qmake.conf b/.qmake.conf index c9a0eee13..a39ef3e21 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -10,6 +10,7 @@ CONFIG *= enable_new_dtags # OSX10.6 is not supported in Qt5.4 macx:isEqual(QT_MAJOR_VERSION,5):greaterThan(QT_MINOR_VERSION, 3): CONFIG *= c++11 android: CONFIG*=c++11 +else: CONFIG*=c++17 QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8 QMAKE_IOS_DEPLOYMENT_TARGET = 6.0 From f0c7cc1f4d99f5012e75317009f00937ad5a3fce Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Wed, 8 Feb 2023 16:40:56 +0800 Subject: [PATCH 08/10] ENH: macOS compatible --- .qmake.conf | 11 ++++++++--- src/codec/video/VideoDecoderVideoToolbox.cpp | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.qmake.conf b/.qmake.conf index a39ef3e21..d8ad71d96 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -14,8 +14,13 @@ else: CONFIG*=c++17 QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8 QMAKE_IOS_DEPLOYMENT_TARGET = 6.0 +CONFIG += no-cuda win32: { -INCLUDEPATH += $$PWD/../avbuild/sdk-mingw--gcc/include -LIBS += -L$$PWD/../avbuild/sdk-mingw--gcc/lib + INCLUDEPATH += $$PWD/../avbuild/sdk-mingw--gcc/include + LIBS += -L$$PWD/../avbuild/sdk-mingw--gcc/lib + CONFIG += no-d3d11va no-dxva +} +mac { + INCLUDEPATH += $$PWD/../avbuild/sdk-macOS10.7x86_64-clang/include + LIBS += -L$$PWD/../avbuild/sdk-macOS10.7x86_64-clang/lib } -CONFIG += no-d3d11va no-dxva no-cuda diff --git a/src/codec/video/VideoDecoderVideoToolbox.cpp b/src/codec/video/VideoDecoderVideoToolbox.cpp index bdf4fdc4e..75e5288f8 100755 --- a/src/codec/video/VideoDecoderVideoToolbox.cpp +++ b/src/codec/video/VideoDecoderVideoToolbox.cpp @@ -219,7 +219,7 @@ VideoFrame VideoDecoderVideoToolbox::frame() f = VideoFrame(d.width, d.height, fmt); f.setBytesPerLine(pitch); // TODO: move to updateFrameInfo - f.setTimestamp(double(d.frame->pkt_pts)/1000.0); + f.setTimestamp(double(d.frame->pts)/1000.0); f.setDisplayAspectRatio(d.getDAR(d.frame)); d.updateColorDetails(&f); if (d.interop_res) { // zero_copy From 09a24de0745c804b62d4b0c7c027331f5ed088f0 Mon Sep 17 00:00:00 2001 From: guochunmao Date: Wed, 8 Feb 2023 22:03:56 +0800 Subject: [PATCH 09/10] ENH: qt 6 compatible --- qml/QmlAV/QQuickItemRenderer.h | 5 ++++- qml/QmlAV/QmlAVPlayer.h | 16 +++++++++++----- qml/QmlAV/QuickFBORenderer.h | 9 +++++++-- qml/QmlAV/QuickSubtitleItem.h | 4 ++++ qml/QmlAVPlayer.cpp | 10 +++++----- qml/QuickFBORenderer.cpp | 4 ++-- qml/QuickSubtitleItem.cpp | 13 +++++++++++++ qml/libQmlAV.pro | 16 ++++++++++++---- qml/plugin.cpp | 6 ++++-- src/AVThread.cpp | 4 ++-- src/filter/FilterManager.cpp | 2 +- 11 files changed, 65 insertions(+), 24 deletions(-) diff --git a/qml/QmlAV/QQuickItemRenderer.h b/qml/QmlAV/QQuickItemRenderer.h index 524bc396f..64f1dcfd8 100644 --- a/qml/QmlAV/QQuickItemRenderer.h +++ b/qml/QmlAV/QQuickItemRenderer.h @@ -97,8 +97,11 @@ class QQuickItemRenderer : public QQuickItem, public VideoRenderer void backgroundColorChanged() Q_DECL_OVERRIDE; protected: bool event(QEvent *e) Q_DECL_OVERRIDE; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; - +#else + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; +#endif bool receiveFrame(const VideoFrame &frame) Q_DECL_OVERRIDE; void drawFrame() Q_DECL_OVERRIDE; // QQuickItem interface diff --git a/qml/QmlAV/QuickFBORenderer.h b/qml/QmlAV/QuickFBORenderer.h index f156c02bb..1226086a9 100644 --- a/qml/QmlAV/QuickFBORenderer.h +++ b/qml/QmlAV/QuickFBORenderer.h @@ -122,9 +122,14 @@ class QuickFBORenderer : public QQuickFramebufferObject, public VideoRenderer bool onSetSaturation(qreal s) Q_DECL_OVERRIDE; void updateRenderRect(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +typedef int list_size_t; +#else +typedef qsizetype list_size_t; +#endif static void vf_append(QQmlListProperty *property, QuickVideoFilter *value); - static int vf_count(QQmlListProperty *property); - static QuickVideoFilter *vf_at(QQmlListProperty *property, int index); + static list_size_t vf_count(QQmlListProperty *property); + static QuickVideoFilter *vf_at(QQmlListProperty *property, list_size_t index); static void vf_clear(QQmlListProperty *property); }; typedef QuickFBORenderer VideoRendererQuickFBO; diff --git a/qml/QmlAV/QuickSubtitleItem.h b/qml/QmlAV/QuickSubtitleItem.h index 250117c96..258163c35 100644 --- a/qml/QmlAV/QuickSubtitleItem.h +++ b/qml/QmlAV/QuickSubtitleItem.h @@ -54,7 +54,11 @@ class QuickSubtitleItem : public QQuickItem, public QuickSubtitleObserver QRectF mapSubRect(const QRect& r, qreal w, qreal h); virtual QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data); virtual bool event(QEvent *e); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); +#else + virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry); +#endif private: QuickSubtitle *m_sub; QSGTexture* m_texture; diff --git a/qml/QuickFBORenderer.cpp b/qml/QuickFBORenderer.cpp index 02177ebb1..42bc291bb 100644 --- a/qml/QuickFBORenderer.cpp +++ b/qml/QuickFBORenderer.cpp @@ -345,13 +345,13 @@ void QuickFBORenderer::vf_append(QQmlListProperty *property, Q self->installFilter(value); } -int QuickFBORenderer::vf_count(QQmlListProperty *property) +QuickFBORenderer::list_size_t QuickFBORenderer::vf_count(QQmlListProperty *property) { QuickFBORenderer* self = static_cast(property->object); return self->d_func().filters.size(); } -QuickVideoFilter* QuickFBORenderer::vf_at(QQmlListProperty *property, int index) +QuickVideoFilter* QuickFBORenderer::vf_at(QQmlListProperty *property, list_size_t index) { QuickFBORenderer* self = static_cast(property->object); return self->d_func().filters.at(index); diff --git a/qml/QuickSubtitleItem.cpp b/qml/QuickSubtitleItem.cpp index cc25da61d..2d2fab55a 100644 --- a/qml/QuickSubtitleItem.cpp +++ b/qml/QuickSubtitleItem.cpp @@ -153,9 +153,22 @@ bool QuickSubtitleItem::event(QEvent *e) return true; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + void QuickSubtitleItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { QQuickItem::geometryChanged(newGeometry, oldGeometry); //geometry will be updated m_remap = true; QCoreApplication::postEvent(this, new QEvent(QEvent::User)); } + +#else + +void QuickSubtitleItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + QQuickItem::geometryChange(newGeometry, oldGeometry); //geometry will be updated + m_remap = true; + QCoreApplication::postEvent(this, new QEvent(QEvent::User)); +} + +#endif diff --git a/qml/libQmlAV.pro b/qml/libQmlAV.pro index e07c3e8c9..73de6aa72 100644 --- a/qml/libQmlAV.pro +++ b/qml/libQmlAV.pro @@ -77,8 +77,6 @@ QMAKE_TARGET_PRODUCT = "QtAV QML" SOURCES += \ plugin.cpp \ - QQuickItemRenderer.cpp \ - SGVideoNode.cpp \ QmlAVPlayer.cpp \ QuickFilter.cpp \ QuickSubtitle.cpp \ @@ -91,14 +89,24 @@ HEADERS += \ QmlAV/QuickSubtitleItem.h \ QmlAV/QuickVideoPreview.h +lessThan(QT_MAJOR_VERSION,6): { + SOURCES += \ + QQuickItemRenderer.cpp \ + SGVideoNode.cpp \ +} + SDK_HEADERS += \ QmlAV/Export.h \ QmlAV/MediaMetaData.h \ - QmlAV/SGVideoNode.h \ - QmlAV/QQuickItemRenderer.h \ QmlAV/QuickFilter.h \ QmlAV/QmlAVPlayer.h +lessThan(QT_MAJOR_VERSION,6): { + SDK_HEADERS += \ + QmlAV/SGVideoNode.h \ + QmlAV/QQuickItemRenderer.h +} + HEADERS *= \ $$SDK_HEADERS diff --git a/qml/plugin.cpp b/qml/plugin.cpp index 10734eeec..c4adebca0 100644 --- a/qml/plugin.cpp +++ b/qml/plugin.cpp @@ -51,7 +51,9 @@ class QtAVQmlPlugin : public QQmlExtensionPlugin void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("QtAV")); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) qmlRegisterType(uri, 1, 3, "VideoOutput"); +#endif qmlRegisterType(uri, 1, 3, "AVPlayer"); qmlRegisterType(uri, 1, 3, "MediaPlayer"); qmlRegisterType(uri, 1, 4, "Subtitle"); @@ -60,8 +62,8 @@ class QtAVQmlPlugin : public QQmlExtensionPlugin #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) qmlRegisterType(uri, 1, 5, "VideoOutput2"); #endif - qmlRegisterUncreatableType(uri, 1, 6, "VideoCapture", trUtf8("VideoCapture is provided by MediaPlayer")); - qmlRegisterType(); + qmlRegisterUncreatableType(uri, 1, 6, "VideoCapture", tr("VideoCapture is provided by MediaPlayer").toUtf8()); + qmlRegisterType(uri, 1, 5, "MediaMetaData"); // FIXME: if version is 2.x, some qtav types will be undefined, why? // 1.7 diff --git a/src/AVThread.cpp b/src/AVThread.cpp index f8f6e89fb..7551ecba6 100644 --- a/src/AVThread.cpp +++ b/src/AVThread.cpp @@ -95,11 +95,11 @@ bool AVThread::installFilter(Filter *filter, int index, bool lock) return true; if (lock) { QMutexLocker locker(&d.mutex); - if (p >= 0) + if (p >= 0 && p < d.filters.size()) d.filters.removeAt(p); d.filters.insert(p, filter); } else { - if (p >= 0) + if (p >= 0 && p < d.filters.size()) d.filters.removeAt(p); d.filters.insert(p, filter); } diff --git a/src/filter/FilterManager.cpp b/src/filter/FilterManager.cpp index e4e0b02ee..8e2e897f0 100644 --- a/src/filter/FilterManager.cpp +++ b/src/filter/FilterManager.cpp @@ -69,7 +69,7 @@ bool FilterManager::insert(Filter *filter, QList &filters, int pos) // already installed at desired position if (p == index) return false; - if (p >= 0) + if (p >= 0 && p < filters.size()) filters.removeAt(p); filters.insert(p, filter); return true; From e041eede79a497962fd51598c13777ac14a75cfb Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Fri, 24 Feb 2023 10:02:29 +0800 Subject: [PATCH 10/10] support custom av format --- src/AVDemuxer.cpp | 13 ++++++++++++- src/QtAV/AVDemuxer.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/AVDemuxer.cpp b/src/AVDemuxer.cpp index 7be82c7e4..b8bd55e93 100644 --- a/src/AVDemuxer.cpp +++ b/src/AVDemuxer.cpp @@ -436,6 +436,13 @@ const QStringList &AVDemuxer::supportedProtocols() return protocols; } +static QMap gCustomsFormats; + +void AVDemuxer::registerCustomFormat(const QString &format, AVInputFormat &input_format) +{ + gCustomsFormats[format] = &input_format; +} + MediaStatus AVDemuxer::mediaStatus() const { return d->media_status; @@ -705,6 +712,8 @@ bool AVDemuxer::setMedia(const QString &fileName) d->input = MediaIO::createForProtocol(scheme); if (d->input) { d->input->setUrl(d->file); + } else if (gCustomsFormats.contains(scheme)) { + d->format_forced = scheme; } } return d->media_changed; @@ -801,7 +810,9 @@ bool AVDemuxer::load() // check special dict keys // d->format_forced can be set from AVFormatContext.format_whitelist if (!d->format_forced.isEmpty()) { - d->input_format = av_find_input_format(d->format_forced.toUtf8().constData()); + d->input_format = gCustomsFormats.value(d->format_forced); + if (d->input_format == nullptr) + d->input_format = av_find_input_format(d->format_forced.toUtf8().constData()); qDebug() << "force format: " << d->format_forced; } int ret = 0; diff --git a/src/QtAV/AVDemuxer.h b/src/QtAV/AVDemuxer.h index 688c82f9c..31da2d3cc 100644 --- a/src/QtAV/AVDemuxer.h +++ b/src/QtAV/AVDemuxer.h @@ -34,6 +34,7 @@ extern "C" { struct AVFormatContext; struct AVCodecContext; +struct AVInputFormat; QT_BEGIN_NAMESPACE class QIODevice; QT_END_NAMESPACE @@ -54,6 +55,7 @@ class Q_AV_EXPORT AVDemuxer : public QObject static const QStringList& supportedExtensions(); /// Supported ffmpeg/libav input protocols(not complete). A static string list static const QStringList& supportedProtocols(); + static void registerCustomFormat(QString const & format, AVInputFormat & input_format); AVDemuxer(QObject *parent = 0); ~AVDemuxer();