Repository: xbmc/xbmc
File: xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp (C++)

Code before:
double CAESinkAUDIOTRACK::GetLatency()
{
  return 0.0;
}

double CAESinkAUDIOTRACK::GetCacheTotal()
{
  // total amount that the audio sink can buffer in units of seconds
  return m_audiotrackbuffer_sec;
}

// this method is supposed to block until all frames are written to the device buffer
// when it returns ActiveAESink will take the next buffer out of a queue
unsigned int CAESinkAUDIOTRACK::AddPackets(uint8_t **data, unsigned int frames, unsigned int offset)
{
  if (!IsInitialized())
    return INT_MAX;

  // If the sink did not move twice the buffer size at least 400 ms in time it was opened
  // take action. Some sinks open with e.g. 128 ms nicely but under the
  // hood need a bit more samples to start moving on sink start.
  // Simple equation: N x stime packages in ms > 400 ms or 2 buffer sizes in ms
  // will result in the error condition triggering.

  const bool isRawPt = m_passthrough && !m_info.m_wantsIECPassthrough;
  bool force_block = false;
  if (!isRawPt)
  {
    const double max_stuck_delay_ms = std::max((m_audiotrackbuffer_sec_orig * 2000.0), 400.0);
    const double stime_ms = 1000.0 * frames / m_format.m_sampleRate;

    if (m_superviseAudioDelay)
    {
      if (m_stuckCounter * stime_ms > max_stuck_delay_ms)
      {
        CLog::Log(LOGERROR, "Sink got stuck with {:f} ms - ask AE for reopening",
                  max_stuck_delay_ms);
        usleep(max_stuck_delay_ms * 1000);
        return INT_MAX;
      }
      else if (m_stuckCounter * stime_ms >= m_audiotrackbuffer_sec_orig * 1000.0)
      {
        CLog::LogF(LOGDEBUG, "Sink filling too fast - throttleing - Fillstate: {} ms!",
                   (m_stuckCounter * stime_ms));
        force_block = true;
      }
    }
  }

  // for debugging only - can be removed if everything is really stable
  uint64_t startTime = CurrentHostCounter();

Review comment (suggestion):
no underscore uses on new code
```suggestion
  bool forceBlock = false;
```

Code after:
double CAESinkAUDIOTRACK::GetLatency()
{
  return 0.0;
}

double CAESinkAUDIOTRACK::GetCacheTotal()
{
  // total amount that the audio sink can buffer in units of seconds
  return m_audiotrackbuffer_sec;
}

// this method is supposed to block until all frames are written to the device buffer
// when it returns ActiveAESink will take the next buffer out of a queue
unsigned int CAESinkAUDIOTRACK::AddPackets(uint8_t **data, unsigned int frames, unsigned int offset)
{
  if (!IsInitialized())
    return INT_MAX;

  // If the sink did not move twice the buffer size at least 400 ms in time it was opened
  // take action. Some sinks open with e.g. 128 ms nicely but under the
  // hood need a bit more samples to start moving on sink start.
  // Simple equation: N x stime packages in ms > 400 ms or 2 buffer sizes in ms
  // will result in the error condition triggering.

  const bool isRawPt = m_passthrough && !m_info.m_wantsIECPassthrough;
  bool forceBlock = false;
  if (!isRawPt)
  {
    const double max_stuck_delay_ms = std::max((m_audiotrackbuffer_sec_orig * 2000.0), 400.0);
    const double stime_ms = 1000.0 * frames / m_format.m_sampleRate;

    if (m_superviseAudioDelay)
    {
      if (m_stuckCounter * stime_ms > max_stuck_delay_ms)
      {
        CLog::Log(LOGERROR, "Sink got stuck with {:f} ms - ask AE for reopening",
                  max_stuck_delay_ms);
        usleep(max_stuck_delay_ms * 1000);
        return INT_MAX;
      }
      else if (m_stuckCounter * stime_ms >= m_audiotrackbuffer_sec_orig * 1000.0)
      {
        CLog::LogF(LOGDEBUG, "Sink filling too fast - throttleing - Fillstate: {} ms!",
                   (m_stuckCounter * stime_ms));
        forceBlock = true;
      }
    }
  }

  // for debugging only - can be removed if everything is really stable
  uint64_t startTime = CurrentHostCounter();