Make audio stream index handling saner in stream switching
commit90bedd0b872b6eea02351aafb62e30ffec5c2152
authorUoti Urpala <uau@glyph.nonexistent.invalid>
Sat, 22 May 2010 05:19:23 +0000 (22 08:19 +0300)
committerUoti Urpala <uau@glyph.nonexistent.invalid>
Sat, 22 May 2010 07:11:25 +0000 (22 10:11 +0300)
tree68463990312e6ceacf23ce9978a77485ffbede02
parente2f894852ce136c9fa5bee3b5d7fb75e8a880786
Make audio stream index handling saner in stream switching

The handling of audio stream numbering was handled in the stream
selection property was a total mess. The most important issue was
confusion between values used as index for demuxer->audio_streams[]
array (consistently stored in demuxer->audio->id) and values stored
in sh_audio->aid and used as "-aid N" option values. Now demuxer audio
switch control functions and demuxer_switch_audio() are supposed to
return the new value for the "-aid" option (internal MPEG demuxers
still don't; the demuxer requirement could perhaps be dropped as it
can be easily calculated afterwards). That is also the value
returned for the "switch_audio" property. The main changes are:

 - Make command.c mp_property_audio() consistently use and return the
   "-aid" values. Before it used that as input but the array index as
   output, with extra mess related to demuxer_switch_audio() return
   value. Don't modify the audio_id option field any more.

 - Make demuxer_switch_audio() always return "-aid" values (like it
   takes as input). There are two changes for this: picking this
   return value in case the demuxer doesn't support switching, and
   overriding demuxer return value (for internal MPEG demuxers).

 - Make demux_lavf return "-aid" values from DEMUXER_CTRL_SWITCH_AUDIO
   code. This isn't actually necessary because of the override part
   above.

Here's some history of the relevant behavior that I looked up:
* For most demuxers array index and "-aid" values are the same. At
  least demux_mkv, (some of?) the internal MPEG demuxers and demux_ogg
  have differed for a long time. demux_ogg doesn't matter because it
  doesn't support stream switching.
* Old code seemed to assume that demuxer_switch_audio() return value was
  array index, but this wasn't true at least for demux_mkv.
* In svn r19951 reimar mostly removed use of the return value.
* In r20162 ptt added mp_property_audio(). This set the global
  audio_id variable (-aid option value) to the return value of
  demuxer_switch_audio() and treated the global as the persistent
  value of the property, apparently assuming that it would be set to
  the "-aid" value, not array index. This was false for internal
  MPEG.
* In r30124 reimar changed the property code so that even though it
  still modified the option value it didn't use that as the value of
  the property any more; instead it incorrectly used the array index.
  This meant that for demux_mkv the return value didn't match -aid any
  more (though input still did, so setting the property and querying
  it didn't match as they used different value systems).
* In r31129 aurel made demux_lavf changes that resulted in its -aid
  and array index values no longer matching either. He didn't change
  the return value from audio switch when changing -aid, so it now
  matched array index only. The latter part didn't cause additional
  problems from r20162 though because either choice would have been
  broken anyway after r30124 as long as they weren't the same value.
command.c
libmpdemux/demux_lavf.c
libmpdemux/demuxer.c