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

Code before:

void CSelectionStreams::Update(const std::shared_ptr<CDVDInputStream>& input,
                               CDVDDemux* demuxer,
                               const std::string& filename2)
{
  if(input && input->IsStreamType(DVDSTREAM_TYPE_DVD))
  {
    std::shared_ptr<CDVDInputStreamNavigator> nav = std::static_pointer_cast<CDVDInputStreamNavigator>(input);
    std::string filename = nav->GetFileName();
    int source = Source(STREAM_SOURCE_NAV, filename);

    std::vector<CDemuxStream*> demuxStreams;
    if (demuxer)
      demuxStreams = demuxer->GetStreams();

    int count;
    count = nav->GetAudioStreamCount();
    for(int i=0;i<count;i++)
    {
      const auto stream =
          std::find_if(demuxStreams.begin(), demuxStreams.end(),
                       [i](const auto& stream)
                       { return stream->type == STREAM_AUDIO && stream->dvdNavId == i; });
      CDemuxStreamAudio* aStream =
          (stream != demuxStreams.end()) ? static_cast<CDemuxStreamAudio*>(*stream) : nullptr;

      SelectionStream s;
      s.source   = source;
      s.type     = STREAM_AUDIO;
      s.id       = i;
      s.flags    = StreamFlags::FLAG_NONE;
      s.filename = filename;

      AudioStreamInfo info = nav->GetAudioStreamInfo(i);
      s.name     = info.name;
      s.codec    = info.codecName;
      if (aStream)
      {
        s.codecDesc = aStream->GetStreamType();
        s.channels = aStream->iChannels;
        s.bitrate = aStream->iBitRate;
      }
      else
      {
        s.codecDesc = info.codecDesc;
        s.channels = info.channels;
      }
      s.language = g_LangCodeExpander.ConvertToISO6392B(info.language);
      s.flags = info.flags;
      Update(s);
    }

Review comment (suggestion):
this can be full removed not really needed,
imo compare "dvdNavId" id to an index count could be not so good idea

when there is no stream pointer is due to menu and menu interludes,
imo better have just one way to get info or the demuxer, or ffmpeg, not mixed

if you really want to keep it, just to get the bitrate, but this information could be obtained from the nav library
there is the bitrate audio attribute but it seems not to work properly

Code after:

void CSelectionStreams::Update(const std::shared_ptr<CDVDInputStream>& input,
                               CDVDDemux* demuxer,
                               const std::string& filename2)
{
  if(input && input->IsStreamType(DVDSTREAM_TYPE_DVD))
  {
    std::shared_ptr<CDVDInputStreamNavigator> nav = std::static_pointer_cast<CDVDInputStreamNavigator>(input);
    std::string filename = nav->GetFileName();
    int source = Source(STREAM_SOURCE_NAV, filename);

    std::vector<CDemuxStream*> demuxStreams;
    if (demuxer)
      demuxStreams = demuxer->GetStreams();

    int count;
    count = nav->GetAudioStreamCount();
    for(int i=0;i<count;i++)
    {
      const auto stream =
          std::find_if(demuxStreams.begin(), demuxStreams.end(),
                       [i](const auto& stream)
                       { return stream->type == STREAM_AUDIO && stream->dvdNavId == i; });
      CDemuxStreamAudio* aStream =
          (stream != demuxStreams.end()) ? static_cast<CDemuxStreamAudio*>(*stream) : nullptr;

      SelectionStream s;
      s.source   = source;
      s.type     = STREAM_AUDIO;
      s.id       = i;
      s.flags    = StreamFlags::FLAG_NONE;
      s.filename = filename;

      AudioStreamInfo info = nav->GetAudioStreamInfo(i);
      s.name     = info.name;
      s.codec    = info.codecName;
      // additional/more reliable info from ffmpeg than IFO nav data
      if (aStream)
      {
        s.codecDesc = aStream->GetStreamType();
        s.channels = aStream->iChannels;
        s.bitrate = aStream->iBitRate;
      }
      else
      {
        s.codecDesc = info.codecDesc;
        s.channels = info.channels;
      }
      s.language = g_LangCodeExpander.ConvertToISO6392B(info.language);
      s.flags = info.flags;
      Update(s);