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

Code before:
      m_processInfo->SeekFinished(0);
      SetCaching(CACHESTATE_FLUSH);

      CDVDMsgPlayerSeekChapter& msg(*std::static_pointer_cast<CDVDMsgPlayerSeekChapter>(pMsg));
      double start = DVD_NOPTS_VALUE;
      int offset = 0;

      // This should always be the case.
      if (m_pDemuxer)
      {
        // SeekChapter does not know about EDL cuts as demuxers are EDL agnostic
        // So get and adjust chapter time
        const std::chrono::milliseconds position{m_pDemuxer->GetChapterPos(msg.GetChapter()) * 1000};
        const auto hasEdit{m_Edl.InEdit(position)};
        double time{static_cast<double>(position.count())};
        if (hasEdit)
        {
          const auto& edit{hasEdit.value()};
          if (edit->action == EDL::Action::CUT)
          {
            // Ensure moving backward/forward doesn't take us past the beginning/end point (which may be cut)
            const bool forward{msg.GetChapter() > GetChapter()};
            const std::chrono::milliseconds absoluteTime{forward ? edit->start : edit->end};
            const std::chrono::milliseconds adjustedTime{m_Edl.GetTimeWithoutCuts(absoluteTime)};
            const auto endTime{std::chrono::duration_cast<std::chrono::milliseconds>(
                std::chrono::duration<double, std::milli>(m_State.timeMax))};
            if (adjustedTime + 50ms > endTime)
              // If close to end then use end of stream otherwise adjustedTime can be a few ms over the end
              // and still cause the video to freeze
              time = m_pDemuxer->GetStreamLength();
            else
              time = static_cast<double>(absoluteTime.count());
          }
        }

        if (m_pDemuxer->SeekTime(time, true, &start))
        {
          FlushBuffers(start, true, true);
          int64_t beforeSeek = GetTime();
          offset = DVD_TIME_TO_MSEC(start) - static_cast<int>(beforeSeek);
          m_callback.OnPlayBackSeekChapter(msg.GetChapter());
        }
      }
      else if (m_pInputStream)
      {
        CDVDInputStream::IChapter* pChapter = m_pInputStream->GetIChapter();
        if (pChapter && pChapter->SeekChapter(msg.GetChapter()))
        {
          FlushBuffers(start, true, true);
          int64_t beforeSeek = GetTime();
          offset = DVD_TIME_TO_MSEC(start) - static_cast<int>(beforeSeek);

Review comment (suggestion):
I don't think the `duration_cast` is needed:
```suggestion
            const auto endTime{std::chrono::duration<double, std::milli>(m_State.timeMax)};
```

Code after:
      m_processInfo->SeekFinished(0);
      SetCaching(CACHESTATE_FLUSH);

      CDVDMsgPlayerSeekChapter& msg(*std::static_pointer_cast<CDVDMsgPlayerSeekChapter>(pMsg));
      double start = DVD_NOPTS_VALUE;
      int offset = 0;

      // This should always be the case.
      if (m_pDemuxer)
      {
        // SeekChapter does not know about EDL cuts as demuxers are EDL agnostic
        // So get and adjust chapter time
        const std::chrono::milliseconds position{m_pDemuxer->GetChapterPos(msg.GetChapter()) *
                                                 1000};
        const auto hasEdit{m_Edl.InEdit(position)};
        double time{static_cast<double>(position.count())};
        if (hasEdit)
        {
          const auto& edit{hasEdit.value()};
          if (edit->action == EDL::Action::CUT)
          {
            // Ensure moving backward/forward doesn't take us past the beginning/end point (which may be cut)
            const bool forward{msg.GetChapter() > GetChapter()};
            const std::chrono::milliseconds absoluteTime{forward ? edit->start : edit->end};
            const std::chrono::milliseconds adjustedTime{m_Edl.GetTimeWithoutCuts(absoluteTime)};
            const auto endTime{std::chrono::duration<double, std::milli>(m_State.timeMax)};
            if (adjustedTime + 50ms > endTime)
              // If close to end then use end of stream otherwise adjustedTime can be a few ms over the end
              // and still cause the video to freeze
              time = m_pDemuxer->GetStreamLength();
            else
              time = static_cast<double>(absoluteTime.count());
          }
        }

        if (m_pDemuxer->SeekTime(time, true, &start))
        {
          FlushBuffers(start, true, true);
          int64_t beforeSeek = GetTime();
          offset = DVD_TIME_TO_MSEC(start) - static_cast<int>(beforeSeek);
          m_callback.OnPlayBackSeekChapter(msg.GetChapter());
        }
      }
      else if (m_pInputStream)
      {
        CDVDInputStream::IChapter* pChapter = m_pInputStream->GetIChapter();
        if (pChapter && pChapter->SeekChapter(msg.GetChapter()))
        {
          FlushBuffers(start, true, true);
          int64_t beforeSeek = GetTime();
          offset = DVD_TIME_TO_MSEC(start) - static_cast<int>(beforeSeek);