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

Code before:
      }
      m_format.m_frames = static_cast<int>(period_size / m_format.m_frameSize);

      CLog::Log(LOGINFO,
                "Audiotrack buffer params are: period time = {:.3f} ms, period size = "
                "{} bytes, num periods = {}",
                period_time * 1000, period_size, m_min_buffer_size / period_size);
    }

    if (m_passthrough && !m_info.m_wantsIECPassthrough)
      m_audiotrackbuffer_sec = rawlength_in_seconds;

    CLog::Log(LOGINFO,
              "Created Audiotrackbuffer with playing time of {:f} ms min buffer size: {} bytes",
              m_audiotrackbuffer_sec * 1000, m_min_buffer_size);

    m_audiotrackbuffer_sec_orig = m_audiotrackbuffer_sec;

    m_jniAudioFormat = m_encoding;
    m_at_jni = CreateAudioTrack(stream, m_sink_sampleRate, atChannelMask,
                                m_encoding, m_min_buffer_size);

    if (!IsInitialized())
    {
      delete m_at_jni;
      m_at_jni = NULL;
      if (!m_passthrough)
      {
        if (atChannelMask != CJNIAudioFormat::CHANNEL_OUT_STEREO &&
            atChannelMask != CJNIAudioFormat::CHANNEL_OUT_5POINT1)
        {
          atChannelMask = CJNIAudioFormat::CHANNEL_OUT_5POINT1;
          CLog::Log(LOGDEBUG, "AESinkAUDIOTRACK - Retrying multichannel playback with a 5.1 layout");
          continue;
        }
        else if (atChannelMask != CJNIAudioFormat::CHANNEL_OUT_STEREO)
        {
          atChannelMask = CJNIAudioFormat::CHANNEL_OUT_STEREO;
          CLog::Log(LOGDEBUG, "AESinkAUDIOTRACK - Retrying with a stereo layout");
          continue;
        }
      }
      else
      {
        if (!retried)
        {
          retried = true;
          CLog::Log(LOGWARNING, "AESinkAUDIOTRACK - Unable to open PT device - will retry once");
          // Seems that some devices don't properly implement pause + flush, which during seek
          // might open the device too fast - let's retry
          usleep(200 * 1000);

Review comment (suggestion):
This seems redundant now because is only two code paths and both calls Deinitialize() anyway:

1. ~Retry path --> code reaches `continue;` go to top and call Deinitialize/Initialize again.~
2. Error path --> "Unable to create AudioTrack" is called  Deinitialize() directly.


Code after:

      CLog::Log(LOGINFO,
                "Audiotrack buffer params are: period time = {:.3f} ms, period size = "
                "{} bytes, num periods = {}",
                period_time * 1000, period_size, m_min_buffer_size / period_size);
    }

    if (m_passthrough && !m_info.m_wantsIECPassthrough)
      m_audiotrackbuffer_sec = rawlength_in_seconds;

    CLog::Log(LOGINFO,
              "Created Audiotrackbuffer with playing time of {:f} ms min buffer size: {} bytes",
              m_audiotrackbuffer_sec * 1000, m_min_buffer_size);

    m_audiotrackbuffer_sec_orig = m_audiotrackbuffer_sec;

    m_jniAudioFormat = m_encoding;
    m_at_jni = CreateAudioTrack(stream, m_sink_sampleRate, atChannelMask,
                                m_encoding, m_min_buffer_size);

    if (!IsInitialized())
    {
      delete m_at_jni;
      m_at_jni = NULL;
      if (!m_passthrough)
      {
        if (atChannelMask != CJNIAudioFormat::CHANNEL_OUT_STEREO &&
            atChannelMask != CJNIAudioFormat::CHANNEL_OUT_5POINT1)
        {
          atChannelMask = CJNIAudioFormat::CHANNEL_OUT_5POINT1;
          CLog::Log(LOGDEBUG, "AESinkAUDIOTRACK - Retrying multichannel playback with a 5.1 layout");
          continue;
        }
        else if (atChannelMask != CJNIAudioFormat::CHANNEL_OUT_STEREO)
        {
          atChannelMask = CJNIAudioFormat::CHANNEL_OUT_STEREO;
          CLog::Log(LOGDEBUG, "AESinkAUDIOTRACK - Retrying with a stereo layout");
          continue;
        }
      }
      else
      {
        if (!retried)
        {
          retried = true;
          CLog::Log(LOGWARNING, "AESinkAUDIOTRACK - Unable to open PT device - will retry once");
          // Seems that some devices don't properly implement pause + flush, which during seek
          // might open the device too fast - let's retry
          usleep(200 * 1000);
          continue;
        }