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

Code before:
    m_messageQueueParent.Put(std::make_shared<CDVDMsg>(CDVDMsg::PLAYER_ABORT));
    return false;
  }

  m_droppedFrames = 0;
  std::string formatName = fmt::format(
      "starfish-{}{}", videoHint.hdrType == StreamHdrType::HDR_TYPE_DOLBYVISION ? "d" : "",
      StringUtils::ToLower(ms_codecMap.at(videoHint.codec).name.data()));
  m_processInfo.SetVideoDecoderName(formatName, true);
  m_processInfo.SetVideoPixelFormat("Surface");
  m_processInfo.SetVideoDimensions(videoHint.width, videoHint.height);
  m_processInfo.SetVideoInterlaced(videoHint.interlaced);
  m_processInfo.SetVideoDeintMethod("hardware");
  m_processInfo.SetVideoDAR(static_cast<float>(videoHint.aspect));
  m_processInfo.SetVideoFps(static_cast<float>(fps));
  if (audioHint.codec != AV_CODEC_ID_NONE)
  {
    if (audioHint.channellayout)
      m_processInfo.SetAudioChannels(CAEUtil::GetAEChannelLayout(audioHint.channellayout));
    else
      m_processInfo.SetAudioChannels(CAEUtil::GuessChLayout(audioHint.channels));
    m_processInfo.SetAudioSampleRate(audioHint.samplerate);
    m_processInfo.SetAudioBitsPerSample(audioHint.bitspersample);
    if (Supports(audioHint.codec, audioHint.cryptoSession != nullptr))
      m_processInfo.SetAudioDecoderName(std::string("starfish-") +
                                        ms_codecMap.at(audioHint.codec).name.data());
    else if (m_audioEncoder)
      m_processInfo.SetAudioDecoderName("starfish-AC3 (transcoding)");
  }

  m_renderManager.ShowVideo(true);
  return true;
}

void CMediaPipelineWebOS::Unload(const bool sync)
{
  CThread::StopThread(true);
  if (m_audioThread.joinable())
    m_audioThread.join();

  if (!m_mediaAPIs->Unload())
    CLog::LogF(LOGERROR, "Unload failed");

  const auto buffer = static_cast<CStarfishVideoBuffer*>(m_picture.videoBuffer);
  buffer->ResetAcbHandle();

  if (sync)
  {
    // wait until m_loaded is false
    std::unique_lock lock(m_eventMutex);
    if (!m_eventCondition.wait_for(lock, 1s, [this] { return !m_loaded; }))

Review comment (suggestion):
```suggestion
                                        ms_codecMap.at(audioHint.codec).name);
```

Code after:
{
  CThread::StopThread(true);
  if (m_audioThread.joinable())
    m_audioThread.join();

  if (!m_mediaAPIs->Unload())
    CLog::LogF(LOGERROR, "Unload failed");

  const auto buffer = static_cast<CStarfishVideoBuffer*>(m_picture.videoBuffer);
  buffer->ResetAcbHandle();

  if (sync)
  {
    // wait until m_loaded is false
    std::unique_lock lock(m_eventMutex);
    if (!m_eventCondition.wait_for(lock, 1s, [this] { return !m_loaded; }))
    {
      CLog::LogF(LOGERROR, "Timeout waiting for m_loaded to be false");
    }
  }
}

std::string CMediaPipelineWebOS::SetupAudio(CDVDStreamInfo& audioHint, CVariant& optInfo)
{
  m_audioCodec = nullptr;
  m_audioEncoder = nullptr;
  m_audioResample = nullptr;
  m_encoderBuffers = nullptr;

  std::string codecName = "AC3";
  if (!Supports(audioHint.codec, audioHint.cryptoSession != nullptr))
  {
    m_audioCodec = std::make_unique<CDVDAudioCodecFFmpeg>(m_processInfo);
    CDVDCodecOptions options;
    m_audioCodec->Open(audioHint, options);
    m_audioEncoder = std::make_unique<CAEEncoderFFmpeg>();
    return codecName;
  }

  codecName = ms_codecMap.at(audioHint.codec).name;
  if (audioHint.codec == AV_CODEC_ID_EAC3)
  {
    optInfo["ac3PlusInfo"]["channels"] = audioHint.channels;
    optInfo["ac3PlusInfo"]["frequency"] = audioHint.samplerate / 1000.0;

    if (audioHint.profile == AV_PROFILE_EAC3_DDP_ATMOS)
    {
      optInfo["ac3PlusInfo"]["channels"] = audioHint.channels + 2;
    }
  }
  if (audioHint.codec == AV_CODEC_ID_AC4)