[MPlayer-users] Binding keys to mplayer?

Torinthiel torinthiel at megapolis.pl
Wed Aug 25 19:41:06 CEST 2004


On Wed, Aug 25, 2004 at 03:55:46PM +0200, Jesse F. Hughes wrote:
> 
> Torinthiel <torinthiel at megapolis.pl> writes:
> 
> > On Wed, Aug 25, 2004 at 02:26:10PM +0200, Jesse F. Hughes wrote:
> >> ,----[ mplayer-wrapper ]
> >> | 
> >> | fifo="/tmp/$$.fifo"
> >> | mkfifo $fifo
> >> | mplayer $@ <$fifo &
> >> | echo -n " ">>$fifo
> >> | 
> >> | mplpid=$!
> >> | 
> >> | IFS=""
> >> | while [ -e /proc/"$mplpid" ]
> >> | do 
> >> |   if read -s -t1 -n1  i
> >> |   then 
> >> |     echo -n -e "$i" >>$fifo; 
> >> |   fi
> >> | done
> >> | 
> >> | rm $fifo
> >> | 
> >> `----
> >
> > You know what? This is called active-waiting, and is BAD.
> > But I don't see any better option.
> 
> Why is it bad?

Because you keep doing something while you should be doing nothing.
This is a less extreme example of this code
while (i);
Which does nothing until i is not 0, but still takes CPU cycles to do
it. And quite a lot of them, as it only checks if i!=0 all the time, no
sleep between and so on. So you just have wasted all time slices the
scheduler has given to this process.
Now, your code is much less extreme. It does some sleep, and for the
scheduler  a whole second of sleep is a lot (remember that scheduler
switches processes many times a second) it's a lot. Probably the best
thing would be to use wait and use signals to tell script that there are
keys waiting. And I have no idea how to do it, no matter bash or C
(at least the part 'signal when keys waiting').

> > Well, something really good would be to pause everything on echo-pause.
> > I mean detect ALL MPlayers, pause these that are running (No idea how).
> > and pause xmms as well. This would be closer to 'incoming call, let's
> > make everything quiet'
> 
> I thought about that, but the problem is that some of those mplayers
> might *already* be paused, so it would un-pause them.  I often have
> two or three mplayers running, with all but one paused (which makes my
> fix admittedly less useful).
> 
> Oh, I see. Pause those that are *running*.  Gosh, that is a good idea.
> 
> But I don't know how to do it either.  I used to check fuser /dev/dsp,
> but now that doesn't work since I use ALSA to mix sounds.  I'll bet
> there's an alternative, though.  All one has to do is check to see
> which processes are sending sound to the mixer (I don't need to pause
> silent mplayers).

If you know how to do it then it would be great. And if you know how to
do it in an -ao independent way than it would be great (I use -ao oss.
And have no problem using alsa in parallel). I'd also consider somehow
measuring if the process does something, but as I cannot (by ps) hit
anything else than nanosleep that's probably even harder. Or examine the
key passed to mplayer - if it's space then remember this one is paused
until any other key. This however poses problems with -slave and
remapping default keys.

> You suck.  Now I have to think about that.  And I was just starting to
> get some work done, too.  Damn.

Now I don't have to think about it ;)

> Anyway, thanks for the comments.  I'm not a BASH guru, obviously.  Now
> if you can just elaborate on active-waiting, please.

Is what I've written above enough?
Torinthiel

-- 
 Waclaw "Torinthiel" Schiller       GG#: 542916, 3073512
   torinthiel(at)megapolis(dot)pl
   gpg: B06901F1 fpr: FAA3 559F CAE9 34DE CDC8  7346 2B6E 39F2 B069 01F1
 "No classmates may be used during this examination"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-users/attachments/20040825/c9fdfce5/attachment.pgp>


More information about the MPlayer-users mailing list