Showing posts with label mpg123. Show all posts
Showing posts with label mpg123. Show all posts

Sunday, September 29, 2019

mpg123 codec and MPlayer 1.1.1 test

My compile of mplayer did not have mpg123 codec. So it uses ffmp2float decoder for mp3.

In 486 PC i downloaded mpg123-1.22.4.tar.bz2

Replaced write_alsa function in alsa.c with this one:
static int write_alsa(audio_output_t *ao, unsigned char *buf, int bytes)
{
snd_pcm_t *pcm=(snd_pcm_t*)ao->userptr;
snd_pcm_uframes_t frames;
snd_pcm_sframes_t written;
frames = snd_pcm_bytes_to_frames(pcm, bytes);
written = snd_pcm_writei(pcm, buf, frames);
if (written == -EINTR) /* interrupted system call */
written = 0;
else if (written == -EPIPE) { /* underrun */
if (snd_pcm_prepare(pcm) >= 0)
written = snd_pcm_writei(pcm, buf, frames);
}
if (written >= 0)
return snd_pcm_frames_to_bytes(pcm, written);
else
{
if(snd_pcm_state(pcm) == SND_PCM_STATE_SUSPENDED)
{
/* Iamnothappyabouthisnothappyreallynot. */
snd_pcm_resume(pcm);
if(snd_pcm_state(pcm) == SND_PCM_STATE_SUSPENDED)
{
error("device still suspended after resume hackery... giving up");
return -1;
}
}
return 0;
}
}
This is present in mpg123-1.14.4 and changed in later versions. If above change is not made then it will not play mp3 files and cpu usage is 100%.

Patch file for download.

Then created package.
Configuration line was:
./configure --prefix=/usr i486-kola-linux --enable-int-quality=yes  --enable-buffer=yes  --enable-modules=no --with-optimization=3
Installed it on 486 and also on my virtual box so i can compile mplayer 1.1.1

After transferring new mplayer binary to 486 made test. Player command line options: -lavdopts lowres=0:skiploopfilter=all:skipidct=bidir -framedrop -af channels 1



Friday, September 27, 2019

mpg123 retest after sound is back

So i still have test file i made older post.
Sad thing is i have lost source changes i made to the lib to get it working. It may be on my Pentium III machine.
But i think i can get it to compile and work again. Maybe will try newer version.

In this video i ran it in X Window. But it will work also strait no console.

./mpg123 http://live-mp3-128.kexp.org:80/kexp128.mp3

Sunday, October 29, 2017

Mplayer 1.3.0 and new dev PC

New dev pc


My pentium 3 had some problems with ext2 filesystem. fsck was forced and it made kernel into panic mode. Used Linux Mint 12 cd to fix this but on next reboot same story. Shit happens. So filesystem was dead.
Installed Slackware 10.1 to virtualbox vm. Recompiled kernel, mpg123 and x86free for s3 (need to make post about this).

Configuration of Mplayer


In last post i used Mplayer version 0.90. It is old :D. So i downloaded version 1.3.0.
I used command line to configure it:
./configure --yasm='' --target=i486-Linux --disable-ftp --disable-tv-v4l1 --disable-tv --disable-qtx --disable-real --disable-win32dll --disable-gif --disable-mmx   --disable-3dnow   --disable-sse --disable-sse2 --disable-sse3 --disable-fastmemcpy --disable-xanim --disable-vm --disable-vesa --disable-svga --disable-xv  --disable-jpeg --disable-gl --disable-mga --disable-sdl --disable-fbdev  --disable-caca --disable-aa --disable-dga1 --disable-dga2 --disable-tga --disable-md5sum --disable-pnm --disable-mng --disable-libvorbis --disable-esd --enable-libmpeg2-internal --enable-libmpeg2 --disable-decoder=mlp --disable-mencoder --disable-freetype --disable-ass --disable-postproc --disable-unrarexec --disable-vidix --disable-vidix-pcidb   --disable-encoder=mlp  --disable-parser=mlp  --disable-protocol=mlp  --disable-demuxer=mlp  --disable-muxer=mlp
  
This is all well and good, but there are problems on config.h and other palces:

  • cmov enabled
  • i686 enabled 
  • gcc native enabled (i have old compiler so it will fail, atomic)
  • make is version 3.80 (needs version 3.82) or there will be error make: *** virtual memory exhausted. Stop.  (http://ppcluddite.blogspot.com/2011/11/) (https://ftp.gnu.org/gnu/make/)
  • atomic.c is not compiled (needs manual makefile change)
  • need to disable hwaccel drivers in allcodes.c
  • unsupported -Werror=format-security option in configure for cc. Configuration fails.


If all these changes are made, it compiles and works.
Compiled file  v0.90 2.5MB vs 12MB v1.3.0

At least it plays videos. :D

To test i made some sample files using Shotcut. mp4 file mpeg4 codec QVBR 41% mp3 16000Hz 16kb/s.

./mplayer -af channels=1 -framedrop testfile.mp4



Sunday, October 22, 2017

Mplayer 0.90

Play some videos

So it is time to test how well this 486 will play mpeg videos. I downloaded oldest version of Mplayer, configured with minimal settings (disabled all that is not needed). Compiled and tested out how well it runs.

First video is without sound.

Second video has sound, reduced to one channel only.


So it can somewhat play, but any larger video then last on here will not play with sound. With -framedrop option it shows black screen and plays audio. Without sound it really slow.

So time to investigate how can i speed this up.
Bad:
  • No hardware yuv
  • No SIMD ( :D)
  • No hardware sound accl
Good
  • Hardware BITBLT

Without profiling mplayer it is clear that mpeg idct takes most of the time.  

static inline void idct_row (int16_t * block)
{
    int x0, x1, x2, x3, x4, x5, x6, x7, x8;
    x1 = block[4] << 11;
    x2 = block[6];
    x3 = block[2];
    x4 = block[1];
    x5 = block[7];
    x6 = block[5];
    x7 = block[3];
    /* shortcut */
    if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
block[0] = block[1] = block[2] = block[3] = block[4] =
    block[5] = block[6] = block[7] = block[0]<<3;
return;
    }
    x0 = (block[0] << 11) + 128; /* for proper rounding in the fourth stage */
    /* first stage */
    x8 = W7 * (x4 + x5);
    x4 = x8 + (W1 - W7) * x4;
    x5 = x8 - (W1 + W7) * x5;
    x8 = W3 * (x6 + x7);
    x6 = x8 - (W3 - W5) * x6;
    x7 = x8 - (W3 + W5) * x7;

    /* second stage */
    x8 = x0 + x1;
    x0 -= x1;
    x1 = W6 * (x3 + x2);
    x2 = x1 - (W2 + W6) * x2;
    x3 = x1 + (W2 - W6) * x3;
    x1 = x4 + x6;
    x4 -= x6;
    x6 = x5 + x7;
    x5 -= x7;

    /* third stage */
    x7 = x8 + x3;
    x8 -= x3;
    x3 = x0 + x2;
    x0 -= x2;
    x2 = (181 * (x4 + x5) + 128) >> 8;
    x4 = (181 * (x4 - x5) + 128) >> 8;

    /* fourth stage */
    block[0] = (x7 + x1) >> 8;
    block[1] = (x3 + x2) >> 8;
    block[2] = (x0 + x4) >> 8;
    block[3] = (x8 + x6) >> 8;
    block[4] = (x8 - x6) >> 8;
    block[5] = (x0 - x4) >> 8;
    block[6] = (x3 - x2) >> 8;
    block[7] = (x7 - x1) >> 8;
}
So, how to speed this up even more. I did search on internet and it cant be made any faster, at least on 486.
Sure, there must be something that can be done.
I found this (http://jpegclub.org/jidctred/), uses 4x4 or 1x1 transform on 8x8 block.

Can we do this with mpeg 8x8 image block? If DCT coefficients are on left top corner we can reduce transform complexity by setting x1, x2, x4, x7 to zero. If we compile with -O3 option we get faster code, as gcc optimizes out some code. Do the same with column filter. Yes, it will reduce video quality.

Success. It plays better. 

Tested with only 2x2 block, but quality of the video was not really good. With the last video. It was blocky. First video played smoothly.

Another problem is gcc compiled code for 486. According to AMD documents and Intels there cpus have pipeline, and gcc compiled code with -O3 is not very good. There are probably AGI stalls in lots of places. (https://www.gamedev.net/articles/programming/general-and-gameplay-programming/optimize-386486pentium-code-r206/) Every clock tick counts.
If you compile for -march=i486 or i386 you get identical code.
So i tested with i586. Code is rearranged differently. Made test program with this idct and with i586 it was better. 18,8 sec vs 18,06 sec.

Last thing is to profile. And result shows that another cpu eater is yuv2rgb_, maybe newer version of mplayer has better conversion?

Sound

Mplayer uses mpg123 for mpeg audio decoding. It uses old version, 0.50. I need to replace this.


Tuesday, October 17, 2017

Linux Kernel 2.2.x or not?

Compile newer version of Linux Kernel

So BasciLinux 2 kernel is version 2.2.16. I wanted to compile newer kernel on another machine. So i completely reinstalled my Pentium III PC, it had Debian based Linux Mint 12 or so. Used slackware-10.1 iso for that. 
First i tested version 2.4.29. It compiled fine. Small copy on to 486 and it will not boot. IDE drivers were missing. Fixed that and it boots.
Next thing was getting it to connect to LAN. Wasted lot of time and realized that it has different structure. I had them built into kernel. Nothing happens. Then made module version. Kernel try's  to load modules with modprobe. Well this is not going to work. So i dropped version 2.4.29. 

Downloaded source of Kernel 2.2.21 to this pentium PC. It wont compile. gcc version was 3.3.5. Complains about lot of stuff:

  • conflicting types for `xtime' (https://www.linux-mips.org/archives/linux-mips/2001-08/msg00014.html)
  • error: long, short, signed or unsigned used invalidly for `slot_tablelen'  (https://www.linux-mips.org/archives/linux-mips/2001-08/msg00014.html)
  • '##'  (https://gcc.gnu.org/ml/gcc-bugs/2000-08/msg00723.html)
  • __asm__  (https://lwn.net/Articles/66793/) quotes are missing in arch i386
  • warning: pasting "(" and "0x0" does not give a valid preprocessing token { (https://forums.anandtech.com/threads/help-linux-kernel-compile-issues.711957/)
  • etc
Finaly managed to compile this kernel. Swapped out my 2.4.29 bzImage. 
Result: Kernel panic
Unable to handle kernel NULL pointer dereference at virtual address 00000f2c 
(https://www.linuxquestions.org/questions/linux-software-2/kernel-panic-swapper-not-syncing-
227208/)
Removed all modules, only blank kernel. Still panic. Gave up. Time wasted again.

Google'ing around the web i noticed another cool-looking distribution: http://delicate-linux.net/

Upgrading to Slackware 10.1 

So i was thinking, maybe i still can use kernel 2.4.29. 486 has CD-ROM, but it cant boot from it. Slackware 10.1 ISO image has ramfs, so i made copy to my dos partition where i boot my kernel with loadlin.exe into ramfs. (Had to increase ramfs size in kernel, another recompilation of many). So after booting from dos i mounted CD-ROM drive and started to install Slackware 10.1 onto my drive. Selected packages i needed. Probably to much. It took forever to install. 2 hours i think.
I had all ready compiled kernel  2.4.29 for 486. I booted again after install was done. It booted to freshly installed hard drive. After some more tweaking with this kernel i was finally happy, it worked.
One thing that was problematic was memory usage. BasicLinux 2 had only small files, no services, etc. 
Window manager fails to start. Could not figure out why. Finally decided to use BasicLinux X Server with icewm. Made some changes in paths in /lib and /usr. I got may GUI. Most of the programs complain about missing lib files. Sure, i dropped newer X Server.

Whanted to compile X Server 6.3 for it. After succesful compilation transfered files to 486.  XF86Config was problematic. X Server complained about Mode is missing. I did not give up. And after some changes in there managed to boot freshly compiled X Server.

Networking

So i have two machines with same version of Slackware. I can use putty and winscp in my main box to get closer over network. It made a lot easier to copy compiled files from Pentium machine over to 486 thru my main box :D.

Sound

Well, it took a wile to get it working. For some reason alsaconf wanted to insmod modules.  I had my sound card compiled into kernel. It did not work for alsaconf.
Removed all sound modules from kernel (recompiled again) and it looked like it works. At least alsamixer started working.
I needed some program that can output some sound. I remembered that in package selection phase i selected cli mp3 player. Namely mpg123. 
Started up this player. First second of the song was ok. But after that i got:
ALSA: underrun, at least 0ms

CPU usage was 99%. There were no music, only noise.

This cant be happening.
So looked around:
http://www.tldp.org/HOWTO/MP3-HOWTO-7.html

In: http://www.mpg123.org/
Plays Layer 3 in stereo on an AMD-486-120Mhz or (of course) a faster machine.

mpg123 version was 0.54. Old. Downloaded latest source, compiled and it hang 486. Really?
I have old distro with old libs. Probably this is reason. It gives a warning if you compile with i486 target :D. Finally used version 1.22.4 with small tweak in alsa module. Reverted on function and it compiled and worked fine.
Command line was:
./configure  --with-optimization=3 --with-cpu=i486  --enable-int-quality=yes  --enable-buffer=yes CFLAGS='-march=i486' --enable-modules=no

 With option -2 CPU usage was 27-36%. Success.

Well, i have internet connection in this old PC. Why not lissen to some online stream. Used (https://www.kexp.org/help/ListenLiveLinks) MP3 32k (Standard, Low Bandwidth).
Made bash file:
#!/bash/sh
./mpg123 http://live-mp3-128.kexp.org:80/kexp128.mp3

I have now radio :D