Skip to content

Commit

Permalink
refactor to setVideoCodecOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Vladyslav Arzhanov <vladarzhanov2001@gmail.com>
  • Loading branch information
vladyslav-arzhanov committed Dec 9, 2024
1 parent f638527 commit 6093d04
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
23 changes: 11 additions & 12 deletions src/QtAVPlayer/qavdemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class QAVDemuxerPrivate
QString inputFormat;
QString inputVideoCodec;
QMap<QString, QString> inputOptions;
QMap<QString, QString> codecOptions;
QMap<QString, QString> videoCodecOptions;

bool eof = false;
QList<QAVPacket> packets;
Expand Down Expand Up @@ -451,11 +451,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";
Expand All @@ -466,18 +461,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<QAVCodec> codec(new QAVVideoCodec);
d->availableStreams.push_back({ int(i), d->ctx, codec });
ret = setup_video_codec(d->inputVideoCodec, d->ctx->streams[i], *static_cast<QAVVideoCodec *>(codec.data()), &opts.dict);
} break;
case AVMEDIA_TYPE_AUDIO:
d->availableStreams.push_back({ int(i), d->ctx, QSharedPointer<QAVCodec>(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<QAVCodec>(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:
Expand Down Expand Up @@ -878,18 +877,18 @@ void QAVDemuxer::setInputOptions(const QMap<QString, QString> &opts)
d->inputOptions = opts;
}

QMap<QString, QString> QAVDemuxer::codecOptions() const
QMap<QString, QString> QAVDemuxer::videoCodecOptions() const
{
Q_D(const QAVDemuxer);
QMutexLocker locker(&d->mutex);
return d->codecOptions;
return d->videoCodecOptions;
}

void QAVDemuxer::setCodecOptions(const QMap<QString, QString> &opts)
void QAVDemuxer::setVideoCodecOptions(const QMap<QString, QString> &opts)
{
Q_D(QAVDemuxer);
QMutexLocker locker(&d->mutex);
d->codecOptions = opts;
d->videoCodecOptions = opts;
}

void QAVDemuxer::onFrameSent(const QAVStreamFrame &frame)
Expand Down
4 changes: 2 additions & 2 deletions src/QtAVPlayer/qavdemuxer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class QAVDemuxer
QMap<QString, QString> inputOptions() const;
void setInputOptions(const QMap<QString, QString> &opts);

QMap<QString, QString> codecOptions() const;
void setCodecOptions(const QMap<QString, QString> &opts);
QMap<QString, QString> videoCodecOptions() const;
void setVideoCodecOptions(const QMap<QString, QString> &opts);

void onFrameSent(const QAVStreamFrame &frame);
QAVStream::Progress progress(const QAVStream &s) const;
Expand Down
12 changes: 6 additions & 6 deletions src/QtAVPlayer/qavplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,23 +1316,23 @@ void QAVPlayer::setInputOptions(const QMap<QString, QString> &opts)
Q_EMIT inputOptionsChanged(opts);
}

QMap<QString, QString> QAVPlayer::codecOptions() const
QMap<QString, QString> QAVPlayer::videoCodecOptions() const
{
Q_D(const QAVPlayer);
return d->demuxer.codecOptions();
return d->demuxer.videoCodecOptions();
}

void QAVPlayer::setCodecOptions(const QMap<QString, QString> &opts)
void QAVPlayer::setVideoCodecOptions(const QMap<QString, QString> &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);
}

/*!
Expand Down
6 changes: 3 additions & 3 deletions src/QtAVPlayer/qavplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class QAVPlayer : public QObject
QMap<QString, QString> inputOptions() const;
void setInputOptions(const QMap<QString, QString> &opts);

QMap<QString, QString> codecOptions() const;
void setCodecOptions(const QMap<QString, QString> &opts);
QMap<QString, QString> videoCodecOptions() const;
void setVideoCodecOptions(const QMap<QString, QString> &opts);

QAVStream::Progress progress(const QAVStream &stream) const;

Expand Down Expand Up @@ -137,7 +137,7 @@ public Q_SLOTS:
void inputFormatChanged(const QString &format);
void inputVideoCodecChanged(const QString &codec);
void inputOptionsChanged(const QMap<QString, QString> &opts);
void codecOptionsChanged(const QMap<QString, QString> &opts);
void videoCodecOptionsChanged(const QMap<QString, QString> &opts);

void videoFrame(const QAVVideoFrame &frame);
void audioFrame(const QAVAudioFrame &frame);
Expand Down

0 comments on commit 6093d04

Please sign in to comment.