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

Code before:
}

void CMediaPipelineWebOS::SetSubtitleDelay(const double delay)
{
  m_subtitleDelay = delay;
}

bool CMediaPipelineWebOS::Load(CDVDStreamInfo videoHint, CDVDStreamInfo audioHint)
{
  std::scoped_lock videoLock(m_videoCriticalSection);
  std::scoped_lock audioLock(m_audioCriticalSection);

  CVariant p;

  if (videoHint.cryptoSession || audioHint.cryptoSession)
  {
    CryptoSessionSystem keySystem = CryptoSessionSystem::CRYPTO_SESSION_SYSTEM_NONE;
    bool isVideoCrypt = false;

    int svpVersion = SVP_VERSION_40;

    if (m_webOSVersion < 6)
      svpVersion = SVP_VERSION_30;

    if (audioHint.cryptoSession)
      keySystem = audioHint.cryptoSession->keySystem;

    if (videoHint.cryptoSession)
    {
      keySystem = videoHint.cryptoSession->keySystem;
      isVideoCrypt = true;
    }

    switch (keySystem)
    {
      case STREAM_CRYPTO_KEY_SYSTEM_NONE:
        break;
      case STREAM_CRYPTO_KEY_SYSTEM_CLEARKEY:
        break;
      case STREAM_CRYPTO_KEY_SYSTEM_WIDEVINE:
        CLog::Log(LOGDEBUG, "Setting drm type to WIDEVINE_MODULAR with svpVersion {}",
                  static_cast<int>(svpVersion));
        p["option"]["externalStreamingInfo"]["svpVersion"] = svpVersion;
        p["option"]["drm"]["type"] = "WIDEVINE_MODULAR";
        break;
      case STREAM_CRYPTO_KEY_SYSTEM_PLAYREADY:
        CLog::Log(LOGDEBUG, "Setting drm type to PLAYREADY with svpVersion {}",
                  static_cast<int>(svpVersion));
        p["option"]["externalStreamingInfo"]["svpVersion"] = svpVersion;
        p["option"]["drm"]["type"] = "PLAYREADY";
        break;

Review comment (bug):
```suggestion
  if (videoHint.cryptoSession || audioHint.cryptoSession)
  {
    CryptoSessionSystem keySystem = CRYPTO_SESSION_SYSTEM_NONE;

    const int svpVersion = m_webOSVersion < 6 ? SVP_VERSION_40 : SVP_VERSION_30;

    if (audioHint.cryptoSession)
    {
      keySystem = audioHint.cryptoSession->keySystem;
    }

    if (videoHint.cryptoSession)
    {
      keySystem = videoHint.cryptoSession->keySystem;
    }

    switch (keySystem)
    {
      case CRYPTO_SESSION_SYSTEM_NONE:
        break;
      case CRYPTO_SESSION_SYSTEM_CLEARKEY:
        break;
      case CRYPTO_SESSION_SYSTEM_WIDEVINE:
        CLog::Log(LOGDEBUG, "Setting drm type to WIDEVINE_MODULAR with svpVersion {}", svpVersion);
        p["option"]["externalStreamingInfo"]["svpVersion"] = svpVersion;
        p["option"]["drm"]["type"] = "WIDEVINE_MODULAR";
        break;
      case CRYPTO_SESSION_SYSTEM_PLAYREADY:
        CLog::Log(LOGDEBUG, "Setting drm type to PLAYREADY with svpVersion {}", svpVersion);
        p["option"]["externalStreamingInfo"]["svpVersion"] = svpVersion;
        p["option"]["drm"]["type"] = "PLAYREADY";
        break;
      default:
        if (audioHint.cryptoSession && !videoHint.cryptoSession)
          CLog::LogF(LOGERROR, "CryptoSession (audio) unsupported: {}",
                     audioHint.cryptoSession->keySystem);
        else if (videoHint.cryptoSession)
          CLog::LogF(LOGERROR, "CryptoSession (video) unsupported: {}",
                     videoHint.cryptoSession->keySystem);
        return false;
    }
```

Code after:

    switch (keySystem)
    {
      case CRYPTO_SESSION_SYSTEM_NONE:
        break;
      case CRYPTO_SESSION_SYSTEM_CLEARKEY:
        break;
      case CRYPTO_SESSION_SYSTEM_WIDEVINE:
        CLog::Log(LOGDEBUG, "Setting drm type to WIDEVINE_MODULAR with svpVersion {}", svpVersion);
        p["option"]["externalStreamingInfo"]["svpVersion"] = svpVersion;
        p["option"]["drm"]["type"] = "WIDEVINE_MODULAR";
        break;
      case CRYPTO_SESSION_SYSTEM_PLAYREADY:
        CLog::Log(LOGDEBUG, "Setting drm type to PLAYREADY with svpVersion {}", svpVersion);
        p["option"]["externalStreamingInfo"]["svpVersion"] = svpVersion;
        p["option"]["drm"]["type"] = "PLAYREADY";
        break;
      default:
        if (audioHint.cryptoSession && !videoHint.cryptoSession)
          CLog::LogF(LOGERROR, "CryptoSession (audio) unsupported: {}",
                     audioHint.cryptoSession->keySystem);
        else if (videoHint.cryptoSession)
          CLog::LogF(LOGERROR, "CryptoSession (video) unsupported: {}",
                     videoHint.cryptoSession->keySystem);
        return false;
    }
  }

  if (!videoHint.width || !videoHint.height)
  {
    CLog::LogF(LOGERROR, "{}", "null size, cannot handle");
    return false;
  }

  CLog::LogF(LOGDEBUG,
             "hints: Width {} x Height {}, Fpsrate {} / Fpsscale {}, "
             "CodecID {}, Level {}, Profile {}, PTS_invalid {}, Tag {}, Extradata-Size: {}",
             videoHint.width, videoHint.height, videoHint.fpsrate, videoHint.fpsscale,
             videoHint.codec, videoHint.level, videoHint.profile, videoHint.ptsinvalid,
             videoHint.codec_tag, videoHint.extradata.GetSize());

  if (!ms_codecMap.contains(videoHint.codec))
  {
    CLog::LogF(LOGDEBUG, "Unsupported video hints.codec({})", videoHint.codec);
    return false;
  }

  SetupBitstreamConverter(videoHint);
  CVariant& contents = p["option"]["externalStreamingInfo"]["contents"];
  if (videoHint.hdrType == StreamHdrType::HDR_TYPE_DOLBYVISION)
  {