Repository: xbmc/xbmc
File: xbmc/cores/VideoPlayer/DVDFileInfo.cpp (C++)

Code before:

  auto end = std::chrono::steady_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
  CLog::LogF(LOGDEBUG, "measured {} ms to extract thumb from file <{}> in {} packets. ",
             duration.count(), redactPath, packetsTried);

  return result;
}

bool CDVDFileInfo::CanExtract(const CFileItem& fileItem)
{
  if (fileItem.m_bIsFolder)
    return false;

  if ((URIUtils::IsPVR(fileItem.GetPath()) &&
       !PVR::UTILS::ProvidesStreamForMetaDataExtraction(fileItem)) ||
      // plugin path not fully resolved
      URIUtils::IsPlugin(fileItem.GetDynPath()) || URIUtils::IsUPnP(fileItem.GetPath()) ||
      NETWORK::IsInternetStream(fileItem) || VIDEO::IsDiscStub(fileItem) ||
      PLAYLIST::IsPlayList(fileItem))
    return false;

  // mostly can't extract from discs and files from discs.
  if (fileItem.IsBluray() || fileItem.IsDVD() || fileItem.IsDiscImage() ||
      VIDEO::IsDVDFile(fileItem, false, true))
    return false;

  // For HTTP/FTP we only allow extraction when on a LAN
  if (URIUtils::IsRemote(fileItem.GetPath()) && !URIUtils::IsOnLAN(fileItem.GetPath()) &&
      (URIUtils::IsFTP(fileItem.GetPath()) || URIUtils::IsHTTP(fileItem.GetPath())))
    return false;

  return true;
}

/**
 * \brief Open the item pointed to by pItem and extract streamdetails
 * \return true if the stream details have changed
 */
bool CDVDFileInfo::GetFileStreamDetails(CFileItem *pItem)
{
  if (!pItem)
    return false;

  if (!CanExtract(*pItem))
    return false;

  std::string strFileNameAndPath;
  if (pItem->HasVideoInfoTag())
    strFileNameAndPath = pItem->GetVideoInfoTag()->m_strFileNameAndPath;


Review comment (performance):
What is the benefit? item.IsBluray() is relatively more expensive because indirectly uses GetOpticalMediaPath() which uses disk i/o.
CanExtract is used by the library scanner and can call this function many times. Small differences add up.

Code after:

  auto end = std::chrono::steady_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
  CLog::LogF(LOGDEBUG, "measured {} ms to extract thumb from file <{}> in {} packets. ",
             duration.count(), redactPath, packetsTried);

  return result;
}

bool CDVDFileInfo::CanExtract(const CFileItem& fileItem)
{
  if (fileItem.m_bIsFolder)
    return false;

  if ((URIUtils::IsPVR(fileItem.GetPath()) &&
       !PVR::UTILS::ProvidesStreamForMetaDataExtraction(fileItem)) ||
      // plugin path not fully resolved
      URIUtils::IsPlugin(fileItem.GetDynPath()) || URIUtils::IsUPnP(fileItem.GetPath()) ||
      NETWORK::IsInternetStream(fileItem) || VIDEO::IsDiscStub(fileItem) ||
      PLAYLIST::IsPlayList(fileItem))
    return false;

  // mostly can't extract from discs and files from discs.
  if (URIUtils::IsBlurayPath(fileItem.GetPath()) || VIDEO::IsBDFile(fileItem) || fileItem.IsDVD() ||
      fileItem.IsDiscImage() || VIDEO::IsDVDFile(fileItem, false, true))
    return false;

  // For HTTP/FTP we only allow extraction when on a LAN
  if (URIUtils::IsRemote(fileItem.GetPath()) && !URIUtils::IsOnLAN(fileItem.GetPath()) &&
      (URIUtils::IsFTP(fileItem.GetPath()) || URIUtils::IsHTTP(fileItem.GetPath())))
    return false;

  return true;
}

/**
 * \brief Open the item pointed to by pItem and extract streamdetails
 * \return true if the stream details have changed
 */
bool CDVDFileInfo::GetFileStreamDetails(CFileItem *pItem)
{
  if (!pItem)
    return false;

  if (!CanExtract(*pItem))
    return false;

  std::string strFileNameAndPath;
  if (pItem->HasVideoInfoTag())
    strFileNameAndPath = pItem->GetVideoInfoTag()->m_strFileNameAndPath;