Improving mp3 streaming (my take)

The problem with mp3 stuttering seems to be caused by the mpegaudio program always forcing its priority back to 10, regardless of what you set it to. I've found that if I hack up the mpegaudio program so it calls "getprio" instead of "setprio", the program will run, and won't mess with its priority settings. Once you make this change, then you can run "nice -n-5 phplay" to start phplay, and mpegaudio will run and stay running at priority 15 instead of 10. On my audrey at least, this completely gets rid of the stuttering playback when streaming through HTTP!

Here is a zip file containing the hacked up phplay and mpegaudio programs: mp3fix.zip (QNX6.0 versions)

Replace your phplay and mpegaudio executables with these (be sure to chmod +x them) and then run "nice -n-5 phplay" to start phplay at an increased priority. It should stay there, and if you run "pidin" you should see the priority shown as 15r instead of 10r like it was before the hack.

If you want to do it yourself

The procedure to hack the mpegaudio program. WARNING this is extremely a hack, because it remaps a setprio(pid,pri) call to a getprio(pid) call. This shouldn't affect things in a program using C-calling convention where the caller cleans up the stack, and it seems to work, but there are no guarantees and this could end up messing up your machine.
  1. change to the directory containing the mpegaudio program. In my case this is /nto/photon/bin:
       # cd /nto/photon/bin
    
  2. make a backup of the phplay and mpegaudio program:s
       # cp phplay phplay.bak
       # cp mpegaudio mpegaudio.bak
    
  3. decompress the phplay and mpegaudio programs
       # flashlzo -d phplay
       # flashlzo -d mpegaudio
    
  4. check your mpegaudio program for the setprio string. You should get the response shown below, giving the "setprio" string. If not, then what follows will not work!!! In that case, stop now!!!
       # dd if=mpegaudio bs=1 count=7 skip=5145
       setprio7+0 records in
       7+0 records out
    
  5. replace this string with "getprio"
       # echo getprio | dd of=mpegaudio bs=1 count=7 seek=5145 conv=notrunc
    
  6. Repeat this on two locations in phplay: 7476 and 535699
       # dd if=phplay bs=1 count=7 skip=7476
       setprio7+0 records in
       7+0 records out
       # dd if=phplay bs=1 count=7 skip=535699
       setprio7+0 records in
       7+0 records out
    
  7. If the results show the "setprio" in both cases, then replace this with "getprio"
       # echo getprio | dd of=phplay bs=1 count=7 seek=7476 conv=notrunc
       # echo getprio | dd of=phplay bs=1 count=7 seek=535699 conv=notrunc
    
  8. check to see if the change worked. You should see the "getprio" string this time.
       # dd if=mpegaudio bs=1 count=7 skip=5145
       getprio7+0 records in
       7+0 records out
       # dd if=phplay bs=1 count=7 skip=7476
       getprio7+0 records in
       7+0 records out
       # dd if=phplay bs=1 count=7 skip=535699
       getprio7+0 records in
       7+0 records out
    
  9. now run phplay at an increased priority, and mpegaudio should take and continue with this priority.
       # nice -n-5 phplay &
    
  10. if all works, you can use the "cmp" script to recompress the mpegaudio and phplay programs, and delete the backup if you want to save some space.
That should solve it. If this doesn't help with the suttering, then make sure you changed the right copy of mpegaudio and phplay as there may be more than one, especially if you have the full QNX distribution mounted using fs-cifs. If this breaks phplay, restore phplay and mpegaudio from the backup.

For QNX6.1 versions, the locations are: phplay=7988, mpegaudio=5181. There is only one location in phplay in the QNX6.1 binaries.