Skip to content

Commit

Permalink
qstring optimize & QT_NO_CAST_FROM_ASCI build error part2
Browse files Browse the repository at this point in the history
QLatin1String:
- QString has override function && no implicitly convert to QString:
indexof,contains,==,insert,append,prepend,
+=,replace,compare,<,startswith,endswith
- not from a raw string
  • Loading branch information
wang-bin committed Aug 8, 2015
1 parent 78c9e39 commit 665f1d9
Show file tree
Hide file tree
Showing 52 changed files with 308 additions and 294 deletions.
2 changes: 1 addition & 1 deletion contrib/capi
23 changes: 12 additions & 11 deletions qml/MediaMetaData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void MediaMetaData::setValuesFromStatistics(const QtAV::Statistics &st)
//setValue(Size, st.);
setValue(Duration, (qint64)QTime(0, 0, 0).msecsTo(st.duration));
if (st.video.available) {
setValue(MediaType, "video");
setValue(MediaType, QStringLiteral("video"));
setValue(VideoFrameRate, st.video.frame_rate);
setValue(VideoBitRate, st.video.bit_rate);
setValue(VideoCodec, st.video.codec);
Expand All @@ -47,7 +47,7 @@ void MediaMetaData::setValuesFromStatistics(const QtAV::Statistics &st)
if (st.audio.available) {
// TODO: what if thumbnail?
if (!st.video.available)
setValue(MediaType, "audio");
setValue(MediaType, QStringLiteral("audio"));
setValue(AudioBitRate, st.audio.bit_rate);
setValue(AudioCodec, st.audio.codec);
setValue(ChannelCount, st.audio_only.channels);
Expand All @@ -65,8 +65,8 @@ void MediaMetaData::setValuesFromStatistics(const QtAV::Statistics &st)
continue;
}
const QString keyName(it.key().toLower());
if (keyName == QStringLiteral("track")) {
int slash = it.value().indexOf(QChar('/'));
if (keyName == QLatin1String("track")) {
int slash = it.value().indexOf(QLatin1Char('/'));
if (slash < 0) {
setValue(TrackNumber, it.value().toInt());
continue;
Expand All @@ -75,8 +75,8 @@ void MediaMetaData::setValuesFromStatistics(const QtAV::Statistics &st)
setValue(TrackCount, it.value().midRef(slash+1).string()->toInt());
continue;
}
if (keyName == QStringLiteral("date")
|| it.key().toLower() == QStringLiteral("creation_time")
if (keyName == QLatin1String("date")
|| it.key().toLower() == QLatin1String("creation_time")
) {
// ISO 8601 is preferred in ffmpeg
bool ok = false;
Expand All @@ -89,8 +89,8 @@ void MediaMetaData::setValuesFromStatistics(const QtAV::Statistics &st)
setValue(Date, QDate::fromString(it.value(), Qt::ISODate));
continue;
}
if (keyName.contains(QStringLiteral("genre"))) {
setValue(Genre, it.value().split(QChar(','))); // ',' ? not sure
if (keyName.contains(QLatin1String("genre"))) {
setValue(Genre, it.value().split(QLatin1Char(','))); // ',' ? not sure
continue;
}
}
Expand All @@ -115,6 +115,7 @@ MediaMetaData::Key MediaMetaData::fromFFmpegName(const QString &name) const
{ Copyright, "copyright" },
// { Date, "date" }, //QDate
{ Language, "language" }, //maybe a list in ffmpeg
{ Language, "lang" },
{ Publisher, "publisher" },
{ Title, "title" },
//{ TrackNumber, "track" }, // can be "current/total"
Expand All @@ -125,7 +126,7 @@ MediaMetaData::Key MediaMetaData::fromFFmpegName(const QString &name) const
{ (Key)-1, 0 },
};
for (int i = 0; (int)key_map[i].key >= 0; ++i) {
if (name.toLower() == key_map[i].name)
if (name.toLower() == QLatin1String(key_map[i].name))
return key_map[i].key;
}
// below are keys not listed in ffmpeg generic tag names and value is a QString
Expand All @@ -139,7 +140,7 @@ MediaMetaData::Key MediaMetaData::fromFFmpegName(const QString &name) const
{ (Key)-1, 0 },
};
for (int i = 0; (int)wm_key[i].key >= 0; ++i) {
if (name.toLower().contains(wm_key[i].name))
if (name.toLower().contains(QLatin1String(wm_key[i].name)))
return wm_key[i].key;
}
return (Key)-1;
Expand All @@ -162,5 +163,5 @@ QString MediaMetaData::name(Key k) const
{
int idx = staticMetaObject.indexOfEnumerator("Key");
const QMetaEnum me = staticMetaObject.enumerator(idx);
return me.valueToKey(k);
return QString::fromLatin1(me.valueToKey(k));
}
8 changes: 4 additions & 4 deletions qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ template<typename ID, typename Factory>
static QStringList idsToNames(QVector<ID> ids) {
QStringList decs;
foreach (ID id, ids) {
decs.append(Factory::name(id).c_str());
decs.append(QString::fromUtf8(Factory::name(id).c_str()));
}
return decs;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ void QmlAVPlayer::classBegin()
connect(mpPlayer->audio(), SIGNAL(volumeChanged(qreal)), SLOT(applyVolume()), Qt::DirectConnection);
connect(mpPlayer->audio(), SIGNAL(muteChanged(bool)), SLOT(applyVolume()), Qt::DirectConnection);

mVideoCodecs << "FFmpeg";
mVideoCodecs << QStringLiteral("FFmpeg");

m_metaData.reset(new MediaMetaData());

Expand Down Expand Up @@ -270,10 +270,10 @@ void QmlAVPlayer::setWallclockAsTimestamps(bool use_wallclock_as_timestamps)
QVariantHash opt = mpPlayer->optionsForFormat();

if (use_wallclock_as_timestamps) {
opt["use_wallclock_as_timestamps"] = 1;
opt[QStringLiteral("use_wallclock_as_timestamps")] = 1;
mpPlayer->setBufferValue(1);
} else {
opt.remove("use_wallclock_as_timestamps");
opt.remove(QStringLiteral("use_wallclock_as_timestamps"));
mpPlayer->setBufferValue(-1);
}
mpPlayer->setOptionsForFormat(opt);
Expand Down
4 changes: 2 additions & 2 deletions qml/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class QtAVQmlPlugin : public QQmlExtensionPlugin
public:
void registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("QtAV"));
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtAV"));
qmlRegisterType<QQuickItemRenderer>(uri, 1, 3, "VideoOutput");
qmlRegisterType<QmlAVPlayer>(uri, 1, 3, "AVPlayer");
qmlRegisterType<QmlAVPlayer>(uri, 1, 3, "MediaPlayer");
Expand All @@ -50,7 +50,7 @@ class QtAVQmlPlugin : public QQmlExtensionPlugin
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
qmlRegisterType<QuickFBORenderer>(uri, 1, 5, "VideoOutput2");
#endif
qmlRegisterUncreatableType<VideoCapture>(uri, 1, 6, "VideoCapture", "VideoCapture is provided by MediaPlayer");
qmlRegisterUncreatableType<VideoCapture>(uri, 1, 6, "VideoCapture", trUtf8("VideoCapture is provided by MediaPlayer"));
qmlRegisterType<MediaMetaData>();
}
};
Expand Down
42 changes: 21 additions & 21 deletions src/AVError.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
AVError.cpp: description
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2013-2015 Wang Bin <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -143,68 +143,68 @@ QString AVError::string() const
errStr = QObject::tr("No error");
break;
case OpenError:
errStr = "Open error";
errStr = QObject::tr("Open error");
break;
case OpenTimedout:
errStr = "Open timed out";
errStr = QObject::tr("Open timed out");
break;
case FindStreamInfoError:
errStr = "Could not find stream info";
errStr = QObject::tr("Could not find stream info");
break;
case StreamNotFound:
errStr = "Stream not found";
errStr = QObject::tr("Stream not found");
break;
case ReadTimedout:
errStr = "Read packet timed out";
errStr = QObject::tr("Read packet timed out");
break;
case ReadError:
errStr = "Read error";
errStr = QObject::tr("Read error");
break;
case SeekError:
errStr = "Seek error";
errStr = QObject::tr("Seek error");
break;
case ResourceError:
errStr = "Resource error";
errStr = QObject::tr("Resource error");
break;

case OpenCodecError:
errStr = "Open codec error";
errStr = QObject::tr("Open codec error");
break;
case CloseCodecError:
errStr = "Close codec error";
errStr = QObject::tr("Close codec error");
break;
case VideoCodecNotFound:
errStr = "Video codec not found";
errStr = QObject::tr("Video codec not found");
break;
case AudioCodecNotFound:
errStr = "Audio codec not found";
errStr = QObject::tr("Audio codec not found");
break;
case SubtitleCodecNotFound:
errStr = "Subtitle codec not found";
errStr = QObject::tr("Subtitle codec not found");
break;
case CodecError:
errStr = "Codec error";
errStr = QObject::tr("Codec error");
break;

case FormatError:
errStr = "Format error";
errStr = QObject::tr("Format error");
break;

case NetworkError:
errStr = "Network error";
errStr = QObject::tr("Network error");
break;

case AccessDenied:
errStr = "Access denied";
errStr = QObject::tr("Access denied");
break;

default:
errStr = "Unknow error";
errStr = QObject::tr("Unknow error");
break;
}
}
if (mFFmpegError != 0) {
errStr += QString("\n(FFmpeg %1: %2)").arg(mFFmpegError, 0, 16).arg(ffmpegErrorString());
errStr += QStringLiteral("\n(FFmpeg %1: %2)").arg(mFFmpegError, 0, 16).arg(ffmpegErrorString());
}
return errStr;
}
Expand All @@ -218,7 +218,7 @@ QString AVError::ffmpegErrorString() const
{
if (mFFmpegError == 0)
return QString();
return av_err2str(mFFmpegError);
return QString::fromUtf8(av_err2str(mFFmpegError));
}

} //namespace QtAV
Expand Down
42 changes: 21 additions & 21 deletions src/AVMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ const QStringList &AVMuxer::supportedProtocols()
if (!protocols.isEmpty())
return protocols;
#if QTAV_HAVE(AVDEVICE)
protocols << "avdevice";
protocols << QStringLiteral("avdevice");
#endif
av_register_all(); // MUST register all input/output formats
void* opq = 0;
const char* protocol = avio_enum_protocols(&opq, 1);
while (protocol) {
// static string, no deep copy needed. but QByteArray::fromRawData(data,size) assumes data is not null terminated and we must give a size
protocols.append(protocol);
protocols.append(QString::fromUtf8(protocol));
protocol = avio_enum_protocols(&opq, 1);
}
return protocols;
Expand All @@ -202,7 +202,7 @@ QIODevice* AVMuxer::ioDevice() const
{
if (!d->io)
return 0;
if (d->io->name() != "QIODevice")
if (d->io->name() != QLatin1String("QIODevice"))
return 0;
return d->io->property("device").value<QIODevice*>();
}
Expand All @@ -221,25 +221,25 @@ bool AVMuxer::setMedia(const QString &fileName)
d->file_orig = fileName;
const QString url_old(d->file);
d->file = fileName.trimmed();
if (d->file.startsWith("mms:"))
d->file.insert(3, 'h');
else if (d->file.startsWith(kFileScheme))
if (d->file.startsWith(QLatin1String("mms:")))
d->file.insert(3, QLatin1Char('h'));
else if (d->file.startsWith(QLatin1String(kFileScheme)))
d->file = getLocalPath(d->file);
d->media_changed = url_old != d->file;
if (d->media_changed) {
d->format_forced.clear();
}
// a local file. return here to avoid protocol checking. If path contains ":", protocol checking will fail
if (d->file.startsWith(QChar('/')))
if (d->file.startsWith(QLatin1Char('/')))
return d->media_changed;
// use MediaIO to support protocols not supported by ffmpeg
int colon = d->file.indexOf(QChar(':'));
int colon = d->file.indexOf(QLatin1Char(':'));
if (colon >= 0) {
#ifdef Q_OS_WIN
if (colon == 1 && d->file.at(0).isLetter())
return d->media_changed;
#endif
const QString scheme = colon == 0 ? "qrc" : d->file.left(colon);
const QString scheme = colon == 0 ? QStringLiteral("qrc") : d->file.left(colon);
// supportedProtocols() is not complete. so try MediaIO 1st, if not found, fallback to libavformat
d->io = MediaIO::createForProtocol(scheme);
if (d->io) {
Expand All @@ -254,13 +254,13 @@ bool AVMuxer::setMedia(QIODevice* device)
d->file = QString();
d->file_orig = QString();
if (d->io) {
if (d->io->name() != "QIODevice") {
if (d->io->name() != QLatin1String("QIODevice")) {
delete d->io;
d->io = 0;
}
}
if (!d->io)
d->io = MediaIO::create("QIODevice");
d->io = MediaIO::create(QStringLiteral("QIODevice"));
QIODevice* old_dev = d->io->property("device").value<QIODevice*>();
d->media_changed = old_dev != device;
if (d->media_changed) {
Expand Down Expand Up @@ -433,22 +433,22 @@ void AVMuxer::Private::applyOptionsForDict()
if (options.isEmpty())
return;
QVariant opt(options);
if (options.contains("avformat"))
opt = options.value("avformat");
if (options.contains(QStringLiteral("avformat")))
opt = options.value(QStringLiteral("avformat"));
Internal::setOptionsToDict(opt, &dict);

if (opt.type() == QVariant::Map) {
QVariantMap avformat_dict(opt.toMap());
if (avformat_dict.contains("format_whitelist")) {
const QString fmts(avformat_dict["format_whitelist"].toString());
if (!fmts.contains(',') && !fmts.isEmpty())
if (avformat_dict.contains(QStringLiteral("format_whitelist"))) {
const QString fmts(avformat_dict[QStringLiteral("format_whitelist")].toString());
if (!fmts.contains(QLatin1Char(',')) && !fmts.isEmpty())
format_forced = fmts; // reset when media changed
}
} else if (opt.type() == QVariant::Hash) {
QVariantHash avformat_dict(opt.toHash());
if (avformat_dict.contains("format_whitelist")) {
const QString fmts(avformat_dict["format_whitelist"].toString());
if (!fmts.contains(',') && !fmts.isEmpty())
if (avformat_dict.contains(QStringLiteral("format_whitelist"))) {
const QString fmts(avformat_dict[QStringLiteral("format_whitelist")].toString());
if (!fmts.contains(QLatin1Char(',')) && !fmts.isEmpty())
format_forced = fmts; // reset when media changed
}
}
Expand All @@ -463,8 +463,8 @@ void AVMuxer::Private::applyOptionsForContext()
return;
}
QVariant opt(options);
if (options.contains("avformat"))
opt = options.value("avformat");
if (options.contains(QStringLiteral("avformat")))
opt = options.value(QStringLiteral("avformat"));
Internal::setOptionsToFFmpegObj(opt, format_ctx);
}
} //namespace QtAV
4 changes: 2 additions & 2 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void AVPlayer::setFile(const QString &path)
// file() is used somewhere else. ensure it is correct
QString p(path);
// QFile does not support "file:"
if (p.startsWith("file:"))
if (p.startsWith(QLatin1String("file:")))
p = getLocalPath(p);
d->reset_state = d->current_source.type() != QVariant::String || d->current_source.toString() != p;
d->current_source = p;
Expand Down Expand Up @@ -865,7 +865,7 @@ bool AVPlayer::setAudioStream(const QString &file, int n)
return false;
QString path(file);
// QFile does not support "file:"
if (path.startsWith("file:"))
if (path.startsWith(QLatin1String("file:")))
path = getLocalPath(path);
if (d->audio_track == n && d->external_audio == path)
return true;
Expand Down
Loading

0 comments on commit 665f1d9

Please sign in to comment.