From aed566d5aee658c30c0942d3cc7ad54d602000a4 Mon Sep 17 00:00:00 2001 From: Vladyslav Arzhanov Date: Mon, 9 Dec 2024 11:31:53 +0200 Subject: [PATCH] refactor to setVideoCodecOptions Signed-off-by: Vladyslav Arzhanov --- src/QtAVPlayer/qavdemuxer.cpp | 22 +++++++++++----------- src/QtAVPlayer/qavdemuxer_p.h | 4 ++-- src/QtAVPlayer/qavplayer.cpp | 12 ++++++------ src/QtAVPlayer/qavplayer.h | 6 +++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/QtAVPlayer/qavdemuxer.cpp b/src/QtAVPlayer/qavdemuxer.cpp index 52cc53d..b188353 100644 --- a/src/QtAVPlayer/qavdemuxer.cpp +++ b/src/QtAVPlayer/qavdemuxer.cpp @@ -103,7 +103,7 @@ class QAVDemuxerPrivate QString inputFormat; QString inputVideoCodec; QMap inputOptions; - QMap codecOptions; + QMap videoCodecOptions; bool eof = false; QList packets; @@ -452,10 +452,6 @@ int QAVDemuxer::resetCodecs() Q_D(QAVDemuxer); int ret = 0; - QAVDictionaryHolder opts; - for (const auto & key: d->codecOptions.keys()) - av_dict_set(&opts.dict, key.toUtf8().constData(), d->codecOptions[key].toUtf8().constData(), 0); - for (std::size_t i = 0; i < d->ctx->nb_streams && ret >= 0; ++i) { if (!d->ctx->streams[i]->codecpar) { qWarning() << "Could not find codecpar"; @@ -466,18 +462,22 @@ int QAVDemuxer::resetCodecs() switch (type) { case AVMEDIA_TYPE_VIDEO: { + QAVDictionaryHolder opts; + for (const auto & key: d->videoCodecOptions.keys()) + av_dict_set(&opts.dict, key.toUtf8().constData(), d->videoCodecOptions[key].toUtf8().constData(), 0); + QSharedPointer codec(new QAVVideoCodec); d->availableStreams.push_back({ int(i), d->ctx, codec }); ret = setup_video_codec(d->inputVideoCodec, d->ctx->streams[i], *static_cast(codec.data()), &opts.dict); } break; case AVMEDIA_TYPE_AUDIO: d->availableStreams.push_back({ int(i), d->ctx, QSharedPointer(new QAVAudioCodec) }); - if (!d->availableStreams.last().codec()->open(d->ctx->streams[i], &opts.dict)) + if (!d->availableStreams.last().codec()->open(d->ctx->streams[i])) qWarning() << "Could not open audio codec for stream:" << i; break; case AVMEDIA_TYPE_SUBTITLE: d->availableStreams.push_back({ int(i), d->ctx, QSharedPointer(new QAVSubtitleCodec) }); - if (!d->availableStreams.last().codec()->open(d->ctx->streams[i], &opts.dict)) + if (!d->availableStreams.last().codec()->open(d->ctx->streams[i])) qWarning() << "Could not open subtitle codec for stream:" << i; break; default: @@ -878,18 +878,18 @@ void QAVDemuxer::setInputOptions(const QMap &opts) d->inputOptions = opts; } -QMap QAVDemuxer::codecOptions() const +QMap QAVDemuxer::videoCodecOptions() const { Q_D(const QAVDemuxer); QMutexLocker locker(&d->mutex); - return d->codecOptions; + return d->videoCodecOptions; } -void QAVDemuxer::setCodecOptions(const QMap &opts) +void QAVDemuxer::setVideoCodecOptions(const QMap &opts) { Q_D(QAVDemuxer); QMutexLocker locker(&d->mutex); - d->codecOptions = opts; + d->videoCodecOptions = opts; } void QAVDemuxer::onFrameSent(const QAVStreamFrame &frame) diff --git a/src/QtAVPlayer/qavdemuxer_p.h b/src/QtAVPlayer/qavdemuxer_p.h index 29134be..a4192e6 100644 --- a/src/QtAVPlayer/qavdemuxer_p.h +++ b/src/QtAVPlayer/qavdemuxer_p.h @@ -89,8 +89,8 @@ class QAVDemuxer QMap inputOptions() const; void setInputOptions(const QMap &opts); - QMap codecOptions() const; - void setCodecOptions(const QMap &opts); + QMap videoCodecOptions() const; + void setVideoCodecOptions(const QMap &opts); void onFrameSent(const QAVStreamFrame &frame); QAVStream::Progress progress(const QAVStream &s) const; diff --git a/src/QtAVPlayer/qavplayer.cpp b/src/QtAVPlayer/qavplayer.cpp index ca6b472..f1c4330 100644 --- a/src/QtAVPlayer/qavplayer.cpp +++ b/src/QtAVPlayer/qavplayer.cpp @@ -1316,23 +1316,23 @@ void QAVPlayer::setInputOptions(const QMap &opts) Q_EMIT inputOptionsChanged(opts); } -QMap QAVPlayer::codecOptions() const +QMap QAVPlayer::videoCodecOptions() const { Q_D(const QAVPlayer); - return d->demuxer.codecOptions(); + return d->demuxer.videoCodecOptions(); } -void QAVPlayer::setCodecOptions(const QMap &opts) +void QAVPlayer::setVideoCodecOptions(const QMap &opts) { Q_D(QAVPlayer); - auto current = codecOptions(); + auto current = videoCodecOptions(); if (opts == current) return; qCDebug(lcAVPlayer) << __FUNCTION__ << ":" << current << "->" << opts; - d->demuxer.setCodecOptions(opts); - Q_EMIT codecOptionsChanged(opts); + d->demuxer.setVideoCodecOptions(opts); + Q_EMIT videoCodecOptionsChanged(opts); } /*! diff --git a/src/QtAVPlayer/qavplayer.h b/src/QtAVPlayer/qavplayer.h index 54df799..acbad78 100644 --- a/src/QtAVPlayer/qavplayer.h +++ b/src/QtAVPlayer/qavplayer.h @@ -100,8 +100,8 @@ class QAVPlayer : public QObject QMap inputOptions() const; void setInputOptions(const QMap &opts); - QMap codecOptions() const; - void setCodecOptions(const QMap &opts); + QMap videoCodecOptions() const; + void setVideoCodecOptions(const QMap &opts); QAVStream::Progress progress(const QAVStream &stream) const; @@ -137,7 +137,7 @@ public Q_SLOTS: void inputFormatChanged(const QString &format); void inputVideoCodecChanged(const QString &codec); void inputOptionsChanged(const QMap &opts); - void codecOptionsChanged(const QMap &opts); + void videoCodecOptionsChanged(const QMap &opts); void videoFrame(const QAVVideoFrame &frame); void audioFrame(const QAVAudioFrame &frame);