xvid on opensolaris

trying to compile xvid on opensolaris …

why compiling it !?

I am actually interested to build mplayer on opensolaris, with xvid and x264 support.

First things first: download mplayer sources from their website, they have an svn repository one can use to download the latest version:

$ svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

If you do not have subversion, try to install it using the following command:

$ pfexec pkg install SUNWsvn

you should have now a directory called mplayer, it has the sources we want in there. Mplayer uses the GNU autotools, let’s configure the sources:

$ ./configure
Detected operating system: SunOS
Detected host architecture: i386
Checking for gcc version ... 3.4.3
Checking for host cc ... gcc
Checking for cross compilation ... no
Checking for CPU vendor ... AuthenticAMD (15:107:2)
Checking for CPU type ...  AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
Checking for kernel support of mmx ... yes
Checking for kernel support of mmxext ... yes
Checking for kernel support of 3dnow ... yes
Checking for kernel support of 3dnowext ... yes
Checking for kernel support of sse ... yes
Checking for kernel support of sse2 ... yes
Checking for kernel support of cmov ... yes
Checking for mtrr support ... yes
Checking for GCC & CPU optimization abilities ... k8
Checking for byte order ... little-endian
...
...
Config files successfully generated by ./configure  !

Install prefix: /usr/local
Data directory: /usr/local/share/mplayer
Config direct.: /usr/local/etc/mplayer

Byte order: little-endian
Optimizing for: k8

Languages:
Messages/GUI: en
Manual pages: en

Enabled optional drivers:
Input: dvdnav(internal) ftp tv libdvdcss(internal) dvdread(internal) vcd smb network
Codecs: libavcodec(internal) qtx xanim win32 faad2(internal) libmpeg2(internal) liba52(internal) mp3lib(internal) speex tremor(internal)
Audio output: sdl mpegpes(file)
Video output: sdl pnm jpeg png mpegpes(file) cvidix yuv4mpeg md5sum tga
  Disabled optional drivers:
    Input: vstream pvr radio tv-teletext tv-v4l2 tv-v4l1 tv-dshow live555 nemesi cddb cdda dvb 
    Codecs: libschroedinger libdirac x264 xvid libdv libamr_wb libamr_nb real faac musepack libdca libtheora toolame twolame libmad liblzo gif 
    Audio output: sun alsa openal jack pulse nas esd arts oss v4l2 ivtv dxr2 
    Video output: zr zr2 v4l2 ivtv dxr3 dxr2 vesa gif89a fbdev svga caca aa ggi xmga mga xvidix winvidix opengl 3dfx dga vdpau xvmc xv x11 dfbmga directfb bl xvr100 tdfx_vid wii s3fb tdfxfb

Hum, not so good. The summary says we are missing a bunch of codecs I am interested in: x264 xvid libtheora.
Some output drivers are also missing: xv x11 opengl.

I am so used to get mplayer from linux that I almost forgot how it was to build everything from source …
But there also some good things about that: I will bee able to have some tweaking for my cpu (at least that’s my hope).

compiling xvid

So now, we need to get the missing codecs/drivers and compile them so mplayer can use them. First let’s get xvid:

$ wget http://downloads.xvid.org/downloads/xvidcore-1.2.1.tar.gz

Using the SUN compiler to compile xvid is not supported, from the FAQ:

Q: Are there instructions available how to compile Xvid with my compiler?
A: Have a look at the install readme file that comes along with Xvid. It describes how to use the Xvid build scripts to compile Xvid with gcc under Linux or MinGW/CygWin. Xvid can also be compiled with Microsoft Visual C++ compiler using the provided project files included in the build directory. For other compilers you’re pretty much on your own. It should be not very difficult however to make the code compile with a different compiler.

Ok so let’s try it, otherwise why having the source code :-) ?

compiler to be used

The compiler that I want to use is the sun compiler, version on my opensolaris box:

    $ cc -V
    cc: Sun Ceres C 5.10 SunOS_i386 2009/03/06
    usage: cc [ options] files.  Use 'cc -flags' for details

assembler to be used for xvid

If available, I want to use assembly code provided by xvid. xvid uses nasm to assemble the code. Time to get it:

$ wget http://www.nasm.us/pub/nasm/releasebuilds/2.06rc11/nasm-2.06rc11.tar.gz

then we compile and install it:

    $ gtar xzf nasm-2.06rc11.tar.gz
    $ cd nasm-2.06rc11
    $ CC=/usr/bin/suncc CFLAGS='-xtarget=native' ./configure
    checking for prefix by checking for nasm... /usr/local/bin/nasm
    checking for gcc... /usr/bin/suncc
    checking for C compiler default output file name... a.out
    checking whether the C compiler works... yes
    ...

Note that the compiler used is suncc, the c compiler from sun and not gcc.
When compiling some warnings are given:

cc: Warning: illegal option -d=c99

For now I will ignore them – the option was dropped anyway. It’s now time to install nasm:

    $ pfexec make install
    mkdir -p /usr/local/bin
    /usr/bin/ginstall -c nasm /usr/local/bin/nasm
    /usr/bin/ginstall -c ndisasm /usr/local/bin/ndisasm
    mkdir -p /usr/local/share/man/man1
    /usr/bin/ginstall -c -m 644 ./nasm.1 /usr/local/share/man/man1/nasm.1
    /usr/bin/ginstall -c -m 644 ./ndisasm.1 /usr/local/share/man/man1/ndisasm.1

cool, now let’s go back to xvid.

tweaking the xvid source

Since I want to be able to work on this source tree from time to time, I’ll track this directory content using mercurial.

    $ hg init
    $ hg add

let’s give it a first try, let’s go to the build directory:

    $ cd build/generic
    $ CC=/usr/bin/suncc CFLAGS='-xtarget=native' ./configure
    .... 
    $ make
    make: Fatal error in reader: Makefile, line 82: Badly formed macro assignment

So … chances are that we have a gnu makefile here:

gmake
  D: =build
  C: ./decoder.c
"../../src/portab.h", line 439: warning: no explicit type given
"../../src/portab.h", line 439: syntax error before or at: void
"../../src/portab.h", line 447: warning: no explicit type given
"../../src/portab.h", line 447: syntax error before or at: int64_t
"../../src/global.h", line 63: warning: no explicit type given
"../../src/global.h", line 63: syntax error before or at: int
"../../src/global.h", line 70: warning: no explicit type given
"../../src/global.h", line 70: syntax error before or at: int
"../../src/global.h", line 234: warning: no explicit type given
"../../src/global.h", line 234: syntax error before or at: uint32_t
"../../src/image/image.h", line 41: cannot have void object: __inline
"../../src/image/image.h", line 42: syntax error before or at: image_null

It was a gnu makefile, hence gmake took care of it. The source files use some gcc extension, like __inline. There is a c99 keyword for it, that does pretty much the same thing: inline.
We reconfigure the package:

$ CC=/usr/bin/suncc CFLAGS='-D__inline=inline -xtarget=native' ./configure

hum … Too many warnings:

"../../src/encoder.c", line 1085: warning: integer overflow detected: op "<<"
"../../src/encoder.c", line 1112: warning: integer overflow detected: op "<<"
"../../src/encoder.c", line 1150: warning: integer overflow detected: op "<<"
...
"../../src/xvid.c", line 105: warning: assignment type mismatch:
	pointer to void "=" pointer to function(int) returning void
...
"../../src/bitstream/mbcoding.c", line 1848: warning: initializer will be sign-extended: -1
"../../src/bitstream/mbcoding.c", line 1859: warning: initializer will be sign-extended: -1
"../../src/bitstream/mbcoding.c", line 1895: warning: initializer will be sign-extended: -1
...

overflow is scary … I’ll need to check the code and see whats going on.

The linker problem can be solved by installing the following patch found here.

Edit from May 13th 2009: I finally added a patch for SUN compiler to get xvid to compile without too many warnings, you can find it here


About this entry