[nas] mpg123 on NAS questions

Paul Fox pgf at foxharp.boston.ma.us
Wed Jan 9 07:20:03 MST 2002

i've been using the NAS-enabled version of mpg123 for a
while, and it works very well, but i've noticed a couple of
things i'd like to fix.  not being terribly familiar with
the nas library api, i thought i'd ask for some direction
before diving in.

i've cc'ed michael hipp (mpg123 author) since he obviously
may have something to say too.  michael -- i hope you don't
mind -- i didn't see any other address for mpg123 problem
reports.  (i'm running 0.59r -- i looked at 0.59s before
sending this mail, but don't see anything there that would
affect either of these problems.)

problem 1 -- when i try and use mpg123 with irmp3 as a
    front-end control program, it seems that mpg123 reports
    that a song has finished playing a bit prematurely. 
    what happens is that mpg123 finishes sending data to
    NAS, reports that its finished to its front end
    controller, and irmp3 either kills it off or starts the
    next song, but in either case this breaks the mpg123
    connection to NAS, and the end of the song is truncated.
    when mpg123 is exiting, it waits correctly for the data
    to finish playing -- so i guess the call to AuCloseServer
    in that case is causing the right thing to happen.  i
    was able to fix the early truncation problem by
    inserting calls to audio_reset_parameters() just before
    each instance of sending a "generic_sendmsg("P 0");"
    report.  this causes the audio connection to be closed
    and reopened after every song, which seems like
    overkill.  but i tried just doing an AuSync() and
    AuFlush() at that point and that didn't do the trick.
    what's the right NAS call to ensure output has been
    written to the device?  (i can't quite tell from the man
    pages whether i'd want AuSync or AuFlush.)  surely there's
    a way to wait for the server to drain?
    oddly, when i added the close/reopen (via audio_reset_paramters())
    i also found that i had to add an AuSync/AuFlush pair to
    the audio_close routine to make it all work right. 
    clearly i'm a little confused about how this should all work.

    for what its worth, here's a patch for what i have now.  but
    it's clearly not right.  (the first chunk of patch is in

diff -u -r mpg123-0.59r/audio_nas.c mpg123-0.59r.new/audio_nas.c
--- mpg123-0.59r/audio_nas.c	Wed Nov  5 16:24:16 1997
+++ mpg123-0.59r.new/audio_nas.c	Wed Jan  9 09:10:11 2002
@@ -332,6 +332,8 @@
     while (!info.finished) {
+    AuSync(info.aud,1);
+    AuFlush(info.aud);
diff -u -r mpg123-0.59r/control_generic.c mpg123-0.59r.new/control_generic.c
--- mpg123-0.59r/control_generic.c	Thu Jun 17 05:20:29 1999
+++ mpg123-0.59r.new/control_generic.c	Wed Jan  9 09:08:35 2002
@@ -154,6 +154,7 @@
 				if (!read_frame(fr)) {
 					mode = MODE_STOPPED;
+					audio_reset_parameters(&ai);
 					generic_sendmsg("P 0");
@@ -252,6 +253,7 @@
 				if (mode != MODE_STOPPED) {
 					mode = MODE_STOPPED;
+					audio_reset_parameters(&ai);
 					generic_sendmsg("P 0");

problem 2 -- when mpg123 is "paused", via its control
    interface, it stops sending data immediately, but of
    course there's quite a bit of sound buffered in NAS at
    that point, and it can take many seconds for the pause
    to take effect.  is there a NAS "suspend" api that could
    be invoked somehow at that point to stop the flow
    immediately?  the same problem is noticed is one simply
    sends mpg123 a STOP signal -- sounds keeps coming out
    for quite a long time.

 paul fox, pgf at foxharp.boston.ma.us (arlington, ma, where it's 23.2 degrees)

More information about the Nas mailing list