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

Code before:

int CVideoPlayer::GetPrograms(std::vector<ProgramInfo>& programs)
{
  std::unique_lock lock(m_content.m_section);
  programs = m_programs;
  return programs.size();
}

void CVideoPlayer::SetProgram(int progId)
{
  m_messenger.Put(std::make_shared<CDVDMsgInt>(CDVDMsg::PLAYER_SET_PROGRAM, progId));
}

int CVideoPlayer::GetProgramsCount() const
{
  std::unique_lock lock(m_content.m_section);
  return m_programs.size();
}

void CVideoPlayer::SetUpdateStreamDetails()
{
  m_messenger.Put(std::make_shared<CDVDMsg>(CDVDMsg::PLAYER_SET_UPDATE_STREAM_DETAILS));
}


void CVideoPlayer::NotifySubtitleUpdate(bool bStatus, bool bStreamInfo)
{
  CVariant data;
  data["player"]["playerid"] = static_cast<int>(CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist());
  if (bStatus)
  {
    data["property"]["subtitleenabled"] = m_processInfo->GetVideoSettings().m_SubtitleOn;
  }
  if (bStreamInfo)
  {
    int iStream = m_processInfo->GetVideoSettings().m_SubtitleStream;
    SubtitleStreamInfo info;
    GetSubtitleStreamInfo(iStream, info);
    if (info.valid)
    {
      CVariant contentEntry(CVariant::VariantTypeObject);
      contentEntry["index"] = iStream;
      contentEntry["isdefault"] = (info.flags & StreamFlags::FLAG_DEFAULT) != 0;
      contentEntry["isforced"] = (info.flags & StreamFlags::FLAG_FORCED) != 0;
      contentEntry["isimpaired"] = (info.flags & StreamFlags::FLAG_VISUAL_IMPAIRED) != 0;
      contentEntry["language"] = info.language;
      contentEntry["name"] = info.name;
      data["property"]["currentsubtitle"] = contentEntry;
    } else if (!bStatus) return;
  }
  CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Player, "OnPropertyChanged", data);

Review comment (suggestion):
Given the current usage, I think there should be a single enum parameter, something like
enum class SubtitleChange
{
STATUS_CHANGE,
STREAMINFO_CHANGE,
};


Code after:
    info.valid = false;
    info.language.clear();
    info.flags = StreamFlags::FLAG_NONE;
    return;
  }

  const SelectionStream& s = m_content.m_selectionStreams.Get(StreamType::SUBTITLE, index);
  info.name = s.name;

  if (s.type == StreamType::NONE)
    info.name += "(Invalid)";

  info.valid = true;
  info.language = s.language;
  info.codecName = s.codec;
  info.flags = s.flags;
  info.isExternal = STREAM_SOURCE_MASK(s.source) == STREAM_SOURCE_DEMUX_SUB ||
                    STREAM_SOURCE_MASK(s.source) == STREAM_SOURCE_TEXT;
}

void CVideoPlayer::SetSubtitle(int iStream)
{
  m_messenger.Put(std::make_shared<CDVDMsgPlayerSetSubtitleStream>(iStream));
  m_processInfo->GetVideoSettingsLocked().SetSubtitleStream(iStream);
  NotifySubtitleUpdate(SubtitleChange::FLAG_STREAMINFO_CHANGE);
}

int CVideoPlayer::GetSubtitleCount() const
{
  std::unique_lock lock(m_content.m_section);
  return m_content.m_selectionStreams.CountType(StreamType::SUBTITLE);
}

int CVideoPlayer::GetSubtitle()
{
  std::unique_lock lock(m_content.m_section);
  return m_content.m_subtitleIndex;
}

int CVideoPlayer::GetPrograms(std::vector<ProgramInfo>& programs)
{
  std::unique_lock lock(m_content.m_section);
  programs = m_programs;
  return programs.size();
}

void CVideoPlayer::SetProgram(int progId)
{
  m_messenger.Put(std::make_shared<CDVDMsgInt>(CDVDMsg::PLAYER_SET_PROGRAM, progId));
}