Ver Fonte

Abort if device-ID couldn't be read or written properly

If this file can't be accessed, the codecs folder is probably not
accessible as a whole. Playback won't work at all. So error out early.

Also cache the device-ID instead of recreating or loading it from the
disk file it every time to guarantee the ID remains the same.
Vincent Lang há 8 anos atrás
pai
commit
6224efcfdc
1 ficheiros alterados com 8 adições e 3 exclusões
  1. 8 3
      src/player/CodecsComponent.cpp

+ 8 - 3
src/player/CodecsComponent.cpp

@@ -85,6 +85,8 @@ static QSize g_mediaFoundationH264MaxResolution;
 static QString g_codecVersion;
 static QList<CodecDriver> g_cachedCodecList;
 
+static QString g_deviceID;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 static QString getBuildType()
 {
@@ -246,7 +248,7 @@ bool CodecDriver::isWhitelistedSystemVideoCodec() const
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Returns "" on error.
-static QString getDeviceID()
+static QString loadDeviceID()
 {
   QFile path(QDir(codecsRootPath()).absoluteFilePath(".device-id"));
   if (path.exists())
@@ -303,7 +305,7 @@ void Codecs::preinitCodecs()
   qputenv("FFMPEG_EXTERNAL_LIBS", escapedPath.toUtf8().data());
 #endif
 
-  getDeviceID();
+  g_deviceID = loadDeviceID();
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -355,6 +357,9 @@ static bool probeDecoder(QString decoder, QString resourceName)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 void Codecs::probeCodecs()
 {
+  if (g_deviceID == "")
+    throw FatalException("Could not read device-id.");
+
 #ifdef Q_OS_WIN32
   if (probeDecoder("h264_mf", ":/testmedia/high_4096x2304.h264"))
     g_mediaFoundationH264MaxResolution = QSize(4096, 2304);
@@ -438,7 +443,7 @@ void CodecsFetcher::startNext()
   QString host = "https://plex.tv";
   QUrl url = QUrl(host + "/api/codecs/" + codec.getMangledName());
   QUrlQuery query;
-  query.addQueryItem("deviceId", getDeviceID());
+  query.addQueryItem("deviceId", g_deviceID);
   query.addQueryItem("version", g_codecVersion);
   query.addQueryItem("build", getBuildType());
   query.addQueryItem("oldestPreviousVersion", SettingsComponent::Get().oldestPreviousVersion());