CLE266 MPEG decoding

From CourvilleWiki

Jump to: navigation, search

Contents

CLE266 MPEG decoding support

Introduction

In order to get hardware CLE266 MPEG2 decoding support two ways are possible:

  1. the old way: rely on libddmpeg and a via_v4l_drv patched kernel. Note that in that case, in order to have hardware MPEG decoding working with the VIA CLE266 engine you _*need to be root*_ when running the desired application otherwise all you risk to get a black screen and a big fat segfault. Gryle revealed me that it comes from the fact that libddmpeg has some hardware I/O instructions (inb or outb) and only root or the kernel is allowed to do that;
  2. the new way: implement it using a nonstandard VLD XvMC extension of the XFree/Xorg server. This is the unichrome much cleaner solution.

In terms of trends the second method is the one recommended since now all major applications (mythtv/xine/mplayer) are supported (either by means of a patch or in their cvs version).


Required steps

  1. install a 2.4 or 2.6 kernel properly patched and configured
  2. install a XFree or Xorg version patched with unichrome driver and XvMC library support
  3. install 3D dri binaries either from via website or the dri project (recompilation is a long process)
  4. install if required old ddmpeg CLE266 accelerated MPEG decoding library
  5. check that modules are inserted in the right order (no kidding this is an important step...)
Kernel 2.4.x-epia installation:

Important note: this section is no longer updated, it is left here for reference sake. I recommend to upgrade to a 2.6.x kernel.

  • install a custom 2.4.26 epia kernel:
    1. retreive vanilla linux-2.4.26 kernel from [1]
    2. patch it with IamTheOne epia patch [2]: it already contains ivors mpeg kernel patch (from [3])
    3. when configuring the kernel enable the following options for full support of epia hardware (my .config files CONFIG.ezra-2.4 or CONFIG.nehemiah-2.4 are available under [4]): <*> means enabled, <M> means module
Code maturity level options

<*> Prompt for development and/or incomplete code/drivers

Processor type and features

(CyrixIII/VIA-C3) Processor family for ezra CPU
(VIA-C3-2) Processor family for nehemiah CPU

CPU Frequency scaling

<*> CPU Frequency scaling

<*> CPU frequency table helpers
<*> Support for governing from userspace
<M> Longhaul CPU Usage Governer
<M> VIA Cyrix III Longhaul

General setup ACPI Support

<*> ACPI Support

<M> AC Adapter
<M> Button
<M> Fan
<M> Processor
<M> Thermal Zone

Parallel port support

<M> Parallel port support
<M> PC-style hardware

Plug and Play configuration

<*> Plug and Play support

Networking options

<*> Packet socket

Block devices

<M> Normal floppy disk support
<M> Loopback device support

ATA/IDE/MFM/RLL support

<*> ATA/IDE/MFM/RLL support

IDE, ATA and ATAPI Block devices

<*> Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support
<*> Include IDE/ATA-2 DISK support

<*> Use multi-mode by default
<*> Auto-Geometry Resizing support

<*> Include IDE/ATAPI CDROM support
<*> PCI IDE chipset support

<*> Sharing PCI IDE interrupts support
<*> Generic PCI bus-master DMA support
<*> VIA82CXXX chipset support

SCSI support

<M> SCSI support

<M> SCSI disk support
<M> SCSI CD-ROM support
<M> SCSI generic support

IEEE 1394 support

<M> IEEE 1394 support
<M> OHCI-1394 support
<M> OHCI-1394 Video support
<M> SBP-2 support: Harddisks etc.
<M> Ethernet over 1394
<M> OHCI-DV I/O support
<M> Raw IEEE1394 I/O support

Network device support

<*> Network device support
<M> Dummy net driver support

Ethernet (10 or 100Mbit)

<*> Ethernet (10 or 100Mbit)
<*> EISA, VLB, PCI and on board controllers

<*> VIA Rhine support
<*> Use MMIO instead of PIO (EXPERIMENTAL)

IrDA (infrared) support <M> IrDA subsystem support

<M> IrLAN protocol
<M> IrCOMM protocol
<*> Ultra (connectionless) protocol

Infrared-port device drivers

<M> IrTTY (uses Linux serial driver)
<M> IrPORT (IrDA serial driver)
<*> Serial dongle support

Input core support

<*> Input core support

<M> Keyboard support
<M> Mouse support

Character devices I2C support

<M> I2C support
<M> I2C bit-banging interfaces
<M> I2C device interface
<M> I2C /proc interface (required for hardware sensors)

Mice

<*> Mouse Support (not serial and bus mice)

<*> PS/2 mouse (aka "auxiliary device") support

<*> Intel/AMD/VIA HW Random Number Generator support
<*> Enhanced Real Time Clock Support
<M> DirectFB CLE266 Support
<M> /dev/agpgart (AGP Support)

<*> VIA chipset support

Direct Rendering Manager (XFree86 DRI support)

<*> Direct Rendering Manager (XFree86 DRI support)

<M> VIA CLE266

Multimedia devices

<M> Video For Linux

Video For Linux

<*> V4L information in proc filesystem
<M> CLE266 Support

File systems

<*> Ext3 journalling file system support
<*> ISO 9660 CDROM file system support

<*> Microsoft Joliet CDROM extensions

<*> /proc file system support
<*> /dev file system support

<*> Automatically mount at boot

<*> Second extended fs support

Console drivers

<*> VGA text console
<*> Video mode selection support

Frame-buffer support

<*> Support for frame buffer devices

(Via_Logo) Frame buffer Boot Logo
<*> VESA VGA graphics console
<M> Via CLE266 support

Sound

<M> Sound card support

<M> VIA 82C686 Audio Codec
<*> VIA 82C686 MIDI

USB support

<*> Support for USB

<*> Preliminary USB device filesystem
<M> EHCI HCD (USB 2.0) support
<M> UHCI (Intel PIIX4, VIA, ...) support
<M> UHCI Alternate Driver (JE) support
<M> USB Mass Storage support
<M> USB Printer support
<M> USB Human Interface Device (full HID) support

<*> HID input layer support
<*> /dev/hiddev raw HID device support

<M> USB HIDBP Keyboard (basic) support
<M> USB HIDBP Mouse (basic) support

On debian you can use the following procedure to create clean packages: you need to choose between config=ezra and config=nehemiah in the script depending on the version of your CPU (i.e. C3 for ezra or C3-2 for nehemiah)

kver=2.4.26
epiaver=2
config=ezra
config=nehemiah
rev=`date +%Y%m%d`
apt-get install alsa-source
apt-get install i2c-source
apt-get install lm-sensors-source
apt-get install lirc-modules-source
rm -rf /usr/src/modules/*
cd /usr/src
find -name '*.tar.gz' -maxdepth 1 -exec tar xzf {} \;
find -name '*.tar.bz2' -maxdepth 1 -exec tar xjf {} \;
rm -rf linux-${kver}
wget -nd -P . http://www.kernel.org/linux/kernel/v2.4/linux-${kver}.tar.bz2
tar jxvf ~/linux-${kver}.tar.bz2
ln -s linux-${kver} linux
wget -nd -P . http://www.courville.org/debian/${config}/CONFIG.${config}-2.4
cd linux
wget -nd -P . http://epia.kalf.org/epia_kernel/patch-${kver}-epia${epiaver}.gz
zcat $kbase/epia/patch-${kver}-epia${epiaver}.gz | patch -p1
cp ../CONFIG.$config .config
make menuconfig
make-kpkg clean
make-kpkg --arch-in-name --revision=$config.$rev --bzimage kernel_image modules_image
cp .config ../CONFIG.$config
cd ..
dpkg -i kernel-image-${kver}-epia${epiaver}-${config}*${rev}_i386.deb alsa-modules-${kver}-epia${epiaver}-${config}*${rev}_i386.deb
Kernel 2.6.x-epia installation:
  • prepare debian to migrate to 2.6 by getting following packages:
apt-get install libglib2.0-0/experimental libglib2.0-data/experimental libglib2.0-dev/experimental libatk1.0-0/experimental libpango1.0-0/exp libpango1.0-common/experimental
apt-get install udev sysfsutils module-init-tools alsa-base libesd-alsa0
mkdir /sys
  • install a custom 2.6.x epia kernel:
    1. retreive vanilla linux-2.6.x kernel from [5]
    2. not required anymore for mpeg support: patch it with IamTheOne epia patch [6]. Note that it no longer contains ivors mpeg kernel patch (from [7])
    3. if you are interested (optional) in via padlock support (nehemiah only ACE xcrypt group instructions) get the patch at [8] and apply it with cat /root/src/crypto-api-2.6.x.diff | patch -p1; cat /root/src/crypto-dev-padlock-2.6.x.diff | patch -p1
    4. in order to get vt1211 chipset support in lm-sensors retreive the module at [9]. For that purpose you need to edit manually /usr/src/linux-2.6.x-ezra/drivers/i2c/chips/Makefile and add right before the botom (forcing the module) obj-m += vt1211.o without forgetting to place the vt1211.c file there.
    5. check out as well the enhanced random generator support patch for nehemiah available at [10]
    6. more importantly if you wish to do a pvr now -epia patches do not include lirc you will need to retreive latest version as a subpatch at [11] derived from [12] (note: not compiling with 2.6.x...) or alternatively go with lirc cvs [13] or latest kind of stable snapshot [14] (safe way with 2.6.x)
    7. when configuring the kernel in order to allow full support of epia hardware please enable the options present in my kernel .config files CONFIG.ezra-2.6 or CONFIG.nehemiah-2.6 available at [15] (sorry I have not yet done a little table like the one present for 2.4.x).

On debian you can use the following procedure to create clean packages: you need to choose between config=ezra and config=nehemiah in the script depending on the version of your CPU (i.e. C3 for ezra or C3-2 for nehemiah)

kver=2.6.9
epiaver=1
config=ezra
config=nehemiah
rev=`date +%Y%m%d`
cd /usr/src
rm -rf linux-${kver}
wget -nd -P . http://www.kernel.org/linux/kernel/v2.6/linux-${kver}.tar.bz2
tar jxvf ~/linux-${kver}.tar.bz2
ln -s linux-${kver} linux
wget -nd -P . http://www.courville.org/debian/${config}/CONFIG.${config}-2.6
cd linux
#wget -nd -P . http://epia.kalf.org/epia_kernel/patch-${kver}-epia${epiaver}.gz
#zcat $kbase/epia/patch-${kver}-epia${epiaver}.gz | patch -p1
cp ../CONFIG.$config .config
make menuconfig
make-kpkg clean
make-kpkg --arch-in-name --revision=$config.$rev --bzimage kernel_image
cp .config ../CONFIG.$config
cd ..
dpkg -i kernel-image-${kver}-epia${epiaver}-${config}*${rev}_i386.deb
  • in order to get MPEG2 harware decoding and DRI support you need to use latest DRM kernel module:
cd /tmp
cvs -z3 -d:pserver:anonymous@dri.freedesktop.org:/cvs/dri co drm
cd drm/linux-core
make DRM_MODULES=via
mkdir -p /lib/modules/${kver}-epia${epiaver}/kernel/drivers/char/drm
cp via.ko drm.ko /lib/modules/${kver}-epia${epiaver}/kernel/drivers/char/drm
depmod -a
Unichrome XFree installation

Many flavors of XFree exist: XFree/Xorg release/cvs snapshot. Only the XFree case will be treated here. If you wish to work with bleeding cvs edge you can retrieve it using:

cd ~/compil
cvs -d :pserver:anoncvs@anoncvs.xfree86.org:/cvs login
passwd: 'anoncvs'
cvs -z3 -d :pserver:anoncvs@anoncvs.xfree86.org:/cvs co xc

And apply what is recommended below. For stability sake I would rather advise to adopt the following procedure:

  • retreive latest version of xfree [16]: 4.4.0 and apply unichrome cummulative XFree epia patch that can be retreived here [17].

Note that the unichrome patches can potentially not apply cleanly on latest XFree cvs snapshot.

unichrome_ver=28
xvmc_ver=0.13.3
wget -nd -P . ftp://ftp.xfree86.org/pub/XFree86/develsnaps/XFree86-4.4.0.tar.bz2
tar jxf XFree86-4.4.0.tar.bz2
#wget -nd -P . http://prdownloads.sourceforge.net/unichrome/XFree86-4.4-libviaXvMC-${xvmc_ver}-patch.bz2
#wget -nd -P . http://prdownloads.sourceforge.net/unichrome/unichrome-X-r${unichrome_ver}.tar.gz
cd xc
bzcat ../XFree86-4.4-libviaXvMC-${xvmc_ver}-patch.bz2 | patch -p1
cd programs/Xserver/hw/xfree86/drivers
mv via via.orig
tar zxvf ../../../../../../unichrome-X-r${unichrome_ver}.tar.gz
ln -s unichrome-X-r${unichrome_ver} via
cd ../../../../../
  • create a host specific configuration file xc/config/cf/host.def containing for the ezra processor
#define DefaultGcc2i386Opt -march=c3 -O2 -fomit-frame-pointer -mmmx -m3dnow
/* #define BuildServersOnly YES */
#define GccWarningOptions -pipe
#define HasMTRRSupport YES
#define HasMMXSupport YES
#define Has3DNowSupport YES
#define HasSSESupport NO
#define ProjectRoot /opt/X11R6-ezra
#define NothingOutsideProjectRoot YES
#define EtcX11Directory ProjectRoot/etc

xor for the nehemiah processor:

#define DefaultGcc2i386Opt -march=i686 -O2 -fomit-frame-pointer -ffast-math -finline-functions -msse -mfpmath=sse,387
/* #define BuildServersOnly YES */
#define GccWarningOptions -pipe
#define HasMTRRSupport YES
#define HasMMXSupport YES
#define Has3DNowSupport YES
#define HasSSESupport NO
#define ProjectRoot /opt/X11R6-nehemiah
#define NothingOutsideProjectRoot YES
#define EtcX11Directory ProjectRoot/etc
  • recompile the whole through a make World >& World.log in xc/
  • install it: make install && make install.man
  • create the appropriate link ln -s /opt/X11R6-${config} /opt/X11R6 with config=ezra or config=nehemiah
  • change your PATH variable to execute first /opt/X11R6/bin binaries: export PATH=/opt/X11R6/bin:${PATH}
  • change global library paths by editing /etc/ld.so.conf file and adding on top of it:
/opt/X11R6/lib

An alternative method (i.e.: not to be combined with the previous one!!!) for the XFree consists in working on separate source trees building independantly latest release of xfree (without erasing the build) and via driver using latest cvs version of unichrome. This can be achieved following these steps:

  • now retreive the cvs head of via driver from unichrome and recompile it:
#cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/unichrome login
#cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/unichrome checkout xfree86
#cd xfree86
wget -nd -P . http://www.courville.org/debian/unichrome-X-r${unicrhome_ver}.tar.gz
tar zxvf unichrome-X-r${unichrome_ver}.tar.gz
cd unichrome-X-r${version}
xmkmf ../xc
make && make install && make install.man
config=ezra
cp via_drv.o ~www-data/debian/$config

that's it for plain xfree!

  • for supporting the XvMC (mpeg decoding) retreive the latest library source from unichrome cvs tree (do not forget to enable the XvMC extension in your XF86Config-4):
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/unichrome login
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/unichrome checkout libxvmc
cd libxvmc
xmkmf ../xc
make && make install && make install.man
ldconfig -v
3D DRI support

From my own experience it is easier (i.e. less painful) to install either the via binaries or the DRI project binaries. In the past I used to do the following:

  • in order to use dri from via own cle266 graphic engine linux drivers [18] install the following via binaries after uncompressing the [19] package: via_dri.so, libdri.a, libGL.so.1.2, libglut.so.3.7.0. Note that all these libraries can be stripped to gain space (e.g. strip via_dri.so).
PREFIX=/opt/X11R6
cp via_dri.so ${PREFIX}/lib/modules/dri/
cp libdri.a ${PREFIX}/lib/modules/extensions/
cp libGL.so.1.2 ${PREFIX}/lib/
cp -f libGL.so.1.2 ${PREFIX}/lib/
rm -f ${PREFIX}/lib/libGL.so
rm -f ${PREFIX}/lib/libGL.so.1
ln -s ${PREFIX}/lib/libGL.so.1.2 ${PREFIX}/lib/libGL.so
ln -s ${PREFIX}/lib/libGL.so.1.2 ${PREFIX}/lib/libGL.so.1
rm -f /usr/lib/libGL.so
rm -f /usr/lib/libGL.so.1
ln -s ${PREFIX}/lib/libGL.so.1.2 /usr/lib/libGL.so
ln -s ${PREFIX}/lib/libGL.so.1.2 /usr/lib/libGL.so.1
cp libglut.so.3.7.0 /usr/lib/
cp -f libglut.so.3.7.0 /usr/lib
cp -f libglut.so.3.7.0 /usr/lib
rm -f /usr/lib/libglut.so.3
ln -sf /usr/lib/libglut.so.3.7.0 /usr/lib/libglut.so.3

Now thanks to the unichrome project team I simply do:

dri_ver=041225
PREFIX=/opt/X11R6
cd /tmp
wget -nd -P . http://prdownloads.sourceforge.net/unichrome/opensource_${dri_ver}.tbz2
cd $PREFIX/lib
tar zxpvf /tmp/opensource_${dri_ver}.tgz

Still some adjustments are required to have dri fully functionnal due to the fact that two installations of XFree are present: the classical debian one in /usr/X11R6 (damn still 4.3.0...) and the new custom one /opt/X11R6:

cd /usr/X11R6/lib/
mv libGL.so.1.2 libGL.so.1.2.orig
ln -s /opt/X11R6/lib/libGL.so.1.2 libGL.so.1.2
cd /usr/X11R6/lib/modules/dri
ln -s /opt/X11R6/lib/modules/dri/unichrome_dri.so unichrome_dri.so

And now the magic goes, test it with:

LIBGL_DEBUG=verbose glxinfo
glxgears
tuxracer
  • Boost up a bit the 3D performance exploiting the AGP ring-buffer in DRM: use the following option in /opt/X11R6/etc/XF86Cofnig-4: Option "EnableAGPDMA". It requires the new 3D MESA driver, unichrome version superior to R28 and at least DRM 2.2.0. The main advantage is that it is possible at the same time to use AGP for MPEG2 decoding and also run 3D... It provides a significant glxgears frame rate increase.
Deprecated ddmpeg CLE266 dedicated accelerated MPEG decoding library
  • recompile latest libddmpeg (1.6) from http://www.ivor.it/cle266/ and install libddmpeg.so in /usr/X11R6/lib and /opt/X11R6/lib. Note that in order to allow coexistence with via own binary library in /usr/X11R6/lib, with previous versions (<1.6) I had to modify libddmpeg Makefile the following manner (diff -u wise)
--- libddmpeg-1.5/Makefile      2004-01-05 14:42:39.000000000 +0100
+++ libddmpeg-1.5-bragon/Makefile       2004-01-09 13:50:35.000000000 +0100
@@ -1,5 +1,6 @@
 SHELL = /bin/sh

+CC = gcc
 RM = rm -f
 LD = ld
 LN = ln -s
@@ -17,8 +18,9 @@
        $(CC) -c $(DDMPEG_CFLAGS) -o $@ $<

 $(DDMPEG): $(DDMPEG_OBJS)
-       $(LD) $(DDMPEG_LIBS) -shared -soname $(DDMPEG) -o $(DDMPEG) $(DDMPEG_OBJS)
-#      $(LD) $(DDMPEG_LIBS) -lpthread -soname $(DDMPEG) -o $(DDMPEG) $(DDMPEG_OBJS)
+       $(LD) $(DDMPEG_LIBS) -lc -shared -soname $(DDMPEG) -o $(DDMPEG) $(DDMPEG_OBJS)
+#      $(LD) $(DDMPEG_LIBS) -lc -lm -lpthread -soname $(DDMPEG) -o $(DDMPEG) $(DDMPEG_OBJS)

 clean:
        $(RM) src/*.o *.so

otherwise /opt/X11R6/lib/libddmpeg.so was never picked, /usr/X11R6/lib/libddmpeg.so was chosen instead.

Adopt right order for module insertion
  • comply with the following order when loading modules in /etc/modules and load ivtv or bttv modules _*after*_ via_v4l_drv in order to reserve /dev/video0, /dev/video1 and /dev/video3 for via_v4l_drv (_*this is mandatory*_):
    • for 2.4 kernel:
agpgart
via_v4l_drv
    • for 2.6 kernel:
agpgart
via_agp
via_v4l_drv
drm
via

Already compiled kernel and patched xfree (4.4.0) according the above method

Misc notes

Other host.def options in order to reduce the time for XFree recompilation
#define BuildFontServer         NO
#define BuildSpeedo             NO
#define BuildType1              NO
#define BuildCID                NO
#define BuildFreeType           NO
#define BuildXTrueType          NO
#define BuildFonts              NO
#define Build75DpiFonts         NO
#define Build100DpiFonts        NO
#define BuildSpeedoFonts        NO
#define BuildType1Fonts         NO
#define BuildCIDFonts           NO
#define BuildTrueTypeFonts      NO
#define BuildCyrillicFonts      NO
#define MakeLocalFontDir        NO

If you need only the server part you can also use: #define BuildServersOnly YES.

Application side:

Use the following links to make your application cle266 mpeg hw decoding enabled:

  1. mplayer patch for supporting cle266 mpeg decoding with unichrome and libxvmc [20]
mplayer_ver=1.0pre6a
tar jxf MPlayer-${mplayer_ver}.tar.bz2
cd MPlayer-${mplayer_ver}
vi debian/rules
>> ./configure --with-x11incdir=/opt/X11R6/include --with-x11libdir=/opt/X11R6/lib --prefix=/usr --confdir=/etc/mplayer --enable-runtime-cpudetection --enable-gui --enable-lirc --enable-xxmc  --with-xxmclib=viaXvMC $(DEB_BUILD_OPTIONS)
bzcat ~/unichrome/MPlayer-1.0pre6a-unichrome-0.5.bz2 | patch -p1
dpkg-buildpackage
package=mplayer
mkdir /opt/$package
cd /opt/$package
ar x ${package}*.deb
tar zxpvf data.tar.gz
rm data.tar.gz control.tar.gz debian-binary
/opt/mplayer/usr/bin/mplayer -vo xvmc -vc ffmpeg12mc file.mpg
  1. mythtv patch for supporting cle266 mpeg decoding with unichrome and libxvmc [21]
  2. unichrome xine plugin [22]
  3. mp2player test software [23] to check that hardware mpeg decoding is indeed working:
./configure --x-includes=/opt/X11R6/include --x-libraries=/opt/X11R6/lib --includedir=/opt/X11R6/include --libdir=/opt/X11R6/lib

edit Makefile and add to include first your new debian opt XFree installation:

DEFAULT_INCLUDES = -I/opt/X11R6/include -I. -I$(srcdir) -I.

then use mp2player on this Mplayer sample file: [24], it should play fine...

Personal tools