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

Code before:
      overlays, [startTime = newOverlay->iPTSStartTime](const std::shared_ptr<CDVDOverlay>& overlay)
      { overlay->iPTSStopTime = startTime; });

  m_overlays.emplace_back(newOverlay);
}

VecOverlays* CDVDOverlayContainer::GetOverlays()
{
  return &m_overlays;
}

namespace
{
bool IsOverlayFinished(const std::shared_ptr<CDVDOverlay>& overlay,
                       double pts,
                       std::set<double>& forcedStartTimes)
{
  // Remove non-forced overlays that have expired
  if (!overlay->bForced && overlay->iPTSStopTime <= pts && overlay->iPTSStopTime != 0.0)
    return true;

  // Remove forced overlays replaced by newer ones
  if (overlay->bForced)
  {
    if (!forcedStartTimes.empty() &&
        (forcedStartTimes.size() > 1 || *forcedStartTimes.begin() != overlay->iPTSStartTime))
      return true;

    if (overlay->iPTSStartTime < pts)
      forcedStartTimes.insert(overlay->iPTSStartTime);
  }
  return false;
}
} // namespace

void CDVDOverlayContainer::CleanUp(double pts)
{
  std::unique_lock lock(*this);

  std::set<double> forcedStartTimes;
  for (auto it = m_overlays.end(); it != m_overlays.begin();)
  {
    --it;
    if (IsOverlayFinished(*it, pts, forcedStartTimes))
      it = m_overlays.erase(it);
  }
}

void CDVDOverlayContainer::Flush()
{
  std::unique_lock lock(*this);

Review comment (suggestion):
I think preserving that part of the comment is important. The previous part is outdated and can go.
What little information is available should be preserved

Code after:
}

VecOverlays* CDVDOverlayContainer::GetOverlays()
{
  return &m_overlays;
}

VecOverlays::iterator CDVDOverlayContainer::Remove(VecOverlays::iterator itOverlay)
{
  std::unique_lock lock(*this);
  return m_overlays.erase(itOverlay);
}

void CDVDOverlayContainer::CleanUp(double pts)
{
  std::unique_lock lock(*this);

  auto it = m_overlays.begin();
  while (it != m_overlays.end())
  {
    const std::shared_ptr<CDVDOverlay>& pOverlay = *it;

    // never delete forced overlays, they are used in menu's
    // clear takes care of removing them
    // also if stoptime = 0, it means the next subtitles will use its starttime as the stoptime
    // which means we cannot delete overlays with stoptime 0
    if (!pOverlay->bForced && pOverlay->iPTSStopTime <= pts && pOverlay->iPTSStopTime != 0)
    {
      //CLog::Log(LOGDEBUG,"CDVDOverlay::CleanUp, removing {}", (int)(pts / 1000));
      //CLog::Log(LOGDEBUG,"CDVDOverlay::CleanUp, remove, start : {}, stop : {}", (int)(pOverlay->iPTSStartTime / 1000), (int)(pOverlay->iPTSStopTime / 1000));
      it = Remove(it);
      continue;
    }
    else if (pOverlay->bForced)
    {
      //Check for newer replacements
      auto it2 = it;
      bool bNewer = false;
      while (!bNewer && ++it2 != m_overlays.end())
      {
        const std::shared_ptr<CDVDOverlay>& pOverlay2 = *it2;
        // There can be multiple overlays queued at same start point.
        // Skip them to find a new start point.
        if (pOverlay2->bForced && pOverlay2->iPTSStartTime <= pts)
          bNewer = true;
      }

      if (bNewer)
      {
        it = Remove(it);
        continue;