mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-28 01:09:19 +00:00
fix(VideoCodecsModel): do not replace used codecs on update + many fixes
This commit is contained in:
parent
b0c1f64914
commit
0c8aea3d00
5 changed files with 53 additions and 25 deletions
|
|
@ -166,6 +166,10 @@ void App::initContentApp () {
|
|||
|
||||
initLocale(config);
|
||||
} else {
|
||||
// Update and download codecs.
|
||||
VideoCodecsModel::updateCodecs();
|
||||
VideoCodecsModel::downloadUpdatableCodecs(this);
|
||||
|
||||
// Don't quit if last window is closed!!!
|
||||
setQuitOnLastWindowClosed(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -60,23 +60,19 @@ namespace {
|
|||
|
||||
VideoCodecsModel::VideoCodecsModel (QObject *parent) : AbstractCodecsModel(parent) {
|
||||
load();
|
||||
|
||||
// Update codec if it exists a new version.
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
updateCodecVersion("H264", cPluginUrlH264, cH264InstallName);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool VideoCodecsModel::updateCodecVersion (
|
||||
static bool downloadUpdatableCodec (
|
||||
QObject *parent,
|
||||
const QString &codecsFolder,
|
||||
const QString &mime,
|
||||
const QString &downloadUrl,
|
||||
const QString &installName
|
||||
) {
|
||||
QString codecsFolder = Utils::coreStringToAppString(Paths::getCodecsDirPath());
|
||||
QString versionFilePath = codecsFolder + mime + ".txt";
|
||||
QFile versionFile(versionFilePath);
|
||||
|
||||
if (!versionFile.exists() && !QFileInfo::exists(codecsFolder + cH264InstallName))
|
||||
if (!versionFile.exists() && !QFileInfo::exists(codecsFolder + installName))
|
||||
return false; // Must be downloaded one time before.
|
||||
|
||||
if (!versionFile.open(QIODevice::ReadOnly))
|
||||
|
|
@ -86,24 +82,24 @@ bool VideoCodecsModel::updateCodecVersion (
|
|||
|
||||
qInfo() << QStringLiteral("Updating `%1` codec...").arg(mime);
|
||||
|
||||
FileDownloader *fileDownloader = new FileDownloader(this);
|
||||
fileDownloader->setUrl(QUrl(cPluginUrlH264));
|
||||
FileDownloader *fileDownloader = new FileDownloader(parent);
|
||||
fileDownloader->setUrl(QUrl(downloadUrl));
|
||||
fileDownloader->setDownloadFolder(codecsFolder);
|
||||
|
||||
FileExtractor *fileExtractor = new FileExtractor(fileDownloader);
|
||||
fileExtractor->setExtractFolder(codecsFolder);
|
||||
fileExtractor->setExtractName(cH264InstallName);
|
||||
fileExtractor->setExtractName(installName + ".in");
|
||||
|
||||
QObject::connect(fileDownloader, &FileDownloader::downloadFinished, this, [fileExtractor](const QString &filePath) {
|
||||
QObject::connect(fileDownloader, &FileDownloader::downloadFinished, [fileExtractor](const QString &filePath) {
|
||||
fileExtractor->setFile(filePath);
|
||||
fileExtractor->extract();
|
||||
});
|
||||
|
||||
QObject::connect(fileDownloader, &FileDownloader::downloadFailed, this, [fileDownloader]() {
|
||||
QObject::connect(fileDownloader, &FileDownloader::downloadFailed, [fileDownloader]() {
|
||||
fileDownloader->deleteLater();
|
||||
});
|
||||
|
||||
QObject::connect(fileExtractor, &FileExtractor::extractFinished, this, [fileDownloader, fileExtractor, versionFilePath, downloadUrl]() {
|
||||
QObject::connect(fileExtractor, &FileExtractor::extractFinished, [fileDownloader, fileExtractor, versionFilePath, downloadUrl]() {
|
||||
QFile versionFile(versionFilePath);
|
||||
if (!versionFile.open(QIODevice::WriteOnly)) {
|
||||
qWarning() << QStringLiteral("Unable to write codec version in: `%1`.").arg(versionFilePath);
|
||||
|
|
@ -119,7 +115,7 @@ bool VideoCodecsModel::updateCodecVersion (
|
|||
fileDownloader->deleteLater();
|
||||
});
|
||||
|
||||
QObject::connect(fileExtractor, &FileExtractor::extractFailed, this, [fileDownloader]() {
|
||||
QObject::connect(fileExtractor, &FileExtractor::extractFailed, [fileDownloader]() {
|
||||
fileDownloader->remove();
|
||||
fileDownloader->deleteLater();
|
||||
});
|
||||
|
|
@ -129,6 +125,32 @@ bool VideoCodecsModel::updateCodecVersion (
|
|||
return true;
|
||||
}
|
||||
|
||||
void VideoCodecsModel::updateCodecs () {
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
static const QString codecSuffix = QStringLiteral(".%1").arg(cLibraryExtension);
|
||||
|
||||
QDirIterator it(Utils::coreStringToAppString(Paths::getCodecsDirPath()));
|
||||
while (it.hasNext()) {
|
||||
QFileInfo info(it.next());
|
||||
if (info.suffix() == "in") {
|
||||
QString codecName = info.completeBaseName();
|
||||
if (codecName.endsWith(codecSuffix)) {
|
||||
QString codecPath = info.dir().path() + QDir::separator() + codecName;
|
||||
QFile::remove(codecPath);
|
||||
QFile::rename(info.filePath(), codecPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
}
|
||||
|
||||
void VideoCodecsModel::downloadUpdatableCodecs (QObject *parent) {
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
QString codecsFolder = Utils::coreStringToAppString(Paths::getCodecsDirPath());
|
||||
downloadUpdatableCodec(parent, codecsFolder, "H264", cPluginUrlH264, cH264InstallName);
|
||||
#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
}
|
||||
|
||||
void VideoCodecsModel::updateCodecs (list<shared_ptr<linphone::PayloadType>> &codecs) {
|
||||
CoreManager::getInstance()->getCore()->setVideoPayloadTypes(codecs);
|
||||
}
|
||||
|
|
@ -147,7 +169,7 @@ void VideoCodecsModel::load () {
|
|||
QLibrary(info.filePath()).load();
|
||||
}
|
||||
core->reloadMsPlugins("");
|
||||
#endif
|
||||
#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
|
||||
// Add codecs.
|
||||
auto codecs = core->getVideoPayloadTypes();
|
||||
|
|
@ -160,7 +182,7 @@ void VideoCodecsModel::load () {
|
|||
return codec->getMimeType() == "H264";
|
||||
}) == codecs.end())
|
||||
addDownloadableCodec("H264", cH264Description, cPluginUrlH264, cH264InstallName);
|
||||
#endif
|
||||
#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
|
||||
}
|
||||
|
||||
void VideoCodecsModel::reload () {
|
||||
|
|
|
|||
|
|
@ -33,11 +33,12 @@ class VideoCodecsModel : public AbstractCodecsModel {
|
|||
public:
|
||||
VideoCodecsModel (QObject *parent = Q_NULLPTR);
|
||||
|
||||
static void updateCodecs ();
|
||||
static void downloadUpdatableCodecs (QObject *parent);
|
||||
|
||||
private:
|
||||
void updateCodecs (std::list<std::shared_ptr<linphone::PayloadType>> &codecs) override;
|
||||
|
||||
bool updateCodecVersion (const QString &mime, const QString &downloadUrl, const QString &installName);
|
||||
|
||||
void load ();
|
||||
void reload () override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ DialogPlus {
|
|||
property alias downloadUrl: fileDownloader.url
|
||||
property alias installFolder: fileDownloader.downloadFolder
|
||||
property bool extract: false
|
||||
property string installName
|
||||
property string mime
|
||||
property string installName // Right install name.
|
||||
property string mime // Human readable name.
|
||||
|
||||
property bool _installing: false
|
||||
property int _exitStatus: -1 // Not downloaded for the moment.
|
||||
|
|
|
|||
|
|
@ -620,15 +620,16 @@ function times (n, cb, context) {
|
|||
|
||||
function unscapeHtml (str) {
|
||||
return str.replace(/&/g, '&')
|
||||
.replace(/</g, '\u2063<')
|
||||
.replace(/>/g, '\u2063>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '\u2063<')
|
||||
.replace(/>/g, '\u2063>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
function write (fileName, text) {
|
||||
// TODO: Deal with async.
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('PUT', 'file://' + fileName, false);
|
||||
request.send(text);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue