The computer I use to watch DVDs (and other stuff) with has three sound outputs: via HDMI to the TV, via the built-in analogue sound port to my wireless headphones, and via a USB sound card to external stereo speakers. Which one I use depends on what I’m watching and what time of day it is.
So it would be nice to be able to change where the sound goes to on the fly. mplayer doesn’t have built-in support for it, but you could do this externally via a PulseAudio or the like, but since mplayer is occupying the screen and getting the commands, it seemed easier to just hack mplayer.
And, besides, each audio sink needs a different video/audio delay. The TV, for instance, delays the picture a bit, so if I’m listening over the headphones, I need to subtract a tenth of a second for the audio delay. Or something. I just experimented until I got something where Jon Stewart looked marginally less unhinged.
It turned out that adding commands to mplayer is really easy, but digging into the code this big can be pretty bewildering. So if you ever want to add commands and keystrokes to mplayer, I’ve put the patch on the interwebs. It probably won’t apply cleanly to your specific mplayer version (and you wouldn’t want to, since it hard-codes my specific commands), but it should give you a rough idea of where to poke around.