[SCM] FFmpeg packaging branch, master, updated. upstream/0.svn20090110-28-g2236cc3

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Tue Jan 20 08:15:45 UTC 2009


The following commit has been merged in the master branch:
commit 9b722ed9d5ca3b3224f09f2d5fabf8270e55e068
Author: Reinhard Tartler <siretart at tauware.de>
Date:   Mon Jan 19 22:37:27 2009 +0100

    Imported Upstream version 0.svn20090119

diff --git a/.svnrevision b/.svnrevision
new file mode 100644
index 0000000..b3c1ca2
--- /dev/null
+++ b/.svnrevision
@@ -0,0 +1 @@
+16681
diff --git a/Changelog b/Changelog
index d785492..577980f 100644
--- a/Changelog
+++ b/Changelog
@@ -138,10 +138,12 @@ version <next>
 - Nellymoser ASAO encoder
 - ASS and SSA demuxer and muxer
 - liba52 wrapper removed
+- SVQ3 watermark decoding support
 - Speex decoding via libspeex
 - Electronic Arts TGQ decoder
 - RV30 and RV40 decoder
 - QCELP / PureVoice decoder
+- hybrid WavPack support
 
 version 0.4.9-pre1:
 
@@ -224,6 +226,7 @@ version 0.4.9-pre1:
 - more accurate deblock filter
 - padding support
 - many optimizations and bugfixes
+- FunCom ISS audio file demuxer and according ADPCM decoding
 
 version 0.4.8:
 
diff --git a/MAINTAINERS b/MAINTAINERS
index b0e9630..8b2ac15 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -313,6 +313,7 @@ GnuPG Fingerprints of maintainers and others who have svn write access
 ======================================================================
 
 Benoit Fouet                  B22A 4F4F 43EF 636B BB66 FCDC 0023 AE1E 2985 49C8
+Diego Biurrun                 8227 1E31 B6D9 4994 7427 E220 9CAE D6CC 4757 FCC5
 Michael Niedermayer           9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB
 Reimar Döffinger              C61D 16E5 9E2C D10C 8958 38A4 0899 A2B9 06D4 D9C7
 Reynaldo H. Verdejo Pinochet  6E27 CD34 170C C78E 4D4F 5F40 C18E 077F 3114 452A
diff --git a/Makefile b/Makefile
index 00b275d..2c94537 100644
--- a/Makefile
+++ b/Makefile
@@ -149,10 +149,12 @@ uninstall-vhook:
 	rm -f $(addprefix "$(SHLIBDIR)/",$(ALLHOOKS_SRCS:.c=$(SLIBSUF)))
 	-rmdir "$(SHLIBDIR)/vhook/"
 
-clean::
+testclean:
+	rm -rf tests/vsynth1 tests/vsynth2 tests/data tests/asynth1.sw tests/*~
+
+clean:: testclean
 	rm -f $(ALLPROGS) $(ALLPROGS_G) output_example$(EXESUF)
 	rm -f doc/*.html doc/*.pod doc/*.1
-	rm -rf tests/vsynth1 tests/vsynth2 tests/data tests/asynth1.sw tests/*~
 	rm -f $(addprefix tests/,$(addsuffix $(EXESUF),audiogen videogen rotozoom seek_test tiny_psnr))
 	rm -f $(addprefix tools/,$(addsuffix $(EXESUF),cws2fws pktdumper qt-faststart trasher))
 	rm -f vhook/*.o vhook/*~ vhook/*.so vhook/*.dylib vhook/*.dll
diff --git a/cmdutils.c b/cmdutils.c
index 32ffefa..b28c00d 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -30,21 +30,15 @@
 
 #include "config.h"
 #include "libavformat/avformat.h"
-#ifdef CONFIG_AVFILTER
 #include "libavfilter/avfilter.h"
-#endif
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
-#ifdef CONFIG_POSTPROC
 #include "libpostproc/postprocess.h"
-#endif
 #include "libavutil/avstring.h"
 #include "libavcodec/opt.h"
 #include "cmdutils.h"
 #include "version.h"
-#ifdef CONFIG_NETWORK
 #include "libavformat/network.h"
-#endif
 
 #undef exit
 
@@ -54,6 +48,8 @@ AVCodecContext *avctx_opts[CODEC_TYPE_NB];
 AVFormatContext *avformat_opts;
 struct SwsContext *sws_opts;
 
+const int this_year = 2009;
+
 double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
 {
     char *tail;
@@ -255,7 +251,7 @@ void print_error(const char *filename, int err)
     case AVERROR(ENOENT):
         fprintf(stderr, "%s: no such file or directory\n", filename);
         break;
-#ifdef CONFIG_NETWORK
+#if CONFIG_NETWORK
     case AVERROR(FF_NETERROR(EPROTONOSUPPORT)):
         fprintf(stderr, "%s: Unsupported network protocol\n", filename);
         break;
@@ -279,21 +275,21 @@ static void print_all_lib_versions(FILE* outstream, int indent)
     PRINT_LIB_VERSION(outstream, avcodec,  AVCODEC,  indent);
     PRINT_LIB_VERSION(outstream, avformat, AVFORMAT, indent);
     PRINT_LIB_VERSION(outstream, avdevice, AVDEVICE, indent);
-#ifdef CONFIG_AVFILTER
+#if CONFIG_AVFILTER
     PRINT_LIB_VERSION(outstream, avfilter, AVFILTER, indent);
 #endif
-#ifdef CONFIG_SWSCALE
+#if CONFIG_SWSCALE
     PRINT_LIB_VERSION(outstream, swscale,  SWSCALE,  indent);
 #endif
-#ifdef CONFIG_POSTPROC
+#if CONFIG_POSTPROC
     PRINT_LIB_VERSION(outstream, postproc, POSTPROC, indent);
 #endif
 }
 
 void show_banner(void)
 {
-    fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-2009 Fabrice Bellard, et al.\n",
-            program_name, program_birth_year);
+    fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d Fabrice Bellard, et al.\n",
+            program_name, program_birth_year, this_year);
     fprintf(stderr, "  configuration: " FFMPEG_CONFIGURATION "\n");
     print_all_lib_versions(stderr, 1);
     fprintf(stderr, "  built on " __DATE__ " " __TIME__);
@@ -311,7 +307,7 @@ void show_version(void) {
 
 void show_license(void)
 {
-#ifdef CONFIG_NONFREE
+#if CONFIG_NONFREE
     printf(
     "This version of %s has nonfree parts compiled in.\n"
     "Therefore it is not legally redistributable.\n",
diff --git a/cmdutils.h b/cmdutils.h
index beba333..39f4919 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -37,6 +37,8 @@ extern const char program_name[];
  */
 extern const int program_birth_year;
 
+extern const int this_year;
+
 extern const char **opt_names;
 extern AVCodecContext *avctx_opts[CODEC_TYPE_NB];
 extern AVFormatContext *avformat_opts;
diff --git a/common.mak b/common.mak
index 8ac6ee0..6d007cc 100644
--- a/common.mak
+++ b/common.mak
@@ -71,7 +71,7 @@ TESTS := $(addprefix $(SUBDIR),$(TESTS))
 
 DEP_LIBS:=$(foreach NAME,$(FFLIBS),lib$(NAME)/$($(BUILD_SHARED:yes=S)LIBNAME))
 
-ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h))
+ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
 checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))
 
 DEPS := $(OBJS:.o=.d)
diff --git a/configure b/configure
index 56606aa..b80bb38 100755
--- a/configure
+++ b/configure
@@ -145,6 +145,7 @@ show_help(){
   echo "  --disable-ssse3          disable SSSE3 optimizations"
   echo "  --disable-armv5te        disable armv5te optimizations"
   echo "  --disable-armv6          disable armv6 optimizations"
+  echo "  --disable-armv6t2        disable armv6t2 optimizations"
   echo "  --disable-armvfp         disable ARM VFP optimizations"
   echo "  --disable-iwmmxt         disable iwmmxt optimizations"
   echo "  --disable-mmi            disable MMI optimizations"
@@ -426,10 +427,9 @@ print_config(){
         ucname="`toupper $cfg`"
         if enabled $cfg; then
             echo "#define ${pfx}${ucname} 1" >> $header
-            echo "#define ENABLE_${ucname} 1" >> $header
             echo "${pfx}${ucname}=yes" >> $makefile
         else
-            echo "#define ENABLE_${ucname} 0" >> $header
+            echo "#define ${pfx}${ucname} 0" >> $header
         fi
     done
 }
@@ -740,6 +740,7 @@ CONFIG_LIST="
     avisynth
     beos_netserver
     bzlib
+    fastdiv
     ffmpeg
     ffplay
     ffserver
@@ -874,6 +875,7 @@ HAVE_LIST="
     roundf
     sdl
     sdl_video_size
+    setmode
     socklen_t
     soundcard_h
     poll_h
@@ -884,6 +886,7 @@ HAVE_LIST="
     sys_videoio_h
     termios_h
     threads
+    truncf
     winsock2_h
     yasm
 "
@@ -991,6 +994,8 @@ mjpeg_encoder_select="aandct"
 mpeg1video_encoder_select="aandct"
 mpeg2video_encoder_select="aandct"
 mpeg4_encoder_select="aandct"
+mpeg_vdpau_decoder_deps="vdpau"
+mpeg1_vdpau_decoder_deps="vdpau"
 mpeg_xvmc_decoder_deps="xvmc X11_extensions_XvMClib_h"
 msmpeg4v1_encoder_select="aandct"
 msmpeg4v2_encoder_select="aandct"
@@ -1224,11 +1229,11 @@ show_list() {
 for opt do
     optval="${opt#*=}"
     case "$opt" in
-    --extra-cflags=*) add_cflags "$optval"
+    --extra-cflags=*) add_cflags $optval
     ;;
-    --extra-ldflags=*) add_ldflags "$optval"
+    --extra-ldflags=*) add_ldflags $optval
     ;;
-    --extra-libs=*) add_extralibs "$optval"
+    --extra-libs=*) add_extralibs $optval
     ;;
     --disable-devices) disable $INDEV_LIST $OUTDEV_LIST
     ;;
@@ -1302,15 +1307,17 @@ check_cflags -std=c99
 
 case "$arch" in
     i386|i486|i586|i686|i86pc|BePC)
-        arch="x86_32"
+        arch="x86"
+        subarch="x86_32"
         enable fast_unaligned
     ;;
     x86_64|amd64)
-        arch="x86_32"
+        arch="x86"
+        subarch="x86_32"
         enable cmov
         enable fast_cmov
         enable fast_unaligned
-        check_cc <<EOF && enable fast_64bit && arch="x86_64"
+        check_cc <<EOF && enable fast_64bit && subarch="x86_64"
         int test[sizeof(char*) - 7];
 EOF
     ;;
@@ -1320,6 +1327,7 @@ EOF
     alpha)
         arch="alpha"
         enable fast_64bit
+        check_cflags -mieee
     ;;
     "Power Macintosh"|ppc|powerpc)
         arch="ppc"
@@ -1338,7 +1346,8 @@ EOF
         enable fast_64bit
     ;;
     sun4u|sparc64)
-        arch="sparc64"
+        arch="sparc"
+        subarch="sparc64"
         enable fast_64bit
     ;;
     sparc)
@@ -1372,16 +1381,14 @@ EOF
     ;;
 esac
 
-enable $arch
-enabled_any x86_32 x86_64 && enable x86
-enabled     sparc64       && enable sparc
+enable $arch $subarch
 
 # OS specific
 case $target_os in
     beos|haiku|zeta)
         prefix_default="$HOME/config"
         # helps building libavcodec
-        add_cflags "-DPIC -fomit-frame-pointer"
+        add_cflags -DPIC -fomit-frame-pointer
         # 3 gcc releases known for BeOS, each with ugly bugs
         gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
         case "$gcc_version" in
@@ -1389,7 +1396,7 @@ case $target_os in
             disable mmx
             ;;
           *20010315*) echo "BeBits gcc"
-            add_cflags "-fno-expensive-optimizations"
+            add_cflags -fno-expensive-optimizations
             ;;
         esac
         SHFLAGS=-nostart
@@ -1444,7 +1451,7 @@ case $target_os in
     mingw32*)
         target_os=mingw32
         LIBTARGET=i386
-        if test $arch = x86_64; then
+        if enabled x86_64; then
             disable need_memalign
             LIBTARGET=x64
         fi
@@ -1497,7 +1504,7 @@ case $target_os in
         disable $INDEV_LIST $OUTDEV_LIST
         network_extralibs="-lsocket"
         EXESUF=".exe"
-        objformat="win32"
+        objformat="coff"
         enable dos_paths
         ;;
     linux)
@@ -1602,11 +1609,11 @@ test -z "$need_memalign" && need_memalign="$mmx"
 #Darwin CC versions
 if test $target_os = darwin; then
     if $cc -v 2>&1 | grep -q xlc; then
-        add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto"
+        add_cflags -qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto
     else
-        add_cflags "-pipe"
-        check_cflags "-force_cpusubtype_ALL"
-        check_cflags "-Wno-sign-compare"
+        add_cflags -pipe
+        check_cflags -force_cpusubtype_ALL
+        check_cflags -Wno-sign-compare
         enabled shared || check_cflags -mdynamic-no-pic
     fi
 fi
@@ -1620,68 +1627,71 @@ if test $cpu != "generic"; then
     }
     case $cpu in
         601|ppc601|PowerPC601)
-            add_cflags "-mcpu=601"
+            add_cflags -mcpu=601
             warn_altivec enabled PPC601
         ;;
         603*|ppc603*|PowerPC603*)
-            add_cflags "-mcpu=603"
+            add_cflags -mcpu=603
             warn_altivec enabled PPC603
         ;;
         604*|ppc604*|PowerPC604*)
-            add_cflags "-mcpu=604"
+            add_cflags -mcpu=604
             warn_altivec enabled PPC604
         ;;
         G3|g3|75*|ppc75*|PowerPC75*)
-            add_cflags "-mcpu=750 -mpowerpc-gfxopt"
+            add_cflags -mcpu=750 -mpowerpc-gfxopt
             warn_altivec enabled PPC75x
         ;;
         G4|g4|745*|ppc745*|PowerPC745*)
-            add_cflags "-mcpu=7450 -mpowerpc-gfxopt"
+            add_cflags -mcpu=7450 -mpowerpc-gfxopt
             warn_altivec disabled PPC745x
         ;;
         74*|ppc74*|PowerPC74*)
-            add_cflags "-mcpu=7400 -mpowerpc-gfxopt"
+            add_cflags -mcpu=7400 -mpowerpc-gfxopt
             warn_altivec disabled PPC74xx
         ;;
         G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
-            add_cflags "-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
+            add_cflags -mcpu=970 -mpowerpc-gfxopt -mpowerpc64
             warn_altivec disabled PPC970
             enable ppc64
         ;;
         Cell|CELL|cell)
-            add_cflags "-mcpu=cell"
+            add_cflags -mcpu=cell
             warn_altivec disabled Cell
             enable ppc64
         ;;
         # targets that do NOT support conditional mov (cmov)
         i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
-            add_cflags "-march=$cpu"
+            add_cflags -march=$cpu
             disable cmov
         ;;
         # targets that do support conditional mov (cmov)
         i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
-            add_cflags "-march=$cpu"
+            add_cflags -march=$cpu
             enable cmov
             enable fast_cmov
         ;;
         # targets that do support conditional mov but on which it's slow
         pentium4|pentium4m|prescott|nocona)
-            add_cflags "-march=$cpu"
+            add_cflags -march=$cpu
             enable cmov
             disable fast_cmov
         ;;
         sparc64)
-            add_cflags "-mcpu=v9"
+            add_cflags -mcpu=v9
         ;;
         arm11*|cortex*)
-            add_cflags "-mcpu=$cpu"
+            add_cflags -mcpu=$cpu
             enable fast_unaligned
         ;;
         armv*)
-            add_cflags "-march=$cpu"
+            add_cflags -march=$cpu
         ;;
         arm*)
-            add_cflags "-mcpu=$cpu"
+            add_cflags -mcpu=$cpu
+        ;;
+        ev4|ev45|ev5|ev56|pca56|ev6|ev67)
+            add_cflags -mcpu=$cpu
         ;;
         *)
             echo "WARNING: Unknown CPU \"$cpu\", ignored."
@@ -1746,7 +1756,7 @@ EOF
 
     check_asm bswap '"bswap %%eax" ::: "%eax"'
 
-    YASMFLAGS="-f $objformat -DARCH_$(toupper $arch)"
+    YASMFLAGS="-f $objformat -DARCH_$(toupper $subarch)"
     enabled     x86_64        && append YASMFLAGS "-m amd64"
     enabled_all x86_64 shared && append YASMFLAGS "-DPIC"
     case "$objformat" in
@@ -1759,9 +1769,7 @@ fi
 
 # check for assembler specific support
 
-if test $arch = "ppc"; then
-    check_asm dcbzl '"dcbzl 0, 1"'
-fi
+enabled ppc && check_asm dcbzl '"dcbzl 0, 1"'
 
 # check for SIMD availability
 
@@ -1799,7 +1807,7 @@ enabled mmi     && check_asm mmi     '"lq $2, 0($2)"'
 enabled neon    && check_asm neon    '"vadd.i16 q0, q0, q0"'
 enabled vis     && check_asm vis     '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc
 
-enabled vis && add_cflags "-mcpu=ultrasparc -mtune=ultrasparc"
+enabled vis && add_cflags -mcpu=ultrasparc -mtune=ultrasparc
 
 # ---
 # big/little-endian test
@@ -1824,6 +1832,7 @@ check_func  inet_aton $network_extralibs
 check_func  memalign
 check_func  mkstemp
 check_func  posix_memalign
+check_func_headers io.h setmode
 check_func_headers windows.h GetProcessTimes
 
 check_header conio.h
@@ -1874,7 +1883,7 @@ done
 check_lib math.h sin -lm
 
 # test for C99 functions in math.h
-for func in llrint lrint lrintf round roundf; do
+for func in llrint lrint lrintf round roundf truncf; do
     check_exec <<EOF && enable $func || disable $func
 #include <math.h>
 int main(void) { return ($func(3.999f) > 0)?0:1; }
@@ -2040,6 +2049,7 @@ check_cflags -Wno-pointer-sign
 check_cflags -Wcast-qual
 check_cflags -Wwrite-strings
 check_cflags -Wtype-limits
+check_cflags -Wundef
 enabled extra_warnings && check_cflags -Winline
 
 # add some linker flags
@@ -2053,10 +2063,10 @@ if enabled small; then
     optimizations="small"
 elif enabled optimizations; then
     if $cc -v 2>&1 | grep -q xlc; then
-        add_cflags  "-O5"
-        add_ldflags "-O5"
+        add_cflags  -O5
+        add_ldflags -O5
     else
-        add_cflags "-O3"
+        add_cflags -O3
     fi
 fi
 check_cflags -fno-math-errno
@@ -2082,15 +2092,15 @@ fi
 if enabled shared; then
     # LIBOBJFLAGS may have already been set in the OS configuration
     if test -z "$LIBOBJFLAGS" ; then
-        case "$arch" in
+        case "${subarch-$arch}" in
             x86_64|ia64|alpha|sparc*|power*|parisc*|mips*) LIBOBJFLAGS='$(PIC)' ;;
         esac
     fi
 fi
 
 if enabled gprof; then
-    add_cflags  "-p"
-    add_ldflags "-p"
+    add_cflags  -p
+    add_ldflags -p
 fi
 
 VHOOKCFLAGS="-fPIC"
@@ -2136,7 +2146,7 @@ if test "$extra_version" != ""; then
     echo "version string suffix     $extra_version"
 fi
 echo "big-endian                ${bigendian-no}"
-if test $arch = "x86_32" -o $arch = "x86_64"; then
+if enabled x86; then
     echo "yasm                      ${yasm-no}"
     echo "MMX enabled               ${mmx-no}"
     echo "SSE enabled               ${sse-no}"
@@ -2145,7 +2155,7 @@ if test $arch = "x86_32" -o $arch = "x86_64"; then
     echo "EBX available             ${ebx_available-no}"
     echo "EBP available             ${ebp_available-no}"
 fi
-if test $arch = "arm"; then
+if enabled arm; then
     echo "ARMv5TE enabled           ${armv5te-no}"
     echo "ARMv6 enabled             ${armv6-no}"
     echo "ARMv6T2 enabled           ${armv6t2-no}"
@@ -2153,10 +2163,10 @@ if test $arch = "arm"; then
     echo "IWMMXT enabled            ${iwmmxt-no}"
     echo "NEON enabled              ${neon-no}"
 fi
-if test $arch = "mips"; then
+if enabled mips; then
     echo "MMI enabled               ${mmi-no}"
 fi
-if test $arch = "ppc"; then
+if enabled ppc; then
     echo "AltiVec enabled           ${altivec-no}"
     echo "dcbzl available           ${dcbzl-no}"
 fi
@@ -2322,6 +2332,8 @@ fi
 echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak
 echo "EXTRALIBS=$extralibs" >> config.mak
 
+echo "ARCH=$arch" >> config.mak
+
 print_config ARCH_   $TMPH config.mak $ARCH_LIST
 print_config HAVE_   $TMPH config.mak $HAVE_LIST
 print_config CONFIG_ $TMPH config.mak $CONFIG_LIST       \
diff --git a/doc/faq.texi b/doc/faq.texi
index e070fd2..0d923a4 100644
--- a/doc/faq.texi
+++ b/doc/faq.texi
@@ -426,7 +426,7 @@ you need the debug information, used the *_g versions.
 @section I do not like the LGPL, can I contribute code under the GPL instead?
 
 Yes, as long as the code is optional and can easily and cleanly be placed
-under #ifdef CONFIG_GPL without breaking anything. So for example a new codec
+under #if CONFIG_GPL without breaking anything. So for example a new codec
 or filter would be OK under GPL while a bug fix to LGPL code would not.
 
 @section I want to compile xyz.c alone but my compiler produced many errors.
diff --git a/doc/ffmpeg-doc.texi b/doc/ffmpeg-doc.texi
index 840ed89..499c36f 100644
--- a/doc/ffmpeg-doc.texi
+++ b/doc/ffmpeg-doc.texi
@@ -830,6 +830,9 @@ The following binary operators are available: @code{+}, @code{-},
 The following unary operators are available: @code{+}, @code{-},
 @code{(...)}.
 
+The following statements are available: @code{ld}, @code{st},
+ at code{while}.
+
 The following functions are available:
 @table @var
 @item sinh(x)
@@ -838,16 +841,22 @@ The following functions are available:
 @item sin(x)
 @item cos(x)
 @item tan(x)
+ at item atan(x)
+ at item asin(x)
+ at item acos(x)
 @item exp(x)
 @item log(x)
+ at item abs(x)
 @item squish(x)
 @item gauss(x)
- at item abs(x)
+ at item mod(x, y)
 @item max(x, y)
 @item min(x, y)
+ at item eq(x, y)
+ at item gte(x, y)
 @item gt(x, y)
+ at item lte(x, y)
 @item lt(x, y)
- at item eq(x, y)
 @item bits2qp(bits)
 @item qp2bits(qp)
 @end table
diff --git a/doc/general.texi b/doc/general.texi
index b594fe1..17d2cd5 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -74,6 +74,8 @@ library:
     @tab .fli/.flc files
 @item FLV                       @tab X @tab X
     @tab Macromedia Flash video files
+ at item FunCom ISS                @tab   @tab X
+    @tab Audio format used in various games from FunCom like The Longest Journey.
 @item GXF                       @tab X @tab X
     @tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley
          playout servers.
@@ -385,6 +387,8 @@ following image formats are supported:
 @item Intel Music Coder      @tab     @tab  X
 @item Interplay MVE DPCM     @tab     @tab  X
     @tab Used in various Interplay computer games.
+ at item ISS IMA ADPCM          @tab     @tab  X
+    @tab Used in FunCom games.
 @item MAXIS EA ADPCM         @tab     @tab  X
     @tab Used in Sim City 3000.
 @item Microsoft ADPCM        @tab  X  @tab  X
diff --git a/ffmpeg.c b/ffmpeg.c
index aac071e..cdb5e20 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -41,23 +41,23 @@
 #include "libavutil/avstring.h"
 #include "libavformat/os_support.h"
 
-#ifdef HAVE_SYS_RESOURCE_H
+#if HAVE_SYS_RESOURCE_H
 #include <sys/types.h>
 #include <sys/resource.h>
-#elif defined(HAVE_GETPROCESSTIMES)
+#elif HAVE_GETPROCESSTIMES
 #include <windows.h>
 #endif
 
-#ifdef HAVE_SYS_SELECT_H
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 
-#ifdef HAVE_TERMIOS_H
+#if HAVE_TERMIOS_H
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include <termios.h>
-#elif defined(HAVE_CONIO_H)
+#elif HAVE_CONIO_H
 #include <conio.h>
 #endif
 #undef time //needed because HAVE_AV_CONFIG_H is defined on top
@@ -295,7 +295,7 @@ typedef struct AVInputFile {
     int nb_streams;       /* nb streams we are aware of */
 } AVInputFile;
 
-#ifdef HAVE_TERMIOS_H
+#if HAVE_TERMIOS_H
 
 /* init terminal so that we can grab keys */
 static struct termios oldtty;
@@ -303,7 +303,7 @@ static struct termios oldtty;
 
 static void term_exit(void)
 {
-#ifdef HAVE_TERMIOS_H
+#if HAVE_TERMIOS_H
     tcsetattr (0, TCSANOW, &oldtty);
 #endif
 }
@@ -319,7 +319,7 @@ sigterm_handler(int sig)
 
 static void term_init(void)
 {
-#ifdef HAVE_TERMIOS_H
+#if HAVE_TERMIOS_H
     struct termios tty;
 
     tcgetattr (0, &tty);
@@ -344,7 +344,7 @@ static void term_init(void)
     register a function to be called at normal program termination
     */
     atexit(term_exit);
-#ifdef CONFIG_BEOS_NETSERVER
+#if CONFIG_BEOS_NETSERVER
     fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
 #endif
 }
@@ -352,10 +352,10 @@ static void term_init(void)
 /* read a key without blocking */
 static int read_key(void)
 {
-#if defined(HAVE_TERMIOS_H)
+#if HAVE_TERMIOS_H
     int n = 1;
     unsigned char ch;
-#ifndef CONFIG_BEOS_NETSERVER
+#if !CONFIG_BEOS_NETSERVER
     struct timeval tv;
     fd_set rfds;
 
@@ -372,7 +372,7 @@ static int read_key(void)
 
         return n;
     }
-#elif defined(HAVE_CONIO_H)
+#elif HAVE_CONIO_H
     if(kbhit())
         return(getch());
 #endif
@@ -427,7 +427,7 @@ static int av_exit(int ret)
 
     av_free(video_standard);
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
     void powerpc_display_perf_report(void);
     powerpc_display_perf_report();
 #endif /* CONFIG_POWERPC_PERF */
@@ -684,6 +684,10 @@ static void do_audio_out(AVFormatContext *s,
 
             ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
                                        (short *)audio_buf);
+            if (ret < 0) {
+                fprintf(stderr, "Audio encoding failed\n");
+                av_exit(1);
+            }
             audio_size += ret;
             pkt.stream_index= ost->index;
             pkt.data= audio_out;
@@ -711,6 +715,10 @@ static void do_audio_out(AVFormatContext *s,
         //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
         ret = avcodec_encode_audio(enc, audio_out, size_out,
                                    (short *)buftmp);
+        if (ret < 0) {
+            fprintf(stderr, "Audio encoding failed\n");
+            av_exit(1);
+        }
         audio_size += ret;
         pkt.stream_index= ost->index;
         pkt.data= audio_out;
@@ -760,7 +768,7 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void
         picture2 = picture;
     }
 
-    if (ENABLE_VHOOK)
+    if (CONFIG_VHOOK)
         frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height,
                            1000000 * ist->pts / AV_TIME_BASE);
 
@@ -967,7 +975,7 @@ static void do_video_out(AVFormatContext *s,
             ret = avcodec_encode_video(enc,
                                        bit_buffer, bit_buffer_size,
                                        &big_picture);
-            if (ret == -1) {
+            if (ret < 0) {
                 fprintf(stderr, "Video encoding failed\n");
                 av_exit(1);
             }
@@ -1456,11 +1464,19 @@ static int output_packet(AVInputStream *ist, int ist_index,
                             if(ret <= 0) {
                                 ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
                             }
+                            if (ret < 0) {
+                                fprintf(stderr, "Audio encoding failed\n");
+                                av_exit(1);
+                            }
                             audio_size += ret;
                             pkt.flags |= PKT_FLAG_KEY;
                             break;
                         case CODEC_TYPE_VIDEO:
                             ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
+                            if (ret < 0) {
+                                fprintf(stderr, "Video encoding failed\n");
+                                av_exit(1);
+                            }
                             video_size += ret;
                             if(enc->coded_frame && enc->coded_frame->key_frame)
                                 pkt.flags |= PKT_FLAG_KEY;
@@ -1763,6 +1779,8 @@ static int av_encode(AVFormatContext **output_files,
                 codec->has_b_frames = icodec->has_b_frames;
                 break;
             case CODEC_TYPE_SUBTITLE:
+                codec->width = icodec->width;
+                codec->height = icodec->height;
                 break;
             default:
                 abort();
@@ -2537,7 +2555,7 @@ static void opt_top_field_first(const char *arg)
 static int opt_thread_count(const char *opt, const char *arg)
 {
     thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
-#if !defined(HAVE_THREADS)
+#if !HAVE_THREADS
     if (verbose >= 0)
         fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
 #endif
@@ -2610,7 +2628,7 @@ static void opt_video_tag(const char *arg)
         video_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24);
 }
 
-#ifdef CONFIG_VHOOK
+#if CONFIG_VHOOK
 static void add_frame_hooker(const char *arg)
 {
     int argc = 0;
@@ -3400,12 +3418,12 @@ static void opt_pass(const char *pass_str)
 
 static int64_t getutime(void)
 {
-#ifdef HAVE_GETRUSAGE
+#if HAVE_GETRUSAGE
     struct rusage rusage;
 
     getrusage(RUSAGE_SELF, &rusage);
     return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
-#elif defined(HAVE_GETPROCESSTIMES)
+#elif HAVE_GETPROCESSTIMES
     HANDLE proc;
     FILETIME c, e, k, u;
     proc = GetCurrentProcess();
@@ -3812,7 +3830,7 @@ static const OptionDef options[] = {
     { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
     { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
     { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
-#ifdef CONFIG_VHOOK
+#if CONFIG_VHOOK
     { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" },
 #endif
     { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
diff --git a/ffplay.c b/ffplay.c
index 12190da..88e6b1a 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1684,6 +1684,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
            audio_size = audio_decode_frame(is, &pts);
            if (audio_size < 0) {
                 /* if error, just output silence */
+               is->audio_buf = is->audio_buf1;
                is->audio_buf_size = 1024;
                memset(is->audio_buf, 0, is->audio_buf_size);
            } else {
@@ -2018,7 +2019,7 @@ static int decode_thread(void *arg)
             else
                 av_read_play(ic);
         }
-#if defined(CONFIG_RTSP_DEMUXER) || defined(CONFIG_MMSH_PROTOCOL)
+#if CONFIG_RTSP_DEMUXER || CONFIG_MMSH_PROTOCOL
         if (is->paused &&
                 (!strcmp(ic->iformat->name, "rtsp") ||
                  (ic->pb && !strcmp(url_fileno(ic->pb)->prot->name, "mmsh")))) {
@@ -2070,7 +2071,7 @@ static int decode_thread(void *arg)
         }
         if(url_feof(ic->pb)) {
             av_init_packet(pkt);
-            pkt->data=
+            pkt->data=NULL;
             pkt->size=0;
             pkt->stream_index= is->video_stream;
             packet_queue_put(&is->videoq, pkt);
@@ -2466,7 +2467,7 @@ static int opt_vismv(const char *opt, const char *arg)
 static int opt_thread_count(const char *opt, const char *arg)
 {
     thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
-#if !defined(HAVE_THREADS)
+#if !HAVE_THREADS
     fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
 #endif
     return 0;
@@ -2578,7 +2579,7 @@ int main(int argc, char **argv)
     }
 
     if (!display_disable) {
-#ifdef HAVE_SDL_VIDEO_SIZE
+#if HAVE_SDL_VIDEO_SIZE
         const SDL_VideoInfo *vi = SDL_GetVideoInfo();
         fs_screen_width = vi->current_w;
         fs_screen_height = vi->current_h;
diff --git a/ffpresets/libx264-baseline.ffpreset b/ffpresets/libx264-baseline.ffpreset
new file mode 100644
index 0000000..4766418
--- /dev/null
+++ b/ffpresets/libx264-baseline.ffpreset
@@ -0,0 +1,3 @@
+coder=0
+bf=0
+flags2=-wpred-dct8x8
diff --git a/ffpresets/libx264-ipod320.ffpreset b/ffpresets/libx264-ipod320.ffpreset
new file mode 100644
index 0000000..89441c7
--- /dev/null
+++ b/ffpresets/libx264-ipod320.ffpreset
@@ -0,0 +1,6 @@
+coder=0
+bf=0
+flags2=-wpred-dct8x8
+level=13
+maxrate=768000
+bufsize=3000000
diff --git a/ffpresets/libx264-ipod640.ffpreset b/ffpresets/libx264-ipod640.ffpreset
new file mode 100644
index 0000000..fd58e2a
--- /dev/null
+++ b/ffpresets/libx264-ipod640.ffpreset
@@ -0,0 +1,7 @@
+coder=0
+bf=0
+refs=1
+flags2=-wpred-dct8x8
+level=30
+maxrate=10000000
+bufsize=10000000
diff --git a/ffpresets/libx264-main.ffpreset b/ffpresets/libx264-main.ffpreset
new file mode 100644
index 0000000..d1dc7dd
--- /dev/null
+++ b/ffpresets/libx264-main.ffpreset
@@ -0,0 +1 @@
+flags2=-dct8x8
diff --git a/ffserver.c b/ffserver.c
index 23bb64c..79d1e3a 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -22,25 +22,27 @@
 #define _XOPEN_SOURCE 600
 
 #include "config.h"
-#ifndef HAVE_CLOSESOCKET
+#if !HAVE_CLOSESOCKET
 #define closesocket close
 #endif
 #include <string.h>
 #include <strings.h>
 #include <stdlib.h>
-#include "libavutil/random.h"
-#include "libavutil/avstring.h"
+/* avformat.h defines LIBAVFORMAT_BUILD, include it before all the other libav* headers which use it */
 #include "libavformat/avformat.h"
 #include "libavformat/network.h"
 #include "libavformat/os_support.h"
 #include "libavformat/rtp.h"
 #include "libavformat/rtsp.h"
+#include "libavutil/avstring.h"
+#include "libavutil/random.h"
+#include "libavutil/intreadwrite.h"
 #include "libavcodec/opt.h"
 #include <stdarg.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#ifdef HAVE_POLL_H
+#if HAVE_POLL_H
 #include <poll.h>
 #endif
 #include <errno.h>
@@ -49,7 +51,7 @@
 #include <time.h>
 #include <sys/wait.h>
 #include <signal.h>
-#ifdef HAVE_DLFCN_H
+#if HAVE_DLFCN_H
 #include <dlfcn.h>
 #endif
 
@@ -3708,7 +3710,7 @@ static enum CodecID opt_video_codec(const char *arg)
 
 /* simplistic plugin support */
 
-#ifdef HAVE_DLOPEN
+#if HAVE_DLOPEN
 static void load_module(const char *filename)
 {
     void *dll;
@@ -4186,7 +4188,7 @@ static int parse_ffconfig(const char *filename)
         } else if (!strcasecmp(cmd, "VideoTag")) {
             get_arg(arg, sizeof(arg), &p);
             if ((strlen(arg) == 4) && stream)
-                video_enc.codec_tag = ff_get_fourcc(arg);
+                video_enc.codec_tag = AV_RL32(arg);
         } else if (!strcasecmp(cmd, "BitExact")) {
             if (stream)
                 video_enc.flags |= CODEC_FLAG_BITEXACT;
@@ -4393,7 +4395,7 @@ static int parse_ffconfig(const char *filename)
             }
         } else if (!strcasecmp(cmd, "LoadModule")) {
             get_arg(arg, sizeof(arg), &p);
-#ifdef HAVE_DLOPEN
+#if HAVE_DLOPEN
             load_module(arg);
 #else
             fprintf(stderr, "%s:%d: Module support not compiled into this version: '%s'\n",
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 0fc7a2e..6e22fda 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -24,6 +24,7 @@
  * 4XM codec.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "dsputil.h"
 #include "bitstream.h"
@@ -688,7 +689,7 @@ static int decode_frame(AVCodecContext *avctx,
         av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4));
     }
 
-    if(frame_4cc == ff_get_fourcc("cfrm")){
+    if(frame_4cc == AV_RL32("cfrm")){
         int free_index=-1;
         const int data_size= buf_size - 20;
         const int id= AV_RL32(buf+12);
@@ -729,7 +730,7 @@ static int decode_frame(AVCodecContext *avctx,
             }
 
             cfrm->size= cfrm->id= 0;
-            frame_4cc= ff_get_fourcc("pfrm");
+            frame_4cc= AV_RL32("pfrm");
         }else
             return buf_size;
     }else{
@@ -755,19 +756,19 @@ static int decode_frame(AVCodecContext *avctx,
         return -1;
     }
 
-    if(frame_4cc == ff_get_fourcc("ifr2")){
+    if(frame_4cc == AV_RL32("ifr2")){
         p->pict_type= FF_I_TYPE;
         if(decode_i2_frame(f, buf-4, frame_size) < 0)
             return -1;
-    }else if(frame_4cc == ff_get_fourcc("ifrm")){
+    }else if(frame_4cc == AV_RL32("ifrm")){
         p->pict_type= FF_I_TYPE;
         if(decode_i_frame(f, buf, frame_size) < 0)
             return -1;
-    }else if(frame_4cc == ff_get_fourcc("pfrm") || frame_4cc == ff_get_fourcc("pfr2")){
+    }else if(frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")){
         p->pict_type= FF_P_TYPE;
         if(decode_p_frame(f, buf, frame_size) < 0)
             return -1;
-    }else if(frame_4cc == ff_get_fourcc("snd_")){
+    }else if(frame_4cc == AV_RL32("snd_")){
         av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size);
     }else{
         av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size);
diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index 4376d07..5a5f764 100644
--- a/libavcodec/8bps.c
+++ b/libavcodec/8bps.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3b179d7..fa8b71b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -15,6 +15,7 @@ OBJS = allcodecs.o                                                      \
        imgconvert.o                                                     \
        jrevdct.o                                                        \
        opt.o                                                            \
+       options.o                                                        \
        parser.o                                                         \
        raw.o                                                            \
        resample.o                                                       \
@@ -100,7 +101,7 @@ OBJS-$(CONFIG_H263_ENCODER)            += mpegvideo_enc.o motion_est.o ratecontr
 OBJS-$(CONFIG_H263P_ENCODER)           += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o mpeg12data.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_H264_DECODER)            += h264.o h264idct.o h264pred.o h264_parser.o cabac.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_H264_ENCODER)            += h264enc.o h264dspenc.o
-OBJS-$(CONFIG_H264_VDPAU_DECODER)      += vdpauvideo.o
+OBJS-$(CONFIG_H264_VDPAU_DECODER)      += vdpauvideo.o h264.o h264idct.o h264pred.o h264_parser.o cabac.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_HUFFYUV_DECODER)         += huffyuv.o
 OBJS-$(CONFIG_HUFFYUV_ENCODER)         += huffyuv.o
 OBJS-$(CONFIG_IDCIN_DECODER)           += idcinvideo.o
@@ -123,6 +124,7 @@ OBJS-$(CONFIG_MJPEGB_DECODER)          += mjpegbdec.o mjpegdec.o mjpeg.o
 OBJS-$(CONFIG_MLP_DECODER)             += mlpdec.o mlp_parser.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER)         += mmvideo.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)    += motionpixels.o
+OBJS-$(CONFIG_MP1_DECODER)             += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
 OBJS-$(CONFIG_MP2_DECODER)             += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
 OBJS-$(CONFIG_MP2_ENCODER)             += mpegaudioenc.o mpegaudio.o mpegaudiodata.o
 OBJS-$(CONFIG_MP3_DECODER)             += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
@@ -131,6 +133,8 @@ OBJS-$(CONFIG_MP3ON4_DECODER)          += mpegaudiodec.o mpegaudiodecheader.o mp
 OBJS-$(CONFIG_MPC7_DECODER)            += mpc7.o mpc.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
 OBJS-$(CONFIG_MPC8_DECODER)            += mpc8.o mpc.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
 OBJS-$(CONFIG_MDEC_DECODER)            += mdec.o mpeg12.o mpeg12data.o mpegvideo.o error_resilience.o
+OBJS-$(CONFIG_MPEG_VDPAU_DECODER)      += vdpauvideo.o mpeg12.o mpeg12data.o mpegvideo.o error_resilience.o
+OBJS-$(CONFIG_MPEG1_VDPAU_DECODER)     += vdpauvideo.o mpeg12.o mpeg12data.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_MPEGVIDEO_DECODER)       += mpeg12.o mpeg12data.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_MPEG1VIDEO_DECODER)      += mpeg12.o mpeg12data.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12data.o mpegvideo_enc.o motion_est.o ratecontrol.o mpeg12.o mpeg12data.o mpegvideo.o error_resilience.o
diff --git a/libavcodec/aac.c b/libavcodec/aac.c
index 545f125..6150c30 100644
--- a/libavcodec/aac.c
+++ b/libavcodec/aac.c
@@ -435,7 +435,7 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) {
         ac->sf_offset = 60;
     }
 
-#ifndef CONFIG_HARDCODED_TABLES
+#if !CONFIG_HARDCODED_TABLES
     for (i = 0; i < 428; i++)
         ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.);
 #endif /* CONFIG_HARDCODED_TABLES */
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index 3eab636..76f9bbc 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -899,7 +899,7 @@ const float * const ff_aac_codebook_vectors[] = {
     codebook_vector8, codebook_vector10,
 };
 
-#ifdef CONFIG_HARDCODED_TABLES
+#if CONFIG_HARDCODED_TABLES
 
 /**
  * Table of pow(2, (i - 200)/4.) used for different purposes depending on the
diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index 07574d8..2a8491b 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -65,7 +65,7 @@ extern const uint16_t  ff_aac_spectral_sizes[11];
 
 extern const float *ff_aac_codebook_vectors[];
 
-#ifdef CONFIG_HARDCODED_TABLES
+#if CONFIG_HARDCODED_TABLES
 extern const float ff_aac_pow2sf_tab[316];
 #else
 extern       float ff_aac_pow2sf_tab[316];
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index c4fb3ee..883b723 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -153,7 +153,7 @@ typedef struct ADPCMContext {
 
 /* XXX: implement encoding */
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static int adpcm_encode_init(AVCodecContext *avctx)
 {
     if (avctx->channels > 2)
@@ -1131,6 +1131,33 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
             *samples++ = c->status[0].predictor - c->status[1].predictor;
         }
         break;
+    case CODEC_ID_ADPCM_IMA_ISS:
+        c->status[0].predictor  = (int16_t)AV_RL16(src + 0);
+        c->status[0].step_index = src[2];
+        src += 4;
+        if(st) {
+            c->status[1].predictor  = (int16_t)AV_RL16(src + 0);
+            c->status[1].step_index = src[2];
+            src += 4;
+        }
+
+        while (src < buf + buf_size) {
+
+            if (st) {
+                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+                    src[0] >> 4  , 3);
+                *samples++ = adpcm_ima_expand_nibble(&c->status[1],
+                    src[0] & 0x0F, 3);
+            } else {
+                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+                    src[0] & 0x0F, 3);
+                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+                    src[0] >> 4  , 3);
+            }
+
+            src++;
+        }
+        break;
     case CODEC_ID_ADPCM_IMA_WS:
         /* no per-block initialization; just start decoding the data */
         while (src < buf + buf_size) {
@@ -1589,7 +1616,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
 
 
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 #define ADPCM_ENCODER(id,name,long_name_)       \
 AVCodec name ## _encoder = {                    \
     #name,                                      \
@@ -1607,7 +1634,7 @@ AVCodec name ## _encoder = {                    \
 #define ADPCM_ENCODER(id,name,long_name_)
 #endif
 
-#ifdef CONFIG_DECODERS
+#if CONFIG_DECODERS
 #define ADPCM_DECODER(id,name,long_name_)       \
 AVCodec name ## _decoder = {                    \
     #name,                                      \
@@ -1641,6 +1668,7 @@ ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "IMA Duck DK3 ADPCM");
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "IMA Duck DK4 ADPCM");
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "IMA Electronic Arts EACS ADPCM");
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "IMA Electronic Arts SEAD ADPCM");
+ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "IMA Funcom ISS ADPCM");
 ADPCM_CODEC  (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "IMA QuickTime ADPCM");
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "IMA Loki SDL MJPEG ADPCM");
 ADPCM_CODEC  (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "IMA Wav ADPCM");
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 5512d7f..aa0e896 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "adx.h"
 
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index 6bce31a..1ba8608 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "adx.h"
 
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2d6ce40..77225a6 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -28,18 +28,18 @@
 
 #define REGISTER_ENCODER(X,x) { \
           extern AVCodec x##_encoder; \
-          if(ENABLE_##X##_ENCODER)  register_avcodec(&x##_encoder); }
+          if(CONFIG_##X##_ENCODER)  register_avcodec(&x##_encoder); }
 #define REGISTER_DECODER(X,x) { \
           extern AVCodec x##_decoder; \
-          if(ENABLE_##X##_DECODER)  register_avcodec(&x##_decoder); }
+          if(CONFIG_##X##_DECODER)  register_avcodec(&x##_decoder); }
 #define REGISTER_ENCDEC(X,x)  REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x)
 
 #define REGISTER_PARSER(X,x) { \
           extern AVCodecParser x##_parser; \
-          if(ENABLE_##X##_PARSER)  av_register_codec_parser(&x##_parser); }
+          if(CONFIG_##X##_PARSER)  av_register_codec_parser(&x##_parser); }
 #define REGISTER_BSF(X,x) { \
           extern AVBitStreamFilter x##_bsf; \
-          if(ENABLE_##X##_BSF)     av_register_bitstream_filter(&x##_bsf); }
+          if(CONFIG_##X##_BSF)     av_register_bitstream_filter(&x##_bsf); }
 
 void avcodec_register_all(void)
 {
@@ -108,6 +108,8 @@ void avcodec_register_all(void)
     REGISTER_DECODER  (MPEG2VIDEO, mpeg2video);
     REGISTER_DECODER  (MPEG4, mpeg4);
     REGISTER_DECODER (MPEGVIDEO, mpegvideo);
+    REGISTER_DECODER (MPEG_VDPAU, mpeg_vdpau);
+    REGISTER_DECODER (MPEG1_VDPAU, mpeg1_vdpau);
     REGISTER_DECODER  (MSMPEG4V1, msmpeg4v1);
     REGISTER_DECODER  (MSMPEG4V2, msmpeg4v2);
     REGISTER_DECODER  (MSMPEG4V3, msmpeg4v3);
@@ -188,6 +190,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER (MACE3, mace3);
     REGISTER_DECODER (MACE6, mace6);
     REGISTER_DECODER (MLP, mlp);
+    REGISTER_DECODER (MP1, mp1);
     REGISTER_ENCDEC  (MP2, mp2);
     REGISTER_DECODER (MP3, mp3);
     REGISTER_DECODER (MP3ADU, mp3adu);
@@ -260,6 +263,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4);
     REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
     REGISTER_DECODER (ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
+    REGISTER_DECODER (ADPCM_IMA_ISS, adpcm_ima_iss);
     REGISTER_ENCDEC  (ADPCM_IMA_QT, adpcm_ima_qt);
     REGISTER_DECODER (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
     REGISTER_ENCDEC  (ADPCM_IMA_WAV, adpcm_ima_wav);
diff --git a/libavcodec/alpha/asm.h b/libavcodec/alpha/asm.h
index 1877704..04d4f89 100644
--- a/libavcodec/alpha/asm.h
+++ b/libavcodec/alpha/asm.h
@@ -62,12 +62,12 @@ static inline uint64_t WORD_VEC(uint64_t x)
 
 #ifdef __GNUC__
 #define ldq(p)                                                  \
-    (((union {                                                  \
+    (((const union {                                            \
         uint64_t __l;                                           \
         __typeof__(*(p)) __s[sizeof (uint64_t) / sizeof *(p)];  \
     } *) (p))->__l)
 #define ldl(p)                                                  \
-    (((union {                                                  \
+    (((const union {                                            \
         int32_t __l;                                            \
         __typeof__(*(p)) __s[sizeof (int32_t) / sizeof *(p)];   \
     } *) (p))->__l)
diff --git a/libavcodec/alpha/dsputil_alpha.c b/libavcodec/alpha/dsputil_alpha.c
index c1500b1..34e892c 100644
--- a/libavcodec/alpha/dsputil_alpha.c
+++ b/libavcodec/alpha/dsputil_alpha.c
@@ -22,9 +22,9 @@
 #include "libavcodec/dsputil.h"
 #include "asm.h"
 
-void simple_idct_axp(DCTELEM *block);
-void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block);
-void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_axp(DCTELEM *block);
+void ff_simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block);
 
 void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
                         int line_size, int h);
@@ -42,7 +42,7 @@ void get_pixels_mvi(DCTELEM *restrict block,
 void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2,
                      int stride);
 int pix_abs8x8_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
-int pix_abs16x16_mvi_asm(uint8_t *pix1, uint8_t *pix2, int line_size);
+int pix_abs16x16_mvi_asm(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
 int pix_abs16x16_x2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
 int pix_abs16x16_y2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
 int pix_abs16x16_xy2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
@@ -287,11 +287,6 @@ void put_pixels16_axp_asm(uint8_t *block, const uint8_t *pixels,
     put_pixels_axp_asm(block + 8, pixels + 8, line_size, h);
 }
 
-static int sad16x16_mvi(void *s, uint8_t *a, uint8_t *b, int stride)
-{
-    return pix_abs16x16_mvi_asm(a, b, stride);
-}
-
 void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
 {
     c->put_pixels_tab[0][0] = put_pixels16_axp_asm;
@@ -343,10 +338,9 @@ void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
 
         c->get_pixels       = get_pixels_mvi;
         c->diff_pixels      = diff_pixels_mvi;
-        c->sad[0]           = sad16x16_mvi;
+        c->sad[0]           = pix_abs16x16_mvi_asm;
         c->sad[1]           = pix_abs8x8_mvi;
-//        c->pix_abs[0][0]    = pix_abs16x16_mvi_asm; //FIXME function arguments for the asm must be fixed
-        c->pix_abs[0][0]    = sad16x16_mvi;
+        c->pix_abs[0][0]    = pix_abs16x16_mvi_asm;
         c->pix_abs[1][0]    = pix_abs8x8_mvi;
         c->pix_abs[0][1]    = pix_abs16x16_x2_mvi;
         c->pix_abs[0][2]    = pix_abs16x16_y2_mvi;
@@ -356,7 +350,11 @@ void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
     put_pixels_clamped_axp_p = c->put_pixels_clamped;
     add_pixels_clamped_axp_p = c->add_pixels_clamped;
 
-    c->idct_put = simple_idct_put_axp;
-    c->idct_add = simple_idct_add_axp;
-    c->idct = simple_idct_axp;
+    if (!avctx->lowres &&
+        (avctx->idct_algo == FF_IDCT_AUTO ||
+         avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) {
+        c->idct_put = ff_simple_idct_put_axp;
+        c->idct_add = ff_simple_idct_add_axp;
+        c->idct =     ff_simple_idct_axp;
+    }
 }
diff --git a/libavcodec/alpha/dsputil_alpha_asm.S b/libavcodec/alpha/dsputil_alpha_asm.S
index dbdf279..57b21fc 100644
--- a/libavcodec/alpha/dsputil_alpha_asm.S
+++ b/libavcodec/alpha/dsputil_alpha_asm.S
@@ -53,7 +53,7 @@ put_pixels_axp_asm:
         .frame sp, 0, ra
         .prologue 0
 
-#ifdef CONFIG_GPROF
+#if CONFIG_GPROF
         lda     AT, _mcount
         jsr     AT, (AT), _mcount
 #endif
@@ -150,7 +150,7 @@ put_pixels_clamped_mvi_asm:
         .frame sp, 0, ra
         .prologue 0
 
-#ifdef CONFIG_GPROF
+#if CONFIG_GPROF
         lda     AT, _mcount
         jsr     AT, (AT), _mcount
 #endif
@@ -205,7 +205,7 @@ add_pixels_clamped_mvi_asm:
         .frame sp, 0, ra
         .prologue 0
 
-#ifdef CONFIG_GPROF
+#if CONFIG_GPROF
         lda     AT, _mcount
         jsr     AT, (AT), _mcount
 #endif
diff --git a/libavcodec/alpha/motion_est_mvi_asm.S b/libavcodec/alpha/motion_est_mvi_asm.S
index cdf40b1..2a08b07 100644
--- a/libavcodec/alpha/motion_est_mvi_asm.S
+++ b/libavcodec/alpha/motion_est_mvi_asm.S
@@ -55,14 +55,13 @@ pix_abs16x16_mvi_asm:
         .frame sp, 0, ra, 0
         .prologue 0
 
-#ifdef CONFIG_GPROF
+#if CONFIG_GPROF
         lda     AT, _mcount
         jsr     AT, (AT), _mcount
 #endif
 
-        and     a1, 7, t0
+        and     a2, 7, t0
         clr     v0
-        lda     a3, 16
         beq     t0, $aligned
         .align 4
 $unaligned:
@@ -86,80 +85,80 @@ $unaligned:
            td:  error right  */
 
         /* load line 0 */
-        ldq_u   t0, 0(a1)       # left_u
-        ldq_u   t1, 8(a1)       # mid
-        ldq_u   t2, 16(a1)      # right_u
-        ldq     t3, 0(a0)       # ref left
-        ldq     t4, 8(a0)       # ref right
-        addq    a0, a2, a0      # pix1
-        addq    a1, a2, a1      # pix2
+        ldq_u   t0, 0(a2)       # left_u
+        ldq_u   t1, 8(a2)       # mid
+        ldq_u   t2, 16(a2)      # right_u
+        ldq     t3, 0(a1)       # ref left
+        ldq     t4, 8(a1)       # ref right
+        addq    a1, a3, a1      # pix1
+        addq    a2, a3, a2      # pix2
         /* load line 1 */
-        ldq_u   t5, 0(a1)       # left_u
-        ldq_u   t6, 8(a1)       # mid
-        ldq_u   t7, 16(a1)      # right_u
-        ldq     t8, 0(a0)       # ref left
-        ldq     t9, 8(a0)       # ref right
-        addq    a0, a2, a0      # pix1
-        addq    a1, a2, a1      # pix2
+        ldq_u   t5, 0(a2)       # left_u
+        ldq_u   t6, 8(a2)       # mid
+        ldq_u   t7, 16(a2)      # right_u
+        ldq     t8, 0(a1)       # ref left
+        ldq     t9, 8(a1)       # ref right
+        addq    a1, a3, a1      # pix1
+        addq    a2, a3, a2      # pix2
         /* calc line 0 */
-        extql   t0, a1, t0      # left lo
-        extqh   t1, a1, ta      # left hi
-        extql   t1, a1, tb      # right lo
+        extql   t0, a2, t0      # left lo
+        extqh   t1, a2, ta      # left hi
+        extql   t1, a2, tb      # right lo
         or      t0, ta, t0      # left
-        extqh   t2, a1, t2      # right hi
+        extqh   t2, a2, t2      # right hi
         perr    t3, t0, tc      # error left
         or      t2, tb, t2      # right
         perr    t4, t2, td      # error right
         addq    v0, tc, v0      # add error left
         addq    v0, td, v0      # add error left
         /* calc line 1 */
-        extql   t5, a1, t5      # left lo
-        extqh   t6, a1, ta      # left hi
-        extql   t6, a1, tb      # right lo
+        extql   t5, a2, t5      # left lo
+        extqh   t6, a2, ta      # left hi
+        extql   t6, a2, tb      # right lo
         or      t5, ta, t5      # left
-        extqh   t7, a1, t7      # right hi
+        extqh   t7, a2, t7      # right hi
         perr    t8, t5, tc      # error left
         or      t7, tb, t7      # right
         perr    t9, t7, td      # error right
         addq    v0, tc, v0      # add error left
         addq    v0, td, v0      # add error left
         /* loop */
-        subq    a3,  2, a3      # h -= 2
-        bne     a3, $unaligned
+        subq    a4,  2, a4      # h -= 2
+        bne     a4, $unaligned
         ret
 
         .align 4
 $aligned:
         /* load line 0 */
-        ldq     t0, 0(a1)       # left
-        ldq     t1, 8(a1)       # right
-        addq    a1, a2, a1      # pix2
-        ldq     t2, 0(a0)       # ref left
-        ldq     t3, 8(a0)       # ref right
-        addq    a0, a2, a0      # pix1
+        ldq     t0, 0(a2)       # left
+        ldq     t1, 8(a2)       # right
+        addq    a2, a3, a2      # pix2
+        ldq     t2, 0(a1)       # ref left
+        ldq     t3, 8(a1)       # ref right
+        addq    a1, a3, a1      # pix1
         /* load line 1 */
-        ldq     t4, 0(a1)       # left
-        ldq     t5, 8(a1)       # right
-        addq    a1, a2, a1      # pix2
-        ldq     t6, 0(a0)       # ref left
-        ldq     t7, 8(a0)       # ref right
-        addq    a0, a2, a0      # pix1
+        ldq     t4, 0(a2)       # left
+        ldq     t5, 8(a2)       # right
+        addq    a2, a3, a2      # pix2
+        ldq     t6, 0(a1)       # ref left
+        ldq     t7, 8(a1)       # ref right
+        addq    a1, a3, a1      # pix1
         /* load line 2 */
-        ldq     t8, 0(a1)       # left
-        ldq     t9, 8(a1)       # right
-        addq    a1, a2, a1      # pix2
-        ldq     ta, 0(a0)       # ref left
-        ldq     tb, 8(a0)       # ref right
-        addq    a0, a2, a0      # pix1
+        ldq     t8, 0(a2)       # left
+        ldq     t9, 8(a2)       # right
+        addq    a2, a3, a2      # pix2
+        ldq     ta, 0(a1)       # ref left
+        ldq     tb, 8(a1)       # ref right
+        addq    a1, a3, a1      # pix1
         /* load line 3 */
-        ldq     tc, 0(a1)       # left
-        ldq     td, 8(a1)       # right
-        addq    a1, a2, a1      # pix2
-        ldq     te, 0(a0)       # ref left
-        ldq     tf, 8(a0)       # ref right
+        ldq     tc, 0(a2)       # left
+        ldq     td, 8(a2)       # right
+        addq    a2, a3, a2      # pix2
+        ldq     te, 0(a1)       # ref left
+        ldq     a0, 8(a1)       # ref right
         /* calc line 0 */
         perr    t0, t2, t0      # error left
-        addq    a0, a2, a0      # pix1
+        addq    a1, a3, a1      # pix1
         perr    t1, t3, t1      # error right
         addq    v0, t0, v0      # add error left
         /* calc line 1 */
@@ -175,11 +174,11 @@ $aligned:
         /* calc line 3 */
         perr    tc, te, t0      # error left
         addq    v0, t1, v0      # add error right
-        perr    td, tf, t1      # error right
+        perr    td, a0, t1      # error right
         addq    v0, t0, v0      # add error left
         addq    v0, t1, v0      # add error right
         /* loop */
-        subq    a3,  4, a3      # h -= 4
-        bne     a3, $aligned
+        subq    a4,  4, a4      # h -= 4
+        bne     a4, $aligned
         ret
         .end pix_abs16x16_mvi_asm
diff --git a/libavcodec/alpha/mpegvideo_alpha.c b/libavcodec/alpha/mpegvideo_alpha.c
index 3c32af1..de32545 100644
--- a/libavcodec/alpha/mpegvideo_alpha.c
+++ b/libavcodec/alpha/mpegvideo_alpha.c
@@ -23,32 +23,17 @@
 #include "libavcodec/mpegvideo.h"
 #include "asm.h"
 
-static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block,
-                                    int n, int qscale)
+static void dct_unquantize_h263_axp(DCTELEM *block, int n_coeffs,
+                                    uint64_t qscale, uint64_t qadd)
 {
-    int i, n_coeffs;
-    uint64_t qmul, qadd;
-    uint64_t correction;
-    DCTELEM *orig_block = block;
-    DCTELEM block0;             /* might not be used uninitialized */
+    uint64_t qmul = qscale << 1;
+    uint64_t correction = WORD_VEC(qmul * 255 >> 8);
+    int i;
 
-    qadd = WORD_VEC((qscale - 1) | 1);
-    qmul = qscale << 1;
-    /* This mask kills spill from negative subwords to the next subword.  */
-    correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
-
-    if (!s->h263_aic) {
-        if (n < 4)
-            block0 = block[0] * s->y_dc_scale;
-        else
-            block0 = block[0] * s->c_dc_scale;
-    } else {
-        qadd = 0;
-    }
-    n_coeffs = 63; // does not always use zigzag table
+    qadd = WORD_VEC(qadd);
 
     for(i = 0; i <= n_coeffs; block += 4, i += 4) {
-        uint64_t levels, negmask, zeros, add;
+        uint64_t levels, negmask, zeros, add, sub;
 
         levels = ldq(block);
         if (levels == 0)
@@ -73,71 +58,49 @@ static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block,
         levels *= qmul;
         levels -= correction & (negmask << 16);
 
-        /* Negate qadd for negative levels.  */
-        add = qadd ^ negmask;
-        add += WORD_VEC(0x0001) & negmask;
+        add = qadd & ~negmask;
+        sub = qadd &  negmask;
         /* Set qadd to 0 for levels == 0.  */
         add = zap(add, zeros);
-
         levels += add;
+        levels -= sub;
 
         stq(levels, block);
     }
-
-    if (s->mb_intra && !s->h263_aic)
-        orig_block[0] = block0;
 }
 
-static void dct_unquantize_h263_inter_axp(MpegEncContext *s, DCTELEM *block,
+static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block,
                                     int n, int qscale)
 {
-    int i, n_coeffs;
-    uint64_t qmul, qadd;
-    uint64_t correction;
-
-    qadd = WORD_VEC((qscale - 1) | 1);
-    qmul = qscale << 1;
-    /* This mask kills spill from negative subwords to the next subword.  */
-    correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
+    int n_coeffs;
+    uint64_t qadd;
+    DCTELEM block0 = block[0];
 
-    n_coeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
-
-    for(i = 0; i <= n_coeffs; block += 4, i += 4) {
-        uint64_t levels, negmask, zeros, add;
-
-        levels = ldq(block);
-        if (levels == 0)
-            continue;
-
-#ifdef __alpha_max__
-        /* I don't think the speed difference justifies runtime
-           detection.  */
-        negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
-        negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
-#else
-        negmask = cmpbge(WORD_VEC(0x7fff), levels);
-        negmask &= (negmask >> 1) | (1 << 7);
-        negmask = zap(-1, negmask);
-#endif
-
-        zeros = cmpbge(0, levels);
-        zeros &= zeros >> 1;
-        /* zeros |= zeros << 1 is not needed since qadd <= 255, so
-           zapping the lower byte suffices.  */
+    if (!s->h263_aic) {
+        if (n < 4)
+            block0 *= s->y_dc_scale;
+        else
+            block0 *= s->c_dc_scale;
+        qadd = (qscale - 1) | 1;
+    } else {
+        qadd = 0;
+    }
 
-        levels *= qmul;
-        levels -= correction & (negmask << 16);
+    if(s->ac_pred)
+        n_coeffs = 63;
+    else
+        n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
 
-        /* Negate qadd for negative levels.  */
-        add = qadd ^ negmask;
-        add += WORD_VEC(0x0001) & negmask;
-        /* Set qadd to 0 for levels == 0.  */
-        add = zap(add, zeros);
+    dct_unquantize_h263_axp(block, n_coeffs, qscale, qadd);
 
-        levels += add;
+    block[0] = block0;
+}
 
-        stq(levels, block);
-    }
+static void dct_unquantize_h263_inter_axp(MpegEncContext *s, DCTELEM *block,
+                                    int n, int qscale)
+{
+    int n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
+    dct_unquantize_h263_axp(block, n_coeffs, qscale, (qscale - 1) | 1);
 }
 
 void MPV_common_init_axp(MpegEncContext *s)
diff --git a/libavcodec/alpha/simple_idct_alpha.c b/libavcodec/alpha/simple_idct_alpha.c
index 8c63f1f..45e70dc 100644
--- a/libavcodec/alpha/simple_idct_alpha.c
+++ b/libavcodec/alpha/simple_idct_alpha.c
@@ -255,7 +255,7 @@ static inline void idct_col2(DCTELEM *col)
     stq(l, col + 14 * 4); stq(r, col + 15 * 4);
 }
 
-void simple_idct_axp(DCTELEM *block)
+void ff_simple_idct_axp(DCTELEM *block)
 {
 
     int i;
@@ -295,14 +295,14 @@ void simple_idct_axp(DCTELEM *block)
     }
 }
 
-void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block)
 {
-    simple_idct_axp(block);
+    ff_simple_idct_axp(block);
     put_pixels_clamped_axp_p(block, dest, line_size);
 }
 
-void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block)
+void ff_simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block)
 {
-    simple_idct_axp(block);
+    ff_simple_idct_axp(block);
     add_pixels_clamped_axp_p(block, dest, line_size);
 }
diff --git a/libavcodec/arm/asm.S b/libavcodec/arm/asm.S
index 0aa1639..69d8348 100644
--- a/libavcodec/arm/asm.S
+++ b/libavcodec/arm/asm.S
@@ -38,7 +38,7 @@
         .endm
 
         .macro movrel rd, val
-#if defined(HAVE_ARMV6T2) && !defined(CONFIG_SHARED)
+#if HAVE_ARMV6T2 && !CONFIG_SHARED
         movw            \rd, #:lower16:\val
         movt            \rd, #:upper16:\val
 #else
diff --git a/libavcodec/arm/dsputil_arm.c b/libavcodec/arm/dsputil_arm.c
index eaa6b9e..cb6f6d0 100644
--- a/libavcodec/arm/dsputil_arm.c
+++ b/libavcodec/arm/dsputil_arm.c
@@ -20,7 +20,7 @@
  */
 
 #include "libavcodec/dsputil.h"
-#ifdef HAVE_IPP
+#if HAVE_IPP
 #include <ipp.h>
 #endif
 
@@ -93,7 +93,7 @@ static void simple_idct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
     ff_add_pixels_clamped(block, dest, line_size);
 }
 
-#ifdef HAVE_IPP
+#if HAVE_IPP
 static void simple_idct_ipp(DCTELEM *block)
 {
     ippiDCT8x8Inv_Video_16s_C1I(block);
@@ -108,7 +108,7 @@ void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_s
 static void simple_idct_ipp_add(uint8_t *dest, int line_size, DCTELEM *block)
 {
     ippiDCT8x8Inv_Video_16s_C1I(block);
-#ifdef HAVE_IWMMXT
+#if HAVE_IWMMXT
     add_pixels_clamped_iwmmxt(block, dest, line_size);
 #else
     ff_add_pixels_clamped_ARM(block, dest, line_size);
@@ -118,7 +118,7 @@ static void simple_idct_ipp_add(uint8_t *dest, int line_size, DCTELEM *block)
 
 int mm_support(void)
 {
-    return ENABLE_IWMMXT * FF_MM_IWMMXT;
+    return HAVE_IWMMXT * FF_MM_IWMMXT;
 }
 
 void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
@@ -130,13 +130,13 @@ void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
 
     if (avctx->lowres == 0) {
         if(idct_algo == FF_IDCT_AUTO){
-#if defined(HAVE_IPP)
+#if   HAVE_IPP
             idct_algo = FF_IDCT_IPP;
-#elif defined(HAVE_NEON)
+#elif HAVE_NEON
             idct_algo = FF_IDCT_SIMPLENEON;
-#elif defined(HAVE_ARMV6)
+#elif HAVE_ARMV6
             idct_algo = FF_IDCT_SIMPLEARMV6;
-#elif defined(HAVE_ARMV5TE)
+#elif HAVE_ARMV5TE
             idct_algo = FF_IDCT_SIMPLEARMV5TE;
 #else
             idct_algo = FF_IDCT_ARM;
@@ -153,28 +153,28 @@ void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
             c->idct_add= simple_idct_ARM_add;
             c->idct    = simple_idct_ARM;
             c->idct_permutation_type= FF_NO_IDCT_PERM;
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
         } else if (idct_algo==FF_IDCT_SIMPLEARMV6){
             c->idct_put= ff_simple_idct_put_armv6;
             c->idct_add= ff_simple_idct_add_armv6;
             c->idct    = ff_simple_idct_armv6;
             c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
 #endif
-#ifdef HAVE_ARMV5TE
+#if HAVE_ARMV5TE
         } else if (idct_algo==FF_IDCT_SIMPLEARMV5TE){
             c->idct_put= simple_idct_put_armv5te;
             c->idct_add= simple_idct_add_armv5te;
             c->idct    = simple_idct_armv5te;
             c->idct_permutation_type = FF_NO_IDCT_PERM;
 #endif
-#ifdef HAVE_IPP
+#if HAVE_IPP
         } else if (idct_algo==FF_IDCT_IPP){
             c->idct_put= simple_idct_ipp_put;
             c->idct_add= simple_idct_ipp_add;
             c->idct    = simple_idct_ipp;
             c->idct_permutation_type= FF_NO_IDCT_PERM;
 #endif
-#ifdef HAVE_NEON
+#if HAVE_NEON
         } else if (idct_algo==FF_IDCT_SIMPLENEON){
             c->idct_put= ff_simple_idct_put_neon;
             c->idct_add= ff_simple_idct_add_neon;
@@ -201,17 +201,17 @@ void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
     c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_arm;
     c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm;
 
-#ifdef HAVE_ARMV5TE
+#if HAVE_ARMV5TE
     c->prefetch = ff_prefetch_arm;
 #endif
 
-#ifdef HAVE_IWMMXT
+#if HAVE_IWMMXT
     dsputil_init_iwmmxt(c, avctx);
 #endif
-#ifdef HAVE_ARMVFP
+#if HAVE_ARMVFP
     ff_float_init_arm_vfp(c, avctx);
 #endif
-#ifdef HAVE_NEON
+#if HAVE_NEON
     ff_dsputil_init_neon(c, avctx);
 #endif
 }
diff --git a/libavcodec/arm/dsputil_arm_s.S b/libavcodec/arm/dsputil_arm_s.S
index 639b7b8..9425d33 100644
--- a/libavcodec/arm/dsputil_arm_s.S
+++ b/libavcodec/arm/dsputil_arm_s.S
@@ -24,12 +24,12 @@
 
         preserve8
 
-#ifndef HAVE_PLD
+#if !HAVE_PLD
 .macro pld reg
 .endm
 #endif
 
-#ifdef HAVE_ARMV5TE
+#if HAVE_ARMV5TE
 function ff_prefetch_arm, export=1
         subs    r2, r2, #1
         pld     [r0]
diff --git a/libavcodec/arm/dsputil_vfp.S b/libavcodec/arm/dsputil_vfp.S
index 04c8014..50cfd98 100644
--- a/libavcodec/arm/dsputil_vfp.S
+++ b/libavcodec/arm/dsputil_vfp.S
@@ -133,7 +133,7 @@ function ff_vector_fmul_reverse_vfp, export=1
         bx              lr
         .endfunc
 
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
 /**
  * ARM VFP optimized float to int16 conversion.
  * Assume that len is a positive number and is multiple of 8, destination
diff --git a/libavcodec/arm/float_arm_vfp.c b/libavcodec/arm/float_arm_vfp.c
index 5598aa9..41a7c19 100644
--- a/libavcodec/arm/float_arm_vfp.c
+++ b/libavcodec/arm/float_arm_vfp.c
@@ -29,7 +29,7 @@ void ff_float_init_arm_vfp(DSPContext* c, AVCodecContext *avctx)
 {
     c->vector_fmul = ff_vector_fmul_vfp;
     c->vector_fmul_reverse = ff_vector_fmul_reverse_vfp;
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
     c->float_to_int16 = ff_float_to_int16_vfp;
 #endif
 }
diff --git a/libavcodec/arm/h264dsp_neon.S b/libavcodec/arm/h264dsp_neon.S
index 39a8daf..e57cb6f 100644
--- a/libavcodec/arm/h264dsp_neon.S
+++ b/libavcodec/arm/h264dsp_neon.S
@@ -56,10 +56,11 @@
         .endm
 
 /* chroma_mc8(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y) */
-        .macro  h264_chroma_mc8 avg=0
+        .macro  h264_chroma_mc8 type
+function ff_\type\()_h264_chroma_mc8_neon, export=1
         push            {r4-r7, lr}
         ldrd            r4,  [sp, #20]
-.if \avg
+.ifc \type,avg
         mov             lr,  r0
 .endif
         pld             [r1]
@@ -103,7 +104,7 @@
         vld1.64         {d6, d7}, [r5], r4
         pld             [r1]
         vrshrn.u16      d17, q9,  #6
-.if \avg
+.ifc \type,avg
         vld1.64         {d20}, [lr,:64], r2
         vld1.64         {d21}, [lr,:64], r2
         vrhadd.u8       q8,  q8,  q10
@@ -136,7 +137,7 @@
         vld1.64         {d6}, [r5], r4
         vrshrn.u16      d16, q8,  #6
         vrshrn.u16      d17, q9,  #6
-.if \avg
+.ifc \type,avg
         vld1.64         {d20}, [lr,:64], r2
         vld1.64         {d21}, [lr,:64], r2
         vrhadd.u8       q8,  q8,  q10
@@ -165,7 +166,7 @@
         vext.8          d5,  d4,  d5,  #1
         vrshrn.u16      d16, q8,  #6
         vrshrn.u16      d17, q9,  #6
-.if \avg
+.ifc \type,avg
         vld1.64         {d20}, [lr,:64], r2
         vld1.64         {d21}, [lr,:64], r2
         vrhadd.u8       q8,  q8,  q10
@@ -177,13 +178,15 @@
         bgt             5b
 
         pop             {r4-r7, pc}
+        .endfunc
         .endm
 
 /* chroma_mc4(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y) */
-        .macro  h264_chroma_mc4 avg=0
+        .macro  h264_chroma_mc4 type
+function ff_\type\()_h264_chroma_mc4_neon, export=1
         push            {r4-r7, lr}
         ldrd            r4,  [sp, #20]
-.if \avg
+.ifc \type,avg
         mov             lr,  r0
 .endif
         pld             [r1]
@@ -230,7 +233,7 @@
         vrshrn.u16      d16, q8,  #6
         subs            r3,  r3,  #2
         pld             [r1]
-.if \avg
+.ifc \type,avg
         vld1.32         {d20[0]}, [lr,:32], r2
         vld1.32         {d20[1]}, [lr,:32], r2
         vrhadd.u8       d16, d16, d20
@@ -265,7 +268,7 @@
         vadd.i16        d16, d16, d17
         vadd.i16        d17, d18, d19
         vrshrn.u16      d16, q8,  #6
-.if \avg
+.ifc \type,avg
         vld1.32         {d20[0]}, [lr,:32], r2
         vld1.32         {d20[1]}, [lr,:32], r2
         vrhadd.u8       d16, d16, d20
@@ -295,7 +298,7 @@
         vadd.i16        d17, d18, d19
         pld             [r1]
         vrshrn.u16      d16, q8,  #6
-.if \avg
+.ifc \type,avg
         vld1.32         {d20[0]}, [lr,:32], r2
         vld1.32         {d20[1]}, [lr,:32], r2
         vrhadd.u8       d16, d16, d20
@@ -309,26 +312,16 @@
         bgt             5b
 
         pop             {r4-r7, pc}
+        .endfunc
         .endm
 
         .text
         .align
 
-function ff_put_h264_chroma_mc8_neon, export=1
-        h264_chroma_mc8
-        .endfunc
-
-function ff_avg_h264_chroma_mc8_neon, export=1
-        h264_chroma_mc8 avg=1
-        .endfunc
-
-function ff_put_h264_chroma_mc4_neon, export=1
-        h264_chroma_mc4
-        .endfunc
-
-function ff_avg_h264_chroma_mc4_neon, export=1
-        h264_chroma_mc4 avg=1
-        .endfunc
+        h264_chroma_mc8 put
+        h264_chroma_mc8 avg
+        h264_chroma_mc4 put
+        h264_chroma_mc4 avg
 
         /* H.264 loop filter */
 
diff --git a/libavcodec/arm/mathops.h b/libavcodec/arm/mathops.h
index e36316c..7a9d632 100644
--- a/libavcodec/arm/mathops.h
+++ b/libavcodec/arm/mathops.h
@@ -38,7 +38,7 @@ static inline av_const int MULL(int a, int b, unsigned shift)
 }
 
 #define MULH MULH
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
 static inline av_const int MULH(int a, int b)
 {
     int r;
@@ -73,7 +73,7 @@ static inline av_const int64_t MAC64(int64_t d, int a, int b)
 #define MAC64(d, a, b) ((d) = MAC64(d, a, b))
 #define MLS64(d, a, b) MAC64(d, -(a), b)
 
-#if defined(HAVE_ARMV5TE)
+#if HAVE_ARMV5TE
 
 /* signed 16x16 -> 32 multiply add accumulate */
 #   define MAC16(rt, ra, rb)                                            \
diff --git a/libavcodec/arm/mpegvideo_arm.c b/libavcodec/arm/mpegvideo_arm.c
index 18faed2..4882dd4 100644
--- a/libavcodec/arm/mpegvideo_arm.c
+++ b/libavcodec/arm/mpegvideo_arm.c
@@ -31,10 +31,10 @@ void MPV_common_init_arm(MpegEncContext *s)
      * allow optimized functions for armv5te unless
      * a better iwmmxt function exists
      */
-#ifdef HAVE_ARMV5TE
+#if HAVE_ARMV5TE
     MPV_common_init_armv5te(s);
 #endif
-#ifdef HAVE_IWMMXT
+#if HAVE_IWMMXT
     MPV_common_init_iwmmxt(s);
 #endif
 }
diff --git a/libavcodec/arm/simple_idct_armv6.S b/libavcodec/arm/simple_idct_armv6.S
index 4f3330d..9d6455f 100644
--- a/libavcodec/arm/simple_idct_armv6.S
+++ b/libavcodec/arm/simple_idct_armv6.S
@@ -52,159 +52,159 @@ w57:    .long W57
 /*
   Compute partial IDCT of single row.
   shift = left-shift amount
-  a1 = source address
-  a3 = row[2,0] <= 2 cycles
-  a4 = row[3,1]
+  r0 = source address
+  r2 = row[2,0] <= 2 cycles
+  r3 = row[3,1]
   ip = w42      <= 2 cycles
 
-  Output in registers v1--v8
+  Output in registers r4--r11
 */
         .macro idct_row shift
-        ldr    lr, [pc, #(w46-.-8)]  /* lr = W4 | (W6 << 16) */
-        mov    a2, #(1<<(\shift-1))
-        smlad  v1, a3, ip, a2
-        smlsd  v4, a3, ip, a2
-        ldr    ip, [pc, #(w13-.-8)]  /* ip = W1 | (W3 << 16) */
-        ldr    v7, [pc, #(w57-.-8)]  /* v7 = W5 | (W7 << 16) */
-        smlad  v2, a3, lr, a2
-        smlsd  v3, a3, lr, a2
-
-        smuad  v5, a4, ip            /* v5 = B0 = W1*row[1] + W3*row[3] */
-        smusdx fp, a4, v7            /* fp = B3 = W7*row[1] - W5*row[3] */
-        ldr    lr, [a1, #12]         /* lr = row[7,5] */
-        pkhtb  a3, ip, v7, asr #16   /* a4 = W7 | (W3 << 16) */
-        pkhbt  a2, ip, v7, lsl #16   /* a2 = W1 | (W5 << 16) */
-        smusdx v6, a3, a4            /* v6 = -B1 = W7*row[3] - W3*row[1] */
-        smlad  v5, lr, v7, v5        /* B0 += W5*row[5] + W7*row[7] */
-        smusdx v7, a4, a2            /* v7 = B2 = W5*row[1] - W1*row[3] */
-
-        ldr    a4, [pc, #(w42n-.-8)] /* a4 = -W4 | (-W2 << 16) */
-        smlad  v7, lr, a3, v7        /* B2 += W7*row[5] + W3*row[7] */
-        ldr    a3, [a1, #4]          /* a3 = row[6,4] */
-        smlsdx fp, lr, ip, fp        /* B3 += W3*row[5] - W1*row[7] */
-        ldr    ip, [pc, #(w46-.-8)]  /* ip = W4 | (W6 << 16) */
-        smlad  v6, lr, a2, v6        /* B1 -= W1*row[5] + W5*row[7] */
-
-        smlad  v2, a3, a4, v2        /* A1 += -W4*row[4] - W2*row[6] */
-        smlsd  v3, a3, a4, v3        /* A2 += -W4*row[4] + W2*row[6] */
-        smlad  v1, a3, ip, v1        /* A0 += W4*row[4] + W6*row[6] */
-        smlsd  v4, a3, ip, v4        /* A3 += W4*row[4] - W6*row[6] */
+        ldr    lr, w46               /* lr  = W4 | (W6 << 16) */
+        mov    r1, #(1<<(\shift-1))
+        smlad  r4, r2, ip, r1
+        smlsd  r7, r2, ip, r1
+        ldr    ip, w13               /* ip  = W1 | (W3 << 16) */
+        ldr    r10,w57               /* r10 = W5 | (W7 << 16) */
+        smlad  r5, r2, lr, r1
+        smlsd  r6, r2, lr, r1
+
+        smuad  r8, r3, ip            /* r8  =  B0 = W1*row[1] + W3*row[3] */
+        smusdx r11,r3, r10           /* r11 =  B3 = W7*row[1] - W5*row[3] */
+        ldr    lr, [r0, #12]         /* lr  =  row[7,5] */
+        pkhtb  r2, ip, r10,asr #16   /* r3  =  W7 | (W3 << 16) */
+        pkhbt  r1, ip, r10,lsl #16   /* r1  =  W1 | (W5 << 16) */
+        smusdx r9, r2, r3            /* r9  = -B1 = W7*row[3] - W3*row[1] */
+        smlad  r8, lr, r10,r8        /* B0  +=      W5*row[5] + W7*row[7] */
+        smusdx r10,r3, r1            /* r10 =  B2 = W5*row[1] - W1*row[3] */
+
+        ldr    r3, w42n              /* r3 =  -W4 | (-W2 << 16) */
+        smlad  r10,lr, r2, r10       /* B2 +=  W7*row[5] + W3*row[7] */
+        ldr    r2, [r0, #4]          /* r2 =   row[6,4] */
+        smlsdx r11,lr, ip, r11       /* B3 +=  W3*row[5] - W1*row[7] */
+        ldr    ip, w46               /* ip =   W4 | (W6 << 16) */
+        smlad  r9, lr, r1, r9        /* B1 -=  W1*row[5] + W5*row[7] */
+
+        smlad  r5, r2, r3, r5        /* A1 += -W4*row[4] - W2*row[6] */
+        smlsd  r6, r2, r3, r6        /* A2 += -W4*row[4] + W2*row[6] */
+        smlad  r4, r2, ip, r4        /* A0 +=  W4*row[4] + W6*row[6] */
+        smlsd  r7, r2, ip, r7        /* A3 +=  W4*row[4] - W6*row[6] */
         .endm
 
 /*
   Compute partial IDCT of half row.
   shift = left-shift amount
-  a3 = row[2,0]
-  a4 = row[3,1]
+  r2 = row[2,0]
+  r3 = row[3,1]
   ip = w42
 
-  Output in registers v1--v8
+  Output in registers r4--r11
 */
         .macro idct_row4 shift
-        ldr    lr, [pc, #(w46-.-8)]  /* lr = W4 | (W6 << 16) */
-        ldr    v7, [pc, #(w57-.-8)]  /* v7 = W5 | (W7 << 16) */
-        mov    a2, #(1<<(\shift-1))
-        smlad  v1, a3, ip, a2
-        smlsd  v4, a3, ip, a2
-        ldr    ip, [pc, #(w13-.-8)]  /* ip = W1 | (W3 << 16) */
-        smlad  v2, a3, lr, a2
-        smlsd  v3, a3, lr, a2
-        smusdx fp, a4, v7            /* fp = B3 = W7*row[1] - W5*row[3] */
-        smuad  v5, a4, ip            /* v5 = B0 = W1*row[1] + W3*row[3] */
-        pkhtb  a3, ip, v7, asr #16   /* a4 = W7 | (W3 << 16) */
-        pkhbt  a2, ip, v7, lsl #16   /* a2 = W1 | (W5 << 16) */
-        smusdx v6, a3, a4            /* v6 = -B1 = W7*row[3] - W3*row[1] */
-        smusdx v7, a4, a2            /* v7 = B2 = W5*row[1] - W1*row[3] */
+        ldr    lr, w46               /* lr =  W4 | (W6 << 16) */
+        ldr    r10,w57               /* r10 = W5 | (W7 << 16) */
+        mov    r1, #(1<<(\shift-1))
+        smlad  r4, r2, ip, r1
+        smlsd  r7, r2, ip, r1
+        ldr    ip, w13               /* ip =  W1 | (W3 << 16) */
+        smlad  r5, r2, lr, r1
+        smlsd  r6, r2, lr, r1
+        smusdx r11,r3, r10           /* r11 =  B3 = W7*row[1] - W5*row[3] */
+        smuad  r8, r3, ip            /* r8  =  B0 = W1*row[1] + W3*row[3] */
+        pkhtb  r2, ip, r10,asr #16   /* r3  =  W7 | (W3 << 16) */
+        pkhbt  r1, ip, r10,lsl #16   /* r1  =  W1 | (W5 << 16) */
+        smusdx r9, r2, r3            /* r9  = -B1 = W7*row[3] - W3*row[1] */
+        smusdx r10,r3, r1            /* r10 =  B2 = W5*row[1] - W1*row[3] */
         .endm
 
 /*
   Compute final part of IDCT single row without shift.
-  Input in registers v1--v8
-  Output in registers ip, v1--v3, lr, v5--v7
+  Input in registers r4--r11
+  Output in registers ip, r4--r6, lr, r8--r10
 */
         .macro idct_finish
-        add    ip, v1, v5            /* a2 = A0 + B0 */
-        sub    lr, v1, v5            /* a3 = A0 - B0 */
-        sub    v1, v2, v6            /* a3 = A1 + B1 */
-        add    v5, v2, v6            /* a3 = A1 - B1 */
-        add    v2, v3, v7            /* a2 = A2 + B2 */
-        sub    v6, v3, v7            /* a2 = A2 - B2 */
-        add    v3, v4, fp            /* a3 = A3 + B3 */
-        sub    v7, v4, fp            /* a3 = A3 - B3 */
+        add    ip, r4, r8            /* r1 = A0 + B0 */
+        sub    lr, r4, r8            /* r2 = A0 - B0 */
+        sub    r4, r5, r9            /* r2 = A1 + B1 */
+        add    r8, r5, r9            /* r2 = A1 - B1 */
+        add    r5, r6, r10           /* r1 = A2 + B2 */
+        sub    r9, r6, r10           /* r1 = A2 - B2 */
+        add    r6, r7, r11           /* r2 = A3 + B3 */
+        sub    r10,r7, r11           /* r2 = A3 - B3 */
         .endm
 
 /*
   Compute final part of IDCT single row.
   shift = right-shift amount
-  Input/output in registers v1--v8
+  Input/output in registers r4--r11
 */
         .macro idct_finish_shift shift
-        add    a4, v1, v5            /* a4 = A0 + B0 */
-        sub    a3, v1, v5            /* a3 = A0 - B0 */
-        mov    v1, a4, asr #\shift
-        mov    v5, a3, asr #\shift
-
-        sub    a4, v2, v6            /* a4 = A1 + B1 */
-        add    a3, v2, v6            /* a3 = A1 - B1 */
-        mov    v2, a4, asr #\shift
-        mov    v6, a3, asr #\shift
-
-        add    a4, v3, v7            /* a4 = A2 + B2 */
-        sub    a3, v3, v7            /* a3 = A2 - B2 */
-        mov    v3, a4, asr #\shift
-        mov    v7, a3, asr #\shift
-
-        add    a4, v4, fp            /* a4 = A3 + B3 */
-        sub    a3, v4, fp            /* a3 = A3 - B3 */
-        mov    v4, a4, asr #\shift
-        mov    fp, a3, asr #\shift
+        add    r3, r4, r8            /* r3 = A0 + B0 */
+        sub    r2, r4, r8            /* r2 = A0 - B0 */
+        mov    r4, r3, asr #\shift
+        mov    r8, r2, asr #\shift
+
+        sub    r3, r5, r9            /* r3 = A1 + B1 */
+        add    r2, r5, r9            /* r2 = A1 - B1 */
+        mov    r5, r3, asr #\shift
+        mov    r9, r2, asr #\shift
+
+        add    r3, r6, r10           /* r3 = A2 + B2 */
+        sub    r2, r6, r10           /* r2 = A2 - B2 */
+        mov    r6, r3, asr #\shift
+        mov    r10,r2, asr #\shift
+
+        add    r3, r7, r11           /* r3 = A3 + B3 */
+        sub    r2, r7, r11           /* r2 = A3 - B3 */
+        mov    r7, r3, asr #\shift
+        mov    r11,r2, asr #\shift
         .endm
 
 /*
   Compute final part of IDCT single row, saturating results at 8 bits.
   shift = right-shift amount
-  Input/output in registers v1--v8
+  Input/output in registers r4--r11
 */
         .macro idct_finish_shift_sat shift
-        add    a4, v1, v5            /* a4 = A0 + B0 */
-        sub    ip, v1, v5            /* ip = A0 - B0 */
-        usat   v1, #8, a4, asr #\shift
-        usat   v5, #8, ip, asr #\shift
-
-        sub    a4, v2, v6            /* a4 = A1 + B1 */
-        add    ip, v2, v6            /* ip = A1 - B1 */
-        usat   v2, #8, a4, asr #\shift
-        usat   v6, #8, ip, asr #\shift
-
-        add    a4, v3, v7            /* a4 = A2 + B2 */
-        sub    ip, v3, v7            /* ip = A2 - B2 */
-        usat   v3, #8, a4, asr #\shift
-        usat   v7, #8, ip, asr #\shift
-
-        add    a4, v4, fp            /* a4 = A3 + B3 */
-        sub    ip, v4, fp            /* ip = A3 - B3 */
-        usat   v4, #8, a4, asr #\shift
-        usat   fp, #8, ip, asr #\shift
+        add    r3, r4, r8            /* r3 = A0 + B0 */
+        sub    ip, r4, r8            /* ip = A0 - B0 */
+        usat   r4, #8, r3, asr #\shift
+        usat   r8, #8, ip, asr #\shift
+
+        sub    r3, r5, r9            /* r3 = A1 + B1 */
+        add    ip, r5, r9            /* ip = A1 - B1 */
+        usat   r5, #8, r3, asr #\shift
+        usat   r9, #8, ip, asr #\shift
+
+        add    r3, r6, r10           /* r3 = A2 + B2 */
+        sub    ip, r6, r10           /* ip = A2 - B2 */
+        usat   r6, #8, r3, asr #\shift
+        usat   r10,#8, ip, asr #\shift
+
+        add    r3, r7, r11           /* r3 = A3 + B3 */
+        sub    ip, r7, r11           /* ip = A3 - B3 */
+        usat   r7, #8, r3, asr #\shift
+        usat   r11,#8, ip, asr #\shift
         .endm
 
 /*
   Compute IDCT of single row, storing as column.
-  a1 = source
-  a2 = dest
+  r0 = source
+  r1 = dest
 */
 function idct_row_armv6
-        str    lr, [sp, #-4]!
+        push   {lr}
 
-        ldr    lr, [a1, #12]         /* lr = row[7,5] */
-        ldr    ip, [a1, #4]          /* ip = row[6,4] */
-        ldr    a4, [a1, #8]          /* a4 = row[3,1] */
-        ldr    a3, [a1]              /* a3 = row[2,0] */
+        ldr    lr, [r0, #12]         /* lr = row[7,5] */
+        ldr    ip, [r0, #4]          /* ip = row[6,4] */
+        ldr    r3, [r0, #8]          /* r3 = row[3,1] */
+        ldr    r2, [r0]              /* r2 = row[2,0] */
         orrs   lr, lr, ip
-        cmpeq  lr, a4
-        cmpeq  lr, a3, lsr #16
+        cmpeq  lr, r3
+        cmpeq  lr, r2, lsr #16
         beq    1f
-        str    a2, [sp, #-4]!
-        ldr    ip, [pc, #(w42-.-8)]  /* ip = W4 | (W2 << 16) */
+        push   {r1}
+        ldr    ip, w42               /* ip = W4 | (W2 << 16) */
         cmp    lr, #0
         beq    2f
 
@@ -213,142 +213,142 @@ function idct_row_armv6
 
 2:      idct_row4  ROW_SHIFT
 
-3:      ldr    a2, [sp], #4
+3:      pop    {r1}
         idct_finish_shift ROW_SHIFT
 
-        strh   v1, [a2]
-        strh   v2, [a2, #(16*2)]
-        strh   v3, [a2, #(16*4)]
-        strh   v4, [a2, #(16*6)]
-        strh   fp, [a2, #(16*1)]
-        strh   v7, [a2, #(16*3)]
-        strh   v6, [a2, #(16*5)]
-        strh   v5, [a2, #(16*7)]
-
-        ldr    pc, [sp], #4
-
-1:      mov    a3, a3, lsl #3
-        strh   a3, [a2]
-        strh   a3, [a2, #(16*2)]
-        strh   a3, [a2, #(16*4)]
-        strh   a3, [a2, #(16*6)]
-        strh   a3, [a2, #(16*1)]
-        strh   a3, [a2, #(16*3)]
-        strh   a3, [a2, #(16*5)]
-        strh   a3, [a2, #(16*7)]
-        ldr    pc, [sp], #4
+        strh   r4, [r1]
+        strh   r5, [r1, #(16*2)]
+        strh   r6, [r1, #(16*4)]
+        strh   r7, [r1, #(16*6)]
+        strh   r11,[r1, #(16*1)]
+        strh   r10,[r1, #(16*3)]
+        strh   r9, [r1, #(16*5)]
+        strh   r8, [r1, #(16*7)]
+
+        pop    {pc}
+
+1:      mov    r2, r2, lsl #3
+        strh   r2, [r1]
+        strh   r2, [r1, #(16*2)]
+        strh   r2, [r1, #(16*4)]
+        strh   r2, [r1, #(16*6)]
+        strh   r2, [r1, #(16*1)]
+        strh   r2, [r1, #(16*3)]
+        strh   r2, [r1, #(16*5)]
+        strh   r2, [r1, #(16*7)]
+        pop    {pc}
         .endfunc
 
 /*
   Compute IDCT of single column, read as row.
-  a1 = source
-  a2 = dest
+  r0 = source
+  r1 = dest
 */
 function idct_col_armv6
-        stmfd  sp!, {a2, lr}
+        push   {r1, lr}
 
-        ldr    a3, [a1]              /* a3 = row[2,0] */
-        ldr    ip, [pc, #(w42-.-8)]  /* ip = W4 | (W2 << 16) */
-        ldr    a4, [a1, #8]          /* a4 = row[3,1] */
+        ldr    r2, [r0]              /* r2 = row[2,0] */
+        ldr    ip, w42               /* ip = W4 | (W2 << 16) */
+        ldr    r3, [r0, #8]          /* r3 = row[3,1] */
         idct_row COL_SHIFT
-        ldr    a2, [sp], #4
+        pop    {r1}
         idct_finish_shift COL_SHIFT
 
-        strh   v1, [a2]
-        strh   v2, [a2, #(16*1)]
-        strh   v3, [a2, #(16*2)]
-        strh   v4, [a2, #(16*3)]
-        strh   fp, [a2, #(16*4)]
-        strh   v7, [a2, #(16*5)]
-        strh   v6, [a2, #(16*6)]
-        strh   v5, [a2, #(16*7)]
+        strh   r4, [r1]
+        strh   r5, [r1, #(16*1)]
+        strh   r6, [r1, #(16*2)]
+        strh   r7, [r1, #(16*3)]
+        strh   r11,[r1, #(16*4)]
+        strh   r10,[r1, #(16*5)]
+        strh   r9, [r1, #(16*6)]
+        strh   r8, [r1, #(16*7)]
 
-        ldr    pc, [sp], #4
+        pop    {pc}
         .endfunc
 
 /*
   Compute IDCT of single column, read as row, store saturated 8-bit.
-  a1 = source
-  a2 = dest
-  a3 = line size
+  r0 = source
+  r1 = dest
+  r2 = line size
 */
 function idct_col_put_armv6
-        stmfd  sp!, {a2, a3, lr}
+        push   {r1, r2, lr}
 
-        ldr    a3, [a1]              /* a3 = row[2,0] */
-        ldr    ip, [pc, #(w42-.-8)]  /* ip = W4 | (W2 << 16) */
-        ldr    a4, [a1, #8]          /* a4 = row[3,1] */
+        ldr    r2, [r0]              /* r2 = row[2,0] */
+        ldr    ip, w42               /* ip = W4 | (W2 << 16) */
+        ldr    r3, [r0, #8]          /* r3 = row[3,1] */
         idct_row COL_SHIFT
-        ldmfd  sp!, {a2, a3}
+        pop    {r1, r2}
         idct_finish_shift_sat COL_SHIFT
 
-        strb   v1, [a2], a3
-        strb   v2, [a2], a3
-        strb   v3, [a2], a3
-        strb   v4, [a2], a3
-        strb   fp, [a2], a3
-        strb   v7, [a2], a3
-        strb   v6, [a2], a3
-        strb   v5, [a2], a3
+        strb   r4, [r1], r2
+        strb   r5, [r1], r2
+        strb   r6, [r1], r2
+        strb   r7, [r1], r2
+        strb   r11,[r1], r2
+        strb   r10,[r1], r2
+        strb   r9, [r1], r2
+        strb   r8, [r1], r2
 
-        sub    a2, a2, a3, lsl #3
+        sub    r1, r1, r2, lsl #3
 
-        ldr    pc, [sp], #4
+        pop    {pc}
         .endfunc
 
 /*
   Compute IDCT of single column, read as row, add/store saturated 8-bit.
-  a1 = source
-  a2 = dest
-  a3 = line size
+  r0 = source
+  r1 = dest
+  r2 = line size
 */
 function idct_col_add_armv6
-        stmfd  sp!, {a2, a3, lr}
+        push   {r1, r2, lr}
 
-        ldr    a3, [a1]              /* a3 = row[2,0] */
-        ldr    ip, [pc, #(w42-.-8)]  /* ip = W4 | (W2 << 16) */
-        ldr    a4, [a1, #8]          /* a4 = row[3,1] */
+        ldr    r2, [r0]              /* r2 = row[2,0] */
+        ldr    ip, w42               /* ip = W4 | (W2 << 16) */
+        ldr    r3, [r0, #8]          /* r3 = row[3,1] */
         idct_row COL_SHIFT
-        ldmfd  sp!, {a2, a3}
+        pop    {r1, r2}
         idct_finish
 
-        ldrb   a4, [a2]
-        ldrb   v4, [a2, a3]
-        ldrb   fp, [a2, a3, lsl #2]
-        add    ip, a4, ip, asr #COL_SHIFT
+        ldrb   r3, [r1]
+        ldrb   r7, [r1, r2]
+        ldrb   r11,[r1, r2, lsl #2]
+        add    ip, r3, ip, asr #COL_SHIFT
         usat   ip, #8, ip
-        add    v1, v4, v1, asr #COL_SHIFT
-        strb   ip, [a2], a3
-        ldrb   ip, [a2, a3]
-        usat   v1, #8, v1
-        ldrb   fp, [a2, a3, lsl #2]
-        add    v2, ip, v2, asr #COL_SHIFT
-        usat   v2, #8, v2
-        strb   v1, [a2], a3
-        ldrb   a4, [a2, a3]
-        ldrb   ip, [a2, a3, lsl #2]
-        strb   v2, [a2], a3
-        ldrb   v4, [a2, a3]
-        ldrb   v1, [a2, a3, lsl #2]
-        add    v3, a4, v3, asr #COL_SHIFT
-        usat   v3, #8, v3
-        add    v7, v4, v7, asr #COL_SHIFT
-        usat   v7, #8, v7
-        add    v6, fp, v6, asr #COL_SHIFT
-        usat   v6, #8, v6
-        add    v5, ip, v5, asr #COL_SHIFT
-        usat   v5, #8, v5
-        add    lr, v1, lr, asr #COL_SHIFT
+        add    r4, r7, r4, asr #COL_SHIFT
+        strb   ip, [r1], r2
+        ldrb   ip, [r1, r2]
+        usat   r4, #8, r4
+        ldrb   r11,[r1, r2, lsl #2]
+        add    r5, ip, r5, asr #COL_SHIFT
+        usat   r5, #8, r5
+        strb   r4, [r1], r2
+        ldrb   r3, [r1, r2]
+        ldrb   ip, [r1, r2, lsl #2]
+        strb   r5, [r1], r2
+        ldrb   r7, [r1, r2]
+        ldrb   r4, [r1, r2, lsl #2]
+        add    r6, r3, r6, asr #COL_SHIFT
+        usat   r6, #8, r6
+        add    r10,r7, r10,asr #COL_SHIFT
+        usat   r10,#8, r10
+        add    r9, r11,r9, asr #COL_SHIFT
+        usat   r9, #8, r9
+        add    r8, ip, r8, asr #COL_SHIFT
+        usat   r8, #8, r8
+        add    lr, r4, lr, asr #COL_SHIFT
         usat   lr, #8, lr
-        strb   v3, [a2], a3
-        strb   v7, [a2], a3
-        strb   v6, [a2], a3
-        strb   v5, [a2], a3
-        strb   lr, [a2], a3
+        strb   r6, [r1], r2
+        strb   r10,[r1], r2
+        strb   r9, [r1], r2
+        strb   r8, [r1], r2
+        strb   lr, [r1], r2
 
-        sub    a2, a2, a3, lsl #3
+        sub    r1, r1, r2, lsl #3
 
-        ldr    pc, [sp], #4
+        pop    {pc}
         .endfunc
 
 /*
@@ -358,76 +358,76 @@ function idct_col_add_armv6
 */
         .macro idct_rows func width
         bl     \func
-        add    a1, a1, #(16*2)
-        add    a2, a2, #\width
+        add    r0, r0, #(16*2)
+        add    r1, r1, #\width
         bl     \func
-        add    a1, a1, #(16*2)
-        add    a2, a2, #\width
+        add    r0, r0, #(16*2)
+        add    r1, r1, #\width
         bl     \func
-        add    a1, a1, #(16*2)
-        add    a2, a2, #\width
+        add    r0, r0, #(16*2)
+        add    r1, r1, #\width
         bl     \func
-        sub    a1, a1, #(16*5)
-        add    a2, a2, #\width
+        sub    r0, r0, #(16*5)
+        add    r1, r1, #\width
         bl     \func
-        add    a1, a1, #(16*2)
-        add    a2, a2, #\width
+        add    r0, r0, #(16*2)
+        add    r1, r1, #\width
         bl     \func
-        add    a1, a1, #(16*2)
-        add    a2, a2, #\width
+        add    r0, r0, #(16*2)
+        add    r1, r1, #\width
         bl     \func
-        add    a1, a1, #(16*2)
-        add    a2, a2, #\width
+        add    r0, r0, #(16*2)
+        add    r1, r1, #\width
         bl     \func
 
-        sub    a1, a1, #(16*7)
+        sub    r0, r0, #(16*7)
         .endm
 
 /* void ff_simple_idct_armv6(DCTELEM *data); */
 function ff_simple_idct_armv6, export=1
-        stmfd  sp!, {v1, v2, v3, v4, v5, v6, v7, fp, lr}
+        push   {r4-r11, lr}
         sub    sp, sp, #128
 
-        mov    a2, sp
+        mov    r1, sp
         idct_rows idct_row_armv6, 2
-        mov    a2, a1
-        mov    a1, sp
+        mov    r1, r0
+        mov    r0, sp
         idct_rows idct_col_armv6, 2
 
         add    sp, sp, #128
-        ldmfd  sp!, {v1, v2, v3, v4, v5, v6, v7, fp, pc}
+        pop    {r4-r11, pc}
         .endfunc
 
 /* ff_simple_idct_add_armv6(uint8_t *dest, int line_size, DCTELEM *data); */
 function ff_simple_idct_add_armv6, export=1
-        stmfd  sp!, {a1, a2, v1, v2, v3, v4, v5, v6, v7, fp, lr}
+        push   {r0, r1, r4-r11, lr}
         sub    sp, sp, #128
 
-        mov    a1, a3
-        mov    a2, sp
+        mov    r0, r2
+        mov    r1, sp
         idct_rows idct_row_armv6, 2
-        mov    a1, sp
-        ldr    a2, [sp, #128]
-        ldr    a3, [sp, #(128+4)]
+        mov    r0, sp
+        ldr    r1, [sp, #128]
+        ldr    r2, [sp, #(128+4)]
         idct_rows idct_col_add_armv6, 1
 
         add    sp, sp, #(128+8)
-        ldmfd  sp!, {v1, v2, v3, v4, v5, v6, v7, fp, pc}
+        pop    {r4-r11, pc}
         .endfunc
 
 /* ff_simple_idct_put_armv6(uint8_t *dest, int line_size, DCTELEM *data); */
 function ff_simple_idct_put_armv6, export=1
-        stmfd  sp!, {a1, a2, v1, v2, v3, v4, v5, v6, v7, fp, lr}
+        push   {r0, r1, r4-r11, lr}
         sub    sp, sp, #128
 
-        mov    a1, a3
-        mov    a2, sp
+        mov    r0, r2
+        mov    r1, sp
         idct_rows idct_row_armv6, 2
-        mov    a1, sp
-        ldr    a2, [sp, #128]
-        ldr    a3, [sp, #(128+4)]
+        mov    r0, sp
+        ldr    r1, [sp, #128]
+        ldr    r2, [sp, #(128+4)]
         idct_rows idct_col_put_armv6, 1
 
         add    sp, sp, #(128+8)
-        ldmfd  sp!, {v1, v2, v3, v4, v5, v6, v7, fp, pc}
+        pop    {r4-r11, pc}
         .endfunc
diff --git a/libavcodec/asv1.c b/libavcodec/asv1.c
index 8f16111..ee91f61 100644
--- a/libavcodec/asv1.c
+++ b/libavcodec/asv1.c
@@ -465,7 +465,7 @@ for(i=0; i<s->avctx->extradata_size; i++){
     return (get_bits_count(&a->gb)+31)/32*4;
 }
 
-#if defined(CONFIG_ASV1_ENCODER) || defined(CONFIG_ASV2_ENCODER)
+#if CONFIG_ASV1_ENCODER || CONFIG_ASV2_ENCODER
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
     ASV1Context * const a = avctx->priv_data;
     AVFrame *pict = data;
@@ -519,7 +519,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
 
     return size*4;
 }
-#endif /* defined(CONFIG_ASV1_ENCODER) || defined(CONFIG_ASV2_ENCODER) */
+#endif /* CONFIG_ASV1_ENCODER || CONFIG_ASV2_ENCODER */
 
 static av_cold void common_init(AVCodecContext *avctx){
     ASV1Context * const a = avctx->priv_data;
@@ -569,7 +569,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
     return 0;
 }
 
-#if defined(CONFIG_ASV1_ENCODER) || defined(CONFIG_ASV2_ENCODER)
+#if CONFIG_ASV1_ENCODER || CONFIG_ASV2_ENCODER
 static av_cold int encode_init(AVCodecContext *avctx){
     ASV1Context * const a = avctx->priv_data;
     int i;
@@ -584,7 +584,7 @@ static av_cold int encode_init(AVCodecContext *avctx){
     avctx->extradata= av_mallocz(8);
     avctx->extradata_size=8;
     ((uint32_t*)avctx->extradata)[0]= le2me_32(a->inv_qscale);
-    ((uint32_t*)avctx->extradata)[1]= le2me_32(ff_get_fourcc("ASUS"));
+    ((uint32_t*)avctx->extradata)[1]= le2me_32(AV_RL32("ASUS"));
 
     for(i=0; i<64; i++){
         int q= 32*scale*ff_mpeg1_default_intra_matrix[i];
@@ -593,7 +593,7 @@ static av_cold int encode_init(AVCodecContext *avctx){
 
     return 0;
 }
-#endif /* defined(CONFIG_ASV1_ENCODER) || defined(CONFIG_ASV2_ENCODER) */
+#endif /* CONFIG_ASV1_ENCODER || CONFIG_ASV2_ENCODER */
 
 static av_cold int decode_end(AVCodecContext *avctx){
     ASV1Context * const a = avctx->priv_data;
@@ -631,7 +631,7 @@ AVCodec asv2_decoder = {
     .long_name= NULL_IF_CONFIG_SMALL("ASUS V2"),
 };
 
-#ifdef CONFIG_ASV1_ENCODER
+#if CONFIG_ASV1_ENCODER
 AVCodec asv1_encoder = {
     "asv1",
     CODEC_TYPE_VIDEO,
@@ -645,7 +645,7 @@ AVCodec asv1_encoder = {
 };
 #endif
 
-#ifdef CONFIG_ASV2_ENCODER
+#if CONFIG_ASV2_ENCODER
 AVCodec asv2_encoder = {
     "asv2",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3d3e244..edd4a7b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 10
+#define LIBAVCODEC_VERSION_MINOR 11
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -191,9 +191,6 @@ enum CodecID {
     CODEC_ID_TGV,
     CODEC_ID_TGQ,
 
-    /* "codecs" for HW decoding with VDPAU */
-    CODEC_ID_H264_VDPAU= 0x9000,
-
     /* various PCM "codecs" */
     CODEC_ID_PCM_S16LE= 0x10000,
     CODEC_ID_PCM_S16BE,
@@ -248,6 +245,7 @@ enum CodecID {
     CODEC_ID_ADPCM_IMA_EA_EACS,
     CODEC_ID_ADPCM_EA_XAS,
     CODEC_ID_ADPCM_EA_MAXIS_XA,
+    CODEC_ID_ADPCM_IMA_ISS,
 
     /* AMR */
     CODEC_ID_AMR_NB= 0x12000,
@@ -309,6 +307,7 @@ enum CodecID {
     CODEC_ID_ATRAC3P,
     CODEC_ID_EAC3,
     CODEC_ID_SIPR,
+    CODEC_ID_MP1,
 
     /* subtitle codecs */
     CODEC_ID_DVD_SUBTITLE= 0x17000,
@@ -1399,6 +1398,7 @@ typedef struct AVCodecContext {
 #define FF_IDCT_FAAN          20
 #define FF_IDCT_EA            21
 #define FF_IDCT_SIMPLENEON    22
+#define FF_IDCT_SIMPLEALPHA   23
 
     /**
      * slice count
diff --git a/libavcodec/bfin/mathops.h b/libavcodec/bfin/mathops.h
index 1dd9338..8af789d 100644
--- a/libavcodec/bfin/mathops.h
+++ b/libavcodec/bfin/mathops.h
@@ -22,7 +22,7 @@
 #ifndef AVCODEC_BFIN_MATHOPS_H
 #define AVCODEC_BFIN_MATHOPS_H
 
-#ifdef CONFIG_MPEGAUDIO_HP
+#if CONFIG_MPEGAUDIO_HP
 #define MULH(X,Y) ({ int xxo;                           \
     __asm__ (                                               \
         "a1 = %2.L * %1.L (FU);\n\t"                    \
diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 57f1391..a43f031 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -82,7 +82,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
 
     if(length==0) return;
 
-    if(ENABLE_SMALL || words < 16 || put_bits_count(pb)&7){
+    if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
         for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
     }else{
         for(i=0; put_bits_count(pb)&31; i++)
diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h
index 23bc34d..0f81106 100644
--- a/libavcodec/bitstream.h
+++ b/libavcodec/bitstream.h
@@ -41,7 +41,7 @@
 //#define ALT_BITSTREAM_WRITER
 //#define ALIGNED_BITSTREAM_WRITER
 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
-#   ifdef ARCH_ARM
+#   if ARCH_ARM
 #       define A32_BITSTREAM_READER
 #   else
 #       define ALT_BITSTREAM_READER
@@ -52,7 +52,7 @@
 
 extern const uint8_t ff_reverse[256];
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 // avoid +32 for shift optimization (gcc should do that ...)
 static inline  int32_t NEG_SSR32( int32_t a, int8_t s){
     __asm__ ("sarl %1, %0\n\t"
@@ -196,7 +196,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
 #ifdef BITSTREAM_WRITER_LE
     bit_buf |= value << (32 - bit_left);
     if (n >= bit_left) {
-#ifndef HAVE_FAST_UNALIGNED
+#if !HAVE_FAST_UNALIGNED
         if (3 & (intptr_t) s->buf_ptr) {
             s->buf_ptr[0] = bit_buf      ;
             s->buf_ptr[1] = bit_buf >>  8;
@@ -217,7 +217,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
     } else {
         bit_buf<<=bit_left;
         bit_buf |= value >> (n - bit_left);
-#ifndef HAVE_FAST_UNALIGNED
+#if !HAVE_FAST_UNALIGNED
         if (3 & (intptr_t) s->buf_ptr) {
             s->buf_ptr[0] = bit_buf >> 24;
             s->buf_ptr[1] = bit_buf >> 16;
@@ -243,7 +243,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
 {
 #    ifdef ALIGNED_BITSTREAM_WRITER
-#        if defined(ARCH_X86)
+#        if ARCH_X86
     __asm__ volatile(
         "movl %0, %%ecx                 \n\t"
         "xorl %%eax, %%eax              \n\t"
@@ -274,7 +274,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
     s->index= index;
 #        endif
 #    else //ALIGNED_BITSTREAM_WRITER
-#        if defined(ARCH_X86)
+#        if ARCH_X86
     __asm__ volatile(
         "movl $7, %%ecx                 \n\t"
         "andl %0, %%ecx                 \n\t"
@@ -550,7 +550,7 @@ static inline void skip_bits_long(GetBitContext *s, int n){
         name##_bit_count-= 32;\
     }\
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 #   define SKIP_CACHE(name, gb, num)\
         __asm__(\
             "shldl %2, %1, %0          \n\t"\
diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index e0d7111..0f2178a 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -23,6 +23,7 @@
 #define AVCODEC_BYTESTREAM_H
 
 #include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
 
 #define DEF_T(type, name, bytes, read, write)                             \
 static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\
diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h
index e012727..caed722 100644
--- a/libavcodec/cabac.h
+++ b/libavcodec/cabac.h
@@ -270,7 +270,7 @@ static void refill(CABACContext *c){
     c->bytestream+= CABAC_BITS/8;
 }
 
-#if ! ( defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) )
+#if ! ( ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) )
 static void refill2(CABACContext *c){
     int i, x;
 
@@ -372,7 +372,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
     //FIXME gcc generates duplicate load/stores for c->low and c->range
 #define LOW          "0"
 #define RANGE        "4"
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #define BYTESTART   "16"
 #define BYTE        "24"
 #define BYTEEND     "32"
@@ -381,7 +381,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
 #define BYTE        "16"
 #define BYTEEND     "20"
 #endif
-#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS)
+#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
     int bit;
 
 #ifndef BRANCHLESS_CABAC_DECODER
@@ -467,7 +467,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
 #else /* BRANCHLESS_CABAC_DECODER */
 
 
-#if defined HAVE_FAST_CMOV
+#if HAVE_FAST_CMOV
 #define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
         "mov    "tmp"       , %%ecx                                     \n\t"\
         "shl    $17         , "tmp"                                     \n\t"\
@@ -537,7 +537,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
     );
     bit&=1;
 #endif /* BRANCHLESS_CABAC_DECODER */
-#else /* defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */
+#else /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
     int s = *state;
     int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
     int bit, lps_mask av_unused;
@@ -576,7 +576,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
     if(!(c->low & CABAC_MASK))
         refill2(c);
 #endif /* BRANCHLESS_CABAC_DECODER */
-#endif /* defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */
+#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
     return bit;
 }
 
@@ -637,7 +637,7 @@ static int av_unused get_cabac_bypass(CABACContext *c){
 
 
 static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){
-#if defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__))
+#if ARCH_X86 && !(defined(PIC) && defined(__GNUC__))
     __asm__ volatile(
         "movl "RANGE    "(%1), %%ebx            \n\t"
         "movl "LOW      "(%1), %%eax            \n\t"
diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 60219d4..829d4a0 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -28,6 +28,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "golomb.h"
+#include "mathops.h"
 #include "cavs.h"
 #include "cavsdata.h"
 
@@ -37,7 +38,7 @@
  *
  ****************************************************************************/
 
-static inline int get_bs(vector_t *mvP, vector_t *mvQ, int b) {
+static inline int get_bs(cavs_vector *mvP, cavs_vector *mvQ, int b) {
     if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
         return 2;
     if( (abs(mvP->x - mvQ->x) >= 4) ||  (abs(mvP->y - mvQ->y) >= 4) )
@@ -71,7 +72,7 @@ static inline int get_bs(vector_t *mvP, vector_t *mvQ, int b) {
  * ---------
  *
  */
-void ff_cavs_filter(AVSContext *h, enum mb_t mb_type) {
+void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) {
     DECLARE_ALIGNED_8(uint8_t, bs[8]);
     int qp_avg, alpha, beta, tc;
     int i;
@@ -327,7 +328,7 @@ static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
                         int chroma_height,int delta,int list,uint8_t *dest_y,
                         uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
                         int src_y_offset,qpel_mc_func *qpix_op,
-                        h264_chroma_mc_func chroma_op,vector_t *mv){
+                        h264_chroma_mc_func chroma_op,cavs_vector *mv){
     MpegEncContext * const s = &h->s;
     const int mx= mv->x + src_x_offset*8;
     const int my= mv->y + src_y_offset*8;
@@ -382,7 +383,7 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de
                         uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
                         int x_offset, int y_offset,qpel_mc_func *qpix_put,
                         h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
-                        h264_chroma_mc_func chroma_avg, vector_t *mv){
+                        h264_chroma_mc_func chroma_avg, cavs_vector *mv){
     qpel_mc_func *qpix_op=  qpix_put;
     h264_chroma_mc_func chroma_op= chroma_put;
 
@@ -410,7 +411,7 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de
     }
 }
 
-void ff_cavs_inter(AVSContext *h, enum mb_t mb_type) {
+void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) {
     if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16
         mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0,
                 h->s.dsp.put_cavs_qpel_pixels_tab[0],
@@ -447,14 +448,15 @@ void ff_cavs_inter(AVSContext *h, enum mb_t mb_type) {
  *
  ****************************************************************************/
 
-static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) {
+static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, cavs_vector *src, int distp) {
     int den = h->scale_den[src->ref];
 
     *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
     *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
 }
 
-static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, vector_t *mvB, vector_t *mvC) {
+static inline void mv_pred_median(AVSContext *h, cavs_vector *mvP,
+                        cavs_vector *mvA, cavs_vector *mvB, cavs_vector *mvC) {
     int ax, ay, bx, by, cx, cy;
     int len_ab, len_bc, len_ca, len_mid;
 
@@ -479,13 +481,13 @@ static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, v
     }
 }
 
-void ff_cavs_mv(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
-                enum mv_pred_t mode, enum block_t size, int ref) {
-    vector_t *mvP = &h->mv[nP];
-    vector_t *mvA = &h->mv[nP-1];
-    vector_t *mvB = &h->mv[nP-4];
-    vector_t *mvC = &h->mv[nC];
-    const vector_t *mvP2 = NULL;
+void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
+                enum cavs_mv_pred mode, enum cavs_block size, int ref) {
+    cavs_vector *mvP = &h->mv[nP];
+    cavs_vector *mvA = &h->mv[nP-1];
+    cavs_vector *mvB = &h->mv[nP-4];
+    cavs_vector *mvC = &h->mv[nC];
+    const cavs_vector *mvP2 = NULL;
 
     mvP->ref = ref;
     mvP->dist = h->dist[mvP->ref];
@@ -655,15 +657,15 @@ void ff_cavs_init_pic(AVSContext *h) {
 void ff_cavs_init_top_lines(AVSContext *h) {
     /* alloc top line of predictors */
     h->top_qp       = av_malloc( h->mb_width);
-    h->top_mv[0]    = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
-    h->top_mv[1]    = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
+    h->top_mv[0]    = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector));
+    h->top_mv[1]    = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector));
     h->top_pred_Y   = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
     h->top_border_y = av_malloc((h->mb_width+1)*16);
     h->top_border_u = av_malloc((h->mb_width)*10);
     h->top_border_v = av_malloc((h->mb_width)*10);
 
     /* alloc space for co-located MVs and types */
-    h->col_mv       = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
+    h->col_mv       = av_malloc( h->mb_width*h->mb_height*4*sizeof(cavs_vector));
     h->col_type_base = av_malloc(h->mb_width*h->mb_height);
     h->block        = av_mallocz(64*sizeof(DCTELEM));
 }
diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index 2a1a90e..885a2cd 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -55,7 +55,7 @@
 #define MV_BWD_OFFS                     12
 #define MV_STRIDE                        4
 
-enum mb_t {
+enum cavs_mb {
   I_8X8 = 0,
   P_SKIP,
   P_16X16,
@@ -70,14 +70,14 @@ enum mb_t {
   B_8X8 = 29
 };
 
-enum sub_mb_t {
+enum cavs_sub_mb {
   B_SUB_DIRECT,
   B_SUB_FWD,
   B_SUB_BWD,
   B_SUB_SYM
 };
 
-enum intra_luma_t {
+enum cavs_intra_luma {
   INTRA_L_VERT,
   INTRA_L_HORIZ,
   INTRA_L_LP,
@@ -88,7 +88,7 @@ enum intra_luma_t {
   INTRA_L_DC_128
 };
 
-enum intra_chroma_t {
+enum cavs_intra_chroma {
   INTRA_C_LP,
   INTRA_C_HORIZ,
   INTRA_C_VERT,
@@ -98,7 +98,7 @@ enum intra_chroma_t {
   INTRA_C_DC_128,
 };
 
-enum mv_pred_t {
+enum cavs_mv_pred {
   MV_PRED_MEDIAN,
   MV_PRED_LEFT,
   MV_PRED_TOP,
@@ -107,14 +107,14 @@ enum mv_pred_t {
   MV_PRED_BSKIP
 };
 
-enum block_t {
+enum cavs_block {
   BLK_16X16,
   BLK_16X8,
   BLK_8X16,
   BLK_8X8
 };
 
-enum mv_loc_t {
+enum cavs_mv_loc {
   MV_FWD_D3 = 0,
   MV_FWD_B2,
   MV_FWD_B3,
@@ -142,7 +142,7 @@ DECLARE_ALIGNED_8(typedef, struct) {
     int16_t y;
     int16_t dist;
     int16_t ref;
-} vector_t;
+} cavs_vector;
 
 struct dec_2dvlc {
   int8_t rltab[59][3];
@@ -186,9 +186,9 @@ typedef struct {
        D is the macroblock to the top-left (0)
 
        the same is repeated for backward motion vectors */
-    vector_t mv[2*4*3];
-    vector_t *top_mv[2];
-    vector_t *col_mv;
+    cavs_vector mv[2*4*3];
+    cavs_vector *top_mv[2];
+    cavs_vector *col_mv;
 
     /** luma pred mode cache
        0:    --  B2  B3
@@ -236,9 +236,9 @@ extern const int_fast8_t ff_left_modifier_l[8];
 extern const int_fast8_t ff_top_modifier_l[8];
 extern const int_fast8_t ff_left_modifier_c[7];
 extern const int_fast8_t ff_top_modifier_c[7];
-extern const vector_t ff_cavs_intra_mv;
-extern const vector_t ff_cavs_un_mv;
-extern const vector_t ff_cavs_dir_mv;
+extern const cavs_vector ff_cavs_intra_mv;
+extern const cavs_vector ff_cavs_un_mv;
+extern const cavs_vector ff_cavs_dir_mv;
 
 static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
     *mode = mod_table[*mode];
@@ -253,7 +253,7 @@ static inline void set_intra_mode_default(AVSContext *h) {
     h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
 }
 
-static inline void set_mvs(vector_t *mv, enum block_t size) {
+static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
     switch(size) {
     case BLK_16X16:
         mv[MV_STRIDE  ] = mv[0];
@@ -296,14 +296,14 @@ static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
     return 0;
 }
 
-void ff_cavs_filter(AVSContext *h, enum mb_t mb_type);
+void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
 void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
                                   int block);
 void ff_cavs_load_intra_pred_chroma(AVSContext *h);
 void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
-void ff_cavs_inter(AVSContext *h, enum mb_t mb_type);
-void ff_cavs_mv(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
-                enum mv_pred_t mode, enum block_t size, int ref);
+void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
+void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
+                enum cavs_mv_pred mode, enum cavs_block size, int ref);
 void ff_cavs_init_mb(AVSContext *h);
 int  ff_cavs_next_mb(AVSContext *h);
 void ff_cavs_init_pic(AVSContext *h);
diff --git a/libavcodec/cavsdata.h b/libavcodec/cavsdata.h
index 6d80ac1..b597da1 100644
--- a/libavcodec/cavsdata.h
+++ b/libavcodec/cavsdata.h
@@ -90,14 +90,14 @@ const uint16_t ff_cavs_dequant_mul[64] = {
 
 /** marks block as unavailable, i.e. out of picture
     or not yet decoded */
-const vector_t ff_cavs_un_mv    = {0,0,1,NOT_AVAIL};
+const cavs_vector ff_cavs_un_mv    = {0,0,1,NOT_AVAIL};
 
 /** marks block as "no prediction from this direction"
     e.g. forward motion vector in BWD partition */
-const vector_t ff_cavs_dir_mv   = {0,0,1,REF_DIR};
+const cavs_vector ff_cavs_dir_mv   = {0,0,1,REF_DIR};
 
 /** marks block as using intra prediction */
-const vector_t ff_cavs_intra_mv = {0,0,1,REF_INTRA};
+const cavs_vector ff_cavs_intra_mv = {0,0,1,REF_INTRA};
 
 #define EOB 0,0,0
 
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index 18dcb57..dbf7252 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -59,9 +59,9 @@ static inline void store_mvs(AVSContext *h) {
     h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3];
 }
 
-static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw,
-                                  vector_t *col_mv) {
-    vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS;
+static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
+                                  cavs_vector *col_mv) {
+    cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
     int den = h->direct_den[col_mv->ref];
     int m = col_mv->x >> 31;
 
@@ -77,8 +77,8 @@ static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw,
     pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m);
 }
 
-static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) {
-    vector_t *dst = src + MV_BWD_OFFS;
+static inline void mv_pred_sym(AVSContext *h, cavs_vector *src, enum cavs_block size) {
+    cavs_vector *dst = src + MV_BWD_OFFS;
 
     /* backward mv is the scaled and negated forward mv */
     dst->x = -((src->x * h->sym_factor + 256) >> 9);
@@ -252,7 +252,7 @@ static int decode_mb_i(AVSContext *h, int cbp_code) {
     return 0;
 }
 
-static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
+static void decode_mb_p(AVSContext *h, enum cavs_mb mb_type) {
     GetBitContext *gb = &h->s.gb;
     int ref[4];
 
@@ -296,9 +296,9 @@ static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
     *h->col_type = mb_type;
 }
 
-static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
+static void decode_mb_b(AVSContext *h, enum cavs_mb mb_type) {
     int block;
-    enum sub_mb_t sub_type[4];
+    enum cavs_sub_mb sub_type[4];
     int flags;
 
     ff_cavs_init_mb(h);
@@ -447,7 +447,7 @@ static inline void check_for_slice(AVSContext *h) {
 static int decode_pic(AVSContext *h) {
     MpegEncContext *s = &h->s;
     int skip_count;
-    enum mb_t mb_type;
+    enum cavs_mb mb_type;
 
     if (!s->context_initialized) {
         s->avctx->idct_algo = FF_IDCT_CAVS;
@@ -567,8 +567,8 @@ static int decode_pic(AVSContext *h) {
     if(h->pic_type != FF_B_TYPE) {
         if(h->DPB[1].data[0])
             s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
-        memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture));
-        memcpy(&h->DPB[0], &h->picture, sizeof(Picture));
+        h->DPB[1] = h->DPB[0];
+        h->DPB[0] = h->picture;
         memset(&h->picture,0,sizeof(Picture));
     }
     return 0;
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index 8c2efba..57a9fa5 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 
@@ -77,12 +78,12 @@ static void cinepak_decode_codebook (cvid_codebook *codebook,
     int      i, n;
 
     /* check if this chunk contains 4- or 6-element vectors */
-    n    = (chunk_id & 0x0400) ? 4 : 6;
+    n    = (chunk_id & 0x04) ? 4 : 6;
     flag = 0;
     mask = 0;
 
     for (i=0; i < 256; i++) {
-        if ((chunk_id & 0x0100) && !(mask >>= 1)) {
+        if ((chunk_id & 0x01) && !(mask >>= 1)) {
             if ((data + 4) > eod)
                 break;
 
@@ -91,7 +92,7 @@ static void cinepak_decode_codebook (cvid_codebook *codebook,
             mask  = 0x80000000;
         }
 
-        if (!(chunk_id & 0x0100) || (flag & mask)) {
+        if (!(chunk_id & 0x01) || (flag & mask)) {
             if ((data + n) > eod)
                 break;
 
@@ -144,7 +145,7 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip,
         iv[1] = iv[0] + s->frame.linesize[2];
 
         for (x=strip->x1; x < strip->x2; x+=4) {
-            if ((chunk_id & 0x0100) && !(mask >>= 1)) {
+            if ((chunk_id & 0x01) && !(mask >>= 1)) {
                 if ((data + 4) > eod)
                     return -1;
 
@@ -153,8 +154,8 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip,
                 mask  = 0x80000000;
             }
 
-            if (!(chunk_id & 0x0100) || (flag & mask)) {
-                if (!(chunk_id & 0x0200) && !(mask >>= 1)) {
+            if (!(chunk_id & 0x01) || (flag & mask)) {
+                if (!(chunk_id & 0x02) && !(mask >>= 1)) {
                     if ((data + 4) > eod)
                         return -1;
 
@@ -163,7 +164,7 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip,
                     mask  = 0x80000000;
                 }
 
-                if ((chunk_id & 0x0200) || (~flag & mask)) {
+                if ((chunk_id & 0x02) || (~flag & mask)) {
                     if (data >= eod)
                         return -1;
 
@@ -274,8 +275,8 @@ static int cinepak_decode_strip (CinepakContext *s,
         return -1;
 
     while ((data + 4) <= eod) {
-        chunk_id   = AV_RB16 (&data[0]);
-        chunk_size = AV_RB16 (&data[2]) - 4;
+        chunk_id   = data[0];
+        chunk_size = AV_RB24 (&data[1]) - 4;
         if(chunk_size < 0)
             return -1;
 
@@ -284,25 +285,25 @@ static int cinepak_decode_strip (CinepakContext *s,
 
         switch (chunk_id) {
 
-        case 0x2000:
-        case 0x2100:
-        case 0x2400:
-        case 0x2500:
+        case 0x20:
+        case 0x21:
+        case 0x24:
+        case 0x25:
             cinepak_decode_codebook (strip->v4_codebook, chunk_id,
                 chunk_size, data);
             break;
 
-        case 0x2200:
-        case 0x2300:
-        case 0x2600:
-        case 0x2700:
+        case 0x22:
+        case 0x23:
+        case 0x26:
+        case 0x27:
             cinepak_decode_codebook (strip->v1_codebook, chunk_id,
                 chunk_size, data);
             break;
 
-        case 0x3000:
-        case 0x3100:
-        case 0x3200:
+        case 0x30:
+        case 0x31:
+        case 0x32:
             return cinepak_decode_vectors (s, strip, chunk_id,
                 chunk_size, data);
         }
@@ -357,13 +358,13 @@ static int cinepak_decode (CinepakContext *s)
         if ((s->data + 12) > eod)
             return -1;
 
-        s->strips[i].id = AV_RB16 (s->data);
+        s->strips[i].id = s->data[0];
         s->strips[i].y1 = y0;
         s->strips[i].x1 = 0;
         s->strips[i].y2 = y0 + AV_RB16 (&s->data[8]);
         s->strips[i].x2 = s->avctx->width;
 
-        strip_size = AV_RB16 (&s->data[2]) - 12;
+        strip_size = AV_RB24 (&s->data[1]) - 12;
         s->data   += 12;
         strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size;
 
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c
index c80af01..bb8ae2c 100644
--- a/libavcodec/cljr.c
+++ b/libavcodec/cljr.c
@@ -30,6 +30,7 @@
 
 /* Disable the encoder. */
 #undef CONFIG_CLJR_ENCODER
+#define CONFIG_CLJR_ENCODER 0
 
 typedef struct CLJRContext{
     AVCodecContext *avctx;
@@ -84,7 +85,7 @@ static int decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-#ifdef CONFIG_CLJR_ENCODER
+#if CONFIG_CLJR_ENCODER
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
     CLJRContext * const a = avctx->priv_data;
     AVFrame *pict = data;
@@ -124,7 +125,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
     return 0;
 }
 
-#ifdef CONFIG_CLJR_ENCODER
+#if CONFIG_CLJR_ENCODER
 static av_cold int encode_init(AVCodecContext *avctx){
 
     common_init(avctx);
@@ -146,7 +147,7 @@ AVCodec cljr_decoder = {
     .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
 };
 
-#ifdef CONFIG_CLJR_ENCODER
+#if CONFIG_CLJR_ENCODER
 AVCodec cljr_encoder = {
     "cljr",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/cscd.c b/libavcodec/cscd.c
index ada6a71..55bf2ec 100644
--- a/libavcodec/cscd.c
+++ b/libavcodec/cscd.c
@@ -23,7 +23,7 @@
 
 #include "avcodec.h"
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 #include "libavutil/lzo.h"
@@ -163,7 +163,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
             break;
         }
         case 1: { // zlib compression
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
             unsigned long dlen = c->decomp_size;
             if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK)
                 av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n");
diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c
index 04f75b0..3f62f6d 100644
--- a/libavcodec/dct-test.c
+++ b/libavcodec/dct-test.c
@@ -70,6 +70,8 @@ void simple_idct_armv5te(DCTELEM *data);
 void ff_simple_idct_armv6(DCTELEM *data);
 void ff_simple_idct_neon(DCTELEM *data);
 
+void ff_simple_idct_axp(DCTELEM *data);
+
 struct algo {
   const char *name;
   enum { FDCT, IDCT } is_idct;
@@ -97,14 +99,14 @@ struct algo algos[] = {
   {"INT",             1, j_rev_dct,          idct, MMX_PERM},
   {"SIMPLE-C",        1, ff_simple_idct,     idct, NO_PERM},
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
   {"MMX",             0, ff_fdct_mmx,        fdct, NO_PERM, FF_MM_MMX},
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
   {"MMX2",            0, ff_fdct_mmx2,       fdct, NO_PERM, FF_MM_MMXEXT},
   {"SSE2",            0, ff_fdct_sse2,       fdct, NO_PERM, FF_MM_SSE2},
 #endif
 
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
   {"LIBMPEG2-MMX",    1, ff_mmx_idct,        idct, MMX_PERM, FF_MM_MMX},
   {"LIBMPEG2-MMXEXT", 1, ff_mmxext_idct,     idct, MMX_PERM, FF_MM_MMXEXT},
 #endif
@@ -114,29 +116,33 @@ struct algo algos[] = {
   {"XVID-SSE2",       1, ff_idct_xvid_sse2,  idct, SSE2_PERM, FF_MM_SSE2},
 #endif
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
   {"altivecfdct",     0, fdct_altivec,       fdct, NO_PERM, FF_MM_ALTIVEC},
 #endif
 
-#ifdef ARCH_BFIN
+#if ARCH_BFIN
   {"BFINfdct",        0, ff_bfin_fdct,       fdct, NO_PERM},
   {"BFINidct",        1, ff_bfin_idct,       idct, NO_PERM},
 #endif
 
-#ifdef ARCH_ARM
+#if ARCH_ARM
   {"SIMPLE-ARM",      1, simple_idct_ARM,    idct, NO_PERM },
   {"INT-ARM",         1, j_rev_dct_ARM,      idct, MMX_PERM },
-#ifdef HAVE_ARMV5TE
+#if HAVE_ARMV5TE
   {"SIMPLE-ARMV5TE",  1, simple_idct_armv5te, idct, NO_PERM },
 #endif
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
   {"SIMPLE-ARMV6",    1, ff_simple_idct_armv6, idct, MMX_PERM },
 #endif
-#ifdef HAVE_NEON
+#if HAVE_NEON
   {"SIMPLE-NEON",     1, ff_simple_idct_neon, idct, PARTTRANS_PERM },
 #endif
 #endif /* ARCH_ARM */
 
+#if ARCH_ALPHA
+  {"SIMPLE-ALPHA",    1, ff_simple_idct_axp,  idct, NO_PERM },
+#endif
+
   { 0 }
 };
 
@@ -186,7 +192,7 @@ static DCTELEM block_org[64] __attribute__ ((aligned (8)));
 
 static inline void mmx_emms(void)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     if (cpu_flags & FF_MM_MMX)
         __asm__ volatile ("emms\n\t");
 #endif
diff --git a/libavcodec/dirac_parser.c b/libavcodec/dirac_parser.c
index ac82dca..511563c 100644
--- a/libavcodec/dirac_parser.c
+++ b/libavcodec/dirac_parser.c
@@ -27,6 +27,7 @@
  * @author Marco Gerards <marco at gnu.org>
  */
 
+#include "libavutil/intreadwrite.h"
 #include "parser.h"
 
 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c
index 47467ff..a6cc174 100644
--- a/libavcodec/dnxhddata.c
+++ b/libavcodec/dnxhddata.c
@@ -282,14 +282,6 @@ static const uint8_t dnxhd_1241_ac_index_flag[257] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 };
 
-static const uint16_t dnxhd_1241_run_codes[62] = {
-    0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
-};
-
-static const uint8_t dnxhd_1241_run_bits[62] = {
-    1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-};
-
 static const uint8_t dnxhd_1241_run[62] = {
     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
 };
@@ -346,15 +338,6 @@ static const uint8_t dnxhd_1252_ac_run_flag[257] = {
 static const uint8_t dnxhd_1252_ac_index_flag[257] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 };
-static const uint16_t dnxhd_1252_run_codes[62] = {
-    0, 4, 5, 12, 26, 27, 28, 58, 118, 119, 120, 242, 486, 487, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
-};
-static const uint8_t dnxhd_1252_run_bits[62] = {
-    1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-};
-static const uint8_t dnxhd_1252_run[62] = {
-    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
-};
 
 const CIDEntry ff_dnxhd_cid_table[] = {
     { 1237, 1920, 1080, 0, 606208, 606208, 4, 8,
@@ -376,7 +359,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       dnxhd_1241_dc_codes, dnxhd_1241_dc_bits,
       dnxhd_1241_ac_codes, dnxhd_1241_ac_bits, dnxhd_1241_ac_level,
       dnxhd_1241_ac_run_flag, dnxhd_1241_ac_index_flag,
-      dnxhd_1241_run_codes, dnxhd_1241_run_bits, dnxhd_1241_run,
+      dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1241_run,
       { 185, 220 } },
     { 1242, 1920, 1080, 1, 606208, 303104, 4, 8,
       dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight,
@@ -404,7 +387,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       dnxhd_1252_dc_codes, dnxhd_1252_dc_bits,
       dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_level,
       dnxhd_1252_ac_run_flag, dnxhd_1252_ac_index_flag,
-      dnxhd_1252_run_codes, dnxhd_1252_run_bits, dnxhd_1252_run,
+      dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run,
       { 60, 75, 115, 145 } },
     { 1253, 1920, 1080, 0, 188416, 188416, 4, 8,
       dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index a79a161..f206b72 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -177,7 +177,7 @@ static int dnxhd_encode_init(AVCodecContext *avctx)
 
     dsputil_init(&ctx->m.dsp, avctx);
     ff_dct_common_init(&ctx->m);
-#ifdef HAVE_MMX
+#if HAVE_MMX
     ff_dnxhd_init_mmx(ctx);
 #endif
     if (!ctx->m.dct_quantize)
diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index 74ca9ec..be976e8 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -37,6 +37,7 @@
  * the fourcc 'Axan' in the 'auds' chunk of the AVI header.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct DPCMContext {
diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index 76f5dbb..d53bbed 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -32,6 +32,7 @@
 #include "simple_idct.h"
 #include "faandct.h"
 #include "faanidct.h"
+#include "mathops.h"
 #include "h263.h"
 #include "snow.h"
 
@@ -169,7 +170,7 @@ void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_s
         int j;
         j = src_scantable[i];
         st->permutated[i] = permutation[j];
-#ifdef ARCH_PPC
+#if ARCH_PPC
         st->inverse[j] = i;
 #endif
     }
@@ -340,7 +341,7 @@ static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
 }
 
 
-#ifdef CONFIG_SNOW_ENCODER //dwt is in snow.c
+#if CONFIG_SNOW_ENCODER //dwt is in snow.c
 static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){
     int s, i, j;
     const int dec_count= w==8 ? 3 : 4;
@@ -2711,7 +2712,7 @@ static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int
     }
 }
 
-#ifdef CONFIG_CAVS_DECODER
+#if CONFIG_CAVS_DECODER
 /* AVS specific */
 void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
 
@@ -2729,7 +2730,7 @@ void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
 }
 #endif /* CONFIG_CAVS_DECODER */
 
-#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
+#if CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER
 /* VC-1 specific */
 void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
 
@@ -2743,11 +2744,11 @@ void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
 /* H264 specific */
 void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx);
 
-#if defined(CONFIG_RV30_DECODER)
+#if CONFIG_RV30_DECODER
 void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx);
 #endif /* CONFIG_RV30_DECODER */
 
-#if defined(CONFIG_RV40_DECODER)
+#if CONFIG_RV40_DECODER
 static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
     put_pixels16_xy2_c(dst, src, stride, 16);
 }
@@ -2842,7 +2843,7 @@ static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
 }
 
 static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
-    if(ENABLE_ANY_H263) {
+    if(CONFIG_ANY_H263) {
     int x;
     const int strength= ff_h263_loop_filter_strength[qscale];
 
@@ -2879,7 +2880,7 @@ static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
 }
 
 static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
-    if(ENABLE_ANY_H263) {
+    if(CONFIG_ANY_H263) {
     int y;
     const int strength= ff_h263_loop_filter_strength[qscale];
 
@@ -3467,7 +3468,7 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
         case FF_CMP_NSSE:
             cmp[i]= c->nsse[i];
             break;
-#ifdef CONFIG_SNOW_ENCODER
+#if CONFIG_SNOW_ENCODER
         case FF_CMP_W53:
             cmp[i]= c->w53[i];
             break;
@@ -3518,7 +3519,7 @@ static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
 
 static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
     long i;
-#ifndef HAVE_FAST_UNALIGNED
+#if !HAVE_FAST_UNALIGNED
     if((long)src2 & (sizeof(long)-1)){
         for(i=0; i+7<w; i+=8){
             dst[i+0] = src1[i+0]-src2[i+0];
@@ -3686,7 +3687,7 @@ static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2
     return s->dsp.sum_abs_dctelem(temp);
 }
 
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
 #define DCT8_1D {\
     const int s07 = SRC(0) + SRC(7);\
     const int s16 = SRC(1) + SRC(6);\
@@ -3992,7 +3993,7 @@ static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
 WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
 WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
 WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
 WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
 #endif
 WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
@@ -4249,7 +4250,7 @@ int ff_check_alignment(void){
 
     if((long)&aligned & 15){
         if(!did_fail){
-#if defined(HAVE_MMX) || defined(HAVE_ALTIVEC)
+#if HAVE_MMX || HAVE_ALTIVEC
             av_log(NULL, AV_LOG_ERROR,
                 "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
                 "and may be very slow or crash. This is not a bug in libavcodec,\n"
@@ -4269,7 +4270,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
 
     ff_check_alignment();
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
     if(avctx->dct_algo==FF_DCT_FASTINT) {
         c->fdct = fdct_ifast;
         c->fdct248 = fdct_ifast248;
@@ -4285,7 +4286,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
 #endif //CONFIG_ENCODERS
 
     if(avctx->lowres==1){
-        if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !ENABLE_H264_DECODER){
+        if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
             c->idct_put= ff_jref_idct4_put;
             c->idct_add= ff_jref_idct4_add;
         }else{
@@ -4310,7 +4311,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
             c->idct_add= ff_jref_idct_add;
             c->idct    = j_rev_dct;
             c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
-        }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER || ENABLE_THEORA_DECODER ) &&
+        }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER || CONFIG_THEORA_DECODER ) &&
                 avctx->idct_algo==FF_IDCT_VP3){
             c->idct_put= ff_vp3_idct_put_c;
             c->idct_add= ff_vp3_idct_add_c;
@@ -4326,7 +4327,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
             c->idct_add= ff_faanidct_add;
             c->idct    = ff_faanidct;
             c->idct_permutation_type= FF_NO_IDCT_PERM;
-        }else if(ENABLE_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
+        }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
             c->idct_put= ff_ea_idct_put_c;
             c->idct_permutation_type= FF_NO_IDCT_PERM;
         }else{ //accurate/default
@@ -4337,7 +4338,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
         }
     }
 
-    if (ENABLE_H264_DECODER) {
+    if (CONFIG_H264_DECODER) {
         c->h264_idct_add= ff_h264_idct_add_c;
         c->h264_idct8_add= ff_h264_idct8_add_c;
         c->h264_idct_dc_add= ff_h264_idct_dc_add_c;
@@ -4487,22 +4488,22 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
 
     c->draw_edges = draw_edges_c;
 
-#ifdef CONFIG_CAVS_DECODER
+#if CONFIG_CAVS_DECODER
     ff_cavsdsp_init(c,avctx);
 #endif
-#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
+#if CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER
     ff_vc1dsp_init(c,avctx);
 #endif
-#if defined(CONFIG_WMV2_DECODER) || defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
+#if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER
     ff_intrax8dsp_init(c,avctx);
 #endif
-#if defined(CONFIG_H264_ENCODER)
+#if CONFIG_H264_ENCODER
     ff_h264dspenc_init(c,avctx);
 #endif
-#if defined(CONFIG_RV30_DECODER)
+#if CONFIG_RV30_DECODER
     ff_rv30dsp_init(c,avctx);
 #endif
-#if defined(CONFIG_RV40_DECODER)
+#if CONFIG_RV40_DECODER
     ff_rv40dsp_init(c,avctx);
     c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
     c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
@@ -4527,7 +4528,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     c->hadamard8_diff[4]= hadamard8_intra16_c;
     SET_CMP_FUNC(dct_sad)
     SET_CMP_FUNC(dct_max)
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
     SET_CMP_FUNC(dct264_sad)
 #endif
     c->sad[0]= pix_abs16_c;
@@ -4544,7 +4545,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     c->vsse[4]= vsse_intra16_c;
     c->nsse[0]= nsse16_c;
     c->nsse[1]= nsse8_c;
-#ifdef CONFIG_SNOW_ENCODER
+#if CONFIG_SNOW_ENCODER
     c->w53[0]= w53_16_c;
     c->w53[1]= w53_8_c;
     c->w97[0]= w97_16_c;
@@ -4558,7 +4559,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     c->diff_bytes= diff_bytes_c;
     c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
     c->bswap_buf= bswap_buf;
-#ifdef CONFIG_PNG_DECODER
+#if CONFIG_PNG_DECODER
     c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
 #endif
 
@@ -4572,12 +4573,12 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c;
     c->h264_loop_filter_strength= NULL;
 
-    if (ENABLE_ANY_H263) {
+    if (CONFIG_ANY_H263) {
         c->h263_h_loop_filter= h263_h_loop_filter_c;
         c->h263_v_loop_filter= h263_v_loop_filter_c;
     }
 
-    if (ENABLE_VP3_DECODER || ENABLE_THEORA_DECODER) {
+    if (CONFIG_VP3_DECODER || CONFIG_THEORA_DECODER) {
         c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
         c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
     }
@@ -4587,19 +4588,19 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     c->try_8x8basis= try_8x8basis_c;
     c->add_8x8basis= add_8x8basis_c;
 
-#ifdef CONFIG_SNOW_DECODER
+#if CONFIG_SNOW_DECODER
     c->vertical_compose97i = ff_snow_vertical_compose97i;
     c->horizontal_compose97i = ff_snow_horizontal_compose97i;
     c->inner_add_yblock = ff_snow_inner_add_yblock;
 #endif
 
-#ifdef CONFIG_VORBIS_DECODER
+#if CONFIG_VORBIS_DECODER
     c->vorbis_inverse_coupling = vorbis_inverse_coupling;
 #endif
-#ifdef CONFIG_AC3_DECODER
+#if CONFIG_AC3_DECODER
     c->ac3_downmix = ff_ac3_downmix_c;
 #endif
-#ifdef CONFIG_FLAC_ENCODER
+#if CONFIG_FLAC_ENCODER
     c->flac_compute_autocorr = ff_flac_compute_autocorr;
 #endif
     c->vector_fmul = vector_fmul_c;
@@ -4623,15 +4624,15 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
     memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
 
-    if (ENABLE_MMX)      dsputil_init_mmx   (c, avctx);
-    if (ENABLE_ARM)      dsputil_init_arm   (c, avctx);
-    if (ENABLE_MLIB)     dsputil_init_mlib  (c, avctx);
-    if (ENABLE_VIS)      dsputil_init_vis   (c, avctx);
-    if (ENABLE_ALPHA)    dsputil_init_alpha (c, avctx);
-    if (ENABLE_PPC)      dsputil_init_ppc   (c, avctx);
-    if (ENABLE_MMI)      dsputil_init_mmi   (c, avctx);
-    if (ENABLE_SH4)      dsputil_init_sh4   (c, avctx);
-    if (ENABLE_BFIN)     dsputil_init_bfin  (c, avctx);
+    if (HAVE_MMX)        dsputil_init_mmx   (c, avctx);
+    if (ARCH_ARM)        dsputil_init_arm   (c, avctx);
+    if (CONFIG_MLIB)     dsputil_init_mlib  (c, avctx);
+    if (HAVE_VIS)        dsputil_init_vis   (c, avctx);
+    if (ARCH_ALPHA)      dsputil_init_alpha (c, avctx);
+    if (ARCH_PPC)        dsputil_init_ppc   (c, avctx);
+    if (HAVE_MMI)        dsputil_init_mmi   (c, avctx);
+    if (ARCH_SH4)        dsputil_init_sh4   (c, avctx);
+    if (ARCH_BFIN)       dsputil_init_bfin  (c, avctx);
 
     for(i=0; i<64; i++){
         if(!c->put_2tap_qpel_pixels_tab[0][i])
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index 88ed315..62415b7 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -30,6 +30,7 @@
 #ifndef AVCODEC_DSPUTIL_H
 #define AVCODEC_DSPUTIL_H
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 
@@ -173,7 +174,7 @@ typedef struct ScanTable{
     const uint8_t *scantable;
     uint8_t permutated[64];
     uint8_t raster_end[64];
-#ifdef ARCH_PPC
+#if ARCH_PPC
                 /** Used by dct_quantize_altivec to find last-non-zero */
     DECLARE_ALIGNED(16, uint8_t, inverse[64]);
 #endif
@@ -583,7 +584,7 @@ void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
 
 #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
 
-#if defined(HAVE_MMX)
+#if HAVE_MMX
 
 #undef emms_c
 
@@ -607,23 +608,23 @@ static inline void emms(void)
 
 void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
 
-#elif defined(ARCH_ARM)
+#elif ARCH_ARM
 
 extern int mm_flags;
 
-#ifdef HAVE_NEON
+#if HAVE_NEON
 #   define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
 #   define STRIDE_ALIGN 16
 #endif
 
-#elif defined(ARCH_PPC)
+#elif ARCH_PPC
 
 extern int mm_flags;
 
 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
 #define STRIDE_ALIGN 16
 
-#elif defined(HAVE_MMI)
+#elif HAVE_MMI
 
 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
 #define STRIDE_ALIGN 16
@@ -731,7 +732,8 @@ extern float ff_sine_256 [ 256];
 extern float ff_sine_512 [ 512];
 extern float ff_sine_1024[1024];
 extern float ff_sine_2048[2048];
-extern float *ff_sine_windows[5];
+extern float ff_sine_4096[4096];
+extern float *ff_sine_windows[6];
 
 int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
 void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
diff --git a/libavcodec/dv.c b/libavcodec/dv.c
index e3f54b8..2eb4a41 100644
--- a/libavcodec/dv.c
+++ b/libavcodec/dv.c
@@ -62,7 +62,7 @@ typedef struct DVVideoContext {
 
 #define TEX_VLC_BITS 9
 
-#if ENABLE_SMALL
+#if CONFIG_SMALL
 #define DV_VLC_MAP_RUN_SIZE 15
 #define DV_VLC_MAP_LEV_SIZE 23
 #else
@@ -326,7 +326,7 @@ static av_cold int dvvideo_init(AVCodecContext *avctx)
         for (i = 0; i < NB_DV_VLC - 1; i++) {
            if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE)
                continue;
-#if ENABLE_SMALL
+#if CONFIG_SMALL
            if (dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE)
                continue;
 #endif
@@ -340,7 +340,7 @@ static av_cold int dvvideo_init(AVCodecContext *avctx)
                dv_vlc_len[i] + (!!dv_vlc_level[i]);
         }
         for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) {
-#if ENABLE_SMALL
+#if CONFIG_SMALL
            for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) {
               if (dv_vlc_map[i][j].size == 0) {
                   dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc |
@@ -692,7 +692,7 @@ static int dv_decode_video_segment(AVCodecContext *avctx, DVwork_chunk *work_chu
     return 0;
 }
 
-#if ENABLE_SMALL
+#if CONFIG_SMALL
 /* Converts run and level (where level != 0) pair into vlc, returning bit size */
 static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc)
 {
@@ -1123,7 +1123,7 @@ static int dv_encode_video_segment(AVCodecContext *avctx, DVwork_chunk *work_chu
     return 0;
 }
 
-#ifdef CONFIG_DVVIDEO_DECODER
+#if CONFIG_DVVIDEO_DECODER
 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
    144000 bytes for PAL - or twice those for 50Mbps) */
 static int dvvideo_decode_frame(AVCodecContext *avctx,
@@ -1240,7 +1240,7 @@ static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c,
     return 5;
 }
 
-#ifdef CONFIG_DVVIDEO_ENCODER
+#if CONFIG_DVVIDEO_ENCODER
 static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
 {
     int chan, i, j, k;
@@ -1328,7 +1328,7 @@ static int dvvideo_close(AVCodecContext *c)
 }
 
 
-#ifdef CONFIG_DVVIDEO_ENCODER
+#if CONFIG_DVVIDEO_ENCODER
 AVCodec dvvideo_encoder = {
     "dvvideo",
     CODEC_TYPE_VIDEO,
@@ -1341,7 +1341,7 @@ AVCodec dvvideo_encoder = {
 };
 #endif // CONFIG_DVVIDEO_ENCODER
 
-#ifdef CONFIG_DVVIDEO_DECODER
+#if CONFIG_DVVIDEO_DECODER
 AVCodec dvvideo_decoder = {
     "dvvideo",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/dvdsub_parser.c b/libavcodec/dvdsub_parser.c
index 0893dac..ed6ed36 100644
--- a/libavcodec/dvdsub_parser.c
+++ b/libavcodec/dvdsub_parser.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 /* parser definition */
diff --git a/libavcodec/dxa.c b/libavcodec/dxa.c
index 3d03445..e0f4430 100644
--- a/libavcodec/dxa.c
+++ b/libavcodec/dxa.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #include <zlib.h>
diff --git a/libavcodec/eacmv.c b/libavcodec/eacmv.c
index a9f624e..ffd8f46 100644
--- a/libavcodec/eacmv.c
+++ b/libavcodec/eacmv.c
@@ -28,6 +28,7 @@
  * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_CMV
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct CmvContext {
diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c
index a8787bb..0b72dff 100644
--- a/libavcodec/eatgv.c
+++ b/libavcodec/eatgv.c
@@ -31,7 +31,7 @@
 #include "avcodec.h"
 #define ALT_BITSTREAM_READER_LE
 #include "bitstream.h"
-#include <libavutil/lzo.h>
+#include "libavutil/lzo.h"
 
 #define EA_PREAMBLE_SIZE    8
 #define kVGT_TAG MKTAG('k', 'V', 'G', 'T')
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index bdd3a66..5f8037f 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -563,7 +563,7 @@ static int is_intra_more_likely(MpegEncContext *s){
 
     if(undamaged_count < 5) return 0; //almost all MBs damaged -> use temporal prediction
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
     //prevent dsp.sad() check, that requires access to the image
     if(s->avctx->xvmc_acceleration && s->pict_type==FF_I_TYPE) return 1;
 #endif
@@ -935,7 +935,7 @@ void ff_er_frame_end(MpegEncContext *s){
     }else
         guess_mv(s);
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
     /* the filters below are not XvMC compatible, skip them */
     if(s->avctx->xvmc_acceleration) goto ec_clean;
 #endif
@@ -1024,7 +1024,7 @@ void ff_er_frame_end(MpegEncContext *s){
         v_block_filter(s, s->current_picture.data[2], s->mb_width  , s->mb_height  , s->uvlinesize, 0);
     }
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
 ec_clean:
 #endif
     /* clean a few tables */
diff --git a/libavcodec/fft.c b/libavcodec/fft.c
index 7c8cce8..099ecbe 100644
--- a/libavcodec/fft.c
+++ b/libavcodec/fft.c
@@ -91,7 +91,7 @@ int ff_fft_init(FFTContext *s, int nbits, int inverse)
     s->imdct_half = ff_imdct_half_c;
     s->exptab1 = NULL;
 
-#if defined HAVE_MMX && defined HAVE_YASM
+#if HAVE_MMX && HAVE_YASM
     has_vectors = mm_support();
     if (has_vectors & FF_MM_SSE) {
         /* SSE for P3/P4/K8 */
@@ -110,7 +110,7 @@ int ff_fft_init(FFTContext *s, int nbits, int inverse)
         s->imdct_half = ff_imdct_half_3dn;
         s->fft_calc = ff_fft_calc_3dn;
     }
-#elif defined HAVE_ALTIVEC && !defined ALTIVEC_USE_REFERENCE_C_CODE
+#elif HAVE_ALTIVEC && !defined ALTIVEC_USE_REFERENCE_C_CODE
     has_vectors = mm_support();
     if (has_vectors & FF_MM_ALTIVEC) {
         s->fft_calc = ff_fft_calc_altivec;
@@ -336,7 +336,7 @@ static void fft8(FFTComplex *z)
     TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
 }
 
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
 static void fft16(FFTComplex *z)
 {
     FFTSample t1, t2, t3, t4, t5, t6;
@@ -358,7 +358,7 @@ DECL_FFT(64,32,16)
 DECL_FFT(128,64,32)
 DECL_FFT(256,128,64)
 DECL_FFT(512,256,128)
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
 #define pass pass_big
 #endif
 DECL_FFT(1024,512,256)
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 7211e16..6c7d895 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -30,6 +30,7 @@
 #include "dsputil.h"
 #include "rangecoder.h"
 #include "golomb.h"
+#include "mathops.h"
 
 #define MAX_PLANES 4
 #define CONTEXT_SIZE 32
@@ -350,7 +351,7 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState * const state, int
     return ret;
 }
 
-#ifdef CONFIG_FFV1_ENCODER
+#if CONFIG_FFV1_ENCODER
 static inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){
     PlaneContext * const p= &s->plane[plane_index];
     RangeCoder * const c= &s->c;
@@ -543,7 +544,7 @@ static av_cold int common_init(AVCodecContext *avctx){
     return 0;
 }
 
-#ifdef CONFIG_FFV1_ENCODER
+#if CONFIG_FFV1_ENCODER
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     FFV1Context *s = avctx->priv_data;
@@ -632,7 +633,7 @@ static void clear_state(FFV1Context *f){
     }
 }
 
-#ifdef CONFIG_FFV1_ENCODER
+#if CONFIG_FFV1_ENCODER
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
     FFV1Context *f = avctx->priv_data;
     RangeCoder * const c= &f->c;
@@ -1025,7 +1026,7 @@ AVCodec ffv1_decoder = {
     .long_name= NULL_IF_CONFIG_SMALL("FFmpeg codec #1"),
 };
 
-#ifdef CONFIG_FFV1_ENCODER
+#if CONFIG_FFV1_ENCODER
 AVCodec ffv1_encoder = {
     "ffv1",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index a13e379..748906e 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -775,7 +775,7 @@ static void encode_residual_lpc(int32_t *res, const int32_t *smp, int n,
     for(i=0; i<order; i++) {
         res[i] = smp[i];
     }
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     for(i=order; i<n; i+=2) {
         int j;
         int s = smp[i];
diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c
index 4a8cb5e..d6faa34 100644
--- a/libavcodec/flicvideo.c
+++ b/libavcodec/flicvideo.c
@@ -40,7 +40,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "libavutil/bswap.h"
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define FLI_256_COLOR 4
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 90a20da..1c52836 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -285,7 +285,7 @@ static av_cold int g726_reset(G726Context* c, int index)
     return 0;
 }
 
-#ifdef CONFIG_ADPCM_G726_ENCODER
+#if CONFIG_ADPCM_G726_ENCODER
 static int16_t g726_encode(G726Context* c, int16_t sig)
 {
     uint8_t i;
@@ -342,7 +342,7 @@ static av_cold int g726_close(AVCodecContext *avctx)
     return 0;
 }
 
-#ifdef CONFIG_ADPCM_G726_ENCODER
+#if CONFIG_ADPCM_G726_ENCODER
 static int g726_encode_frame(AVCodecContext *avctx,
                             uint8_t *dst, int buf_size, void *data)
 {
@@ -381,7 +381,7 @@ static int g726_decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-#ifdef CONFIG_ADPCM_G726_ENCODER
+#if CONFIG_ADPCM_G726_ENCODER
 AVCodec adpcm_g726_encoder = {
     "g726",
     CODEC_TYPE_AUDIO,
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 35cd0a0..715f0aa 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -43,6 +43,11 @@
 
 #include "avcodec.h"
 #include "bytestream.h"
+
+/* The GIF format uses reversed order for bitstreams... */
+/* at least they don't use PDP_ENDIAN :) */
+#define BITSTREAM_WRITER_LE
+
 #include "bitstream.h"
 
 /* bitstream minipacket size */
@@ -104,68 +109,6 @@ static const rgb_triplet gif_clut[216] = {
     { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
 };
 
-/* The GIF format uses reversed order for bitstreams... */
-/* at least they don't use PDP_ENDIAN :) */
-/* so we 'extend' PutBitContext. hmmm, OOP :) */
-/* seems this thing changed slightly since I wrote it... */
-
-#ifdef ALT_BITSTREAM_WRITER
-# error no ALT_BITSTREAM_WRITER support for now
-#endif
-
-static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
-{
-    unsigned int bit_buf;
-    int bit_cnt;
-
-    //    printf("put_bits=%d %x\n", n, value);
-    assert(n == 32 || value < (1U << n));
-
-    bit_buf = s->bit_buf;
-    bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
-
-    //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
-    /* XXX: optimize */
-    if (n < (32-bit_cnt)) {
-        bit_buf |= value << (bit_cnt);
-        bit_cnt+=n;
-    } else {
-        bit_buf |= value << (bit_cnt);
-
-        bytestream_put_le32(&s->buf_ptr, bit_buf);
-
-        //printf("bitbuf = %08x\n", bit_buf);
-        if (s->buf_ptr >= s->buf_end)
-            abort();
-//            flush_buffer_rev(s);
-        bit_cnt=bit_cnt + n - 32;
-        if (bit_cnt == 0) {
-            bit_buf = 0;
-        } else {
-            bit_buf = value >> (n - bit_cnt);
-        }
-    }
-
-    s->bit_buf = bit_buf;
-    s->bit_left = 32 - bit_cnt;
-}
-
-/* pad the end of the output stream with zeros */
-static void gif_flush_put_bits_rev(PutBitContext *s)
-{
-    while (s->bit_left < 32) {
-        /* XXX: should test end of buffer */
-        *s->buf_ptr++=s->bit_buf & 0xff;
-        s->bit_buf>>=8;
-        s->bit_left+=8;
-    }
-//    flush_buffer_rev(s);
-    s->bit_left=32;
-    s->bit_buf=0;
-}
-
-/* !RevPutBitContext */
-
 /* GIF header */
 static int gif_image_write_header(uint8_t **bytestream,
                                   int width, int height, int loop_count,
@@ -269,7 +212,7 @@ static int gif_image_write_image(uint8_t **bytestream,
     w = width;
     while(left>0) {
 
-        gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
+        put_bits(&p, 9, 0x0100); /* clear code */
 
         for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
             if (pix_fmt == PIX_FMT_RGB24) {
@@ -278,7 +221,7 @@ static int gif_image_write_image(uint8_t **bytestream,
             } else {
                 v = *ptr++;
             }
-            gif_put_bits_rev(&p, 9, v);
+            put_bits(&p, 9, v);
             if (--w == 0) {
                 w = width;
                 buf += linesize;
@@ -287,8 +230,8 @@ static int gif_image_write_image(uint8_t **bytestream,
         }
 
         if(left<=GIF_CHUNKS) {
-            gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
-            gif_flush_put_bits_rev(&p);
+            put_bits(&p, 9, 0x101); /* end of stream */
+            flush_put_bits(&p);
         }
         if(pbBufPtr(&p) - p.buf > 0) {
             bytestream_put_byte(bytestream, pbBufPtr(&p) - p.buf); /* byte count of the packet */
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 781c007..dc3ae07 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -39,6 +39,7 @@
 #include "mpegvideo.h"
 #include "h263data.h"
 #include "mpeg4data.h"
+#include "mathops.h"
 
 //#undef NDEBUG
 //#include <assert.h>
@@ -54,7 +55,7 @@
 #define H263_MBTYPE_B_VLC_BITS 6
 #define CBPC_B_VLC_BITS 3
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static void h263_encode_block(MpegEncContext * s, DCTELEM * block,
                               int n);
 static void h263p_encode_umotion(MpegEncContext * s, int val);
@@ -72,7 +73,7 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
                               int n, int coded, int intra, int rvlc);
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
 static void mpeg4_encode_visual_object_header(MpegEncContext * s);
 static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number);
@@ -80,7 +81,7 @@ static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_n
 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb);
 static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding);
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static uint8_t uni_DCtab_lum_len[512];
 static uint8_t uni_DCtab_chrom_len[512];
 static uint16_t uni_DCtab_lum_bits[512];
@@ -114,7 +115,7 @@ max run: 29/41
 static uint8_t static_rl_table_store[5][2][2*MAX_RUN + MAX_LEVEL + 3];
 
 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
-#define IS_3IV1 s->codec_tag == ff_get_fourcc("3IV1")
+#define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
 #else
 #define IS_3IV1 0
 #endif
@@ -155,7 +156,7 @@ static void show_pict_info(MpegEncContext *s){
     );
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 static void aspect_to_info(MpegEncContext * s, AVRational aspect){
     int i;
@@ -736,7 +737,7 @@ void ff_h263_update_motion_val(MpegEncContext * s){
     }
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){
     int l, bit_size, code;
@@ -1549,7 +1550,7 @@ void ff_h263_loop_filter(MpegEncContext * s){
     }
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
 {
     int x, y, wrap, a, c, pred_dc, scale;
@@ -1741,7 +1742,7 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
     return *mot_val;
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
 {
     int range, l, bit_size, sign, code, bits;
@@ -2355,7 +2356,7 @@ static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_n
 {
     int vo_ver_id;
 
-    if (!ENABLE_MPEG4_ENCODER)  return;
+    if (!CONFIG_MPEG4_ENCODER)  return;
 
     if(s->max_b_frames || s->quarter_sample){
         vo_ver_id= 5;
@@ -2652,7 +2653,7 @@ void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
 
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 /**
  * encodes the dc value.
@@ -3049,7 +3050,7 @@ static inline void memsetw(short *tab, int val, int n)
         tab[i] = val;
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 void ff_mpeg4_init_partitions(MpegEncContext *s)
 {
@@ -3106,7 +3107,7 @@ int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){
     }
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
 {
@@ -4563,7 +4564,7 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
     } else if (s->mb_intra) {
         /* DC coef */
         if(s->codec_id == CODEC_ID_RV10){
-#ifdef CONFIG_RV10_DECODER
+#if CONFIG_RV10_DECODER
           if (s->rv10_version == 3 && s->pict_type == FF_I_TYPE) {
             int component, diff;
             component = (n <= 3 ? 0 : n - 4 + 1);
@@ -5156,7 +5157,7 @@ int h263_decode_picture_header(MpegEncContext *s)
                     av_log(s, AV_LOG_ERROR, "zero framerate\n");
                     return -1;
                 }
-                gcd= ff_gcd(s->avctx->time_base.den, s->avctx->time_base.num);
+                gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num);
                 s->avctx->time_base.den /= gcd;
                 s->avctx->time_base.num /= gcd;
 //                av_log(s->avctx, AV_LOG_DEBUG, "%d/%d\n", s->avctx->time_base.den, s->avctx->time_base.num);
@@ -5223,7 +5224,7 @@ int h263_decode_picture_header(MpegEncContext *s)
         show_pict_info(s);
      }
 #if 1
-    if (s->pict_type == FF_I_TYPE && s->codec_tag == ff_get_fourcc("ZYGO")){
+    if (s->pict_type == FF_I_TYPE && s->codec_tag == AV_RL32("ZYGO")){
         int i,j;
         for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
         av_log(s->avctx, AV_LOG_DEBUG, "\n");
@@ -5548,7 +5549,7 @@ static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){
             skip_bits1(gb);   /* marker */
             height = get_bits(gb, 13);
             skip_bits1(gb);   /* marker */
-            if(width && height && !(s->width && s->codec_tag == ff_get_fourcc("MP4S"))){ /* they should be non zero but who knows ... */
+            if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){ /* they should be non zero but who knows ... */
                 s->width = width;
                 s->height = height;
 //                printf("width/height: %d %d\n", width, height);
@@ -6062,7 +6063,7 @@ int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
     /* search next start code */
     align_get_bits(gb);
 
-    if(s->codec_tag == ff_get_fourcc("WV1F") && show_bits(gb, 24) == 0x575630){
+    if(s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630){
         skip_bits(gb, 24);
         if(get_bits(gb, 8) == 0xF0)
             goto end;
diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index 2df3be5..fcd821c 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -25,22 +25,22 @@
 #include "config.h"
 #include "msmpeg4.h"
 
-#define ENABLE_ANY_H263_DECODER (ENABLE_H263_DECODER    || \
-                                 ENABLE_H263I_DECODER   || \
-                                 ENABLE_FLV_DECODER     || \
-                                 ENABLE_RV10_DECODER    || \
-                                 ENABLE_RV20_DECODER    || \
-                                 ENABLE_MPEG4_DECODER   || \
-                                 ENABLE_MSMPEG4_DECODER || \
-                                 ENABLE_WMV_DECODER)
-#define ENABLE_ANY_H263_ENCODER (ENABLE_H263_ENCODER    || \
-                                 ENABLE_H263P_ENCODER   || \
-                                 ENABLE_FLV_ENCODER     || \
-                                 ENABLE_RV10_ENCODER    || \
-                                 ENABLE_RV20_ENCODER    || \
-                                 ENABLE_MPEG4_ENCODER   || \
-                                 ENABLE_MSMPEG4_ENCODER || \
-                                 ENABLE_WMV_ENCODER)
-#define ENABLE_ANY_H263 (ENABLE_ANY_H263_DECODER || ENABLE_ANY_H263_ENCODER)
+#define CONFIG_ANY_H263_DECODER (CONFIG_H263_DECODER    || \
+                                 CONFIG_H263I_DECODER   || \
+                                 CONFIG_FLV_DECODER     || \
+                                 CONFIG_RV10_DECODER    || \
+                                 CONFIG_RV20_DECODER    || \
+                                 CONFIG_MPEG4_DECODER   || \
+                                 CONFIG_MSMPEG4_DECODER || \
+                                 CONFIG_WMV_DECODER)
+#define CONFIG_ANY_H263_ENCODER (CONFIG_H263_ENCODER    || \
+                                 CONFIG_H263P_ENCODER   || \
+                                 CONFIG_FLV_ENCODER     || \
+                                 CONFIG_RV10_ENCODER    || \
+                                 CONFIG_RV20_ENCODER    || \
+                                 CONFIG_MPEG4_ENCODER   || \
+                                 CONFIG_MSMPEG4_ENCODER || \
+                                 CONFIG_WMV_ENCODER)
+#define CONFIG_ANY_H263 (CONFIG_ANY_H263_DECODER || CONFIG_ANY_H263_ENCODER)
 
 #endif /* AVCODEC_H263_H */
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index ae318b5..2792ba2 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -111,7 +111,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
         if (MPV_common_init(s) < 0)
             return -1;
 
-    if (ENABLE_MSMPEG4_DECODER && s->h263_msmpeg4)
+    if (CONFIG_MSMPEG4_DECODER && s->h263_msmpeg4)
         ff_msmpeg4_decode_init(s);
     else
         h263_decode_init_vlc(s);
@@ -355,9 +355,9 @@ uint64_t time= rdtsc();
     if(s->flags&CODEC_FLAG_TRUNCATED){
         int next;
 
-        if(ENABLE_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){
+        if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){
             next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
-        }else if(ENABLE_H263_DECODER && s->codec_id==CODEC_ID_H263){
+        }else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){
             next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
         }else{
             av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
@@ -390,9 +390,9 @@ retry:
     }
 
     /* let's go :-) */
-    if (ENABLE_WMV2_DECODER && s->msmpeg4_version==5) {
+    if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) {
         ret= ff_wmv2_decode_picture_header(s);
-    } else if (ENABLE_MSMPEG4_DECODER && s->msmpeg4_version) {
+    } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
         ret = msmpeg4_decode_picture_header(s);
     } else if (s->h263_pred) {
         if(s->avctx->extradata_size && s->picture_number==0){
@@ -421,19 +421,19 @@ retry:
     avctx->has_b_frames= !s->low_delay;
 
     if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
-        if(s->stream_codec_tag == ff_get_fourcc("XVID") ||
-           s->codec_tag == ff_get_fourcc("XVID") || s->codec_tag == ff_get_fourcc("XVIX") ||
-           s->codec_tag == ff_get_fourcc("RMP4"))
+        if(s->stream_codec_tag == AV_RL32("XVID") ||
+           s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") ||
+           s->codec_tag == AV_RL32("RMP4"))
             s->xvid_build= -1;
 #if 0
-        if(s->codec_tag == ff_get_fourcc("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
+        if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
            && s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc
             s->xvid_build= -1;
 #endif
     }
 
     if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
-        if(s->codec_tag == ff_get_fourcc("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
+        if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
             s->divx_version= 400; //divx 4
     }
 
@@ -443,10 +443,10 @@ retry:
     }
 
     if(s->workaround_bugs&FF_BUG_AUTODETECT){
-        if(s->codec_tag == ff_get_fourcc("XVIX"))
+        if(s->codec_tag == AV_RL32("XVIX"))
             s->workaround_bugs|= FF_BUG_XVID_ILACE;
 
-        if(s->codec_tag == ff_get_fourcc("UMP4")){
+        if(s->codec_tag == AV_RL32("UMP4")){
             s->workaround_bugs|= FF_BUG_UMP4;
         }
 
@@ -545,7 +545,7 @@ retry:
 }
 #endif
 
-#if defined(HAVE_MMX)
+#if HAVE_MMX
     if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & FF_MM_MMX)){
         avctx->idct_algo= FF_IDCT_XVIDMMX;
         avctx->coded_width= 0; // force reinit
@@ -620,7 +620,7 @@ retry:
 
     //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type
     //which is not available before MPV_frame_start()
-    if (ENABLE_WMV2_DECODER && s->msmpeg4_version==5){
+    if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){
         ret = ff_wmv2_decode_secondary_picture_header(s);
         if(ret<0) return ret;
         if(ret==1) goto intrax8_decoded;
@@ -647,7 +647,7 @@ retry:
     }
 
     if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==FF_I_TYPE)
-        if(!ENABLE_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){
+        if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){
             s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
         }
 
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index a8bd062..8b023f6 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -32,11 +32,12 @@
 #include "h264data.h"
 #include "h264_parser.h"
 #include "golomb.h"
+#include "mathops.h"
 #include "rectangle.h"
 #include "vdpau_internal.h"
 
 #include "cabac.h"
-#ifdef ARCH_X86
+#if ARCH_X86
 #include "x86/h264_i386.h"
 #endif
 
@@ -1380,8 +1381,8 @@ static const uint8_t *decode_nal(H264Context *h, const uint8_t *src, int *dst_le
         printf("%2X ", src[i]);
 #endif
 
-#ifdef HAVE_FAST_UNALIGNED
-# ifdef HAVE_FAST_64BIT
+#if HAVE_FAST_UNALIGNED
+# if HAVE_FAST_64BIT
 #   define RS 7
     for(i=0; i+1<length; i+=9){
         if(!((~*(uint64_t*)(src+i) & (*(uint64_t*)(src+i) - 0x0100010001000101ULL)) & 0x8000800080008080ULL))
@@ -1641,7 +1642,7 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square,
         qpix_op[luma_xy](dest_y + delta, src_y + delta, h->mb_linesize);
     }
 
-    if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return;
+    if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
 
     if(MB_FIELD){
         // chroma offset when predicting from a field of opposite parity
@@ -2189,7 +2190,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
 
     if(avctx->codec_id == CODEC_ID_SVQ3)
         avctx->pix_fmt= PIX_FMT_YUVJ420P;
-    else if(avctx->codec_id == CODEC_ID_H264_VDPAU)
+    else if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
         avctx->pix_fmt= PIX_FMT_VDPAU_H264;
     else
         avctx->pix_fmt= PIX_FMT_YUV420P;
@@ -2286,7 +2287,7 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src
             if(!MB_MBAFF){
                 *(uint64_t*)(h->top_borders[0][s->mb_x]+ 0)= *(uint64_t*)(src_y +  15*linesize);
                 *(uint64_t*)(h->top_borders[0][s->mb_x]+ 8)= *(uint64_t*)(src_y +8+15*linesize);
-                if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+                if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                     *(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+7*uvlinesize);
                     *(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(src_cr+7*uvlinesize);
                 }
@@ -2294,7 +2295,7 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src
         }else{
             if(!MB_MBAFF){
                 h->left_border[0]= h->top_borders[0][s->mb_x][15];
-                if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+                if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                     h->left_border[34   ]= h->top_borders[0][s->mb_x][16+7  ];
                     h->left_border[34+18]= h->top_borders[0][s->mb_x][16+8+7];
                 }
@@ -2317,7 +2318,7 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src
     *(uint64_t*)(h->top_borders[top_idx][s->mb_x]+0)= *(uint64_t*)(src_y +  16*linesize);
     *(uint64_t*)(h->top_borders[top_idx][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize);
 
-    if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+    if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
         h->left_border[uvoffset+34   ]= h->top_borders[top_idx][s->mb_x][16+7];
         h->left_border[uvoffset+34+18]= h->top_borders[top_idx][s->mb_x][24+7];
         for(i=1; i<9 - skiplast; i++){
@@ -2387,7 +2388,7 @@ b= t;
         }
     }
 
-    if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+    if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
         if(deblock_left){
             for(i = !deblock_top; i<8; i++){
                 XCHG(h->left_border[uvoffset+34   +i*step], src_cb[i*uvlinesize], temp8, xchg);
@@ -2415,7 +2416,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){
     int *block_offset = &h->block_offset[0];
     const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);
     /* is_h264 should always be true if SVQ3 is disabled. */
-    const int is_h264 = !ENABLE_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264;
+    const int is_h264 = !CONFIG_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264;
     void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);
     void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
 
@@ -2471,7 +2472,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){
             if(h->deblocking_filter)
                 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple);
 
-            if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+            if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                 h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);
                 h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);
             }
@@ -2606,7 +2607,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){
             }
         }
 
-        if((simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)) && (h->cbp&0x30)){
+        if((simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) && (h->cbp&0x30)){
             uint8_t *dest[2] = {dest_cb, dest_cr};
             if(transform_bypass){
                 if(IS_INTRA(mb_type) && h->sps.profile_idc==244 && (h->chroma_pred_mode==VERT_PRED8x8 || h->chroma_pred_mode==HOR_PRED8x8)){
@@ -2676,9 +2677,9 @@ static void hl_decode_mb(H264Context *h){
     MpegEncContext * const s = &h->s;
     const int mb_xy= h->mb_xy;
     const int mb_type= s->current_picture.mb_type[mb_xy];
-    int is_complex = ENABLE_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;
+    int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;
 
-    if(ENABLE_H264_ENCODER && !s->decode)
+    if(CONFIG_H264_ENCODER && !s->decode)
         return;
 
     if (is_complex)
@@ -5224,7 +5225,7 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
     uint8_t *last_coeff_ctx_base;
     uint8_t *abs_level_m1_ctx_base;
 
-#ifndef ARCH_X86
+#if !ARCH_X86
 #define CABAC_ON_STACK
 #endif
 #ifdef CABAC_ON_STACK
@@ -5285,7 +5286,7 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
             index[coeff_count++] = last;\
         }
         const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
-#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS)
+#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
         coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, sig_off);
     } else {
         coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index);
@@ -5360,7 +5361,7 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
 
 }
 
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
 static void decode_cabac_residual_dc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
     decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 1);
 }
@@ -5371,7 +5372,7 @@ static void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat
 #endif
 
 static void decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, cat == 0 || cat == 3);
 #else
     if( cat == 0 || cat == 3 ) decode_cabac_residual_dc(h, block, cat, n, scantable, qmul, max_coeff);
@@ -6572,7 +6573,7 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8
         filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp );
     }
 
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     for( dir = 0; dir < 2; dir++ )
         filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, dir);
 #else
@@ -6589,7 +6590,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){
     s->mb_skip_run= -1;
 
     h->is_complex = FRAME_MBAFF || s->picture_structure != PICT_FRAME || s->codec_id != CODEC_ID_H264 ||
-                    (ENABLE_GRAY && (s->flags&CODEC_FLAG_GRAY)) || (ENABLE_H264_ENCODER && s->encoding);
+                    (CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)) || (CONFIG_H264_ENCODER && s->encoding);
 
     if( h->pps.cabac ) {
         int i;
@@ -7293,7 +7294,7 @@ static void execute_decode_slices(H264Context *h, int context_count){
     H264Context *hx;
     int i;
 
-    if(avctx->codec_id == CODEC_ID_H264_VDPAU)
+    if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
         return;
     if(context_count == 1) {
         decode_slice(avctx, &h);
@@ -7423,10 +7424,10 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
                && (avctx->skip_frame < AVDISCARD_BIDIR  || hx->slice_type_nos!=FF_B_TYPE)
                && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE)
                && avctx->skip_frame < AVDISCARD_ALL){
-                if(ENABLE_H264_VDPAU_DECODER && avctx->codec_id == CODEC_ID_H264_VDPAU){
+                if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
                     static const uint8_t start_code[] = {0x00, 0x00, 0x01};
-                    ff_vdpau_h264_add_data_chunk(h, start_code, sizeof(start_code));
-                    ff_vdpau_h264_add_data_chunk(h, &buf[buf_index - consumed], consumed );
+                    ff_vdpau_add_data_chunk(s, start_code, sizeof(start_code));
+                    ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], consumed );
                 }else
                     context_count++;
             }
@@ -7624,6 +7625,9 @@ static int decode_frame(AVCodecContext *avctx,
         s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
         s->current_picture_ptr->pict_type= s->pict_type;
 
+        if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+            ff_vdpau_h264_set_reference_frames(s);
+
         if(!s->dropable) {
             execute_ref_pic_marking(h, h->mmco, h->mmco_index);
             h->prev_poc_msb= h->poc_msb;
@@ -7632,8 +7636,8 @@ static int decode_frame(AVCodecContext *avctx,
         h->prev_frame_num_offset= h->frame_num_offset;
         h->prev_frame_num= h->frame_num;
 
-        if (ENABLE_H264_VDPAU_DECODER && avctx->codec_id == CODEC_ID_H264_VDPAU)
-            ff_vdpau_h264_picture_complete(h);
+        if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+            ff_vdpau_h264_picture_complete(s);
 
         /*
          * FIXME: Error handling code does not seem to support interlaced
@@ -8020,11 +8024,11 @@ AVCodec h264_decoder = {
     .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
 };
 
-#ifdef CONFIG_H264_VDPAU_DECODER
+#if CONFIG_H264_VDPAU_DECODER
 AVCodec h264_vdpau_decoder = {
     "h264_vdpau",
     CODEC_TYPE_VIDEO,
-    CODEC_ID_H264_VDPAU,
+    CODEC_ID_H264,
     sizeof(H264Context),
     decode_init,
     NULL,
@@ -8036,6 +8040,6 @@ AVCodec h264_vdpau_decoder = {
 };
 #endif
 
-#ifdef CONFIG_SVQ3_DECODER
+#if CONFIG_SVQ3_DECODER
 #include "svq3.c"
 #endif
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 40a94a0..5e879fc 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -86,8 +86,8 @@
 #define CHROMA 1
 #endif
 
-#ifndef ENABLE_H264_ENCODER
-#define ENABLE_H264_ENCODER 0
+#ifndef CONFIG_H264_ENCODER
+#define CONFIG_H264_ENCODER 0
 #endif
 
 #define EXTENDED_SAR          255
diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c
index e94f8c6..af79fee 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct H264BSFContext {
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index cfa04c4..4c3b134 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -44,11 +44,11 @@ int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size)
 
     for(i=0; i<buf_size; i++){
         if(state==7){
-#ifdef HAVE_FAST_UNALIGNED
+#if HAVE_FAST_UNALIGNED
         /* we check i<buf_size instead of i+3/7 because its simpler
          * and there should be FF_INPUT_BUFFER_PADDING_SIZE bytes at the end
          */
-#    ifdef HAVE_FAST_64BIT
+#    if HAVE_FAST_64BIT
             while(i<buf_size && !((~*(uint64_t*)(buf+i) & (*(uint64_t*)(buf+i) - 0x0101010101010101ULL)) & 0x8080808080808080ULL))
                 i+=8;
 #    else
@@ -161,8 +161,7 @@ static void close(AVCodecParserContext *s)
 
 
 AVCodecParser h264_parser = {
-    { CODEC_ID_H264,
-      CODEC_ID_H264_VDPAU },
+    { CODEC_ID_H264 },
     sizeof(H264Context),
     NULL,
     h264_parse,
diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c
index bf13e44..7bb825b 100644
--- a/libavcodec/huffyuv.c
+++ b/libavcodec/huffyuv.c
@@ -31,6 +31,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "dsputil.h"
+#include "mathops.h"
 
 #define VLC_BITS 11
 
@@ -261,7 +262,7 @@ static int generate_bits_table(uint32_t *dst, uint8_t *len_table){
     return 0;
 }
 
-#if defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER)
+#if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
 typedef struct {
     uint64_t val;
     int name;
@@ -317,7 +318,7 @@ static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){
         if(i==size) break;
     }
 }
-#endif /* defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER) */
+#endif /* CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER */
 
 static void generate_joint_tables(HYuvContext *s){
     uint16_t symbols[1<<VLC_BITS];
@@ -477,7 +478,7 @@ static int common_init(AVCodecContext *avctx){
     return 0;
 }
 
-#if defined(CONFIG_HUFFYUV_DECODER) || defined(CONFIG_FFVHUFF_DECODER)
+#if CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER
 static av_cold int decode_init(AVCodecContext *avctx)
 {
     HYuvContext *s = avctx->priv_data;
@@ -573,9 +574,9 @@ s->bgr32=1;
 
     return 0;
 }
-#endif /* defined(CONFIG_HUFFYUV_DECODER) || defined(CONFIG_FFVHUFF_DECODER) */
+#endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */
 
-#if defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER)
+#if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
 static int store_table(HYuvContext *s, uint8_t *len, uint8_t *buf){
     int i;
     int index= 0;
@@ -725,7 +726,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     return 0;
 }
-#endif /* defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER) */
+#endif /* CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER */
 
 /* TODO instead of restarting the read when the code isn't in the first level
  * of the joint table, jump into the 2nd level of the individual table. */
@@ -761,7 +762,7 @@ static void decode_gray_bitstream(HYuvContext *s, int count){
     }
 }
 
-#if defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER)
+#if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
 static int encode_422_bitstream(HYuvContext *s, int count){
     int i;
 
@@ -854,7 +855,7 @@ static int encode_gray_bitstream(HYuvContext *s, int count){
     }
     return 0;
 }
-#endif /* defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER) */
+#endif /* CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER */
 
 static av_always_inline void decode_bgr_1(HYuvContext *s, int count, int decorrelate, int alpha){
     int i;
@@ -931,7 +932,7 @@ static int encode_bgr_bitstream(HYuvContext *s, int count){
     return 0;
 }
 
-#if defined(CONFIG_HUFFYUV_DECODER) || defined(CONFIG_FFVHUFF_DECODER)
+#if CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER
 static void draw_slice(HYuvContext *s, int y){
     int h, cy;
     int offset[4];
@@ -1198,7 +1199,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const
 
     return (get_bits_count(&s->gb)+31)/32*4 + table_size;
 }
-#endif /* defined(CONFIG_HUFFYUV_DECODER) || defined(CONFIG_FFVHUFF_DECODER) */
+#endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */
 
 static int common_end(HYuvContext *s){
     int i;
@@ -1209,7 +1210,7 @@ static int common_end(HYuvContext *s){
     return 0;
 }
 
-#if defined(CONFIG_HUFFYUV_DECODER) || defined(CONFIG_FFVHUFF_DECODER)
+#if CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER
 static av_cold int decode_end(AVCodecContext *avctx)
 {
     HYuvContext *s = avctx->priv_data;
@@ -1224,9 +1225,9 @@ static av_cold int decode_end(AVCodecContext *avctx)
 
     return 0;
 }
-#endif /* defined(CONFIG_HUFFYUV_DECODER) || defined(CONFIG_FFVHUFF_DECODER) */
+#endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */
 
-#if defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER)
+#if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
     HYuvContext *s = avctx->priv_data;
     AVFrame *pict = data;
@@ -1431,9 +1432,9 @@ static av_cold int encode_end(AVCodecContext *avctx)
 
     return 0;
 }
-#endif /* defined(CONFIG_HUFFYUV_ENCODER) || defined(CONFIG_FFVHUFF_ENCODER) */
+#endif /* CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER */
 
-#ifdef CONFIG_HUFFYUV_DECODER
+#if CONFIG_HUFFYUV_DECODER
 AVCodec huffyuv_decoder = {
     "huffyuv",
     CODEC_TYPE_VIDEO,
@@ -1449,7 +1450,7 @@ AVCodec huffyuv_decoder = {
 };
 #endif
 
-#ifdef CONFIG_FFVHUFF_DECODER
+#if CONFIG_FFVHUFF_DECODER
 AVCodec ffvhuff_decoder = {
     "ffvhuff",
     CODEC_TYPE_VIDEO,
@@ -1465,7 +1466,7 @@ AVCodec ffvhuff_decoder = {
 };
 #endif
 
-#ifdef CONFIG_HUFFYUV_ENCODER
+#if CONFIG_HUFFYUV_ENCODER
 AVCodec huffyuv_encoder = {
     "huffyuv",
     CODEC_TYPE_VIDEO,
@@ -1479,7 +1480,7 @@ AVCodec huffyuv_encoder = {
 };
 #endif
 
-#ifdef CONFIG_FFVHUFF_ENCODER
+#if CONFIG_FFVHUFF_ENCODER
 AVCodec ffvhuff_encoder = {
     "ffvhuff",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 952ddcb..ac76b78 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -34,7 +34,7 @@
 #include "dsputil.h"
 #include "colorspace.h"
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 #include "x86/mmx.h"
 #include "x86/dsputil_mmx.h"
 #endif
@@ -267,6 +267,12 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
     [PIX_FMT_XVMC_MPEG2_IDCT] = {
         .name = "xvmcidct",
     },
+    [PIX_FMT_VDPAU_MPEG1] = {
+        .name = "vdpau_mpeg1",
+    },
+    [PIX_FMT_VDPAU_MPEG2] = {
+        .name = "vdpau_mpeg2",
+    },
     [PIX_FMT_VDPAU_H264] = {
         .name = "vdpau_h264",
     },
@@ -2089,7 +2095,7 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
     return 0;
 }
 
-#ifndef CONFIG_SWSCALE
+#if !CONFIG_SWSCALE
 static uint8_t y_ccir_to_jpeg[256];
 static uint8_t y_jpeg_to_ccir[256];
 static uint8_t c_ccir_to_jpeg[256];
@@ -2662,7 +2668,7 @@ int img_get_alpha_info(const AVPicture *src,
     return ret;
 }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 #define DEINT_INPLACE_LINE_LUM \
                     movd_m2r(lum_m4[0],mm0);\
                     movd_m2r(lum_m3[0],mm1);\
@@ -2716,7 +2722,7 @@ static void deinterlace_line(uint8_t *dst,
                              const uint8_t *lum,
                              int size)
 {
-#ifndef HAVE_MMX
+#if !HAVE_MMX
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     int sum;
 
@@ -2754,7 +2760,7 @@ static void deinterlace_line(uint8_t *dst,
 static void deinterlace_line_inplace(uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
                              int size)
 {
-#ifndef HAVE_MMX
+#if !HAVE_MMX
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     int sum;
 
diff --git a/libavcodec/imgresample.c b/libavcodec/imgresample.c
index 6ca810c..6e89725 100644
--- a/libavcodec/imgresample.c
+++ b/libavcodec/imgresample.c
@@ -29,7 +29,7 @@
 #include "imgconvert.h"
 #include "libswscale/swscale.h"
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
 #include "ppc/imgresample_altivec.h"
 #endif
 
@@ -153,7 +153,7 @@ static void v_resample(uint8_t *dst, int dst_width, const uint8_t *src,
     }
 }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 
 #include "x86/mmx.h"
 
@@ -340,7 +340,7 @@ static void h_resample(uint8_t *dst, int dst_width, const uint8_t *src,
     } else {
         n = dst_width;
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
     if ((mm_flags & FF_MM_MMX) && NB_TAPS == 4)
         h_resample_fast4_mmx(dst, n,
                              src, src_width, src_start, src_incr, filters);
@@ -397,7 +397,7 @@ static void component_resample(ImgReSampleContext *s,
         }
         /* apply vertical filter */
         phase_y = get_phase(src_y);
-#ifdef HAVE_MMX
+#if HAVE_MMX
         /* desactivated MMX because loss of precision */
         if ((mm_flags & FF_MM_MMX) && NB_TAPS == 4 && 0)
             v_resample4_mmx(output, owidth,
@@ -405,7 +405,7 @@ static void component_resample(ImgReSampleContext *s,
                             &s->v_filters[phase_y][0]);
         else
 #endif
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
         if ((mm_flags & FF_MM_ALTIVEC) && NB_TAPS == 4 && FILTER_BITS <= 6)
             v_resample16_altivec(output, owidth,
                                  s->line_buf + (ring_y - NB_TAPS + 1) * owidth,
@@ -732,7 +732,7 @@ static void dump_filter(int16_t *filter)
     }
 }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 int mm_flags;
 #endif
 
@@ -804,7 +804,7 @@ int main(int argc, char **argv)
     }
 
     /* mmx test */
-#ifdef HAVE_MMX
+#if HAVE_MMX
     av_log(NULL, AV_LOG_INFO, "MMX test\n");
     fact = 0.72;
     xsize = (int)(XSIZE * fact);
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index ec954a4..9a5d5fd 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -36,4 +36,12 @@
  */
 void ff_log_missing_feature(void *avc, const char *feature, int want_sample);
 
+/**
+ * Logs a generic warning message asking for a sample.
+ * @param[in] avc a pointer to an arbitrary struct of which the first field is
+ * a pointer to an AVClass struct
+ * @param[in] msg string containing an optional message, or NULL if no message
+ */
+void ff_log_ask_for_sample(void *avc, const char *msg);
+
 #endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c
index 7842759..02e1584 100644
--- a/libavcodec/jpeglsdec.c
+++ b/libavcodec/jpeglsdec.c
@@ -28,6 +28,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "golomb.h"
+#include "mathops.h"
 #include "mjpeg.h"
 #include "mjpegdec.h"
 #include "jpegls.h"
diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
index f799550..14a81be 100644
--- a/libavcodec/jpeglsenc.c
+++ b/libavcodec/jpeglsenc.c
@@ -28,6 +28,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "golomb.h"
+#include "mathops.h"
 #include "dsputil.h"
 #include "mjpeg.h"
 #include "jpegls.h"
diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c
index 5560b9a..2f16b73 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -45,7 +45,7 @@
 #include "bitstream.h"
 #include "lcl.h"
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 
@@ -65,7 +65,7 @@ typedef struct LclDecContext {
     unsigned int decomp_size;
     // Decompression buffer
     unsigned char* decomp_buf;
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     z_stream zstream;
 #endif
 } LclDecContext;
@@ -174,7 +174,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const
     unsigned char yq, y1q, uq, vq;
     int uqvq;
     unsigned int mthread_inlen, mthread_outlen;
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     int zret; // Zlib return code
 #endif
     unsigned int len = buf_size;
@@ -235,7 +235,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const
         }
         break;
     case CODEC_ID_ZLIB:
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
         /* Using the original dll with normal compression (-1) and RGB format
          * gives a file with ZLIB fourcc, but frame is really uncompressed.
          * To be sure that's true check also frame size */
@@ -524,7 +524,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     c->pic.data[0] = NULL;
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     // Needed if zlib unused or init aborted before inflateInit
     memset(&(c->zstream), 0, sizeof(z_stream));
 #endif
@@ -599,7 +599,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
         }
         break;
     case CODEC_ID_ZLIB:
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
         switch (c->compression) {
         case COMP_ZLIB_HISPEED:
             av_log(avctx, AV_LOG_INFO, "High speed compression.\n");
@@ -648,7 +648,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     /* If needed init zlib */
     if (avctx->codec_id == CODEC_ID_ZLIB) {
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
         c->zstream.zalloc = Z_NULL;
         c->zstream.zfree = Z_NULL;
         c->zstream.opaque = Z_NULL;
@@ -679,14 +679,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
 
     if (c->pic.data[0])
         avctx->release_buffer(avctx, &c->pic);
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     inflateEnd(&(c->zstream));
 #endif
 
     return 0;
 }
 
-#ifdef CONFIG_MSZH_DECODER
+#if CONFIG_MSZH_DECODER
 AVCodec mszh_decoder = {
     "mszh",
     CODEC_TYPE_VIDEO,
@@ -701,7 +701,7 @@ AVCodec mszh_decoder = {
 };
 #endif
 
-#ifdef CONFIG_ZLIB_DECODER
+#if CONFIG_ZLIB_DECODER
 AVCodec zlib_decoder = {
     "zlib",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c
index d026965..680a511 100644
--- a/libavcodec/lclenc.c
+++ b/libavcodec/lclenc.c
@@ -45,7 +45,7 @@
 #include "bitstream.h"
 #include "lcl.h"
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 
@@ -70,7 +70,7 @@ typedef struct LclEncContext {
     unsigned int max_comp_size;
     // Compression buffer
     unsigned char* comp_buf;
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     z_stream zstream;
 #endif
 } LclEncContext;
@@ -87,7 +87,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
     int i;
     int zret; // Zlib return code
 
-#ifndef CONFIG_ZLIB
+#if !CONFIG_ZLIB
     av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled in.\n");
     return -1;
 #else
@@ -144,7 +144,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     LclEncContext *c = avctx->priv_data;
     int zret; // Zlib return code
 
-#ifndef CONFIG_ZLIB
+#if !CONFIG_ZLIB
     av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
     return 1;
 #else
@@ -213,7 +213,7 @@ static av_cold int encode_end(AVCodecContext *avctx)
 
     av_freep(&avctx->extradata);
     av_freep(&c->comp_buf);
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     deflateEnd(&(c->zstream));
 #endif
 
diff --git a/libavcodec/libamr.c b/libavcodec/libamr.c
index 79ca57f..80cb090 100644
--- a/libavcodec/libamr.c
+++ b/libavcodec/libamr.c
@@ -65,7 +65,7 @@
 
 #include "avcodec.h"
 
-#ifdef CONFIG_LIBAMR_NB_FIXED
+#if CONFIG_LIBAMR_NB_FIXED
 
 #define MMS_IO
 
@@ -137,7 +137,7 @@ static void amr_decode_fix_avctx(AVCodecContext * avctx)
     avctx->sample_fmt = SAMPLE_FMT_S16;
 }
 
-#ifdef CONFIG_LIBAMR_NB_FIXED
+#if CONFIG_LIBAMR_NB_FIXED
 /* fixed point version*/
 /* frame size in serial bitstream file (frame type + serial stream + flags) */
 #define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5)
@@ -353,7 +353,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 }
 
 
-#elif defined(CONFIG_LIBAMR_NB) /* Float point version*/
+#elif CONFIG_LIBAMR_NB /* Float point version*/
 
 typedef struct AMRContext {
     int frameCount;
@@ -492,7 +492,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 
 #endif
 
-#if defined(CONFIG_LIBAMR_NB) || defined(CONFIG_LIBAMR_NB_FIXED)
+#if CONFIG_LIBAMR_NB || CONFIG_LIBAMR_NB_FIXED
 
 AVCodec libamr_nb_decoder =
 {
@@ -524,7 +524,7 @@ AVCodec libamr_nb_encoder =
 #endif
 
 /* -----------AMR wideband ------------*/
-#ifdef CONFIG_LIBAMR_WB
+#if CONFIG_LIBAMR_WB
 
 #ifdef _TYPEDEF_H
 //To avoid duplicate typedefs from typedef in amr-nb
diff --git a/libavcodec/libdirac.h b/libavcodec/libdirac.h
index 54db287..b677a7e 100644
--- a/libavcodec/libdirac.h
+++ b/libavcodec/libdirac.h
@@ -28,7 +28,7 @@
 
 #include "config.h"
 
-#ifdef CONFIG_LIBDIRAC
+#if CONFIG_LIBDIRAC
 
 #include "avcodec.h"
 #include <libdirac_common/dirac_types.h>
diff --git a/libavcodec/libfaad.c b/libavcodec/libfaad.c
index c6da20d..7cf39e2 100644
--- a/libavcodec/libfaad.c
+++ b/libavcodec/libfaad.c
@@ -35,12 +35,13 @@
 #endif
 
 /*
- * when CONFIG_LIBFAADBIN is defined the libfaad will be opened at runtime
+ * when CONFIG_LIBFAADBIN is true libfaad will be opened at runtime
  */
 //#undef CONFIG_LIBFAADBIN
-//#define CONFIG_LIBFAADBIN
+//#define CONFIG_LIBFAADBIN 0
+//#define CONFIG_LIBFAADBIN 1
 
-#ifdef CONFIG_LIBFAADBIN
+#if CONFIG_LIBFAADBIN
 #include <dlfcn.h>
 static const char* const libfaadname = "libfaad.so";
 #else
@@ -224,7 +225,7 @@ static av_cold int faac_decode_init(AVCodecContext *avctx)
     FAACContext *s = avctx->priv_data;
     faacDecConfigurationPtr faac_cfg;
 
-#ifdef CONFIG_LIBFAADBIN
+#if CONFIG_LIBFAADBIN
     const char* err = 0;
 
     s->handle = dlopen(libfaadname, RTLD_LAZY);
@@ -259,7 +260,7 @@ static av_cold int faac_decode_init(AVCodecContext *avctx)
 
 #undef dfaac
 
-#ifdef CONFIG_LIBFAADBIN
+#if CONFIG_LIBFAADBIN
     if (err) {
         dlclose(s->handle);
         av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n",
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index bccff00..c91f653 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -28,7 +28,7 @@
 #include "mpegaudio.h"
 #include <lame/lame.h>
 
-#define BUFFER_SIZE (7200 + MPA_FRAME_SIZE + MPA_FRAME_SIZE/4)
+#define BUFFER_SIZE (7200 + 2*MPA_FRAME_SIZE + MPA_FRAME_SIZE/4)
 typedef struct Mp3AudioContext {
     lame_global_flags *gfp;
     int stereo;
@@ -174,10 +174,12 @@ static int MP3lame_encode_frame(AVCodecContext *avctx,
                 );
     }
 
-    if(lame_result==-1) {
-        /* output buffer too small */
-        av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", s->buffer_index, BUFFER_SIZE - s->buffer_index);
-        return 0;
+    if(lame_result < 0){
+        if(lame_result==-1) {
+            /* output buffer too small */
+            av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", s->buffer_index, BUFFER_SIZE - s->buffer_index);
+        }
+        return -1;
     }
 
     s->buffer_index += lame_result;
@@ -185,20 +187,20 @@ static int MP3lame_encode_frame(AVCodecContext *avctx,
     if(s->buffer_index<4)
         return 0;
 
-        len= mp3len(s->buffer, NULL, NULL);
+    len= mp3len(s->buffer, NULL, NULL);
 //av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index);
-        if(len <= s->buffer_index){
-            memcpy(frame, s->buffer, len);
-            s->buffer_index -= len;
+    if(len <= s->buffer_index){
+        memcpy(frame, s->buffer, len);
+        s->buffer_index -= len;
 
-            memmove(s->buffer, s->buffer+len, s->buffer_index);
+        memmove(s->buffer, s->buffer+len, s->buffer_index);
             //FIXME fix the audio codec API, so we do not need the memcpy()
 /*for(i=0; i<len; i++){
     av_log(avctx, AV_LOG_DEBUG, "%2X ", frame[i]);
 }*/
-            return len;
-        }else
-            return 0;
+        return len;
+    }else
+        return 0;
 }
 
 static av_cold int MP3lame_encode_close(AVCodecContext *avctx)
diff --git a/libavcodec/libschroedinger.h b/libavcodec/libschroedinger.h
index 6902a5d..79faefc 100644
--- a/libavcodec/libschroedinger.h
+++ b/libavcodec/libschroedinger.h
@@ -28,7 +28,7 @@
 
 #include "config.h"
 
-#ifdef CONFIG_LIBSCHROEDINGER
+#if CONFIG_LIBSCHROEDINGER
 
 #include <schroedinger/schrobitstream.h>
 #include <schroedinger/schroframe.h>
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index d7f635c..abfa462 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -31,6 +31,7 @@
  */
 
 /* FFmpeg includes */
+#include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
 #include "avcodec.h"
 
diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c
index 3149459..1251fdd 100644
--- a/libavcodec/libxvidff.c
+++ b/libavcodec/libxvidff.c
@@ -28,6 +28,7 @@
 #include <xvid.h>
 #include <unistd.h>
 #include "avcodec.h"
+#include "libavutil/intreadwrite.h"
 #include "libxvid_internal.h"
 
 /**
@@ -166,9 +167,9 @@ av_cold int ff_xvid_encode_init(AVCodecContext *avctx)  {
     xvid_gbl_init.version = XVID_VERSION;
     xvid_gbl_init.debug = 0;
 
-#ifdef ARCH_PPC
+#if ARCH_PPC
     /* Xvid's PPC support is borked, use libavcodec to detect */
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     if( has_altivec() ) {
         xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
     } else
@@ -335,7 +336,7 @@ av_cold int ff_xvid_encode_init(AVCodecContext *avctx)  {
         /* We are claiming to be Xvid */
         x->quicktime_format = 0;
         if(!avctx->codec_tag)
-            avctx->codec_tag = ff_get_fourcc("xvid");
+            avctx->codec_tag = AV_RL32("xvid");
     }
 
     /* Bframes */
@@ -557,7 +558,7 @@ void xvid_correct_framerate(AVCodecContext *avctx) {
     frate = avctx->time_base.den;
     fbase = avctx->time_base.num;
 
-    gcd = ff_gcd(frate, fbase);
+    gcd = av_gcd(frate, fbase);
     if( gcd > 1 ) {
         frate /= gcd;
         fbase /= gcd;
@@ -579,7 +580,7 @@ void xvid_correct_framerate(AVCodecContext *avctx) {
     } else
         est_fbase = 1;
 
-    gcd = ff_gcd(est_frate, est_fbase);
+    gcd = av_gcd(est_frate, est_fbase);
     if( gcd > 1 ) {
         est_frate /= gcd;
         est_fbase /= gcd;
diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index ad5737e..0bd356f 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -27,6 +27,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "golomb.h"
+#include "mathops.h"
 
 enum LOCO_MODE {LOCO_UNKN=0, LOCO_CYUY2=-1, LOCO_CRGB=-2, LOCO_CRGBA=-3, LOCO_CYV12=-4,
  LOCO_YUY2=1, LOCO_UYVY=2, LOCO_RGB=3, LOCO_RGBA=4, LOCO_YV12=5};
diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index 07265c8..33e8cd6 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -24,19 +24,19 @@
 
 #include "libavutil/common.h"
 
-#ifdef ARCH_X86_32
+#if   ARCH_X86_32
 
 #include "x86/mathops.h"
 
-#elif defined(ARCH_ARM)
+#elif ARCH_ARM
 
 #include "arm/mathops.h"
 
-#elif defined(ARCH_PPC)
+#elif ARCH_PPC
 
 #include "ppc/mathops.h"
 
-#elif defined(ARCH_BFIN)
+#elif ARCH_BFIN
 
 #include "bfin/mathops.h"
 
@@ -83,5 +83,35 @@ static av_always_inline int MULH(int a, int b){
 #   define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
 #endif
 
+/* median of 3 */
+#ifndef mid_pred
+#define mid_pred mid_pred
+static inline av_const int mid_pred(int a, int b, int c)
+{
+#if 0
+    int t= (a-b)&((a-b)>>31);
+    a-=t;
+    b+=t;
+    b-= (b-c)&((b-c)>>31);
+    b+= (a-b)&((a-b)>>31);
+
+    return b;
+#else
+    if(a>b){
+        if(c>b){
+            if(c>a) b=a;
+            else    b=c;
+        }
+    }else{
+        if(b>c){
+            if(c>a) b=c;
+            else    b=a;
+        }
+    }
+    return b;
+#endif
+}
+#endif
+
 #endif /* AVCODEC_MATHOPS_H */
 
diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c
index c85b82f..661f09c 100644
--- a/libavcodec/mdct.c
+++ b/libavcodec/mdct.c
@@ -53,8 +53,9 @@ DECLARE_ALIGNED(16, float, ff_sine_256 [ 256]);
 DECLARE_ALIGNED(16, float, ff_sine_512 [ 512]);
 DECLARE_ALIGNED(16, float, ff_sine_1024[1024]);
 DECLARE_ALIGNED(16, float, ff_sine_2048[2048]);
-float *ff_sine_windows[5] = {
-    ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048,
+DECLARE_ALIGNED(16, float, ff_sine_4096[4096]);
+float *ff_sine_windows[6] = {
+    ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
 };
 
 // Generate a sine window.
diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c
index fb27efb..c27927a 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -73,7 +73,7 @@ static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *av
                 *poutbuf_size = poutbufp - *poutbuf;
                 return 1;
             case APP1:
-                if (i + 8 < buf_size && AV_RL32(buf + i + 8) == ff_get_fourcc("mjpg")) {
+                if (i + 8 < buf_size && AV_RL32(buf + i + 8) == AV_RL32("mjpg")) {
                     av_log(avctx, AV_LOG_ERROR, "bitstream already formatted\n");
                     memcpy(*poutbuf, buf, buf_size);
                     *poutbuf_size = buf_size;
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 5dcdb73..08c64a1 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -977,7 +977,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s)
         skip_bits(&s->gb, 8);
 
     if(s->lossless){
-        if(ENABLE_JPEGLS_DECODER && s->ls){
+        if(CONFIG_JPEGLS_DECODER && s->ls){
 //            for(){
 //            reset_ls_coding_parameters(s, 0);
 
@@ -1040,7 +1040,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
     /* buggy AVID, it puts EOI only at every 10th frame */
     /* also this fourcc is used by non-avid files too, it holds some
        informations, but it's always present in AVID creates files */
-    if (id == ff_get_fourcc("AVI1"))
+    if (id == AV_RL32("AVI1"))
     {
         /* structure:
             4bytes      AVI1
@@ -1068,7 +1068,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
 
 //    len -= 2;
 
-    if (id == ff_get_fourcc("JFIF"))
+    if (id == AV_RL32("JFIF"))
     {
         int t_w, t_h, v1, v2;
         skip_bits(&s->gb, 8); /* the trailing zero-byte */
@@ -1098,7 +1098,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
         goto out;
     }
 
-    if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e'))
+    if (id == AV_RL32("Adob") && (get_bits(&s->gb, 8) == 'e'))
     {
         if (s->avctx->debug & FF_DEBUG_PICT_INFO)
             av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n");
@@ -1110,7 +1110,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
         goto out;
     }
 
-    if (id == ff_get_fourcc("LJIF")){
+    if (id == AV_RL32("LJIF")){
         if (s->avctx->debug & FF_DEBUG_PICT_INFO)
             av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n");
         skip_bits(&s->gb, 16); /* version ? */
@@ -1139,7 +1139,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
         id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
         id = be2me_32(id);
         len -= 4;
-        if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */
+        if (id == AV_RL32("mjpg")) /* Apple MJPEG-A */
         {
 #if 0
             skip_bits(&s->gb, 32); /* field size */
@@ -1418,7 +1418,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
                         return -1;
                     break;
                 case LSE:
-                    if (!ENABLE_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0)
+                    if (!CONFIG_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0)
                         return -1;
                     break;
                 case EOI:
diff --git a/libavcodec/mlp.c b/libavcodec/mlp.c
index 7ef7f97..6f10c35 100644
--- a/libavcodec/mlp.c
+++ b/libavcodec/mlp.c
@@ -22,6 +22,7 @@
 #include <stdint.h>
 
 #include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
 #include "mlp.h"
 
 const uint8_t ff_mlp_huffman_tables[3][18][2] = {
diff --git a/libavcodec/mmvideo.c b/libavcodec/mmvideo.c
index 03d86ee..c1f1d36 100644
--- a/libavcodec/mmvideo.c
+++ b/libavcodec/mmvideo.c
@@ -31,6 +31,7 @@
  *  http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define MM_PREAMBLE_SIZE    6
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index d9d48a6..b960e88 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -32,6 +32,7 @@
 #include <limits.h>
 #include "avcodec.h"
 #include "dsputil.h"
+#include "mathops.h"
 #include "mpegvideo.h"
 
 #undef NDEBUG
diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 99e8135..2423f2d 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 
diff --git a/libavcodec/mpc.c b/libavcodec/mpc.c
index 35ccbf6..596a5e9 100644
--- a/libavcodec/mpc.c
+++ b/libavcodec/mpc.c
@@ -29,10 +29,6 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "dsputil.h"
-
-#ifdef CONFIG_MPEGAUDIO_HP
-#define USE_HIGHPRECISION
-#endif
 #include "mpegaudio.h"
 
 #include "mpc.h"
diff --git a/libavcodec/mpc.h b/libavcodec/mpc.h
index 038c34f..df33683 100644
--- a/libavcodec/mpc.h
+++ b/libavcodec/mpc.h
@@ -32,10 +32,6 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "dsputil.h"
-
-#ifdef CONFIG_MPEGAUDIO_HP
-#define USE_HIGHPRECISION
-#endif
 #include "mpegaudio.h"
 
 #include "mpcdata.h"
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index 2db4172..a22baac 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -29,10 +29,6 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "dsputil.h"
-
-#ifdef CONFIG_MPEGAUDIO_HP
-#define USE_HIGHPRECISION
-#endif
 #include "mpegaudio.h"
 
 #include "mpc.h"
diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index c47e74d..29f2e5f 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -29,10 +29,6 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "dsputil.h"
-
-#ifdef CONFIG_MPEGAUDIO_HP
-#define USE_HIGHPRECISION
-#endif
 #include "mpegaudio.h"
 
 #include "mpc.h"
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 52ab50b..92eef72 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -34,6 +34,7 @@
 #include "mpeg12data.h"
 #include "mpeg12decdata.h"
 #include "bytestream.h"
+#include "vdpau_internal.h"
 
 //#undef NDEBUG
 //#include <assert.h>
@@ -303,7 +304,7 @@ static int mpeg_decode_mb(MpegEncContext *s,
         }else
             memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
         s->mb_intra = 1;
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
         //if 1, we memcpy blocks in xvmcvideo
         if(s->avctx->xvmc_acceleration > 1){
             XVMC_pack_pblocks(s,-1);//inter are always full blocks
@@ -516,7 +517,7 @@ static int mpeg_decode_mb(MpegEncContext *s,
                 return -1;
             }
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
             //if 1, we memcpy blocks in xvmcvideo
             if(s->avctx->xvmc_acceleration > 1){
                 XVMC_pack_pblocks(s,cbp);
@@ -1218,7 +1219,12 @@ static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){
 
     if(avctx->xvmc_acceleration)
         return avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
-    else{
+    else if(avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
+        if(avctx->codec_id == CODEC_ID_MPEG1VIDEO)
+            return PIX_FMT_VDPAU_MPEG1;
+        else
+            return PIX_FMT_VDPAU_MPEG2;
+    }else{
         if(s->chroma_format <  2)
             return PIX_FMT_YUV420P;
         else if(s->chroma_format == 2)
@@ -1265,7 +1271,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){
          * that behave like P-frames. */
         avctx->has_b_frames = !(s->low_delay);
 
-        if(avctx->sub_id==1){//s->codec_id==avctx->codec_id==CODEC_ID
+        assert((avctx->sub_id==1) == (avctx->codec_id==CODEC_ID_MPEG1VIDEO));
+        if(avctx->codec_id==CODEC_ID_MPEG1VIDEO){
             //MPEG-1 fps
             avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
             avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
@@ -1306,7 +1313,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){
 
         avctx->pix_fmt = mpeg_get_pixelformat(avctx);
         //until then pix_fmt may be changed right after codec init
-        if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
+        if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
+            s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
             if( avctx->idct_algo == FF_IDCT_AUTO )
                 avctx->idct_algo = FF_IDCT_SIMPLE;
 
@@ -1643,7 +1651,7 @@ static int mpeg_field_start(MpegEncContext *s){
                 }
             }
     }
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
 // MPV_frame_start will call this function too,
 // but we need to call it on every field
     if(s->avctx->xvmc_acceleration)
@@ -1734,7 +1742,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
     }
 
     for(;;) {
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
         //If 1, we memcpy blocks in xvmcvideo.
         if(s->avctx->xvmc_acceleration > 1)
             XVMC_init_block(s);//set s->block
@@ -1916,7 +1924,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
     if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
         return 0;
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
     if(s->avctx->xvmc_acceleration)
         XVMC_field_end(s);
 #endif
@@ -2075,7 +2083,8 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
 
     avctx->pix_fmt = mpeg_get_pixelformat(avctx);
 
-    if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
+    if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
+        s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
         if( avctx->idct_algo == FF_IDCT_AUTO )
             avctx->idct_algo = FF_IDCT_SIMPLE;
 
@@ -2269,7 +2278,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
     }
 #endif
 
-    if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2"))
+    if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == AV_RL32("VCR2"))
         vcr2_init_sequence(avctx);
 
     s->slice_count= 0;
@@ -2303,6 +2312,10 @@ static int decode_chunks(AVCodecContext *avctx,
                     for(i=0; i<s->slice_count; i++)
                         s2->error_count += s2->thread_context[i]->error_count;
                 }
+
+                if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+                    ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count);
+
                 if (slice_end(avctx, picture)) {
                     if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
                         *data_size = sizeof(AVPicture);
@@ -2388,6 +2401,11 @@ static int decode_chunks(AVCodecContext *avctx,
                     return -1;
                 }
 
+                if (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) {
+                    s->slice_count++;
+                    break;
+                }
+
                 if(avctx->thread_count > 1){
                     int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
                     if(threshold <= mb_y){
@@ -2472,7 +2490,7 @@ AVCodec mpegvideo_decoder = {
     .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
 };
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
 static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){
     Mpeg1Context *s;
 
@@ -2507,3 +2525,36 @@ AVCodec mpeg_xvmc_decoder = {
 };
 
 #endif
+
+#if CONFIG_MPEG_VDPAU_DECODER
+AVCodec mpeg_vdpau_decoder = {
+    "mpegvideo_vdpau",
+    CODEC_TYPE_VIDEO,
+    CODEC_ID_MPEG2VIDEO,
+    sizeof(Mpeg1Context),
+    mpeg_decode_init,
+    NULL,
+    mpeg_decode_end,
+    mpeg_decode_frame,
+    CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
+    .flush= ff_mpeg_flush,
+    .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
+};
+#endif
+
+#if CONFIG_MPEG1_VDPAU_DECODER
+AVCodec mpeg1_vdpau_decoder = {
+    "mpeg1video_vdpau",
+    CODEC_TYPE_VIDEO,
+    CODEC_ID_MPEG1VIDEO,
+    sizeof(Mpeg1Context),
+    mpeg_decode_init,
+    NULL,
+    mpeg_decode_end,
+    mpeg_decode_frame,
+    CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
+    .flush= ff_mpeg_flush,
+    .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
+};
+#endif
+
diff --git a/libavcodec/mpegaudio.h b/libavcodec/mpegaudio.h
index 33af18d..96bea31 100644
--- a/libavcodec/mpegaudio.h
+++ b/libavcodec/mpegaudio.h
@@ -30,6 +30,8 @@
 #include "bitstream.h"
 #include "dsputil.h"
 
+#define CONFIG_AUDIO_NONSHORT 0
+
 /* max frame size, in samples */
 #define MPA_FRAME_SIZE 1152
 
@@ -51,10 +53,7 @@
 
 #define MP3_MASK 0xFFFE0CCF
 
-/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
-   audio decoder */
-
-#ifdef USE_HIGHPRECISION
+#if CONFIG_MPEGAUDIO_HP
 #define FRAC_BITS   23   /* fractional bits for sb_samples and dct */
 #define WFRAC_BITS  16   /* fractional bits for window */
 #else
@@ -66,16 +65,18 @@
 
 #define FIX(a)   ((int)((a) * FRAC_ONE))
 
-#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
+#if CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
 typedef int32_t OUT_INT;
 #define OUT_MAX INT32_MAX
 #define OUT_MIN INT32_MIN
 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
+#define OUT_FMT SAMPLE_FMT_S32
 #else
 typedef int16_t OUT_INT;
 #define OUT_MAX INT16_MAX
 #define OUT_MIN INT16_MIN
 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
+#define OUT_FMT SAMPLE_FMT_S16
 #endif
 
 #if FRAC_BITS <= 15
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index e4b17b0..55d865f 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -58,13 +58,16 @@ int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate,
 
     switch(s->layer) {
     case 1:
+        avctx->codec_id = CODEC_ID_MP1;
         *frame_size = 384;
         break;
     case 2:
+        avctx->codec_id = CODEC_ID_MP2;
         *frame_size = 1152;
         break;
     default:
     case 3:
+        avctx->codec_id = CODEC_ID_MP3;
         if (s->lsf)
             *frame_size = 576;
         else
@@ -248,7 +251,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
 
 
 AVCodecParser mpegaudio_parser = {
-    { CODEC_ID_MP2, CODEC_ID_MP3 },
+    { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 },
     sizeof(MpegAudioParseContext),
     mpegaudio_parse_init,
     mpegaudio_parse,
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index a853562..58e4511 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -34,12 +34,6 @@
  *  - test lsf / mpeg25 extensively.
  */
 
-/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
-   audio decoder */
-#ifdef CONFIG_MPEGAUDIO_HP
-#   define USE_HIGHPRECISION
-#endif
-
 #include "mpegaudio.h"
 #include "mpegaudiodecheader.h"
 
@@ -322,11 +316,7 @@ static int decode_init(AVCodecContext * avctx)
 
     s->avctx = avctx;
 
-#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
-    avctx->sample_fmt= SAMPLE_FMT_S32;
-#else
-    avctx->sample_fmt= SAMPLE_FMT_S16;
-#endif
+    avctx->sample_fmt= OUT_FMT;
     s->error_recognition= avctx->error_recognition;
 
     if(avctx->antialias_algo != FF_AA_FLOAT)
@@ -2322,7 +2312,7 @@ static void flush(AVCodecContext *avctx){
     s->last_buf_size= 0;
 }
 
-#ifdef CONFIG_MP3ADU_DECODER
+#if CONFIG_MP3ADU_DECODER
 static int decode_frame_adu(AVCodecContext * avctx,
                         void *data, int *data_size,
                         const uint8_t * buf, int buf_size)
@@ -2372,7 +2362,7 @@ static int decode_frame_adu(AVCodecContext * avctx,
 }
 #endif /* CONFIG_MP3ADU_DECODER */
 
-#ifdef CONFIG_MP3ON4_DECODER
+#if CONFIG_MP3ON4_DECODER
 
 /**
  * Context for MP3On4 decoder
@@ -2534,7 +2524,23 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
 }
 #endif /* CONFIG_MP3ON4_DECODER */
 
-#ifdef CONFIG_MP2_DECODER
+#if CONFIG_MP1_DECODER
+AVCodec mp1_decoder =
+{
+    "mp1",
+    CODEC_TYPE_AUDIO,
+    CODEC_ID_MP1,
+    sizeof(MPADecodeContext),
+    decode_init,
+    NULL,
+    NULL,
+    decode_frame,
+    CODEC_CAP_PARSE_ONLY,
+    .flush= flush,
+    .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
+};
+#endif
+#if CONFIG_MP2_DECODER
 AVCodec mp2_decoder =
 {
     "mp2",
@@ -2550,7 +2556,7 @@ AVCodec mp2_decoder =
     .long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
 };
 #endif
-#ifdef CONFIG_MP3_DECODER
+#if CONFIG_MP3_DECODER
 AVCodec mp3_decoder =
 {
     "mp3",
@@ -2566,7 +2572,7 @@ AVCodec mp3_decoder =
     .long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
 };
 #endif
-#ifdef CONFIG_MP3ADU_DECODER
+#if CONFIG_MP3ADU_DECODER
 AVCodec mp3adu_decoder =
 {
     "mp3adu",
@@ -2582,7 +2588,7 @@ AVCodec mp3adu_decoder =
     .long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
 };
 #endif
-#ifdef CONFIG_MP3ON4_DECODER
+#if CONFIG_MP3ON4_DECODER
 AVCodec mp3on4_decoder =
 {
     "mp3on4",
diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c
index c061d7f..767f823 100644
--- a/libavcodec/mpegaudioenc.c
+++ b/libavcodec/mpegaudioenc.c
@@ -26,6 +26,9 @@
 
 #include "avcodec.h"
 #include "bitstream.h"
+
+#undef  CONFIG_MPEGAUDIO_HP
+#define CONFIG_MPEGAUDIO_HP 0
 #include "mpegaudio.h"
 
 /* currently, cannot change these constants (need to modify
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 43a6e85..4b76e59 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -121,19 +121,19 @@ int ff_dct_common_init(MpegEncContext *s)
         s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
     s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
 
-#if defined(HAVE_MMX)
+#if   HAVE_MMX
     MPV_common_init_mmx(s);
-#elif defined(ARCH_ALPHA)
+#elif ARCH_ALPHA
     MPV_common_init_axp(s);
-#elif defined(CONFIG_MLIB)
+#elif CONFIG_MLIB
     MPV_common_init_mlib(s);
-#elif defined(HAVE_MMI)
+#elif HAVE_MMI
     MPV_common_init_mmi(s);
-#elif defined(ARCH_ARM)
+#elif ARCH_ARM
     MPV_common_init_arm(s);
-#elif defined(HAVE_ALTIVEC)
+#elif HAVE_ALTIVEC
     MPV_common_init_altivec(s);
-#elif defined(ARCH_BFIN)
+#elif ARCH_BFIN
     MPV_common_init_bfin(s);
 #endif
 
@@ -939,7 +939,7 @@ alloc:
         update_noise_reduction(s);
     }
 
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
     if(s->avctx->xvmc_acceleration)
         return XVMC_field_start(s, avctx);
 #endif
@@ -951,7 +951,7 @@ void MPV_frame_end(MpegEncContext *s)
 {
     int i;
     /* draw edge for correct motion prediction if outside */
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
 //just to make sure that all data is rendered.
     if(s->avctx->xvmc_acceleration){
         XVMC_field_end(s);
@@ -1448,7 +1448,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
             ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
                              src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
             ptr_y = s->edge_emu_buffer;
-            if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+            if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
                 ff_emulated_edge_mc(uvbuf  , ptr_cb, s->uvlinesize, 9, 9+field_based,
                                  uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
@@ -1475,7 +1475,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
     sy <<= 2 - lowres;
     pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy);
 
-    if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+    if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
         uvsx <<= 2 - lowres;
         uvsy <<= 2 - lowres;
         pix_op[lowres](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy);
@@ -1581,7 +1581,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
                 my += s->mv[dir][i][1];
             }
 
-        if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
+        if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY))
             chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my);
         break;
     case MV_TYPE_FIELD:
@@ -1736,7 +1736,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
 {
     int mb_x, mb_y;
     const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
-#ifdef CONFIG_XVMC
+#if CONFIG_XVMC
     if(s->avctx->xvmc_acceleration){
         XVMC_decode_mb(s);//xvmc uses pblocks
         return;
@@ -1870,7 +1870,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
                 add_dequant_dct(s, block[2], 2, dest_y + dct_offset             , dct_linesize, s->qscale);
                 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
 
-                if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+                if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                     if (s->chroma_y_shift){
                         add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
                         add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
@@ -1889,7 +1889,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
                 add_dct(s, block[2], 2, dest_y + dct_offset             , dct_linesize);
                 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
 
-                if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+                if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                     if(s->chroma_y_shift){//Chroma420
                         add_dct(s, block[4], 4, dest_cb, uvlinesize);
                         add_dct(s, block[5], 5, dest_cr, uvlinesize);
@@ -1911,7 +1911,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
                     }
                 }//fi gray
             }
-            else if (ENABLE_WMV2) {
+            else if (CONFIG_WMV2) {
                 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
             }
         } else {
@@ -1922,7 +1922,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
                 put_dct(s, block[2], 2, dest_y + dct_offset             , dct_linesize, s->qscale);
                 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
 
-                if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+                if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                     if(s->chroma_y_shift){
                         put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
                         put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
@@ -1941,7 +1941,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
                 s->dsp.idct_put(dest_y + dct_offset             , dct_linesize, block[2]);
                 s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
 
-                if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+                if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                     if(s->chroma_y_shift){
                         s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
                         s->dsp.idct_put(dest_cr, uvlinesize, block[5]);
@@ -1974,7 +1974,7 @@ skip_idct:
 }
 
 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     if(s->out_format == FMT_MPEG1) {
         if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1, 1);
         else                 MPV_decode_mb_internal(s, block, 0, 1);
diff --git a/libavcodec/mpegvideo_common.h b/libavcodec/mpegvideo_common.h
index 6875e85..5651981 100644
--- a/libavcodec/mpegvideo_common.h
+++ b/libavcodec/mpegvideo_common.h
@@ -103,7 +103,7 @@ static inline void gmc1_motion(MpegEncContext *s,
         }
     }
 
-    if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return;
+    if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
 
     motion_x= s->sprite_offset[1][0];
     motion_y= s->sprite_offset[1][1];
@@ -172,7 +172,7 @@ static inline void gmc_motion(MpegEncContext *s,
            a+1, (1<<(2*a+1)) - s->no_rounding,
            s->h_edge_pos, s->v_edge_pos);
 
-    if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return;
+    if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
 
     ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;
     oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;
@@ -321,7 +321,7 @@ if(s->quarter_sample)
                                 src_x, src_y<<field_based,
                                 s->h_edge_pos, s->v_edge_pos);
             ptr_y = s->edge_emu_buffer;
-            if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+            if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
                 ff_emulated_edge_mc(uvbuf ,
                                     ptr_cb, s->uvlinesize,
@@ -352,13 +352,13 @@ if(s->quarter_sample)
 
     pix_op[0][dxy](dest_y, ptr_y, linesize, h);
 
-    if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+    if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
         pix_op[s->chroma_x_shift][uvdxy]
                 (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
         pix_op[s->chroma_x_shift][uvdxy]
                 (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
     }
-    if(!is_mpeg12 && (ENABLE_H261_ENCODER || ENABLE_H261_DECODER) &&
+    if(!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) &&
          s->out_format == FMT_H261){
         ff_h261_loop_filter(s);
     }
@@ -371,7 +371,7 @@ void mpeg_motion(MpegEncContext *s,
                  uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
                  int motion_x, int motion_y, int h)
 {
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     if(s->out_format == FMT_MPEG1)
         mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
                     bottom_field, field_select, ref_picture, pix_op,
@@ -517,7 +517,7 @@ static inline void qpel_motion(MpegEncContext *s,
                             17, 17+field_based, src_x, src_y<<field_based,
                             s->h_edge_pos, s->v_edge_pos);
         ptr_y= s->edge_emu_buffer;
-        if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+        if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
             uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
             ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize,
                                 9, 9 + field_based,
@@ -551,7 +551,7 @@ static inline void qpel_motion(MpegEncContext *s,
         qpix_op[1][dxy](dest_y  , ptr_y  , linesize);
         qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize);
     }
-    if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+    if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
         pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
         pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
     }
@@ -705,7 +705,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
             mx += mv[0][0];
             my += mv[0][1];
         }
-        if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
+        if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY))
             chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
 
         return;
@@ -726,7 +726,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
                         0, 0, 0,
                         ref_picture, pix_op, qpix_op,
                         s->mv[dir][0][0], s->mv[dir][0][1], 16);
-        }else if(!is_mpeg12 && ENABLE_WMV2 && s->mspel){
+        }else if(!is_mpeg12 && CONFIG_WMV2 && s->mspel){
             ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
                         ref_picture, pix_op,
                         s->mv[dir][0][0], s->mv[dir][0][1], 16);
@@ -791,7 +791,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
             }
         }
 
-        if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
+        if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY))
             chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
     }
         break;
@@ -888,7 +888,7 @@ static inline void MPV_motion(MpegEncContext *s,
                               op_pixels_func (*pix_op)[4],
                               qpel_mc_func (*qpix_op)[16])
 {
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     if(s->out_format == FMT_MPEG1)
         MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
                             ref_picture, pix_op, qpix_op, 1);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 72af47a..ec076fd 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -464,7 +464,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
         avctx->b_frame_strategy = 0;
     }
 
-    i= ff_gcd(avctx->time_base.den, avctx->time_base.num);
+    i= av_gcd(avctx->time_base.den, avctx->time_base.num);
     if(i > 1){
         av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n");
         avctx->time_base.den /= i;
@@ -518,14 +518,14 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
         s->mjpeg_hsample[0] = 2;
         s->mjpeg_hsample[1] = 2>>chroma_h_shift;
         s->mjpeg_hsample[2] = 2>>chroma_h_shift;
-        if (!(ENABLE_MJPEG_ENCODER || ENABLE_LJPEG_ENCODER)
+        if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER)
             || ff_mjpeg_encode_init(s) < 0)
             return -1;
         avctx->delay=0;
         s->low_delay=1;
         break;
     case CODEC_ID_H261:
-        if (!ENABLE_H261_ENCODER)  return -1;
+        if (!CONFIG_H261_ENCODER)  return -1;
         if (ff_h261_get_picture_format(s->width, s->height) < 0) {
             av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height);
             return -1;
@@ -535,7 +535,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
         s->low_delay=1;
         break;
     case CODEC_ID_H263:
-        if (!ENABLE_H263_ENCODER)  return -1;
+        if (!CONFIG_H263_ENCODER)  return -1;
         if (h263_get_picture_format(s->width, s->height) == 7) {
             av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height);
             return -1;
@@ -661,7 +661,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
     if(avctx->trellis)
         s->dct_quantize = dct_quantize_trellis_c;
 
-    if((ENABLE_H263P_ENCODER || ENABLE_RV20_ENCODER) && s->modified_quant)
+    if((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant)
         s->chroma_qscale_table= ff_h263_chroma_qscale_table;
     s->progressive_frame=
     s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN));
@@ -670,20 +670,20 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
     ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp);
     ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp);
 
-    if (ENABLE_H261_ENCODER && s->out_format == FMT_H261)
+    if (CONFIG_H261_ENCODER && s->out_format == FMT_H261)
         ff_h261_encode_init(s);
-    if (ENABLE_ANY_H263_ENCODER && s->out_format == FMT_H263)
+    if (CONFIG_ANY_H263_ENCODER && s->out_format == FMT_H263)
         h263_encode_init(s);
-    if (ENABLE_MSMPEG4_ENCODER && s->msmpeg4_version)
+    if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version)
         ff_msmpeg4_encode_init(s);
-    if ((ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER)
+    if ((CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
         && s->out_format == FMT_MPEG1)
         ff_mpeg1_encode_init(s);
 
     /* init q matrix */
     for(i=0;i<64;i++) {
         int j= s->dsp.idct_permutation[i];
-        if(ENABLE_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
+        if(CONFIG_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
             s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
             s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
         }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
@@ -722,7 +722,7 @@ av_cold int MPV_encode_end(AVCodecContext *avctx)
     ff_rate_control_uninit(s);
 
     MPV_common_end(s);
-    if ((ENABLE_MJPEG_ENCODER || ENABLE_LJPEG_ENCODER) && s->out_format == FMT_MJPEG)
+    if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) && s->out_format == FMT_MJPEG)
         ff_mjpeg_encode_close(s);
 
     av_freep(&avctx->extradata);
@@ -1226,7 +1226,7 @@ vbv_retry:
 
         MPV_frame_end(s);
 
-        if (ENABLE_MJPEG_ENCODER && s->out_format == FMT_MJPEG)
+        if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG)
             ff_mjpeg_encode_picture_trailer(s);
 
         if(avctx->rc_buffer_size){
@@ -1687,25 +1687,25 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x,
     switch(s->codec_id){ //FIXME funct ptr could be slightly faster
     case CODEC_ID_MPEG1VIDEO:
     case CODEC_ID_MPEG2VIDEO:
-        if (ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER)
+        if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
             mpeg1_encode_mb(s, s->block, motion_x, motion_y);
         break;
     case CODEC_ID_MPEG4:
-        if (ENABLE_MPEG4_ENCODER)
+        if (CONFIG_MPEG4_ENCODER)
             mpeg4_encode_mb(s, s->block, motion_x, motion_y);
         break;
     case CODEC_ID_MSMPEG4V2:
     case CODEC_ID_MSMPEG4V3:
     case CODEC_ID_WMV1:
-        if (ENABLE_MSMPEG4_ENCODER)
+        if (CONFIG_MSMPEG4_ENCODER)
             msmpeg4_encode_mb(s, s->block, motion_x, motion_y);
         break;
     case CODEC_ID_WMV2:
-        if (ENABLE_WMV2_ENCODER)
+        if (CONFIG_WMV2_ENCODER)
             ff_wmv2_encode_mb(s, s->block, motion_x, motion_y);
         break;
     case CODEC_ID_H261:
-        if (ENABLE_H261_ENCODER)
+        if (CONFIG_H261_ENCODER)
             ff_h261_encode_mb(s, s->block, motion_x, motion_y);
         break;
     case CODEC_ID_H263:
@@ -1713,12 +1713,12 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x,
     case CODEC_ID_FLV1:
     case CODEC_ID_RV10:
     case CODEC_ID_RV20:
-        if (ENABLE_H263_ENCODER || ENABLE_H263P_ENCODER ||
-            ENABLE_FLV_ENCODER  || ENABLE_RV10_ENCODER  || ENABLE_RV20_ENCODER)
+        if (CONFIG_H263_ENCODER || CONFIG_H263P_ENCODER ||
+            CONFIG_FLV_ENCODER  || CONFIG_RV10_ENCODER  || CONFIG_RV20_ENCODER)
             h263_encode_mb(s, s->block, motion_x, motion_y);
         break;
     case CODEC_ID_MJPEG:
-        if (ENABLE_MJPEG_ENCODER)
+        if (CONFIG_MJPEG_ENCODER)
             ff_mjpeg_encode_mb(s, s->block);
         break;
     default:
@@ -1965,13 +1965,13 @@ static int mb_var_thread(AVCodecContext *c, void *arg){
 }
 
 static void write_slice_end(MpegEncContext *s){
-    if(ENABLE_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4){
+    if(CONFIG_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4){
         if(s->partitioned_frame){
             ff_mpeg4_merge_partitions(s);
         }
 
         ff_mpeg4_stuffing(&s->pb);
-    }else if(ENABLE_MJPEG_ENCODER && s->out_format == FMT_MJPEG){
+    }else if(CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG){
         ff_mjpeg_encode_stuffing(&s->pb);
     }
 
@@ -2028,11 +2028,11 @@ static int encode_thread(AVCodecContext *c, void *arg){
     case CODEC_ID_H263:
     case CODEC_ID_H263P:
     case CODEC_ID_FLV1:
-        if (ENABLE_H263_ENCODER || ENABLE_H263P_ENCODER || ENABLE_FLV_ENCODER)
+        if (CONFIG_H263_ENCODER || CONFIG_H263P_ENCODER || CONFIG_FLV_ENCODER)
             s->gob_index = ff_h263_get_gob_height(s);
         break;
     case CODEC_ID_MPEG4:
-        if(ENABLE_MPEG4_ENCODER && s->partitioned_frame)
+        if(CONFIG_MPEG4_ENCODER && s->partitioned_frame)
             ff_mpeg4_init_partitions(s);
         break;
     }
@@ -2072,7 +2072,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
             s->mb_y = mb_y;  // moved into loop, can get changed by H.261
             ff_update_block_index(s);
 
-            if(ENABLE_H261_ENCODER && s->codec_id == CODEC_ID_H261){
+            if(CONFIG_H261_ENCODER && s->codec_id == CODEC_ID_H261){
                 ff_h261_reorder_mb_index(s);
                 xy= s->mb_y*s->mb_stride + s->mb_x;
                 mb_type= s->mb_type[xy];
@@ -2105,7 +2105,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     if(s->start_mb_y != mb_y || mb_x!=0){
                         write_slice_end(s);
 
-                        if(ENABLE_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){
+                        if(CONFIG_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){
                             ff_mpeg4_init_partitions(s);
                         }
                     }
@@ -2132,21 +2132,21 @@ static int encode_thread(AVCodecContext *c, void *arg){
 
                     switch(s->codec_id){
                     case CODEC_ID_MPEG4:
-                        if (ENABLE_MPEG4_ENCODER) {
+                        if (CONFIG_MPEG4_ENCODER) {
                             ff_mpeg4_encode_video_packet_header(s);
                             ff_mpeg4_clean_buffers(s);
                         }
                     break;
                     case CODEC_ID_MPEG1VIDEO:
                     case CODEC_ID_MPEG2VIDEO:
-                        if (ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER) {
+                        if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) {
                             ff_mpeg1_encode_slice_header(s);
                             ff_mpeg1_clean_buffers(s);
                         }
                     break;
                     case CODEC_ID_H263:
                     case CODEC_ID_H263P:
-                        if (ENABLE_H263_ENCODER || ENABLE_H263P_ENCODER)
+                        if (CONFIG_H263_ENCODER || CONFIG_H263P_ENCODER)
                             h263_encode_gob_header(s, mb_y);
                     break;
                     }
@@ -2355,7 +2355,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                         }
                     }
                 }
-                if(ENABLE_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT){
+                if(CONFIG_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT){
                     int mx= s->b_direct_mv_table[xy][0];
                     int my= s->b_direct_mv_table[xy][1];
 
@@ -2366,7 +2366,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
                                  &dmin, &next_block, mx, my);
                 }
-                if(ENABLE_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT0){
+                if(CONFIG_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT0){
                     backup_s.dquant = 0;
                     s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
                     s->mb_intra= 0;
@@ -2381,7 +2381,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     if(coded){
                         int mx,my;
                         memcpy(s->mv, best_s.mv, sizeof(s->mv));
-                        if(ENABLE_MPEG4_ENCODER && best_s.mv_dir & MV_DIRECT){
+                        if(CONFIG_MPEG4_ENCODER && best_s.mv_dir & MV_DIRECT){
                             mx=my=0; //FIXME find the one we actually used
                             ff_mpeg4_set_direct_mv(s, mx, my);
                         }else if(best_s.mv_dir&MV_DIR_BACKWARD){
@@ -2429,7 +2429,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                 }
                 s->last_bits= put_bits_count(&s->pb);
 
-                if (ENABLE_ANY_H263_ENCODER &&
+                if (CONFIG_ANY_H263_ENCODER &&
                     s->out_format == FMT_H263 && s->pict_type!=FF_B_TYPE)
                     ff_h263_update_motion_val(s);
 
@@ -2479,7 +2479,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     }
                     break;
                 case CANDIDATE_MB_TYPE_DIRECT:
-                    if (ENABLE_MPEG4_ENCODER) {
+                    if (CONFIG_MPEG4_ENCODER) {
                         s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT;
                         s->mb_intra= 0;
                         motion_x=s->b_direct_mv_table[xy][0];
@@ -2488,7 +2488,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     }
                     break;
                 case CANDIDATE_MB_TYPE_DIRECT0:
-                    if (ENABLE_MPEG4_ENCODER) {
+                    if (CONFIG_MPEG4_ENCODER) {
                         s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT;
                         s->mb_intra= 0;
                         ff_mpeg4_set_direct_mv(s, 0, 0);
@@ -2556,7 +2556,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                 // RAL: Update last macroblock type
                 s->last_mv_dir = s->mv_dir;
 
-                if (ENABLE_ANY_H263_ENCODER &&
+                if (CONFIG_ANY_H263_ENCODER &&
                     s->out_format == FMT_H263 && s->pict_type!=FF_B_TYPE)
                     ff_h263_update_motion_val(s);
 
@@ -2587,7 +2587,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize);
             }
             if(s->loop_filter){
-                if(ENABLE_ANY_H263_ENCODER && s->out_format == FMT_H263)
+                if(CONFIG_ANY_H263_ENCODER && s->out_format == FMT_H263)
                     ff_h263_loop_filter(s);
             }
 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb));
@@ -2595,7 +2595,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
     }
 
     //not beautiful here but we must write it before flushing so it has to be here
-    if (ENABLE_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == FF_I_TYPE)
+    if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == FF_I_TYPE)
         msmpeg4_encode_ext_header(s);
 
     write_slice_end(s);
@@ -2666,13 +2666,13 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
     if(s->adaptive_quant){
         switch(s->codec_id){
         case CODEC_ID_MPEG4:
-            if (ENABLE_MPEG4_ENCODER)
+            if (CONFIG_MPEG4_ENCODER)
                 ff_clean_mpeg4_qscales(s);
             break;
         case CODEC_ID_H263:
         case CODEC_ID_H263P:
         case CODEC_ID_FLV1:
-            if (ENABLE_H263_ENCODER||ENABLE_H263P_ENCODER||ENABLE_FLV_ENCODER)
+            if (CONFIG_H263_ENCODER||CONFIG_H263P_ENCODER||CONFIG_FLV_ENCODER)
                 ff_clean_h263_qscales(s);
             break;
         }
@@ -2716,7 +2716,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
     // RAL: Condition added for MPEG1VIDEO
     if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
         set_frame_distances(s);
-    if(ENABLE_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4)
+    if(CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4)
         ff_set_mpeg4_time(s);
 
     s->me.scene_change_score=0;
@@ -2871,31 +2871,31 @@ static int encode_picture(MpegEncContext *s, int picture_number)
     s->last_bits= put_bits_count(&s->pb);
     switch(s->out_format) {
     case FMT_MJPEG:
-        if (ENABLE_MJPEG_ENCODER)
+        if (CONFIG_MJPEG_ENCODER)
             ff_mjpeg_encode_picture_header(s);
         break;
     case FMT_H261:
-        if (ENABLE_H261_ENCODER)
+        if (CONFIG_H261_ENCODER)
             ff_h261_encode_picture_header(s, picture_number);
         break;
     case FMT_H263:
-        if (ENABLE_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2)
+        if (CONFIG_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2)
             ff_wmv2_encode_picture_header(s, picture_number);
-        else if (ENABLE_MSMPEG4_ENCODER && s->h263_msmpeg4)
+        else if (CONFIG_MSMPEG4_ENCODER && s->h263_msmpeg4)
             msmpeg4_encode_picture_header(s, picture_number);
-        else if (ENABLE_MPEG4_ENCODER && s->h263_pred)
+        else if (CONFIG_MPEG4_ENCODER && s->h263_pred)
             mpeg4_encode_picture_header(s, picture_number);
-        else if (ENABLE_RV10_ENCODER && s->codec_id == CODEC_ID_RV10)
+        else if (CONFIG_RV10_ENCODER && s->codec_id == CODEC_ID_RV10)
             rv10_encode_picture_header(s, picture_number);
-        else if (ENABLE_RV20_ENCODER && s->codec_id == CODEC_ID_RV20)
+        else if (CONFIG_RV20_ENCODER && s->codec_id == CODEC_ID_RV20)
             rv20_encode_picture_header(s, picture_number);
-        else if (ENABLE_FLV_ENCODER && s->codec_id == CODEC_ID_FLV1)
+        else if (CONFIG_FLV_ENCODER && s->codec_id == CODEC_ID_FLV1)
             ff_flv_encode_picture_header(s, picture_number);
-        else if (ENABLE_ANY_H263_ENCODER)
+        else if (CONFIG_ANY_H263_ENCODER)
             h263_encode_picture_header(s, picture_number);
         break;
     case FMT_MPEG1:
-        if (ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER)
+        if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
             mpeg1_encode_picture_header(s, picture_number);
         break;
     case FMT_H264:
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 58d1a97..c5aa306 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -62,7 +62,7 @@ static uint32_t v2_dc_chroma_table[512][2];
 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
 static void init_h263_dc_for_msmpeg4(void);
 static inline void msmpeg4_memsetw(short *tab, int val, int n);
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val);
 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra);
 #endif //CONFIG_ENCODERS
@@ -79,7 +79,7 @@ int frame_count = 0;
 
 #include "msmpeg4data.h"
 
-#ifdef CONFIG_ENCODERS //strangely gcc includes this even if it is not references
+#if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
 #endif //CONFIG_ENCODERS
 
@@ -109,7 +109,7 @@ static void common_init(MpegEncContext * s)
         s->y_dc_scale_table= wmv1_y_dc_scale_table;
         s->c_dc_scale_table= wmv1_c_dc_scale_table;
         break;
-#if defined(CONFIG_WMV3_DECODER)||defined(CONFIG_VC1_DECODER)
+#if CONFIG_WMV3_DECODER || CONFIG_VC1_DECODER
     case 6:
         s->y_dc_scale_table= wmv3_dc_scale_table;
         s->c_dc_scale_table= wmv3_dc_scale_table;
@@ -134,7 +134,7 @@ static void common_init(MpegEncContext * s)
     }
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 /* build the table which associate a (x,y) motion vector to a vlc */
 static void init_mv_table(MVTable *tab)
@@ -411,7 +411,7 @@ int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block
     return pred;
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 
 void ff_msmpeg4_encode_motion(MpegEncContext * s,
                                   int mx, int my)
@@ -653,7 +653,7 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
        necessitate to modify mpegvideo.c. The problem comes from the
        fact they decided to store the quantized DC (which would lead
        to problems if Q could vary !) */
-#if (defined(ARCH_X86)) && !defined PIC
+#if ARCH_X86 && !defined PIC
     __asm__ volatile(
         "movl %3, %%eax         \n\t"
         "shrl $1, %%eax         \n\t"
@@ -673,7 +673,7 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
         : "%eax", "%edx"
     );
 #else
-    /* #elif defined (ARCH_ALPHA) */
+    /* #elif ARCH_ALPHA */
     /* Divisions are extremely costly on Alpha; optimize the most
        common case. But they are costly everywhere...
      */
@@ -1142,7 +1142,7 @@ int ff_msmpeg4_decode_init(MpegEncContext *s)
         s->decode_mb= msmpeg4v34_decode_mb;
         break;
     case 5:
-        if (ENABLE_WMV2_DECODER)
+        if (CONFIG_WMV2_DECODER)
             s->decode_mb= ff_wmv2_decode_mb;
     case 6:
         //FIXME + TODO VC1 decode mb
@@ -1362,7 +1362,7 @@ static inline void msmpeg4_memsetw(short *tab, int val, int n)
         tab[i] = val;
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
 {
     int range, bit_size, sign, code, bits;
diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h
index 1442959..cc34f0a 100644
--- a/libavcodec/msmpeg4.h
+++ b/libavcodec/msmpeg4.h
@@ -49,19 +49,19 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
                             int n, int coded, const uint8_t *scan_table);
 int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
 
-#define ENABLE_MSMPEG4_DECODER (ENABLE_MSMPEG4V1_DECODER || \
-                                ENABLE_MSMPEG4V2_DECODER || \
-                                ENABLE_MSMPEG4V3_DECODER || \
-                                ENABLE_WMV2_DECODER      || \
-                                ENABLE_VC1_DECODER       || \
-                                ENABLE_WMV3_DECODER)
-#define ENABLE_MSMPEG4_ENCODER (ENABLE_MSMPEG4V1_ENCODER || \
-                                ENABLE_MSMPEG4V2_ENCODER || \
-                                ENABLE_MSMPEG4V3_ENCODER || \
-                                ENABLE_WMV2_ENCODER)
-#define ENABLE_MSMPEG4 (ENABLE_MSMPEG4_DECODER || ENABLE_MSMPEG4_ENCODER)
-#define ENABLE_WMV2 (ENABLE_WMV2_DECODER || ENABLE_WMV2_ENCODER)
-#define ENABLE_WMV_DECODER (ENABLE_WMV1_DECODER || ENABLE_WMV2_DECODER)
-#define ENABLE_WMV_ENCODER (ENABLE_WMV1_ENCODER || ENABLE_WMV2_ENCODER)
+#define CONFIG_MSMPEG4_DECODER (CONFIG_MSMPEG4V1_DECODER || \
+                                CONFIG_MSMPEG4V2_DECODER || \
+                                CONFIG_MSMPEG4V3_DECODER || \
+                                CONFIG_WMV2_DECODER      || \
+                                CONFIG_VC1_DECODER       || \
+                                CONFIG_WMV3_DECODER)
+#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V1_ENCODER || \
+                                CONFIG_MSMPEG4V2_ENCODER || \
+                                CONFIG_MSMPEG4V3_ENCODER || \
+                                CONFIG_WMV2_ENCODER)
+#define CONFIG_MSMPEG4 (CONFIG_MSMPEG4_DECODER || CONFIG_MSMPEG4_ENCODER)
+#define CONFIG_WMV2 (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER)
+#define CONFIG_WMV_DECODER (CONFIG_WMV1_DECODER || CONFIG_WMV2_DECODER)
+#define CONFIG_WMV_ENCODER (CONFIG_WMV1_ENCODER || CONFIG_WMV2_ENCODER)
 
 #endif /* AVCODEC_MSMPEG4_H */
diff --git a/libavcodec/msrledec.c b/libavcodec/msrledec.c
index 7d09ed9..0a7fda2 100644
--- a/libavcodec/msrledec.c
+++ b/libavcodec/msrledec.c
@@ -26,6 +26,7 @@
  *   http://www.multimedia.cx/msrle.txt
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define FETCH_NEXT_STREAM_BYTE() \
diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c
index 8621d66..c208d47 100644
--- a/libavcodec/msvideo1.c
+++ b/libavcodec/msvideo1.c
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define PALETTE_COUNT 256
diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index dfbb41c..c0a856e 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -53,8 +53,6 @@ typedef struct NellyMoserDecodeContext {
     DECLARE_ALIGNED_16(float,imdct_out[NELLY_BUF_LEN * 2]);
 } NellyMoserDecodeContext;
 
-static DECLARE_ALIGNED_16(float,sine_window[128]);
-
 static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *audio, float *a_in)
 {
     int bot, top;
@@ -63,8 +61,8 @@ static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *
     top = NELLY_BUF_LEN-1;
 
     while (bot < NELLY_BUF_LEN) {
-        audio[bot] = a_in [bot]*sine_window[bot]
-                    +state[bot]*sine_window[top] + s->add_bias;
+        audio[bot] = a_in [bot]*ff_sine_128[bot]
+                    +state[bot]*ff_sine_128[top] + s->add_bias;
 
         bot++;
         top--;
@@ -144,8 +142,8 @@ static av_cold int decode_init(AVCodecContext * avctx) {
     }
 
     /* Generate overlap window */
-    if (!sine_window[0])
-        ff_sine_window_init(sine_window, 128);
+    if (!ff_sine_128[127])
+        ff_sine_window_init(ff_sine_128, 128);
 
     avctx->sample_fmt = SAMPLE_FMT_S16;
     avctx->channel_layout = CH_LAYOUT_MONO;
diff --git a/libavcodec/opt.h b/libavcodec/opt.h
index c968930..0e39e3d 100644
--- a/libavcodec/opt.h
+++ b/libavcodec/opt.h
@@ -28,6 +28,7 @@
  */
 
 #include "libavutil/rational.h"
+#include "avcodec.h"
 
 enum AVOptionType{
     FF_OPT_TYPE_FLAGS,
diff --git a/libavcodec/options.c b/libavcodec/options.c
new file mode 100644
index 0000000..953dfe6
--- /dev/null
+++ b/libavcodec/options.c
@@ -0,0 +1,453 @@
+/*
+ * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni at gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file options.c
+ * Options definition for AVCodecContext.
+ */
+
+#include "avcodec.h"
+#include "opt.h"
+#include <float.h>              /* FLT_MIN, FLT_MAX */
+
+static const char* context_to_name(void* ptr) {
+    AVCodecContext *avc= ptr;
+
+    if(avc && avc->codec && avc->codec->name)
+        return avc->codec->name;
+    else
+        return "NULL";
+}
+
+#define OFFSET(x) offsetof(AVCodecContext,x)
+#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
+//these names are too long to be readable
+#define V AV_OPT_FLAG_VIDEO_PARAM
+#define A AV_OPT_FLAG_AUDIO_PARAM
+#define S AV_OPT_FLAG_SUBTITLE_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+#define AV_CODEC_DEFAULT_BITRATE 200*1000
+
+static const AVOption options[]={
+{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
+{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
+{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
+{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, 0, UINT_MAX, V|A|E|D, "flags"},
+{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
+{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
+{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
+{"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
+{"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
+{"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
+{"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
+{"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
+{"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
+{"pass1", "use internal 2pass ratecontrol in first  pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
+{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
+{"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
+{"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
+{"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
+{"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
+{"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
+{"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
+{"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
+{"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D|E, "flags"},
+{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
+{"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, V|A|E, "flags"},
+{"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
+{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
+{"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
+{"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
+{"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
+{"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
+{"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
+{"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
+{"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"},
+{"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
+{"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
+{"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
+{"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
+{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
+{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
+{"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, ME_ZERO, INT_MIN, INT_MAX, V|E, "me_method" },
+{"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" },
+{"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" },
+{"esa", "esa motion estimation (alias for full)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" },
+{"tesa", "tesa motion estimation", 0, FF_OPT_TYPE_CONST, ME_TESA, INT_MIN, INT_MAX, V|E, "me_method" },
+{"dia", "dia motion estimation (alias for epzs)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" },
+{"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, ME_LOG, INT_MIN, INT_MAX, V|E, "me_method" },
+{"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, ME_PHODS, INT_MIN, INT_MAX, V|E, "me_method" },
+{"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, ME_X1, INT_MIN, INT_MAX, V|E, "me_method" },
+{"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, ME_HEX, INT_MIN, INT_MAX, V|E, "me_method" },
+{"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, ME_UMH, INT_MIN, INT_MAX, V|E, "me_method" },
+{"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, ME_ITER, INT_MIN, INT_MAX, V|E, "me_method" },
+{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
+{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E},
+{"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
+{"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
+{"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, 0.5, -FLT_MAX, FLT_MAX, V|E},
+{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, 0.5, 0, FLT_MAX, V|E},
+{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, 2, 1, 51, V|E},
+{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, 31, 1, 51, V|E},
+{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, 3, INT_MIN, INT_MAX, V|E},
+{"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, 0, FF_MAX_B_FRAMES, V|E},
+{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E},
+{"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
+{"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
+{"ps", "rtp payload size in bits", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
+{"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
+{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
+{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
+{"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
+{"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
+{"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
+{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
+{"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
+{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
+{"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
+{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
+{"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
+{"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
+{"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"},
+{"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"},
+{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|D|E, "strict"},
+{"very", "strictly conform to a older more strict version of the spec or reference software", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_VERY_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E},
+{"er", "set error detection aggressivity", OFFSET(error_recognition), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"},
+{"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
+{"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
+{"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
+{"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
+{"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
+{"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
+{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 99, V|E},
+{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
+{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
+{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|E},
+{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, -FLT_MAX, FLT_MAX, V|E},
+{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
+{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
+{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
+{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
+{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
+{"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
+{"int", "accurate integer", 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
+{"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
+{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
+{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
+{"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
+{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
+{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV5TE, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearmv6", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV6, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simpleneon", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLENEON, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplealpha", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEALPHA, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"},
+{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
+{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
+{"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
+{"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
+{"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
+{"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
+{"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
+{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
+{"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
+{"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
+{"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
+{"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
+{"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
+{"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
+{"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
+{"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
+{"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
+{"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
+{"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
+{"er", "error recognition", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
+{"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
+{"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
+{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
+{"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
+{"buffers", "picture buffer allocations", 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUFFERS, INT_MIN, INT_MAX, V|D, "debug"},
+{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
+{"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"vsse","sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
+#if CONFIG_SNOW_ENCODER
+{"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
+#endif
+{"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
+{"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
+{"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
+{"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
+{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
+{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
+{"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"},
+{"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"},
+{"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"},
+{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
+{"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
+{"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
+{"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
+{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT,  2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
+{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
+{"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR, 0, UINT_MAX, V|A|E|D, "flags2"},
+{"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
+{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
+{"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
+{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
+{"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
+{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D},
+{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
+{"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
+{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
+{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
+{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
+{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
+{"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"},
+{"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"},
+{"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"},
+{"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"},
+{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
+{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
+{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
+{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
+{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E},
+{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E},
+{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E},
+{"skip_loop_filter", NULL, OFFSET(skip_loop_filter), FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"skip_idct"       , NULL, OFFSET(skip_idct)       , FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"skip_frame"      , NULL, OFFSET(skip_frame)      , FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"none"            , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONE   , INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"default"         , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"noref"           , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONREF , INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"bidir"           , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_BIDIR  , INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"nokey"           , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONKEY , INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"all"             , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_ALL    , INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E},
+{"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E},
+{"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
+{"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, V|E},
+{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E},
+{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E},
+{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
+{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E},
+{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
+{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
+{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
+{"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
+{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
+{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
+{"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
+{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
+{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
+{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
+{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
+{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
+{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
+{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
+{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
+{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
+{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
+{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
+{"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
+{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
+{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
+{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
+{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},
+{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D},
+{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},
+{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"},
+{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"},
+{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), FF_OPT_TYPE_FLOAT, 1.0/3, 0.0, FLT_MAX, V|E},
+{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use),  FF_OPT_TYPE_FLOAT, 3,     0.0, FLT_MAX, V|E},
+{NULL},
+};
+
+#undef A
+#undef V
+#undef S
+#undef E
+#undef D
+#undef DEFAULT
+
+static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
+
+void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
+    int flags=0;
+    memset(s, 0, sizeof(AVCodecContext));
+
+    s->av_class= &av_codec_context_class;
+
+    s->codec_type = codec_type;
+    if(codec_type == CODEC_TYPE_AUDIO)
+        flags= AV_OPT_FLAG_AUDIO_PARAM;
+    else if(codec_type == CODEC_TYPE_VIDEO)
+        flags= AV_OPT_FLAG_VIDEO_PARAM;
+    else if(codec_type == CODEC_TYPE_SUBTITLE)
+        flags= AV_OPT_FLAG_SUBTITLE_PARAM;
+    av_opt_set_defaults2(s, flags, flags);
+
+    s->time_base= (AVRational){0,1};
+    s->get_buffer= avcodec_default_get_buffer;
+    s->release_buffer= avcodec_default_release_buffer;
+    s->get_format= avcodec_default_get_format;
+    s->execute= avcodec_default_execute;
+    s->sample_aspect_ratio= (AVRational){0,1};
+    s->pix_fmt= PIX_FMT_NONE;
+    s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
+
+    s->palctrl = NULL;
+    s->reget_buffer= avcodec_default_reget_buffer;
+}
+
+AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
+    AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
+
+    if(avctx==NULL) return NULL;
+
+    avcodec_get_context_defaults2(avctx, codec_type);
+
+    return avctx;
+}
+
+void avcodec_get_context_defaults(AVCodecContext *s){
+    avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
+}
+
+AVCodecContext *avcodec_alloc_context(void){
+    return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
+}
+
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 84aa098..9952809 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -214,7 +214,7 @@ static int pcm_encode_frame(AVCodecContext *avctx,
             *dst++ = v - 128;
         }
         break;
-#if WORDS_BIGENDIAN
+#ifdef WORDS_BIGENDIAN
     case CODEC_ID_PCM_F64LE:
         ENCODE(int64_t, le64, samples, dst, n, 0, 0)
         break;
@@ -417,7 +417,7 @@ static int pcm_decode_frame(AVCodecContext *avctx,
         }
         samples= (short*)dstu8;
         break;
-#if WORDS_BIGENDIAN
+#ifdef WORDS_BIGENDIAN
     case CODEC_ID_PCM_F64LE:
         DECODE(int64_t, le64, src, samples, n, 0, 0)
         break;
@@ -507,7 +507,7 @@ static int pcm_decode_frame(AVCodecContext *avctx,
     return src - buf;
 }
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
 #define PCM_ENCODER(id,sample_fmt_,name,long_name_) \
 AVCodec name ## _encoder = {                    \
     #name,                                      \
@@ -525,7 +525,7 @@ AVCodec name ## _encoder = {                    \
 #define PCM_ENCODER(id,sample_fmt_,name,long_name_)
 #endif
 
-#ifdef CONFIG_DECODERS
+#if CONFIG_DECODERS
 #define PCM_DECODER(id,sample_fmt_,name,long_name_)         \
 AVCodec name ## _decoder = {                    \
     #name,                                      \
diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c
index b62ea75..3ff1209 100644
--- a/libavcodec/pnmenc.c
+++ b/libavcodec/pnmenc.c
@@ -354,7 +354,7 @@ static int pam_probe(AVProbeData *pd)
 #endif
 
 
-#ifdef CONFIG_PGM_ENCODER
+#if CONFIG_PGM_ENCODER
 AVCodec pgm_encoder = {
     "pgm",
     CODEC_TYPE_VIDEO,
@@ -369,7 +369,7 @@ AVCodec pgm_encoder = {
 };
 #endif // CONFIG_PGM_ENCODER
 
-#ifdef CONFIG_PGMYUV_ENCODER
+#if CONFIG_PGMYUV_ENCODER
 AVCodec pgmyuv_encoder = {
     "pgmyuv",
     CODEC_TYPE_VIDEO,
@@ -384,7 +384,7 @@ AVCodec pgmyuv_encoder = {
 };
 #endif // CONFIG_PGMYUV_ENCODER
 
-#ifdef CONFIG_PPM_ENCODER
+#if CONFIG_PPM_ENCODER
 AVCodec ppm_encoder = {
     "ppm",
     CODEC_TYPE_VIDEO,
@@ -399,7 +399,7 @@ AVCodec ppm_encoder = {
 };
 #endif // CONFIG_PPM_ENCODER
 
-#ifdef CONFIG_PBM_ENCODER
+#if CONFIG_PBM_ENCODER
 AVCodec pbm_encoder = {
     "pbm",
     CODEC_TYPE_VIDEO,
@@ -414,7 +414,7 @@ AVCodec pbm_encoder = {
 };
 #endif // CONFIG_PBM_ENCODER
 
-#ifdef CONFIG_PAM_ENCODER
+#if CONFIG_PAM_ENCODER
 AVCodec pam_encoder = {
     "pam",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/ppc/dsputil_altivec.c b/libavcodec/ppc/dsputil_altivec.c
index 44cce6a..e183432 100644
--- a/libavcodec/ppc/dsputil_altivec.c
+++ b/libavcodec/ppc/dsputil_altivec.c
@@ -1450,6 +1450,6 @@ void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx)
 
     c->hadamard8_diff[0] = hadamard8_diff16_altivec;
     c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
-    if (ENABLE_VORBIS_DECODER)
+    if (CONFIG_VORBIS_DECODER)
         c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec;
 }
diff --git a/libavcodec/ppc/dsputil_ppc.c b/libavcodec/ppc/dsputil_ppc.c
index 124453e..ce04cf6 100644
--- a/libavcodec/ppc/dsputil_ppc.c
+++ b/libavcodec/ppc/dsputil_ppc.c
@@ -24,7 +24,7 @@
 
 #include "dsputil_ppc.h"
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
 #include "dsputil_altivec.h"
 
 void fdct_altivec(int16_t *block);
@@ -48,7 +48,7 @@ int mm_flags = 0;
 int mm_support(void)
 {
     int result = 0;
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     if (has_altivec()) {
         result |= FF_MM_ALTIVEC;
     }
@@ -56,7 +56,7 @@ int mm_support(void)
     return result;
 }
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
 unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
 /* list below must match enum in dsputil_ppc.h */
 static unsigned char* perfname[] = {
@@ -91,7 +91,7 @@ static unsigned char* perfname[] = {
 #include <stdio.h>
 #endif
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
 void powerpc_display_perf_report(void)
 {
     int i, j;
@@ -165,7 +165,7 @@ POWERPC_PERF_STOP_COUNT(powerpc_clear_blocks_dcbz32, 1);
 
 /* same as above, when dcbzl clear a whole 128B cache line
    i.e. the PPC970 aka G5 */
-#ifdef HAVE_DCBZL
+#if HAVE_DCBZL
 void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
 {
 POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz128, 1);
@@ -195,7 +195,7 @@ void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
 }
 #endif
 
-#ifdef HAVE_DCBZL
+#if HAVE_DCBZL
 /* check dcbz report how many bytes are set to 0 by dcbz */
 /* update 24/06/2003 : replace dcbz by dcbzl to get
    the intended effect (Apple "fixed" dcbz)
@@ -261,21 +261,21 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
             break;
     }
 
-#ifdef HAVE_ALTIVEC
-    if(ENABLE_H264_DECODER) dsputil_h264_init_ppc(c, avctx);
+#if HAVE_ALTIVEC
+    if(CONFIG_H264_DECODER) dsputil_h264_init_ppc(c, avctx);
 
     if (has_altivec()) {
         mm_flags |= FF_MM_ALTIVEC;
 
         dsputil_init_altivec(c, avctx);
-        if(ENABLE_SNOW_DECODER) snow_init_altivec(c, avctx);
-        if(ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER)
+        if(CONFIG_SNOW_DECODER) snow_init_altivec(c, avctx);
+        if(CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER)
             vc1dsp_init_altivec(c, avctx);
         float_init_altivec(c, avctx);
         int_init_altivec(c, avctx);
         c->gmc1 = gmc1_altivec;
 
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
         if (avctx->dct_algo == FF_DCT_AUTO ||
             avctx->dct_algo == FF_DCT_ALTIVEC) {
             c->fdct = fdct_altivec;
@@ -291,7 +291,7 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
             }
         }
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
         {
             int i, j;
             for (i = 0 ; i < powerpc_perf_total ; i++) {
diff --git a/libavcodec/ppc/dsputil_ppc.h b/libavcodec/ppc/dsputil_ppc.h
index 578c961..d9740ce 100644
--- a/libavcodec/ppc/dsputil_ppc.h
+++ b/libavcodec/ppc/dsputil_ppc.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_PPC_DSPUTIL_PPC_H
 #define AVCODEC_PPC_DSPUTIL_PPC_H
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
 void powerpc_display_perf_report(void);
 /* the 604* have 2, the G3* have 4, the G4s have 6,
    and the G5 are completely different (they MUST use
@@ -68,7 +68,7 @@ enum powerpc_data_index {
 };
 extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
 
-#ifndef HAVE_PPC64
+#if !HAVE_PPC64
 #define POWERP_PMC_DATATYPE unsigned long
 #define POWERPC_GET_PMC1(a) __asm__ volatile("mfspr %0, 937" : "=r" (a))
 #define POWERPC_GET_PMC2(a) __asm__ volatile("mfspr %0, 938" : "=r" (a))
diff --git a/libavcodec/ppc/gcc_fixes.h b/libavcodec/ppc/gcc_fixes.h
index efa7a57..a97921f 100644
--- a/libavcodec/ppc/gcc_fixes.h
+++ b/libavcodec/ppc/gcc_fixes.h
@@ -25,7 +25,7 @@
 
 #include "config.h"
 
-#ifdef HAVE_ALTIVEC_H
+#if HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
 
diff --git a/libavcodec/ppc/idct_altivec.c b/libavcodec/ppc/idct_altivec.c
index 94b6598..d262282 100644
--- a/libavcodec/ppc/idct_altivec.c
+++ b/libavcodec/ppc/idct_altivec.c
@@ -161,7 +161,7 @@ void idct_put_altivec(uint8_t* dest, int stride, vec_s16* block)
 POWERPC_PERF_DECLARE(altivec_idct_put_num, 1);
     vec_u8 tmp;
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
 POWERPC_PERF_START_COUNT(altivec_idct_put_num, 1);
 #endif
     IDCT
@@ -192,7 +192,7 @@ POWERPC_PERF_DECLARE(altivec_idct_add_num, 1);
     vec_u8 perm1;
     vec_u8 p0, p1, p;
 
-#ifdef CONFIG_POWERPC_PERF
+#if CONFIG_POWERPC_PERF
 POWERPC_PERF_START_COUNT(altivec_idct_add_num, 1);
 #endif
 
diff --git a/libavcodec/ppc/mathops.h b/libavcodec/ppc/mathops.h
index edfe2ea..beba351 100644
--- a/libavcodec/ppc/mathops.h
+++ b/libavcodec/ppc/mathops.h
@@ -23,7 +23,7 @@
 #ifndef AVCODEC_PPC_MATHOPS_H
 #define AVCODEC_PPC_MATHOPS_H
 
-#if defined(ARCH_PPC_405)
+#if ARCH_PPC_405
 /* signed 16x16 -> 32 multiply add accumulate */
 #define MAC16(rt, ra, rb) \
     __asm__ ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
diff --git a/libavcodec/ppc/util_altivec.h b/libavcodec/ppc/util_altivec.h
index c54d0ea..b52c159 100644
--- a/libavcodec/ppc/util_altivec.h
+++ b/libavcodec/ppc/util_altivec.h
@@ -28,7 +28,7 @@
 
 #include "config.h"
 
-#ifdef HAVE_ALTIVEC_H
+#if HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
 
diff --git a/libavcodec/ptx.c b/libavcodec/ptx.c
index 79424b9..2ab45b0 100644
--- a/libavcodec/ptx.c
+++ b/libavcodec/ptx.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct PTXContext {
diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index c65b094..56551fd 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -680,10 +680,7 @@ static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_
     if(bitrate == SILENCE)
     {
         //FIXME: Remove experimental warning when tested with samples.
-        av_log(avctx, AV_LOG_WARNING, "'Blank frame handling is experimental."
-                      " If you want to help, upload a sample "
-                      "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
-                      "and contact the ffmpeg-devel mailing list.\n");
+        ff_log_ask_for_sample(avctx, "'Blank frame handling is experimental.");
     }
     return bitrate;
 }
diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index e1b67d0..67fa0dd 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -38,11 +38,6 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "dsputil.h"
-
-#ifdef CONFIG_MPEGAUDIO_HP
-#define USE_HIGHPRECISION
-#endif
-
 #include "mpegaudio.h"
 
 #include "qdm2data.h"
diff --git a/libavcodec/qdrw.c b/libavcodec/qdrw.c
index e0e4142..80b84a0 100644
--- a/libavcodec/qdrw.c
+++ b/libavcodec/qdrw.c
@@ -24,6 +24,7 @@
  * Apple QuickDraw codec.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct QdrawContext{
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index 33a7eb5..306a074 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct QtrleContext {
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index c88059a..31c3da7 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -184,7 +184,7 @@ int ff_rate_control_init(MpegEncContext *s)
 
         //FIXME maybe move to end
         if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) {
-#ifdef CONFIG_LIBXVID
+#if CONFIG_LIBXVID
             return ff_xvid_rate_control_init(s);
 #else
             av_log(s->avctx, AV_LOG_ERROR, "Xvid ratecontrol requires libavcodec compiled with Xvid support.\n");
@@ -260,7 +260,7 @@ void ff_rate_control_uninit(MpegEncContext *s)
     ff_eval_free(rcc->rc_eq_eval);
     av_freep(&rcc->entry);
 
-#ifdef CONFIG_LIBXVID
+#if CONFIG_LIBXVID
     if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
         ff_xvid_rate_control_uninit(s);
 #endif
@@ -678,7 +678,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
     Picture * const pic= &s->current_picture;
     emms_c();
 
-#ifdef CONFIG_LIBXVID
+#if CONFIG_LIBXVID
     if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
         return ff_xvid_rate_estimate_qscale(s, dry_run);
 #endif
diff --git a/libavcodec/rectangle.h b/libavcodec/rectangle.h
index a1dfb5c..563c988 100644
--- a/libavcodec/rectangle.h
+++ b/libavcodec/rectangle.h
@@ -64,7 +64,7 @@ static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride,
         *(uint32_t*)(p + 3*stride)= v;
     }else if(w==8){
     //gcc can't optimize 64bit math on x86_32
-#ifdef HAVE_FAST_64BIT
+#if HAVE_FAST_64BIT
         const uint64_t v= val*0x0100000001ULL;
         *(uint64_t*)(p + 0*stride)= v;
         if(h==1) return;
diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index ad830e7..2bd7b15 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 
diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index 3b405cc..a5622cd 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -60,6 +60,7 @@
 #include "roqvideo.h"
 #include "bytestream.h"
 #include "elbg.h"
+#include "mathops.h"
 
 #define CHROMA_BIAS 1
 
diff --git a/libavcodec/rpza.c b/libavcodec/rpza.c
index ddf3954..ddfe05c 100644
--- a/libavcodec/rpza.c
+++ b/libavcodec/rpza.c
@@ -39,6 +39,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct RpzaContext {
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index ad09c07..cba319c 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -230,7 +230,7 @@ int rv_decode_dc(MpegEncContext *s, int n)
 }
 
 
-#if defined(CONFIG_RV10_ENCODER) || defined(CONFIG_RV20_ENCODER)
+#if CONFIG_RV10_ENCODER || CONFIG_RV20_ENCODER
 /* write RV 1.0 compatible frame header */
 void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
 {
@@ -304,7 +304,7 @@ static int get_num(GetBitContext *gb)
 }
 #endif
 
-#endif /* defined(CONFIG_RV10_ENCODER) || defined(CONFIG_RV20_ENCODER) */
+#endif /* CONFIG_RV10_ENCODER || CONFIG_RV20_ENCODER */
 
 /* read RV 1.0 compatible frame header */
 static int rv10_decode_picture_header(MpegEncContext *s)
diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c
index 97d87b0..0c6f343 100644
--- a/libavcodec/rv30.c
+++ b/libavcodec/rv30.c
@@ -38,6 +38,7 @@ static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn
     int mb_bits;
     int w = r->s.width, h = r->s.height;
     int mb_size;
+    int rpr;
 
     memset(si, 0, sizeof(SliceInfo));
     if(get_bits(gb, 3))
@@ -49,7 +50,11 @@ static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn
     si->quant = get_bits(gb, 5);
     skip_bits1(gb);
     si->pts = get_bits(gb, 13);
-    skip_bits(gb, r->rpr);
+    rpr = get_bits(gb, r->rpr);
+    if(rpr){
+        w = r->s.avctx->extradata[6 + rpr*2] << 2;
+        h = r->s.avctx->extradata[7 + rpr*2] << 2;
+    }
     si->width  = w;
     si->height = h;
     mb_size = ((w + 15) >> 4) * ((h + 15) >> 4);
@@ -248,6 +253,10 @@ static av_cold int rv30_decode_init(AVCodecContext *avctx)
     }
     r->rpr = (avctx->extradata[1] & 7) >> 1;
     r->rpr = FFMIN(r->rpr + 1, 3);
+    if(avctx->extradata_size - 8 < (r->rpr - 1) * 2){
+        av_log(avctx, AV_LOG_ERROR, "Insufficient extradata - need at least %d bytes, got %d\n",
+               6 + r->rpr * 2, avctx->extradata_size);
+    }
     r->parse_slice_header = rv30_parse_slice_header;
     r->decode_intra_types = rv30_decode_intra_types;
     r->decode_mb_info     = rv30_decode_mb_info;
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 450327e..8a14e08 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -28,6 +28,7 @@
 #include "dsputil.h"
 #include "mpegvideo.h"
 #include "golomb.h"
+#include "mathops.h"
 #include "rectangle.h"
 
 #include "rv34vlc.h"
diff --git a/libavcodec/s3tc.c b/libavcodec/s3tc.c
index fc035e5..546ee21 100644
--- a/libavcodec/s3tc.c
+++ b/libavcodec/s3tc.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "s3tc.h"
 
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 6d0aace..eda91c2 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -305,7 +305,7 @@ static int shorten_decode_frame(AVCodecContext *avctx,
     {
         int maxnlpc = 0;
         /* shorten signature */
-        if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("ajkg"))) {
+        if (get_bits_long(&s->gb, 32) != bswap_32(AV_RL32("ajkg"))) {
             av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
             return -1;
         }
diff --git a/libavcodec/simple_idct.c b/libavcodec/simple_idct.c
index 2cf9e8d..914b491 100644
--- a/libavcodec/simple_idct.c
+++ b/libavcodec/simple_idct.c
@@ -59,13 +59,13 @@
 static inline void idctRowCondDC (DCTELEM * row)
 {
         int a0, a1, a2, a3, b0, b1, b2, b3;
-#ifdef HAVE_FAST_64BIT
+#if HAVE_FAST_64BIT
         uint64_t temp;
 #else
         uint32_t temp;
 #endif
 
-#ifdef HAVE_FAST_64BIT
+#if HAVE_FAST_64BIT
 #ifdef WORDS_BIGENDIAN
 #define ROW0_MASK 0xffff000000000000LL
 #else
@@ -127,7 +127,7 @@ static inline void idctRowCondDC (DCTELEM * row)
         b3 = MUL16(W7, row[1]);
         MAC16(b3, -W5, row[3]);
 
-#ifdef HAVE_FAST_64BIT
+#if HAVE_FAST_64BIT
         temp = ((uint64_t*)row)[1];
 #else
         temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
diff --git a/libavcodec/smc.c b/libavcodec/smc.c
index e05e0b1..197c053 100644
--- a/libavcodec/smc.c
+++ b/libavcodec/smc.c
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define CPAIR 2
diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index e3e5aa9..b4a0d5a 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -23,6 +23,7 @@
 #include "snow.h"
 
 #include "rangecoder.h"
+#include "mathops.h"
 
 #include "mpegvideo.h"
 
@@ -4670,7 +4671,7 @@ AVCodec snow_decoder = {
     .long_name = NULL_IF_CONFIG_SMALL("Snow"),
 };
 
-#ifdef CONFIG_SNOW_ENCODER
+#if CONFIG_SNOW_ENCODER
 AVCodec snow_encoder = {
     "snow",
     CODEC_TYPE_VIDEO,
@@ -4773,7 +4774,7 @@ int main(void){
                 }
                 error= (int)(sqrt(error)+0.5);
                 errors[level][orientation]= error;
-                if(g) g=ff_gcd(g, error);
+                if(g) g=av_gcd(g, error);
                 else g= error;
             }
         }
diff --git a/libavcodec/snow.h b/libavcodec/snow.h
index b208e5f..5d5ae1e 100644
--- a/libavcodec/snow.h
+++ b/libavcodec/snow.h
@@ -125,7 +125,7 @@ void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTE
 void ff_snow_horizontal_compose97i(IDWTELEM *b, int width);
 void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
 
-#ifdef CONFIG_SNOW_ENCODER
+#if CONFIG_SNOW_ENCODER
 int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
 int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
 #else
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index 6e0bdc8..44b4582 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -408,7 +408,7 @@ static int predictor_calc_error(int *k, int *state, int order, int error)
     return x;
 }
 
-#if defined(CONFIG_SONIC_ENCODER) || defined(CONFIG_SONIC_LS_ENCODER)
+#if CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER
 // Heavily modified Levinson-Durbin algorithm which
 // copes better with quantization, and calculates the
 // actual whitened result as it goes.
@@ -479,12 +479,12 @@ static void modified_levinson_durbin(int *window, int window_entries,
 
     av_free(state);
 }
-#endif /* defined(CONFIG_SONIC_ENCODER) || defined(CONFIG_SONIC_LS_ENCODER) */
+#endif /* CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER */
 
 static const int samplerate_table[] =
     { 44100, 22050, 11025, 96000, 48000, 32000, 24000, 16000, 8000 };
 
-#if defined(CONFIG_SONIC_ENCODER) || defined(CONFIG_SONIC_LS_ENCODER)
+#if CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER
 static inline int code_samplerate(int samplerate)
 {
     switch (samplerate)
@@ -747,9 +747,9 @@ static int sonic_encode_frame(AVCodecContext *avctx,
     flush_put_bits(&pb);
     return (put_bits_count(&pb)+7)/8;
 }
-#endif /* defined(CONFIG_SONIC_ENCODER) || defined(CONFIG_SONIC_LS_ENCODER) */
+#endif /* CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER */
 
-#ifdef CONFIG_SONIC_DECODER
+#if CONFIG_SONIC_DECODER
 static av_cold int sonic_decode_init(AVCodecContext *avctx)
 {
     SonicContext *s = avctx->priv_data;
@@ -936,7 +936,7 @@ static int sonic_decode_frame(AVCodecContext *avctx,
 }
 #endif /* CONFIG_SONIC_DECODER */
 
-#ifdef CONFIG_SONIC_ENCODER
+#if CONFIG_SONIC_ENCODER
 AVCodec sonic_encoder = {
     "sonic",
     CODEC_TYPE_AUDIO,
@@ -950,7 +950,7 @@ AVCodec sonic_encoder = {
 };
 #endif
 
-#ifdef CONFIG_SONIC_LS_ENCODER
+#if CONFIG_SONIC_LS_ENCODER
 AVCodec sonic_ls_encoder = {
     "sonicls",
     CODEC_TYPE_AUDIO,
@@ -964,7 +964,7 @@ AVCodec sonic_ls_encoder = {
 };
 #endif
 
-#ifdef CONFIG_SONIC_DECODER
+#if CONFIG_SONIC_DECODER
 AVCodec sonic_decoder = {
     "sonic",
     CODEC_TYPE_AUDIO,
diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index c8f021f..f7a7f9c 100644
--- a/libavcodec/sunrast.c
+++ b/libavcodec/sunrast.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define RT_OLD          0
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index d306149..fe1d7ed 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -37,6 +37,7 @@
 #include "avcodec.h"
 #include "dsputil.h"
 #include "mpegvideo.h"
+#include "mathops.h"
 
 #include "svq1.h"
 
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 49ad3d3..2a96f34 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -119,7 +119,7 @@ static void svq1_write_header(SVQ1Context *s, int frame_type)
 #define QUALITY_THRESHOLD 100
 #define THRESHOLD_MULTIPLIER 0.6
 
-#if defined(HAVE_ALTIVEC)
+#if HAVE_ALTIVEC
 #undef vector
 #endif
 
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index f438ba8..e3f014a 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -40,7 +40,7 @@
  *  http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
  */
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 
@@ -849,7 +849,7 @@ static int svq3_decode_init(AVCodecContext *avctx)
             h->unknown_svq3_flag = get_bits1(&gb);
             avctx->has_b_frames = !s->low_delay;
             if (h->unknown_svq3_flag) {
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
                 unsigned watermark_width  = svq3_get_ue_golomb(&gb);
                 unsigned watermark_height = svq3_get_ue_golomb(&gb);
                 int u1 = svq3_get_ue_golomb(&gb);
diff --git a/libavcodec/targa.c b/libavcodec/targa.c
index f9bc343..56a6876 100644
--- a/libavcodec/targa.c
+++ b/libavcodec/targa.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 enum TargaCompr{
diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
index 958ae50..21747bb 100644
--- a/libavcodec/targaenc.c
+++ b/libavcodec/targaenc.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "rle.h"
 
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 582076b..9880391 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -25,7 +25,7 @@
  * @author Konstantin Shishkov
  */
 #include "avcodec.h"
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 #include "lzw.h"
@@ -78,7 +78,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
     int c, line, pixels, code;
     const uint8_t *ssrc = src;
     int width = s->width * s->bpp >> 3;
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     uint8_t *zbuf; unsigned long outlen;
 
     if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){
@@ -298,7 +298,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
             break;
         case TIFF_DEFLATE:
         case TIFF_ADOBE_DEFLATE:
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
             break;
 #else
             av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index c440454..6d95e89 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -25,7 +25,7 @@
  * @author Bartlomiej Wolowiec
  */
 #include "avcodec.h"
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 #include "bytestream.h"
@@ -151,7 +151,7 @@ static int encode_strip(TiffEncoderContext * s, const int8_t * src,
 {
 
     switch (compr) {
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     case TIFF_DEFLATE:
     case TIFF_ADOBE_DEFLATE:
         {
@@ -229,7 +229,7 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
         s->compr = TIFF_RAW;
     } else if(avctx->compression_level == 2) {
         s->compr = TIFF_LZW;
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     } else if ((avctx->compression_level >= 3)) {
         s->compr = TIFF_DEFLATE;
 #endif
@@ -315,7 +315,7 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
         }
     }
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
         uint8_t *zbuf;
         int zlen, zn;
diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index 3df71cb..2c0b22f 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #include "truespeech_data.h"
diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index adf48b2..2400acb 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -209,11 +209,11 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
         return -1;
 
     init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
-    if (show_bits_long(&s->gb, 32) == ff_get_fourcc("TTA1"))
+    if (show_bits_long(&s->gb, 32) == AV_RL32("TTA1"))
     {
         /* signature */
         skip_bits(&s->gb, 32);
-//        if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("TTA1"))) {
+//        if (get_bits_long(&s->gb, 32) != bswap_32(AV_RL32("TTA1"))) {
 //            av_log(s->avctx, AV_LOG_ERROR, "Missing magic\n");
 //            return -1;
 //        }
diff --git a/libavcodec/txd.c b/libavcodec/txd.c
index 284b00d..44bbad4 100644
--- a/libavcodec/txd.c
+++ b/libavcodec/txd.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "s3tc.h"
 
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index dcd7602..7499957 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -36,11 +36,12 @@
 #include "opt.h"
 #include "imgconvert.h"
 #include "audioconvert.h"
+#include "internal.h"
 #include <stdlib.h>
 #include <stdarg.h>
 #include <limits.h>
 #include <float.h>
-#if !defined(HAVE_MKSTEMP)
+#if !HAVE_MKSTEMP
 #include <fcntl.h>
 #endif
 
@@ -251,7 +252,7 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
 //picture size unneccessarily in some cases. The solution here is not
 //pretty and better ideas are welcome!
-#ifdef HAVE_MMX
+#if HAVE_MMX
             if(s->codec_id == CODEC_ID_SVQ1)
                 stride_align[i]= 16;
             else
@@ -383,428 +384,6 @@ enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum
     return fmt[0];
 }
 
-static const char* context_to_name(void* ptr) {
-    AVCodecContext *avc= ptr;
-
-    if(avc && avc->codec && avc->codec->name)
-        return avc->codec->name;
-    else
-        return "NULL";
-}
-
-#define OFFSET(x) offsetof(AVCodecContext,x)
-#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
-//these names are too long to be readable
-#define V AV_OPT_FLAG_VIDEO_PARAM
-#define A AV_OPT_FLAG_AUDIO_PARAM
-#define S AV_OPT_FLAG_SUBTITLE_PARAM
-#define E AV_OPT_FLAG_ENCODING_PARAM
-#define D AV_OPT_FLAG_DECODING_PARAM
-
-#define AV_CODEC_DEFAULT_BITRATE 200*1000
-
-static const AVOption options[]={
-{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
-{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
-{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
-{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, 0, UINT_MAX, V|A|E|D, "flags"},
-{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
-{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
-{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
-{"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
-{"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
-{"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
-{"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
-{"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
-{"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
-{"pass1", "use internal 2pass ratecontrol in first  pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
-{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
-{"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
-{"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
-{"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
-{"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
-{"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
-{"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
-{"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
-{"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D|E, "flags"},
-{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
-{"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, V|A|E, "flags"},
-{"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
-{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
-{"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
-{"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
-{"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
-{"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
-{"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
-{"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
-{"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"},
-{"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
-{"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
-{"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
-{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
-{"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, ME_ZERO, INT_MIN, INT_MAX, V|E, "me_method" },
-{"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" },
-{"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" },
-{"esa", "esa motion estimation (alias for full)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" },
-{"tesa", "tesa motion estimation", 0, FF_OPT_TYPE_CONST, ME_TESA, INT_MIN, INT_MAX, V|E, "me_method" },
-{"dia", "dia motion estimation (alias for epzs)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" },
-{"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, ME_LOG, INT_MIN, INT_MAX, V|E, "me_method" },
-{"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, ME_PHODS, INT_MIN, INT_MAX, V|E, "me_method" },
-{"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, ME_X1, INT_MIN, INT_MAX, V|E, "me_method" },
-{"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, ME_HEX, INT_MIN, INT_MAX, V|E, "me_method" },
-{"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, ME_UMH, INT_MIN, INT_MAX, V|E, "me_method" },
-{"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, ME_ITER, INT_MIN, INT_MAX, V|E, "me_method" },
-{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
-{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E},
-{"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
-{"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
-{"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, 0.5, -FLT_MAX, FLT_MAX, V|E},
-{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, 0.5, 0, FLT_MAX, V|E},
-{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, 2, 1, 51, V|E},
-{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, 31, 1, 51, V|E},
-{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, 3, INT_MIN, INT_MAX, V|E},
-{"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, 0, FF_MAX_B_FRAMES, V|E},
-{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E},
-{"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
-{"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
-{"ps", "rtp payload size in bits", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
-{"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
-{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
-{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
-{"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
-{"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
-{"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
-{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
-{"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
-{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
-{"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
-{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
-{"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
-{"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
-{"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"},
-{"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"},
-{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|D|E, "strict"},
-{"very", "strictly conform to a older more strict version of the spec or reference software", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_VERY_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E},
-{"er", "set error detection aggressivity", OFFSET(error_recognition), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"},
-{"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
-{"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
-{"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
-{"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
-{"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
-{"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
-{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 99, V|E},
-{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
-{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
-{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|E},
-{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, -FLT_MAX, FLT_MAX, V|E},
-{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
-{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
-{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
-{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
-{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
-{"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
-{"int", "accurate integer", 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
-{"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
-{"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
-{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
-{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV5TE, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearmv6", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV6, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simpleneon", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLENEON, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"},
-{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
-{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
-{"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
-{"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
-{"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
-{"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
-{"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
-{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
-{"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
-{"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
-{"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
-{"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
-{"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
-{"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
-{"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
-{"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
-{"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
-{"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
-{"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
-{"er", "error recognition", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
-{"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
-{"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
-{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
-{"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
-{"buffers", "picture buffer allocations", 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUFFERS, INT_MIN, INT_MAX, V|D, "debug"},
-{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
-{"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"vsse","sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
-#ifdef CONFIG_SNOW_ENCODER
-{"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
-#endif
-{"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
-{"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
-{"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
-{"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
-{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
-{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
-{"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"},
-{"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"},
-{"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"},
-{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
-{"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
-{"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
-{"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
-{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT,  2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
-{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
-{"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR, 0, UINT_MAX, V|A|E|D, "flags2"},
-{"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
-{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
-{"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
-{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
-{"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
-{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D},
-{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
-{"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
-{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
-{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
-{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
-{"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"},
-{"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"},
-{"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"},
-{"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"},
-{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
-{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
-{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
-{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E},
-{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E},
-{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E},
-{"skip_loop_filter", NULL, OFFSET(skip_loop_filter), FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"skip_idct"       , NULL, OFFSET(skip_idct)       , FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"skip_frame"      , NULL, OFFSET(skip_frame)      , FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"none"            , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONE   , INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"default"         , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"noref"           , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONREF , INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"bidir"           , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_BIDIR  , INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"nokey"           , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONKEY , INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"all"             , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_ALL    , INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E},
-{"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E},
-{"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
-{"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, V|E},
-{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E},
-{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E},
-{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
-{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E},
-{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
-{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
-{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
-{"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
-{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
-{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
-{"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
-{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
-{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
-{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
-{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
-{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
-{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
-{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
-{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
-{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
-{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
-{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
-{"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
-{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
-{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
-{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
-{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},
-{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D},
-{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},
-{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"},
-{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"},
-{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), FF_OPT_TYPE_FLOAT, 1.0/3, 0.0, FLT_MAX, V|E},
-{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use),  FF_OPT_TYPE_FLOAT, 3,     0.0, FLT_MAX, V|E},
-{NULL},
-};
-
-#undef A
-#undef V
-#undef S
-#undef E
-#undef D
-#undef DEFAULT
-
-static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
-
-void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
-    int flags=0;
-    memset(s, 0, sizeof(AVCodecContext));
-
-    s->av_class= &av_codec_context_class;
-
-    s->codec_type = codec_type;
-    if(codec_type == CODEC_TYPE_AUDIO)
-        flags= AV_OPT_FLAG_AUDIO_PARAM;
-    else if(codec_type == CODEC_TYPE_VIDEO)
-        flags= AV_OPT_FLAG_VIDEO_PARAM;
-    else if(codec_type == CODEC_TYPE_SUBTITLE)
-        flags= AV_OPT_FLAG_SUBTITLE_PARAM;
-    av_opt_set_defaults2(s, flags, flags);
-
-    s->time_base= (AVRational){0,1};
-    s->get_buffer= avcodec_default_get_buffer;
-    s->release_buffer= avcodec_default_release_buffer;
-    s->get_format= avcodec_default_get_format;
-    s->execute= avcodec_default_execute;
-    s->sample_aspect_ratio= (AVRational){0,1};
-    s->pix_fmt= PIX_FMT_NONE;
-    s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
-
-    s->palctrl = NULL;
-    s->reget_buffer= avcodec_default_reget_buffer;
-}
-
-AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
-    AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
-
-    if(avctx==NULL) return NULL;
-
-    avcodec_get_context_defaults2(avctx, codec_type);
-
-    return avctx;
-}
-
-void avcodec_get_context_defaults(AVCodecContext *s){
-    avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
-}
-
-AVCodecContext *avcodec_alloc_context(void){
-    return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
-}
-
 void avcodec_get_frame_defaults(AVFrame *pic){
     memset(pic, 0, sizeof(AVFrame));
 
@@ -990,7 +569,7 @@ int avcodec_close(AVCodecContext *avctx)
         return -1;
     }
 
-    if (ENABLE_THREADS && avctx->thread_opaque)
+    if (HAVE_THREADS && avctx->thread_opaque)
         avcodec_thread_free(avctx);
     if (avctx->codec->close)
         avctx->codec->close(avctx);
@@ -1068,12 +647,6 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
 
     if (p) {
         codec_name = p->name;
-        if (!encode && enc->codec_id == CODEC_ID_MP3) {
-            if (enc->sub_id == 2)
-                codec_name = "mp2";
-            else if (enc->sub_id == 1)
-                codec_name = "mp1";
-        }
     } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
         /* fake mpeg2 transport stream codec (currently not
            registered) */
@@ -1121,7 +694,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
                          display_aspect_ratio.num, display_aspect_ratio.den);
             }
             if(av_log_get_level() >= AV_LOG_DEBUG){
-                int g= ff_gcd(enc->time_base.num, enc->time_base.den);
+                int g= av_gcd(enc->time_base.num, enc->time_base.den);
                 snprintf(buf + strlen(buf), buf_size - strlen(buf),
                      ", %d/%d",
                      enc->time_base.num/g, enc->time_base.den/g);
@@ -1328,7 +901,7 @@ int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
     }
 }
 
-#if !defined(HAVE_THREADS)
+#if !HAVE_THREADS
 int avcodec_thread_init(AVCodecContext *s, int thread_count){
     return -1;
 }
@@ -1355,7 +928,7 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  * and opened file name in **filename. */
 int av_tempfile(char *prefix, char **filename) {
     int fd=-1;
-#if !defined(HAVE_MKSTEMP)
+#if !HAVE_MKSTEMP
     *filename = tempnam(".", prefix);
 #else
     size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
@@ -1366,7 +939,7 @@ int av_tempfile(char *prefix, char **filename) {
         av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
         return -1;
     }
-#if !defined(HAVE_MKSTEMP)
+#if !HAVE_MKSTEMP
     fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
 #else
     snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
@@ -1517,8 +1090,16 @@ void ff_log_missing_feature(void *avc, const char *feature, int want_sample)
             "occurs, it means that your file has a feature which has not "
             "been implemented.", feature);
     if(want_sample)
-        av_log(avc, AV_LOG_WARNING, " If you want to help, upload a sample "
-                "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
-                "and contact the ffmpeg-devel mailing list.");
-    av_log(avc, AV_LOG_WARNING, "\n");
+        ff_log_ask_for_sample(avc, NULL);
+    else
+        av_log(avc, AV_LOG_WARNING, "\n");
+}
+
+void ff_log_ask_for_sample(void *avc, const char *msg)
+{
+    if (msg)
+        av_log(avc, AV_LOG_WARNING, "%s ", msg);
+    av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
+            "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
+            "and contact the ffmpeg-devel mailing list.\n");
 }
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 62a0a97..dee0adc 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -34,6 +34,7 @@
 #include "msmpeg4data.h"
 #include "unary.h"
 #include "simple_idct.h"
+#include "mathops.h"
 
 #undef NDEBUG
 #include <assert.h>
@@ -314,30 +315,39 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
  * @return whether other 3 pairs should be filtered or not
  * @see 8.6
  */
-static int vc1_filter_line(uint8_t* src, int stride, int pq){
-    int a0, a1, a2, a3, d, clip, filt3 = 0;
+static int av_always_inline vc1_filter_line(uint8_t* src, int stride, int pq){
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
 
-    a0     = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
-    if(FFABS(a0) < pq){
-        a1 = (2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3;
-        a2 = (2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3;
-        a3 = FFMIN(FFABS(a1), FFABS(a2));
-        if(a3 < FFABS(a0)){
-            d = 5 * ((a0 >=0 ? a3 : -a3) - a0) / 8;
-            clip = (src[-1*stride] - src[ 0*stride])/2;
+    int a0 = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
+    int a0_sign = a0 >> 31;        /* Store sign */
+    a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
+    if(a0 < pq){
+        int a1 = FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
+        int a2 = FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
+        if(a1 < a0 || a2 < a0){
+            int clip = src[-1*stride] - src[ 0*stride];
+            int clip_sign = clip >> 31;
+            clip = ((clip ^ clip_sign) - clip_sign)>>1;
             if(clip){
-                filt3 = 1;
-                if(clip > 0)
-                    d = av_clip(d, 0, clip);
-                else
-                    d = av_clip(d, clip, 0);
-                src[-1*stride] = cm[src[-1*stride] - d];
-                src[ 0*stride] = cm[src[ 0*stride] + d];
+                int a3 = FFMIN(a1, a2);
+                int d = 5 * (a3 - a0);
+                int d_sign = (d >> 31);
+                d = ((d ^ d_sign) - d_sign) >> 3;
+                d_sign ^= a0_sign;
+
+                if( d_sign ^ clip_sign )
+                    d = 0;
+                else{
+                    d = FFMIN(d, clip);
+                    d = (d ^ d_sign) - d_sign;          /* Restore sign */
+                    src[-1*stride] = cm[src[-1*stride] - d];
+                    src[ 0*stride] = cm[src[ 0*stride] + d];
+                }
+                return 1;
             }
         }
     }
-    return filt3;
+    return 0;
 }
 
 /**
@@ -1007,8 +1017,8 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
     if(get_bits1(gb)) { //Display Info - decoding is not affected by it
         int w, h, ar = 0;
         av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
-        v->s.avctx->width  = v->s.width  = w = get_bits(gb, 14) + 1;
-        v->s.avctx->height = v->s.height = h = get_bits(gb, 14) + 1;
+        v->s.avctx->coded_width  = w = get_bits(gb, 14) + 1;
+        v->s.avctx->coded_height = h = get_bits(gb, 14) + 1;
         av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
         if(get_bits1(gb))
             ar = get_bits(gb, 4);
@@ -1019,6 +1029,7 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
             h = get_bits(gb, 8);
             v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
         }
+        av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den);
 
         if(get_bits1(gb)){ //framerate stuff
             if(get_bits1(gb)) {
@@ -1086,13 +1097,13 @@ static int decode_entry_point(AVCodecContext *avctx, GetBitContext *gb)
     }
     if(v->extended_mv)
         v->extended_dmv = get_bits1(gb);
-    if(get_bits1(gb)) {
+    if((v->range_mapy_flag = get_bits1(gb))) {
         av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
-        skip_bits(gb, 3); // Y range, ignored for now
+        v->range_mapy = get_bits(gb, 3);
     }
-    if(get_bits1(gb)) {
+    if((v->range_mapuv_flag = get_bits1(gb))) {
         av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
-        skip_bits(gb, 3); // UV range, ignored for now
+        v->range_mapuv = get_bits(gb, 3);
     }
 
     av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
@@ -3205,8 +3216,8 @@ static int vc1_decode_p_mb(VC1Context *v)
                             left_cbp = v->cbp[s->mb_x - 1]            >> (i * 4);
                             top_cbp  = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
                         }else{
-                            left_cbp = (i & 1) ? (pat >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
-                            top_cbp  = (i & 2) ? (pat >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
+                            left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
+                            top_cbp  = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
                         }
                         if(left_cbp & 0xC)
                             vc1_loop_filter(s->dest[dst_idx] + off, 1, i & 4 ? s->uvlinesize : s->linesize, 8, mquant);
@@ -3222,9 +3233,13 @@ static int vc1_decode_p_mb(VC1Context *v)
                             left_cbp = v->cbp[s->mb_x - 1]            >> (i * 4);
                             top_cbp  = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
                         }else{
-                            left_cbp = (i & 1) ? (pat >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
-                            top_cbp  = (i & 2) ? (pat >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
+                            left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
+                            top_cbp  = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
                         }
+                        if(left_cbp & 0xC)
+                            vc1_loop_filter(s->dest[dst_idx] + off, 1, i & 4 ? s->uvlinesize : s->linesize, 8, mquant);
+                        if(top_cbp  & 0xA)
+                            vc1_loop_filter(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, 1, 8, mquant);
                     }
                     pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), filter, left_cbp, top_cbp);
                     block_cbp |= pat << (i << 2);
@@ -3332,8 +3347,8 @@ static int vc1_decode_p_mb(VC1Context *v)
                             left_cbp = v->cbp[s->mb_x - 1]            >> (i * 4);
                             top_cbp  = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
                         }else{
-                            left_cbp = (i & 1) ? (pat >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
-                            top_cbp  = (i & 2) ? (pat >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
+                            left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
+                            top_cbp  = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
                         }
                         if(left_cbp & 0xC)
                             vc1_loop_filter(s->dest[dst_idx] + off, 1, i & 4 ? s->uvlinesize : s->linesize, 8, mquant);
@@ -3349,9 +3364,13 @@ static int vc1_decode_p_mb(VC1Context *v)
                             left_cbp = v->cbp[s->mb_x - 1]            >> (i * 4);
                             top_cbp  = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
                         }else{
-                            left_cbp = (i & 1) ? (pat >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
-                            top_cbp  = (i & 2) ? (pat >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
+                            left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1]           >> ((i+1)*4));
+                            top_cbp  = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
                         }
+                        if(left_cbp & 0xC)
+                            vc1_loop_filter(s->dest[dst_idx] + off, 1, i & 4 ? s->uvlinesize : s->linesize, 8, mquant);
+                        if(top_cbp  & 0xA)
+                            vc1_loop_filter(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, 1, 8, mquant);
                     }
                     pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), filter, left_cbp, top_cbp);
                     block_cbp |= pat << (i << 2);
diff --git a/libavcodec/vcr1.c b/libavcodec/vcr1.c
index d9d4ce9..c3b3556 100644
--- a/libavcodec/vcr1.c
+++ b/libavcodec/vcr1.c
@@ -32,6 +32,7 @@
 
 /* Disable the encoder. */
 #undef CONFIG_VCR1_ENCODER
+#define CONFIG_VCR1_ENCODER 0
 
 typedef struct VCR1Context{
     AVCodecContext *avctx;
@@ -116,7 +117,7 @@ static int decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-#ifdef CONFIG_VCR1_ENCODER
+#if CONFIG_VCR1_ENCODER
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
     VCR1Context * const a = avctx->priv_data;
     AVFrame *pict = data;
@@ -156,7 +157,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
     return 0;
 }
 
-#ifdef CONFIG_VCR1_ENCODER
+#if CONFIG_VCR1_ENCODER
 static av_cold int encode_init(AVCodecContext *avctx){
 
     common_init(avctx);
@@ -178,7 +179,7 @@ AVCodec vcr1_decoder = {
     .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
 };
 
-#ifdef CONFIG_VCR1_ENCODER
+#if CONFIG_VCR1_ENCODER
 AVCodec vcr1_encoder = {
     "vcr1",
     CODEC_TYPE_VIDEO,
diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h
index 2d03356..a28ad7f 100644
--- a/libavcodec/vdpau.h
+++ b/libavcodec/vdpau.h
@@ -70,6 +70,7 @@ struct vdpau_render_state {
 
     /** picture parameter information for all supported codecs */
     union VdpPictureInfo {
+        VdpPictureInfoMPEG1Or2 mpeg;
         VdpPictureInfoH264     h264;
     } info;
 
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index 6af2495..4f993af 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -25,10 +25,15 @@
 #define AVCODEC_VDPAU_INTERNAL_H
 
 #include <stdint.h>
-#include "h264.h"
+#include "mpegvideo.h"
 
-void ff_vdpau_h264_add_data_chunk(H264Context *h, const uint8_t *buf,
-                                  int buf_size);
-void ff_vdpau_h264_picture_complete(H264Context *h);
+void ff_vdpau_add_data_chunk(MpegEncContext *s, const uint8_t *buf,
+                             int buf_size);
+
+void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
+                                    int buf_size, int slice_count);
+
+void ff_vdpau_h264_set_reference_frames(MpegEncContext *s);
+void ff_vdpau_h264_picture_complete(MpegEncContext *s);
 
 #endif /* AVCODEC_VDPAU_INTERNAL_H */
diff --git a/libavcodec/vdpauvideo.c b/libavcodec/vdpauvideo.c
index 8b42823..b5b91cb 100644
--- a/libavcodec/vdpauvideo.c
+++ b/libavcodec/vdpauvideo.c
@@ -37,9 +37,9 @@
  * @{
  */
 
-static void vdpau_h264_set_reference_frames(H264Context *h)
+void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
 {
-    MpegEncContext * s = &h->s;
+    H264Context *h = s->avctx->priv_data;
     struct vdpau_render_state * render, * render_ref;
     VdpReferenceFrameH264 * rf, * rf2;
     Picture * pic;
@@ -106,17 +106,14 @@ static void vdpau_h264_set_reference_frames(H264Context *h)
     }
 }
 
-void ff_vdpau_h264_add_data_chunk(H264Context *h, const uint8_t *buf, int buf_size)
+void ff_vdpau_add_data_chunk(MpegEncContext *s,
+                             const uint8_t *buf, int buf_size)
 {
-    MpegEncContext * s = &h->s;
     struct vdpau_render_state * render;
 
     render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
     assert(render);
 
-    if (!render->bitstream_buffers_used)
-        vdpau_h264_set_reference_frames(h);
-
     render->bitstream_buffers= av_fast_realloc(
         render->bitstream_buffers,
         &render->bitstream_buffers_allocated,
@@ -129,9 +126,9 @@ void ff_vdpau_h264_add_data_chunk(H264Context *h, const uint8_t *buf, int buf_si
     render->bitstream_buffers_used++;
 }
 
-void ff_vdpau_h264_picture_complete(H264Context *h)
+void ff_vdpau_h264_picture_complete(MpegEncContext *s)
 {
-    MpegEncContext * s = &h->s;
+    H264Context *h = s->avctx->priv_data;
     struct vdpau_render_state * render;
 
     render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
@@ -180,4 +177,59 @@ void ff_vdpau_h264_picture_complete(H264Context *h)
     render->bitstream_buffers_used = 0;
 }
 
+void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
+                                    int buf_size, int slice_count)
+{
+    struct vdpau_render_state * render, * last, * next;
+    int i;
+
+    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
+    assert(render);
+
+    /* fill VdpPictureInfoMPEG1Or2 struct */
+    render->info.mpeg.picture_structure          = s->picture_structure;
+    render->info.mpeg.picture_coding_type        = s->pict_type;
+    render->info.mpeg.intra_dc_precision         = s->intra_dc_precision;
+    render->info.mpeg.frame_pred_frame_dct       = s->frame_pred_frame_dct;
+    render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors;
+    render->info.mpeg.intra_vlc_format           = s->intra_vlc_format;
+    render->info.mpeg.alternate_scan             = s->alternate_scan;
+    render->info.mpeg.q_scale_type               = s->q_scale_type;
+    render->info.mpeg.top_field_first            = s->top_field_first;
+    render->info.mpeg.full_pel_forward_vector    = s->full_pel[0]; // MPEG-1 only.  Set 0 for MPEG-2
+    render->info.mpeg.full_pel_backward_vector   = s->full_pel[1]; // MPEG-1 only.  Set 0 for MPEG-2
+    render->info.mpeg.f_code[0][0]               = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert.
+    render->info.mpeg.f_code[0][1]               = s->mpeg_f_code[0][1];
+    render->info.mpeg.f_code[1][0]               = s->mpeg_f_code[1][0];
+    render->info.mpeg.f_code[1][1]               = s->mpeg_f_code[1][1];
+    for (i = 0; i < 64; ++i) {
+        render->info.mpeg.intra_quantizer_matrix[i]     = s->intra_matrix[i];
+        render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
+    }
+
+    render->info.mpeg.forward_reference          = VDP_INVALID_HANDLE;
+    render->info.mpeg.backward_reference         = VDP_INVALID_HANDLE;
+
+    switch(s->pict_type){
+    case  FF_B_TYPE:
+        next = (struct vdpau_render_state*)s->next_picture.data[0];
+        assert(next);
+        render->info.mpeg.backward_reference     = next->surface;
+        // no return here, going to set forward prediction
+    case  FF_P_TYPE:
+        last = (struct vdpau_render_state*)s->last_picture.data[0];
+        if (!last) // FIXME: Does this test make sense?
+            last = render; // predict second field from the first
+        render->info.mpeg.forward_reference      = last->surface;
+    }
+
+    ff_vdpau_add_data_chunk(s, buf, buf_size);
+
+    render->info.mpeg.slice_count                = slice_count;
+
+    if (slice_count)
+        ff_draw_horiz_band(s, 0, s->avctx->height);
+    render->bitstream_buffers_used               = 0;
+}
+
 /* @}*/
diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c
index 328abbb..48f76bf 100644
--- a/libavcodec/vmdav.c
+++ b/libavcodec/vmdav.c
@@ -44,6 +44,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define VMD_HEADER_SIZE 0x330
diff --git a/libavcodec/vmnc.c b/libavcodec/vmnc.c
index c07d001..5a7e5b0 100644
--- a/libavcodec/vmnc.c
+++ b/libavcodec/vmnc.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 enum EncTypes {
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 2737025..73e285e 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -2021,7 +2021,7 @@ static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb)
     return 0;
 }
 
-#ifdef CONFIG_THEORA_DECODER
+#if CONFIG_THEORA_DECODER
 static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
 {
     Vp3DecodeContext *s = avctx->priv_data;
diff --git a/libavcodec/vqavideo.c b/libavcodec/vqavideo.c
index 028895f..c392a82 100644
--- a/libavcodec/vqavideo.c
+++ b/libavcodec/vqavideo.c
@@ -68,6 +68,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #define PALETTE_COUNT 256
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index b89723e..c1558f1 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -28,9 +28,15 @@
  * WavPack lossless audio decoder
  */
 
+#define WV_MONO         0x00000004
 #define WV_JOINT_STEREO 0x00000010
 #define WV_FALSE_STEREO 0x40000000
 
+#define WV_HYBRID_MODE    0x00000008
+#define WV_HYBRID_SHAPE   0x00000008
+#define WV_HYBRID_BITRATE 0x00000200
+#define WV_HYBRID_BALANCE 0x00000400
+
 enum WP_ID_Flags{
     WP_IDF_MASK   = 0x1F,
     WP_IDF_IGNORE = 0x20,
@@ -66,19 +72,27 @@ typedef struct Decorr {
     int samplesB[8];
 } Decorr;
 
+typedef struct WvChannel {
+    int median[3];
+    int slow_level, error_limit;
+    int bitrate_acc, bitrate_delta;
+} WvChannel;
+
 typedef struct WavpackContext {
     AVCodecContext *avctx;
+    int frame_flags;
     int stereo, stereo_in;
     int joint;
     uint32_t CRC;
     GetBitContext gb;
     int data_size; // in bits
     int samples;
-    int median[6];
     int terms;
     Decorr decorr[MAX_TERMS];
     int zero, one, zeroes;
     int and, or, shift;
+    int hybrid, hybrid_bitrate;
+    WvChannel ch[2];
 } WavpackContext;
 
 // exponent table copied from WavPack source
@@ -101,6 +115,25 @@ static const uint8_t wp_exp2_table [256] = {
     0xea, 0xec, 0xed, 0xee, 0xf0, 0xf1, 0xf2, 0xf4, 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfc, 0xfd, 0xff
 };
 
+static const uint8_t wp_log2_table [] = {
+    0x00, 0x01, 0x03, 0x04, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x10, 0x11, 0x12, 0x14, 0x15,
+    0x16, 0x18, 0x19, 0x1a, 0x1c, 0x1d, 0x1e, 0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2a,
+    0x2c, 0x2d, 0x2e, 0x2f, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3d, 0x3e,
+    0x3f, 0x41, 0x42, 0x43, 0x44, 0x45, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
+    0x52, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,
+    0x64, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x74, 0x75,
+    0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,
+    0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
+    0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4,
+    0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb2,
+    0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc0,
+    0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcb, 0xcc, 0xcd, 0xce,
+    0xcf, 0xd0, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd8, 0xd9, 0xda, 0xdb,
+    0xdc, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe4, 0xe5, 0xe6, 0xe7, 0xe7,
+    0xe8, 0xe9, 0xea, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xee, 0xef, 0xf0, 0xf1, 0xf1, 0xf2, 0xf3, 0xf4,
+    0xf4, 0xf5, 0xf6, 0xf7, 0xf7, 0xf8, 0xf9, 0xf9, 0xfa, 0xfb, 0xfc, 0xfc, 0xfd, 0xfe, 0xff, 0xff
+};
+
 static av_always_inline int wp_exp2(int16_t val)
 {
     int res, neg = 0;
@@ -116,10 +149,28 @@ static av_always_inline int wp_exp2(int16_t val)
     return neg ? -res : res;
 }
 
+static av_always_inline int wp_log2(int32_t val)
+{
+    int bits;
+
+    if(!val)
+        return 0;
+    if(val == 1)
+        return 256;
+    val += val >> 9;
+    bits = av_log2(val) + 1;
+    if(bits < 9)
+        return (bits << 8) + wp_log2_table[(val << (9 - bits)) & 0xFF];
+    else
+        return (bits << 8) + wp_log2_table[(val >> (bits - 9)) & 0xFF];
+}
+
+#define LEVEL_DECAY(a)  ((a + 0x80) >> 8)
+
 // macros for manipulating median values
-#define GET_MED(n) ((median[n] >> 4) + 1)
-#define DEC_MED(n) median[n] -= ((median[n] + (128>>n) - 2) / (128>>n)) * 2
-#define INC_MED(n) median[n] += ((median[n] + (128>>n)) / (128>>n)) * 5
+#define GET_MED(n) ((c->median[n] >> 4) + 1)
+#define DEC_MED(n) c->median[n] -= ((c->median[n] + (128>>n) - 2) / (128>>n)) * 2
+#define INC_MED(n) c->median[n] += ((c->median[n] + (128>>n)) / (128>>n)) * 5
 
 // macros for applying weight
 #define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \
@@ -148,24 +199,63 @@ static av_always_inline int get_tail(GetBitContext *gb, int k)
     return res;
 }
 
-static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int *last)
+static void update_error_limit(WavpackContext *ctx)
+{
+    int i, br[2], sl[2];
+
+    for(i = 0; i <= ctx->stereo_in; i++){
+        ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta;
+        br[i] = ctx->ch[i].bitrate_acc >> 16;
+        sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level);
+    }
+    if(ctx->stereo_in && ctx->hybrid_bitrate){
+        int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
+        if(balance > br[0]){
+            br[1] = br[0] << 1;
+            br[0] = 0;
+        }else if(-balance > br[0]){
+            br[0] <<= 1;
+            br[1] = 0;
+        }else{
+            br[1] = br[0] + balance;
+            br[0] = br[0] - balance;
+        }
+    }
+    for(i = 0; i <= ctx->stereo_in; i++){
+        if(ctx->hybrid_bitrate){
+            if(sl[i] - br[i] > -0x100)
+                ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100);
+            else
+                ctx->ch[i].error_limit = 0;
+        }else{
+            ctx->ch[i].error_limit = wp_exp2(br[i]);
+        }
+    }
+}
+
+static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int channel, int *last)
 {
     int t, t2;
     int sign, base, add, ret;
+    WvChannel *c = &ctx->ch[channel];
 
     *last = 0;
 
-    if((ctx->median[0] < 2U) && (ctx->median[3] < 2U) && !ctx->zero && !ctx->one){
+    if((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one){
         if(ctx->zeroes){
             ctx->zeroes--;
-            if(ctx->zeroes)
+            if(ctx->zeroes){
+                c->slow_level -= LEVEL_DECAY(c->slow_level);
                 return 0;
+            }
         }else{
             t = get_unary_0_33(gb);
             if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));
             ctx->zeroes = t;
             if(ctx->zeroes){
-                memset(ctx->median, 0, sizeof(ctx->median));
+                memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));
+                memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));
+                c->slow_level -= LEVEL_DECAY(c->slow_level);
                 return 0;
             }
         }
@@ -201,6 +291,9 @@ static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int
         ctx->zero = !ctx->one;
     }
 
+    if(ctx->hybrid && !channel)
+        update_error_limit(ctx);
+
     if(!t){
         base = 0;
         add = GET_MED(0) - 1;
@@ -223,8 +316,23 @@ static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int
         INC_MED(1);
         INC_MED(2);
     }
-    ret = base + get_tail(gb, add);
+    if(!c->error_limit){
+        ret = base + get_tail(gb, add);
+    }else{
+        int mid = (base*2 + add + 1) >> 1;
+        while(add > c->error_limit){
+            if(get_bits1(gb)){
+                add -= (mid - base);
+                base = mid;
+            }else
+                add = mid - base - 1;
+            mid = (base*2 + add + 1) >> 1;
+        }
+        ret = mid;
+    }
     sign = get_bits1(gb);
+    if(ctx->hybrid_bitrate)
+        c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
     return sign ? ~ret : ret;
 }
 
@@ -238,9 +346,9 @@ static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst)
 
     s->one = s->zero = s->zeroes = 0;
     do{
-        L = wv_get_value(s, gb, s->median, &last);
+        L = wv_get_value(s, gb, 0, &last);
         if(last) break;
-        R = wv_get_value(s, gb, s->median + 3, &last);
+        R = wv_get_value(s, gb, 1, &last);
         if(last) break;
         for(i = 0; i < s->terms; i++){
             t = s->decorr[i].value;
@@ -320,7 +428,7 @@ static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst)
 
     s->one = s->zero = s->zeroes = 0;
     do{
-        T = wv_get_value(s, gb, s->median, &last);
+        T = wv_get_value(s, gb, 0, &last);
         S = 0;
         if(last) break;
         for(i = 0; i < s->terms; i++){
@@ -374,6 +482,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
     int16_t *samples = data;
     int samplecount;
     int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0;
+    int got_hybrid = 0;
     const uint8_t* buf_end = buf + buf_size;
     int i, j, id, size, ssize, weights, t;
 
@@ -383,7 +492,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
     }
 
     memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
-    memset(s->median, 0, sizeof(s->median));
+    memset(s->ch, 0, sizeof(s->ch));
     s->and = s->or = s->shift = 0;
 
     s->samples = AV_RL32(buf); buf += 4;
@@ -396,8 +505,11 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
         av_log(avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n");
         return -1;
     }
-    s->stereo_in = (AV_RL32(buf) & WV_FALSE_STEREO) ? 0 : s->stereo;
-    s->joint = AV_RL32(buf) & WV_JOINT_STEREO; buf += 4;
+    s->frame_flags = AV_RL32(buf); buf += 4;
+    s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
+    s->joint = s->frame_flags & WV_JOINT_STEREO;
+    s->hybrid = s->frame_flags & WV_HYBRID_MODE;
+    s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
     s->CRC = AV_RL32(buf); buf += 4;
     // parse metadata blocks
     while(buf < buf_end){
@@ -500,12 +612,38 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
                 buf += ssize;
                 continue;
             }
-            for(i = 0; i < 3 * (s->stereo_in + 1); i++){
-                s->median[i] = wp_exp2(AV_RL16(buf));
-                buf += 2;
+            for(j = 0; j <= s->stereo_in; j++){
+                for(i = 0; i < 3; i++){
+                    s->ch[j].median[i] = wp_exp2(AV_RL16(buf));
+                    buf += 2;
+                }
             }
             got_entropy = 1;
             break;
+        case WP_ID_HYBRID:
+            if(s->hybrid_bitrate){
+                for(i = 0; i <= s->stereo_in; i++){
+                    s->ch[i].slow_level = wp_exp2(AV_RL16(buf));
+                    buf += 2;
+                    size -= 2;
+                }
+            }
+            for(i = 0; i < (s->stereo_in + 1); i++){
+                s->ch[i].bitrate_acc = AV_RL16(buf) << 16;
+                buf += 2;
+                size -= 2;
+            }
+            if(size > 0){
+                for(i = 0; i < (s->stereo_in + 1); i++){
+                    s->ch[i].bitrate_delta = wp_exp2((int16_t)AV_RL16(buf));
+                    buf += 2;
+                }
+            }else{
+                for(i = 0; i < (s->stereo_in + 1); i++)
+                    s->ch[i].bitrate_delta = 0;
+            }
+            got_hybrid = 1;
+            break;
         case WP_ID_INT32INFO:
             if(size != 4 || *buf){
                 av_log(avctx, AV_LOG_ERROR, "Invalid INT32INFO, size = %i, sent_bits = %i\n", size, *buf);
@@ -550,6 +688,10 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
         av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
         return -1;
     }
+    if(s->hybrid && !got_hybrid){
+        av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
+        return -1;
+    }
     if(!got_bs){
         av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
         return -1;
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 696d73b..e5d8269 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -21,6 +21,7 @@
 #include "avcodec.h"
 #include "dsputil.h"
 #include "mpegvideo.h"
+#include "mathops.h"
 #include "msmpeg4.h"
 #include "msmpeg4data.h"
 #include "intrax8.h"
diff --git a/libavcodec/ws-snd1.c b/libavcodec/ws-snd1.c
index 24753b0..2dc49fc 100644
--- a/libavcodec/ws-snd1.c
+++ b/libavcodec/ws-snd1.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 /**
diff --git a/libavcodec/x86/cpuid.c b/libavcodec/x86/cpuid.c
index 664bac3..033ac0d 100644
--- a/libavcodec/x86/cpuid.c
+++ b/libavcodec/x86/cpuid.c
@@ -44,7 +44,7 @@ int mm_support(void)
     int max_std_level, max_ext_level, std_caps=0, ext_caps=0;
     x86_reg a, c;
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #define PUSHF "pushfq\n\t"
 #define POPF "popfq\n\t"
 #else
@@ -83,7 +83,7 @@ int mm_support(void)
             rval |= FF_MM_MMX;
         if (std_caps & (1<<25))
             rval |= FF_MM_MMXEXT
-#ifdef HAVE_SSE
+#if HAVE_SSE
                   | FF_MM_SSE;
         if (std_caps & (1<<26))
             rval |= FF_MM_SSE2;
diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c
index 1d93351..0167308 100644
--- a/libavcodec/x86/dsputil_mmx.c
+++ b/libavcodec/x86/dsputil_mmx.c
@@ -620,7 +620,7 @@ static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
         "paddb %%mm1, %%mm6             \n\t"
 
 static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
-    if(ENABLE_ANY_H263) {
+    if(CONFIG_ANY_H263) {
     const int strength= ff_h263_loop_filter_strength[qscale];
 
     __asm__ volatile(
@@ -670,7 +670,7 @@ static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int
 }
 
 static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
-    if(ENABLE_ANY_H263) {
+    if(CONFIG_ANY_H263) {
     const int strength= ff_h263_loop_filter_strength[qscale];
     DECLARE_ALIGNED(8, uint64_t, temp[4]);
     uint8_t *btemp= (uint8_t*)temp;
@@ -880,7 +880,7 @@ static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *
         "pabsw     %%mm5, %%mm5 \n"
 
 PAETH(mmx2, ABS3_MMX2)
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 PAETH(ssse3, ABS3_SSSE3)
 #endif
 
@@ -1765,7 +1765,7 @@ void ff_mmxext_idct(DCTELEM *block);
 
 /* XXX: those functions should be suppressed ASAP when all IDCTs are
    converted */
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
 static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
 {
     ff_mmx_idct (block);
@@ -2147,7 +2147,7 @@ static void vector_fmul_add_add_sse(float *dst, const float *src0, const float *
 
 static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
                                       const float *win, float add_bias, int len){
-#ifdef HAVE_6REGS
+#if HAVE_6REGS
     if(add_bias == 0){
         x86_reg i = -len*4;
         x86_reg j = len*4-8;
@@ -2182,7 +2182,7 @@ static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float
 
 static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
                                    const float *win, float add_bias, int len){
-#ifdef HAVE_6REGS
+#if HAVE_6REGS
     if(add_bias == 0){
         x86_reg i = -len*4;
         x86_reg j = len*4-16;
@@ -2324,7 +2324,7 @@ static void float_to_int16_sse2(int16_t *dst, const float *src, long len){
     );
 }
 
-#ifdef HAVE_YASM
+#if HAVE_YASM
 void ff_float_to_int16_interleave6_sse(int16_t *dst, const float **src, int len);
 void ff_float_to_int16_interleave6_3dnow(int16_t *dst, const float **src, int len);
 void ff_float_to_int16_interleave6_3dn2(int16_t *dst, const float **src, int len);
@@ -2332,7 +2332,7 @@ void ff_x264_deblock_v_luma_sse2(uint8_t *pix, int stride, int alpha, int beta,
 void ff_x264_deblock_h_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
 void ff_x264_deblock_v8_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta);
 void ff_x264_deblock_h_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta);
-#ifdef ARCH_X86_32
+#if ARCH_X86_32
 static void ff_x264_deblock_v_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta)
 {
     ff_x264_deblock_v8_luma_intra_mmxext(pix+0, stride, alpha, beta);
@@ -2555,7 +2555,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
                 c->idct_add= ff_simple_idct_add_mmx;
                 c->idct    = ff_simple_idct_mmx;
                 c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
             }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
                 if(mm_flags & FF_MM_MMXEXT){
                     c->idct_put= ff_libmpeg2mmx2_idct_put;
@@ -2568,7 +2568,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
                 }
                 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
 #endif
-            }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER || ENABLE_THEORA_DECODER) &&
+            }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER || CONFIG_THEORA_DECODER) &&
                      idct_algo==FF_IDCT_VP3){
                 if(mm_flags & FF_MM_SSE2){
                     c->idct_put= ff_vp3_idct_put_sse2;
@@ -2631,7 +2631,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
 
         c->draw_edges = draw_edges_mmx;
 
-        if (ENABLE_ANY_H263) {
+        if (CONFIG_ANY_H263) {
             c->h263_v_loop_filter= h263_v_loop_filter_mmx;
             c->h263_h_loop_filter= h263_h_loop_filter_mmx;
         }
@@ -2684,7 +2684,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
                 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
                 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
 
-                if (ENABLE_VP3_DECODER || ENABLE_THEORA_DECODER) {
+                if (CONFIG_VP3_DECODER || CONFIG_THEORA_DECODER) {
                     c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2;
                     c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2;
                 }
@@ -2760,10 +2760,10 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
             c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2;
             c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2;
 
-            if (ENABLE_CAVS_DECODER)
+            if (CONFIG_CAVS_DECODER)
                 ff_cavsdsp_init_mmx2(c, avctx);
 
-            if (ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER)
+            if (CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER)
                 ff_vc1dsp_init_mmx(c, avctx);
 
             c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2;
@@ -2818,7 +2818,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
             c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_3dnow;
             c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_3dnow;
 
-            if (ENABLE_CAVS_DECODER)
+            if (CONFIG_CAVS_DECODER)
                 ff_cavsdsp_init_3dnow(c, avctx);
         }
 
@@ -2853,7 +2853,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
             H264_QPEL_FUNCS(3, 2, sse2);
             H264_QPEL_FUNCS(3, 3, sse2);
         }
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
         if(mm_flags & FF_MM_SSSE3){
             H264_QPEL_FUNCS(1, 0, ssse3);
             H264_QPEL_FUNCS(1, 1, ssse3);
@@ -2876,14 +2876,14 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
         }
 #endif
 
-#if defined(CONFIG_GPL) && defined(HAVE_YASM)
+#if CONFIG_GPL && HAVE_YASM
         if( mm_flags&FF_MM_MMXEXT ){
-#ifdef ARCH_X86_32
+#if ARCH_X86_32
             c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_mmxext;
             c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_mmxext;
 #endif
             if( mm_flags&FF_MM_SSE2 ){
-#if defined(ARCH_X86_64) || !defined(__ICC) || __ICC > 1100
+#if ARCH_X86_64 || !defined(__ICC) || __ICC > 1100
                 c->h264_v_loop_filter_luma = ff_x264_deblock_v_luma_sse2;
                 c->h264_h_loop_filter_luma = ff_x264_deblock_h_luma_sse2;
                 c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_sse2;
@@ -2896,10 +2896,10 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
         }
 #endif
 
-#ifdef CONFIG_SNOW_DECODER
+#if CONFIG_SNOW_DECODER
         if(mm_flags & FF_MM_SSE2 & 0){
             c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2;
-#ifdef HAVE_7REGS
+#if HAVE_7REGS
             c->vertical_compose97i = ff_snow_vertical_compose97i_sse2;
 #endif
             c->inner_add_yblock = ff_snow_inner_add_yblock_sse2;
@@ -2907,7 +2907,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
         else{
             if(mm_flags & FF_MM_MMXEXT){
             c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx;
-#ifdef HAVE_7REGS
+#if HAVE_7REGS
             c->vertical_compose97i = ff_snow_vertical_compose97i_mmx;
 #endif
             }
@@ -2953,7 +2953,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
         }
     }
 
-    if (ENABLE_ENCODERS)
+    if (CONFIG_ENCODERS)
         dsputilenc_init_mmx(c, avctx);
 
 #if 0
diff --git a/libavcodec/x86/dsputil_mmx.h b/libavcodec/x86/dsputil_mmx.h
index 87617e3..3124519 100644
--- a/libavcodec/x86/dsputil_mmx.h
+++ b/libavcodec/x86/dsputil_mmx.h
@@ -104,7 +104,7 @@ extern const double ff_pd_2[2];
     SBUTTERFLY(t, b, c, wd, q)   /* t= a2 b2 c2 d2 e2 f2 g2 h2 */\
                                  /* c= a3 b3 c3 d3 e3 f3 g3 h3 */
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 // permutes 01234567 -> 05736421
 #define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
     SBUTTERFLY(a,b,%%xmm8,wd,dqa)\
diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c
index 76b3678..d1ee111 100644
--- a/libavcodec/x86/dsputilenc_mmx.c
+++ b/libavcodec/x86/dsputilenc_mmx.c
@@ -25,6 +25,7 @@
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
+#include "libavcodec/mathops.h"
 #include "dsputil_mmx.h"
 
 
@@ -1015,7 +1016,7 @@ static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t
     MMABS_SUM(%%xmm7, %%xmm9, %%xmm1)\
     "paddusw %%xmm1, %%xmm0           \n\t"
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #define MMABS_SUM_8x8_SSE2 MMABS_SUM_8x8_NOSPILL
 #else
 #define MMABS_SUM_8x8_SSE2\
@@ -1180,7 +1181,7 @@ HADAMARD8_DIFF_SSE2(sse2)
 #undef MMABS_SUM_8x8
 #undef HSUM
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 #define MMABS(a,z)         MMABS_SSSE3(a,z)
 #define MMABS_SUM_8x8      MMABS_SUM_8x8_NOSPILL
 HADAMARD8_DIFF_SSE2(ssse3)
@@ -1245,7 +1246,7 @@ DCT_SAD_FUNC(mmx2)
 DCT_SAD_FUNC(sse2)
 #undef MMABS
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 #define MMABS(a,z)    MMABS_SSSE3(a,z)
 DCT_SAD_FUNC(ssse3)
 #undef MMABS
@@ -1325,7 +1326,7 @@ static int ssd_int8_vs_int16_mmx(const int8_t *pix1, const int16_t *pix2, int si
 #undef SCALE_OFFSET
 #undef PMULHRW
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 #undef PHADDD
 #define DEF(x) x ## _ssse3
 #define SET_RND(x)
@@ -1413,11 +1414,11 @@ void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
             c->sum_abs_dctelem= sum_abs_dctelem_sse2;
             c->hadamard8_diff[0]= hadamard8_diff16_sse2;
             c->hadamard8_diff[1]= hadamard8_diff_sse2;
-            if (ENABLE_FLAC_ENCODER)
+            if (CONFIG_FLAC_ENCODER)
                 c->flac_compute_autocorr = ff_flac_compute_autocorr_sse2;
         }
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
         if(mm_flags & FF_MM_SSSE3){
             if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
                 c->try_8x8basis= try_8x8basis_ssse3;
diff --git a/libavcodec/x86/fft_sse.c b/libavcodec/x86/fft_sse.c
index deced3b..3d9f1c5 100644
--- a/libavcodec/x86/fft_sse.c
+++ b/libavcodec/x86/fft_sse.c
@@ -108,7 +108,7 @@ void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input
             ::"r"(-4*k), "r"(4*k),
               "r"(input+n4), "r"(tcos+n8), "r"(tsin+n8)
         );
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
         // if we have enough regs, don't let gcc make the luts latency-bound
         // but if not, latency is faster than spilling
         __asm__("movlps %%xmm0, %0 \n"
diff --git a/libavcodec/x86/h264_i386.h b/libavcodec/x86/h264_i386.h
index 909c274..2394a8e 100644
--- a/libavcodec/x86/h264_i386.h
+++ b/libavcodec/x86/h264_i386.h
@@ -33,9 +33,7 @@
 
 //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
 //as that would make optimization work hard)
-#if defined(ARCH_X86) && defined(HAVE_7REGS)     && \
-    defined(HAVE_EBX_AVAILABLE)                  && \
-    !defined(BROKEN_RELOCATIONS)
+#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
 static int decode_significance_x86(CABACContext *c, int max_coeff,
                                    uint8_t *significant_coeff_ctx_base,
                                    int *index){
@@ -149,7 +147,7 @@ static int decode_significance_8x8_x86(CABACContext *c,
     );
     return coeff_count;
 }
-#endif /* defined(ARCH_X86) && defined(HAVE_7REGS) &&                 */
-       /* defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */
+#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE */
+       /* !defined(BROKEN_RELOCATIONS) */
 
 #endif /* AVCODEC_X86_H264_I386_H */
diff --git a/libavcodec/x86/h264dsp_mmx.c b/libavcodec/x86/h264dsp_mmx.c
index 8eeb657..9342d78 100644
--- a/libavcodec/x86/h264dsp_mmx.c
+++ b/libavcodec/x86/h264dsp_mmx.c
@@ -472,7 +472,7 @@ static void ff_h264_idct_add8_mmx2(uint8_t **dest, const int *block_offset, DCTE
     }
 }
 
-#if defined(CONFIG_GPL) && defined(HAVE_YASM)
+#if CONFIG_GPL && HAVE_YASM
 static void ff_h264_idct_dc_add8_mmx2(uint8_t *dst, int16_t *block, int stride)
 {
     __asm__ volatile(
@@ -1488,7 +1488,7 @@ static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, u
 }\
 
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
 static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
     int h=16;\
@@ -2065,7 +2065,7 @@ QPEL_H264_V_XMM(put_,       PUT_OP, sse2)
 QPEL_H264_V_XMM(avg_,  AVG_MMX2_OP, sse2)
 QPEL_H264_HV_XMM(put_,       PUT_OP, sse2)
 QPEL_H264_HV_XMM(avg_,  AVG_MMX2_OP, sse2)
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 QPEL_H264_H_XMM(put_,       PUT_OP, ssse3)
 QPEL_H264_H_XMM(avg_,  AVG_MMX2_OP, ssse3)
 QPEL_H264_HV2_XMM(put_,       PUT_OP, ssse3)
@@ -2079,7 +2079,7 @@ H264_MC_4816(3dnow)
 H264_MC_4816(mmx2)
 H264_MC_816(H264_MC_V, sse2)
 H264_MC_816(H264_MC_HV, sse2)
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 H264_MC_816(H264_MC_H, ssse3)
 H264_MC_816(H264_MC_HV, ssse3)
 #endif
@@ -2161,7 +2161,7 @@ static void avg_h264_chroma_mc4_3dnow(uint8_t *dst/*align 8*/, uint8_t *src/*ali
 #undef H264_CHROMA_MC4_TMPL
 #undef H264_CHROMA_MC8_MV0
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 #define AVG_OP(X)
 #undef H264_CHROMA_MC8_TMPL
 #undef H264_CHROMA_MC4_TMPL
diff --git a/libavcodec/x86/idct_sse2_xvid.c b/libavcodec/x86/idct_sse2_xvid.c
index d8711a2..789167f 100644
--- a/libavcodec/x86/idct_sse2_xvid.c
+++ b/libavcodec/x86/idct_sse2_xvid.c
@@ -103,7 +103,7 @@ DECLARE_ASM_CONST(16, int32_t, walkenIdctRounders[]) = {
 #define CLEAR_ODD(r) "pxor  "r","r" \n\t"
 #define PUT_ODD(dst) "pshufhw  $0x1B, %%xmm2, "dst"   \n\t"
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 
 # define ROW0 "%%xmm8"
 # define REG0 ROW0
@@ -371,7 +371,7 @@ inline void ff_idct_xvid_sse2(short *block)
     JZ("%%esi", "1f")
     "5:                                                          \n\t"
     iMTX_MULT("7*16(%0)", MANGLE(iTab2), ROUND(walkenIdctRounders+5*16), PUT_ODD(ROW7))
-#ifndef ARCH_X86_64
+#if !ARCH_X86_64
     iLLM_HEAD
 #endif
     iLLM_PASS("%0")
diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h
index 95377ac..6bd4b17 100644
--- a/libavcodec/x86/mathops.h
+++ b/libavcodec/x86/mathops.h
@@ -22,6 +22,9 @@
 #ifndef AVCODEC_X86_MATHOPS_H
 #define AVCODEC_X86_MATHOPS_H
 
+#include "config.h"
+#include "libavutil/common.h"
+
 #define MULL(ra, rb, shift) \
         ({ int rt, dummy; __asm__ (\
             "imull %3               \n\t"\
@@ -40,4 +43,25 @@
      __asm__ ("imull %2\n\t" : "=A"(rt) : "a" ((int)ra), "g" ((int)rb));\
      rt; })
 
+#if HAVE_CMOV
+/* median of 3 */
+#define mid_pred mid_pred
+static inline av_const int mid_pred(int a, int b, int c)
+{
+    int i=b;
+    __asm__ volatile(
+        "cmp    %2, %1 \n\t"
+        "cmovg  %1, %0 \n\t"
+        "cmovg  %2, %1 \n\t"
+        "cmp    %3, %1 \n\t"
+        "cmovl  %3, %1 \n\t"
+        "cmp    %1, %0 \n\t"
+        "cmovg  %1, %0 \n\t"
+        :"+&r"(i), "+&r"(a)
+        :"r"(b), "r"(c)
+    );
+    return i;
+}
+#endif
+
 #endif /* AVCODEC_X86_MATHOPS_H */
diff --git a/libavcodec/x86/mpegvideo_mmx.c b/libavcodec/x86/mpegvideo_mmx.c
index 406d3b8..2abd4d5 100644
--- a/libavcodec/x86/mpegvideo_mmx.c
+++ b/libavcodec/x86/mpegvideo_mmx.c
@@ -583,25 +583,30 @@ static void  denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){
     );
 }
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 #define HAVE_SSSE3_BAK
 #endif
 #undef HAVE_SSSE3
+#define HAVE_SSSE3 0
 
 #undef HAVE_SSE2
 #undef HAVE_MMX2
+#define HAVE_SSE2 0
+#define HAVE_MMX2 0
 #define RENAME(a) a ## _MMX
 #define RENAMEl(a) a ## _mmx
 #include "mpegvideo_mmx_template.c"
 
-#define HAVE_MMX2
+#undef HAVE_MMX2
+#define HAVE_MMX2 1
 #undef RENAME
 #undef RENAMEl
 #define RENAME(a) a ## _MMX2
 #define RENAMEl(a) a ## _mmx2
 #include "mpegvideo_mmx_template.c"
 
-#define HAVE_SSE2
+#undef HAVE_SSE2
+#define HAVE_SSE2 1
 #undef RENAME
 #undef RENAMEl
 #define RENAME(a) a ## _SSE2
@@ -609,7 +614,8 @@ static void  denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){
 #include "mpegvideo_mmx_template.c"
 
 #ifdef HAVE_SSSE3_BAK
-#define HAVE_SSSE3
+#undef HAVE_SSSE3
+#define HAVE_SSSE3 1
 #undef RENAME
 #undef RENAMEl
 #define RENAME(a) a ## _SSSE3
@@ -637,7 +643,7 @@ void MPV_common_init_mmx(MpegEncContext *s)
         }
 
         if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
             if(mm_flags & FF_MM_SSSE3){
                 s->dct_quantize= dct_quantize_SSSE3;
             } else
diff --git a/libavcodec/x86/mpegvideo_mmx_template.c b/libavcodec/x86/mpegvideo_mmx_template.c
index a1aae5f..dbc94d3 100644
--- a/libavcodec/x86/mpegvideo_mmx_template.c
+++ b/libavcodec/x86/mpegvideo_mmx_template.c
@@ -29,7 +29,7 @@
 #undef SAVE_SIGN
 #undef RESTORE_SIGN
 
-#if defined(HAVE_SSE2)
+#if HAVE_SSE2
 #define MMREG_WIDTH "16"
 #define MM "%%xmm"
 #define MOVQ "movdqa"
@@ -48,7 +48,7 @@
 #define MMREG_WIDTH "8"
 #define MM "%%mm"
 #define MOVQ "movq"
-#if defined(HAVE_MMX2)
+#if HAVE_MMX2
 #define SPREADW(a) "pshufw $0, "a", "a" \n\t"
 #define PMAXW(a,b) "pmaxsw "a", "b"     \n\t"
 #define PMAX(a,b) \
@@ -74,7 +74,7 @@
 #endif
 #endif
 
-#ifdef HAVE_SSSE3
+#if HAVE_SSSE3
 #define SAVE_SIGN(a,b) \
             "movdqa "b", "a"            \n\t"\
             "pabsw  "b", "b"            \n\t"
@@ -219,7 +219,7 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
         SPREADW(MM"1")
         "psubusw "MM"1, "MM"4               \n\t"
         "packuswb "MM"4, "MM"4              \n\t"
-#ifdef HAVE_SSE2
+#if HAVE_SSE2
         "packuswb "MM"4, "MM"4              \n\t"
 #endif
         "movd "MM"4, %0                     \n\t" // *overflow
diff --git a/libavcodec/x86/snowdsp_mmx.c b/libavcodec/x86/snowdsp_mmx.c
index 9311978..8374a63 100644
--- a/libavcodec/x86/snowdsp_mmx.c
+++ b/libavcodec/x86/snowdsp_mmx.c
@@ -386,7 +386,7 @@ void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){
     }
 }
 
-#ifdef HAVE_7REGS
+#if HAVE_7REGS
 #define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\
         ""op" ("r",%%"REG_d"), %%"t0"      \n\t"\
         ""op" 16("r",%%"REG_d"), %%"t1"    \n\t"\
diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 12b00b1..236c22c 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct XanContext {
diff --git a/libavcodec/xiph.c b/libavcodec/xiph.c
index 6554264..2f4f25c 100644
--- a/libavcodec/xiph.c
+++ b/libavcodec/xiph.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "xiph.h"
 
 int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
diff --git a/libavcodec/xl.c b/libavcodec/xl.c
index b6911dd..8af9a32 100644
--- a/libavcodec/xl.c
+++ b/libavcodec/xl.c
@@ -24,6 +24,7 @@
  * Miro VideoXL codec.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct VideoXLContext{
diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c
index e36ff27..6943ff3 100644
--- a/libavcodec/zmbv.c
+++ b/libavcodec/zmbv.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #include <zlib.h>
diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
index 79478de..a960f7a 100644
--- a/libavcodec/zmbvenc.c
+++ b/libavcodec/zmbvenc.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 #include <zlib.h>
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index b94db63..342e26e 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -29,10 +29,10 @@ unsigned avdevice_version(void)
 
 #define REGISTER_MUXER(X,x) { \
           extern AVOutputFormat x##_muxer; \
-          if(ENABLE_##X##_MUXER)   av_register_output_format(&x##_muxer); }
+          if(CONFIG_##X##_MUXER)   av_register_output_format(&x##_muxer); }
 #define REGISTER_DEMUXER(X,x) { \
           extern AVInputFormat x##_demuxer; \
-          if(ENABLE_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }
+          if(CONFIG_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }
 #define REGISTER_MUXDEMUX(X,x)  REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x)
 
 void avdevice_register_all(void)
diff --git a/libavdevice/audio.c b/libavdevice/audio.c
index d056711..4344ecb 100644
--- a/libavdevice/audio.c
+++ b/libavdevice/audio.c
@@ -25,7 +25,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_SOUNDCARD_H
+#if HAVE_SOUNDCARD_H
 #include <soundcard.h>
 #else
 #include <sys/soundcard.h>
@@ -311,7 +311,7 @@ static int audio_read_close(AVFormatContext *s1)
     return 0;
 }
 
-#ifdef CONFIG_OSS_DEMUXER
+#if CONFIG_OSS_DEMUXER
 AVInputFormat oss_demuxer = {
     "oss",
     NULL_IF_CONFIG_SMALL("Open Sound System capture"),
@@ -324,7 +324,7 @@ AVInputFormat oss_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_OSS_MUXER
+#if CONFIG_OSS_MUXER
 AVOutputFormat oss_muxer = {
     "oss",
     NULL_IF_CONFIG_SMALL("Open Sound System playback"),
diff --git a/libavdevice/beosaudio.cpp b/libavdevice/beosaudio.cpp
index def1fad..84e7c77 100644
--- a/libavdevice/beosaudio.cpp
+++ b/libavdevice/beosaudio.cpp
@@ -33,7 +33,7 @@ extern "C" {
 #include "libavformat/avformat.h"
 }
 
-#ifdef HAVE_BSOUNDRECORDER
+#if HAVE_BSOUNDRECORDER
 #include <SoundRecorder.h>
 using namespace BPrivate::Media::Experimental;
 #endif
@@ -63,7 +63,7 @@ typedef struct {
     sem_id output_sem;
     int output_index;
     BSoundPlayer *player;
-#ifdef HAVE_BSOUNDRECORDER
+#if HAVE_BSOUNDRECORDER
     BSoundRecorder *recorder;
 #endif
     int has_quit; /* signal callbacks not to wait */
@@ -150,7 +150,7 @@ static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, co
     }
 }
 
-#ifdef HAVE_BSOUNDRECORDER
+#if HAVE_BSOUNDRECORDER
 /* called back by BSoundRecorder */
 static void audiorecord_callback(void *cookie, bigtime_t timestamp, void *buffer, size_t bufferSize, const media_multi_audio_format &format)
 {
@@ -192,7 +192,7 @@ static int audio_open(AudioData *s, int is_output, const char *audio_device)
     media_raw_audio_format format;
     media_multi_audio_format iformat;
 
-#ifndef HAVE_BSOUNDRECORDER
+#if !HAVE_BSOUNDRECORDER
     if (!is_output)
         return AVERROR(EIO); /* not for now */
 #endif
@@ -210,7 +210,7 @@ static int audio_open(AudioData *s, int is_output, const char *audio_device)
     s->frame_size = AUDIO_BLOCK_SIZE;
     /* bump up the priority (avoid realtime though) */
     set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1);
-#ifdef HAVE_BSOUNDRECORDER
+#if HAVE_BSOUNDRECORDER
     if (!is_output) {
         bool wait_for_input = false;
         if (audio_device && !strcmp(audio_device, "wait:"))
@@ -273,7 +273,7 @@ static int audio_close(AudioData *s)
     }
     if (s->player)
         delete s->player;
-#ifdef HAVE_BSOUNDRECORDER
+#if HAVE_BSOUNDRECORDER
     if (s->recorder)
         delete s->recorder;
 #endif
diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index ea9a6e2..86590d0 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -26,13 +26,13 @@
 
 #define _BSD_SOURCE 1
 #include "libavformat/avformat.h"
-#if defined (HAVE_DEV_BKTR_IOCTL_METEOR_H) && defined (HAVE_DEV_BKTR_IOCTL_BT848_H)
+#if HAVE_DEV_BKTR_IOCTL_METEOR_H && HAVE_DEV_BKTR_IOCTL_BT848_H
 # include <dev/bktr/ioctl_meteor.h>
 # include <dev/bktr/ioctl_bt848.h>
-#elif defined (HAVE_MACHINE_IOCTL_METEOR_H) && defined (HAVE_MACHINE_IOCTL_BT848_H)
+#elif HAVE_MACHINE_IOCTL_METEOR_H && HAVE_MACHINE_IOCTL_BT848_H
 # include <machine/ioctl_meteor.h>
 # include <machine/ioctl_bt848.h>
-#elif defined (HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H) && defined (HAVE_DEV_VIDEO_METEOR_IOCTL_BT848_H)
+#elif HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H && HAVE_DEV_VIDEO_METEOR_IOCTL_BT848_H
 # include <dev/video/meteor/ioctl_meteor.h>
 # include <dev/video/bktr/ioctl_bt848.h>
 #elif HAVE_DEV_IC_BT8XX_H
diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c
index c01a374..0d8e36a 100644
--- a/libavdevice/libdc1394.c
+++ b/libavdevice/libdc1394.c
@@ -23,9 +23,9 @@
 #include "config.h"
 #include "libavformat/avformat.h"
 
-#if ENABLE_LIBDC1394_2
+#if HAVE_LIBDC1394_2
 #include <dc1394/dc1394.h>
-#elif ENABLE_LIBDC1394_1
+#elif HAVE_LIBDC1394_1
 #include <libraw1394/raw1394.h>
 #include <libdc1394/dc1394_control.h>
 
@@ -45,10 +45,10 @@
 #undef free
 
 typedef struct dc1394_data {
-#if ENABLE_LIBDC1394_1
+#if HAVE_LIBDC1394_1
     raw1394handle_t handle;
     dc1394_cameracapture camera;
-#elif ENABLE_LIBDC1394_2
+#elif HAVE_LIBDC1394_2
     dc1394_t *d;
     dc1394camera_t *camera;
     dc1394video_frame_t *frame;
@@ -142,7 +142,7 @@ out:
     return -1;
 }
 
-#if ENABLE_LIBDC1394_1
+#if HAVE_LIBDC1394_1
 static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
 {
     dc1394_data* dc1394 = c->priv_data;
@@ -236,7 +236,7 @@ static int dc1394_v1_close(AVFormatContext * context)
     return 0;
 }
 
-#elif ENABLE_LIBDC1394_2
+#elif HAVE_LIBDC1394_2
 static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
 {
     dc1394_data* dc1394 = c->priv_data;
@@ -359,7 +359,7 @@ AVInputFormat libdc1394_demuxer = {
 };
 
 #endif
-#if ENABLE_LIBDC1394_1
+#if HAVE_LIBDC1394_1
 AVInputFormat libdc1394_demuxer = {
     .name           = "libdc1394",
     .long_name      = NULL_IF_CONFIG_SMALL("dc1394 v.1 A/V grab"),
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 1efed83..e6e142a 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -35,7 +35,7 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/time.h>
-#ifdef HAVE_SYS_VIDEOIO_H
+#if HAVE_SYS_VIDEOIO_H
 #include <sys/videoio.h>
 #else
 #include <asm/types.h>
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 8ea0528..dff6114 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -24,7 +24,7 @@
 
 #define REGISTER_FILTER(X,x,y) { \
           extern AVFilter avfilter_##y##_##x ; \
-          if(ENABLE_##X##_FILTER )  avfilter_register(&avfilter_##y##_##x ); }
+          if(CONFIG_##X##_FILTER )  avfilter_register(&avfilter_##y##_##x ); }
 
 void avfilter_register_all(void)
 {
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 218a83b..1dbc016 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -250,6 +250,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h)
 {
     uint8_t *src[4], *dst[4];
     int i, j, hsub, vsub;
+    void (*draw_slice)(AVFilterLink *, int, int);
 
     /* copy the slice if needed for permission reasons */
     if(link->srcpic) {
@@ -279,8 +280,9 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h)
         }
     }
 
-    if(link_dpad(link).draw_slice)
-        link_dpad(link).draw_slice(link, y, h);
+    if(!(draw_slice = link_dpad(link).draw_slice))
+        draw_slice = avfilter_default_draw_slice;
+    draw_slice(link, y, h);
 }
 
 AVFilter *avfilter_get_by_name(const char *name)
@@ -339,7 +341,7 @@ AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name)
     if (!filter)
         return 0;
 
-    ret = av_malloc(sizeof(AVFilterContext));
+    ret = av_mallocz(sizeof(AVFilterContext));
 
     ret->av_class = &avfilter_class;
     ret->filter   = filter;
@@ -347,14 +349,18 @@ AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name)
     ret->priv     = av_mallocz(filter->priv_size);
 
     ret->input_count  = pad_count(filter->inputs);
-    ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
-    memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad)*ret->input_count);
-    ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
+    if (ret->input_count) {
+        ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
+        memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count);
+        ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
+    }
 
     ret->output_count = pad_count(filter->outputs);
-    ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
-    memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad)*ret->output_count);
-    ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
+    if (ret->output_count) {
+        ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
+        memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count);
+        ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
+    }
 
     return ret;
 }
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 75d8c76..f0d221c 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -23,7 +23,7 @@
 #define AVFILTER_AVFILTER_H
 
 #define LIBAVFILTER_VERSION_MAJOR  0
-#define LIBAVFILTER_VERSION_MINOR  1
+#define LIBAVFILTER_VERSION_MINOR  2
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@@ -347,15 +347,17 @@ struct AVFilterPad
     int (*config_props)(AVFilterLink *link);
 };
 
-/** Default handler for start_frame() for video inputs */
+/** default handler for start_frame() for video inputs */
 void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
-/** Default handler for end_frame() for video inputs */
+/** default handler for draw_slice() for video inputs */
+void avfilter_default_draw_slice(AVFilterLink *link, int y, int h);
+/** default handler for end_frame() for video inputs */
 void avfilter_default_end_frame(AVFilterLink *link);
-/** Default handler for config_props() for video outputs */
+/** default handler for config_props() for video outputs */
 int avfilter_default_config_output_link(AVFilterLink *link);
-/** Default handler for config_props() for video inputs */
+/** default handler for config_props() for video inputs */
 int avfilter_default_config_input_link (AVFilterLink *link);
-/** Default handler for get_video_buffer() for video inputs */
+/** default handler for get_video_buffer() for video inputs */
 AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link,
                                                   int perms);
 /**
@@ -430,7 +432,7 @@ struct AVFilterContext
  * destination filters between which this link exists, and the indexes of
  * the pads involved.  In addition, this link also contains the parameters
  * which have been negotiated and agreed upon between the filter, such as
- * image dimensions, format, etc
+ * image dimensions, format, etc.
  */
 struct AVFilterLink
 {
@@ -491,7 +493,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
 int avfilter_config_links(AVFilterContext *filter);
 
 /**
- * Request a picture buffer with a specific set of permissions
+ * Request a picture buffer with a specific set of permissions.
  * @param link  the output link to the filter from which the picture will
  *              be requested
  * @param perms the required access permissions
@@ -526,7 +528,7 @@ int avfilter_poll_frame(AVFilterLink *link);
 void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
 
 /**
- * Notify the next filter that the current frame has finished
+ * Notify the next filter that the current frame has finished.
  * @param link the output link the frame was sent over
  */
 void avfilter_end_frame(AVFilterLink *link);
@@ -614,7 +616,7 @@ void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
                          AVFilterPad **pads, AVFilterLink ***links,
                          AVFilterPad *newpad);
 
-/** insert a new input pad for the filter */
+/** Insert a new input pad for the filter. */
 static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
                                          AVFilterPad *p)
 {
@@ -622,7 +624,7 @@ static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
                         &f->input_pads, &f->inputs, p);
 }
 
-/** insert a new output pad for the filter */
+/** Insert a new output pad for the filter. */
 static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
                                           AVFilterPad *p)
 {
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index da63545..9d20644 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -82,6 +82,17 @@ void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
     }
 }
 
+void avfilter_default_draw_slice(AVFilterLink *link, int y, int h)
+{
+    AVFilterLink *out = NULL;
+
+    if(link->dst->output_count)
+        out = link->dst->outputs[0];
+
+    if(out)
+        avfilter_draw_slice(out, y, h);
+}
+
 void avfilter_default_end_frame(AVFilterLink *link)
 {
     AVFilterLink *out = NULL;
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index e7019ea..1fb1158 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -376,6 +376,13 @@ int avfilter_parse_graph(AVFilterGraph *graph, const char *filters,
         index++;
     } while(chr == ',' || chr == ';');
 
+    if (*filters) {
+        av_log(log_ctx, AV_LOG_ERROR,
+               "Unable to parse graph description substring: \"%s\"\n",
+               filters - 1);
+        goto fail;
+    }
+
     if(open_inputs && !strcmp(open_inputs->name, "out") && curr_inputs) {
         /* Last output can be omitted if it is "[out]" */
         const char *tmp = "[out]";
diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index f853716..c792a77 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -27,27 +27,28 @@
  *   http://www.pcisys.net/~melanson/codecs/
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
-#define  RIFF_TAG MKTAG('R', 'I', 'F', 'F')
-#define _4XMV_TAG MKTAG('4', 'X', 'M', 'V')
-#define  LIST_TAG MKTAG('L', 'I', 'S', 'T')
-#define  HEAD_TAG MKTAG('H', 'E', 'A', 'D')
-#define  TRK__TAG MKTAG('T', 'R', 'K', '_')
-#define  MOVI_TAG MKTAG('M', 'O', 'V', 'I')
-#define  VTRK_TAG MKTAG('V', 'T', 'R', 'K')
-#define  STRK_TAG MKTAG('S', 'T', 'R', 'K')
-#define  std__TAG MKTAG('s', 't', 'd', '_')
-#define  name_TAG MKTAG('n', 'a', 'm', 'e')
-#define  vtrk_TAG MKTAG('v', 't', 'r', 'k')
-#define  strk_TAG MKTAG('s', 't', 'r', 'k')
-#define  ifrm_TAG MKTAG('i', 'f', 'r', 'm')
-#define  pfrm_TAG MKTAG('p', 'f', 'r', 'm')
-#define  cfrm_TAG MKTAG('c', 'f', 'r', 'm')
-#define  ifr2_TAG MKTAG('i', 'f', 'r', '2')
-#define  pfr2_TAG MKTAG('p', 'f', 'r', '2')
-#define  cfr2_TAG MKTAG('c', 'f', 'r', '2')
-#define  snd__TAG MKTAG('s', 'n', 'd', '_')
+#define     RIFF_TAG MKTAG('R', 'I', 'F', 'F')
+#define  FOURXMV_TAG MKTAG('4', 'X', 'M', 'V')
+#define     LIST_TAG MKTAG('L', 'I', 'S', 'T')
+#define     HEAD_TAG MKTAG('H', 'E', 'A', 'D')
+#define     TRK__TAG MKTAG('T', 'R', 'K', '_')
+#define     MOVI_TAG MKTAG('M', 'O', 'V', 'I')
+#define     VTRK_TAG MKTAG('V', 'T', 'R', 'K')
+#define     STRK_TAG MKTAG('S', 'T', 'R', 'K')
+#define     std__TAG MKTAG('s', 't', 'd', '_')
+#define     name_TAG MKTAG('n', 'a', 'm', 'e')
+#define     vtrk_TAG MKTAG('v', 't', 'r', 'k')
+#define     strk_TAG MKTAG('s', 't', 'r', 'k')
+#define     ifrm_TAG MKTAG('i', 'f', 'r', 'm')
+#define     pfrm_TAG MKTAG('p', 'f', 'r', 'm')
+#define     cfrm_TAG MKTAG('c', 'f', 'r', 'm')
+#define     ifr2_TAG MKTAG('i', 'f', 'r', '2')
+#define     pfr2_TAG MKTAG('p', 'f', 'r', '2')
+#define     cfr2_TAG MKTAG('c', 'f', 'r', '2')
+#define     snd__TAG MKTAG('s', 'n', 'd', '_')
 
 #define vtrk_SIZE 0x44
 #define strk_SIZE 0x28
@@ -83,7 +84,7 @@ typedef struct FourxmDemuxContext {
 static int fourxm_probe(AVProbeData *p)
 {
     if ((AV_RL32(&p->buf[0]) != RIFF_TAG) ||
-        (AV_RL32(&p->buf[8]) != _4XMV_TAG))
+        (AV_RL32(&p->buf[8]) != FOURXMV_TAG))
         return 0;
 
     return AVPROBE_SCORE_MAX;
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 10a461c..231afbb 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -5,7 +5,7 @@ FFLIBS = avcodec avutil
 
 HEADERS = avformat.h avio.h rtsp.h rtspcodes.h
 
-OBJS = allformats.o cutils.o metadata.o metadata_compat.o os_support.o sdp.o utils.o
+OBJS = allformats.o cutils.o metadata.o metadata_compat.o options.o os_support.o sdp.o utils.o
 
 # muxers/demuxers
 OBJS-$(CONFIG_AAC_DEMUXER)               += raw.o
@@ -78,6 +78,7 @@ OBJS-$(CONFIG_IMAGE2PIPE_MUXER)          += img2.o
 OBJS-$(CONFIG_INGENIENT_DEMUXER)         += raw.o
 OBJS-$(CONFIG_IPMOVIE_DEMUXER)           += ipmovie.o
 OBJS-$(CONFIG_IPOD_MUXER)                += movenc.o riff.o isom.o avc.o
+OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
 OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
 OBJS-$(CONFIG_M4V_DEMUXER)               += raw.o
 OBJS-$(CONFIG_M4V_MUXER)                 += raw.o
@@ -93,7 +94,7 @@ OBJS-$(CONFIG_MMF_MUXER)                 += mmf.o riff.o
 OBJS-$(CONFIG_MOV_DEMUXER)               += mov.o riff.o isom.o
 OBJS-$(CONFIG_MOV_MUXER)                 += movenc.o riff.o isom.o avc.o
 OBJS-$(CONFIG_MP2_MUXER)                 += mp3.o
-OBJS-$(CONFIG_MP3_DEMUXER)               += mp3.o
+OBJS-$(CONFIG_MP3_DEMUXER)               += mp3.o id3v2.o
 OBJS-$(CONFIG_MP3_MUXER)                 += mp3.o
 OBJS-$(CONFIG_MP4_MUXER)                 += movenc.o riff.o isom.o avc.o
 OBJS-$(CONFIG_MPC_DEMUXER)               += mpc.o
diff --git a/libavformat/aiff.c b/libavformat/aiff.c
index 8bd69c2..70569ed 100644
--- a/libavformat/aiff.c
+++ b/libavformat/aiff.c
@@ -170,7 +170,7 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
     return num_frames;
 }
 
-#ifdef CONFIG_AIFF_MUXER
+#if CONFIG_AIFF_MUXER
 typedef struct {
     int64_t form;
     int64_t frames;
@@ -439,7 +439,7 @@ static int aiff_read_packet(AVFormatContext *s,
     return 0;
 }
 
-#ifdef CONFIG_AIFF_DEMUXER
+#if CONFIG_AIFF_DEMUXER
 AVInputFormat aiff_demuxer = {
     "aiff",
     NULL_IF_CONFIG_SMALL("Audio IFF"),
@@ -453,7 +453,7 @@ AVInputFormat aiff_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_AIFF_MUXER
+#if CONFIG_AIFF_MUXER
 AVOutputFormat aiff_muxer = {
     "aiff",
     NULL_IF_CONFIG_SMALL("Audio IFF"),
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 43243f8..c7c0cc8 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -24,17 +24,17 @@
 
 #define REGISTER_MUXER(X,x) { \
     extern AVOutputFormat x##_muxer; \
-    if(ENABLE_##X##_MUXER) av_register_output_format(&x##_muxer); }
+    if(CONFIG_##X##_MUXER) av_register_output_format(&x##_muxer); }
 
 #define REGISTER_DEMUXER(X,x) { \
     extern AVInputFormat x##_demuxer; \
-    if(ENABLE_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }
+    if(CONFIG_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }
 
 #define REGISTER_MUXDEMUX(X,x)  REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x)
 
 #define REGISTER_PROTOCOL(X,x) { \
     extern URLProtocol x##_protocol; \
-    if(ENABLE_##X##_PROTOCOL) register_protocol(&x##_protocol); }
+    if(CONFIG_##X##_PROTOCOL) register_protocol(&x##_protocol); }
 
 /* If you do not call this function, then you can select exactly which
    formats you want to support */
@@ -101,6 +101,7 @@ void av_register_all(void)
     REGISTER_DEMUXER  (INGENIENT, ingenient);
     REGISTER_DEMUXER  (IPMOVIE, ipmovie);
     REGISTER_MUXER    (IPOD, ipod);
+    REGISTER_DEMUXER  (ISS, iss);
     REGISTER_DEMUXER  (LMLM4, lmlm4);
     REGISTER_MUXDEMUX (M4V, m4v);
     REGISTER_MUXDEMUX (MATROSKA, matroska);
@@ -168,7 +169,7 @@ void av_register_all(void)
     REGISTER_MUXER    (RTP, rtp);
     REGISTER_DEMUXER  (RTSP, rtsp);
     REGISTER_DEMUXER  (SDP, sdp);
-#ifdef CONFIG_SDP_DEMUXER
+#if CONFIG_SDP_DEMUXER
     av_register_rtp_dynamic_payload_handlers();
     av_register_rdt_dynamic_payload_handlers();
 #endif
diff --git a/libavformat/amr.c b/libavformat/amr.c
index 1f62351..cbc4ec5 100644
--- a/libavformat/amr.c
+++ b/libavformat/amr.c
@@ -30,7 +30,7 @@ Only mono files are supported.
 static const char AMR_header [] = "#!AMR\n";
 static const char AMRWB_header [] = "#!AMR-WB\n";
 
-#ifdef CONFIG_AMR_MUXER
+#if CONFIG_AMR_MUXER
 static int amr_write_header(AVFormatContext *s)
 {
     ByteIOContext *pb = s->pb;
@@ -166,7 +166,7 @@ static int amr_read_packet(AVFormatContext *s,
     return 0;
 }
 
-#ifdef CONFIG_AMR_DEMUXER
+#if CONFIG_AMR_DEMUXER
 AVInputFormat amr_demuxer = {
     "amr",
     NULL_IF_CONFIG_SMALL("3GPP AMR file format"),
@@ -178,7 +178,7 @@ AVInputFormat amr_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_AMR_MUXER
+#if CONFIG_AMR_MUXER
 AVOutputFormat amr_muxer = {
     "amr",
     NULL_IF_CONFIG_SMALL("3GPP AMR file format"),
diff --git a/libavformat/ape.c b/libavformat/ape.c
index 5ab92b1..34b1d14 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -22,6 +22,7 @@
 
 #include <stdio.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define ENABLE_DEBUG 0
diff --git a/libavformat/asf-enc.c b/libavformat/asf-enc.c
index e1f3c1b..94d208f 100644
--- a/libavformat/asf-enc.c
+++ b/libavformat/asf-enc.c
@@ -812,14 +812,14 @@ static int asf_write_trailer(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_ASF_MUXER
+#if CONFIG_ASF_MUXER
 AVOutputFormat asf_muxer = {
     "asf",
     NULL_IF_CONFIG_SMALL("ASF format"),
     "video/x-ms-asf",
     "asf,wmv,wma",
     sizeof(ASFContext),
-#ifdef CONFIG_LIBMP3LAME
+#if CONFIG_LIBMP3LAME
     CODEC_ID_MP3,
 #else
     CODEC_ID_MP2,
@@ -833,14 +833,14 @@ AVOutputFormat asf_muxer = {
 };
 #endif
 
-#ifdef CONFIG_ASF_STREAM_MUXER
+#if CONFIG_ASF_STREAM_MUXER
 AVOutputFormat asf_stream_muxer = {
     "asf_stream",
     NULL_IF_CONFIG_SMALL("ASF format"),
     "video/x-ms-asf",
     "asf,wmv,wma",
     sizeof(ASFContext),
-#ifdef CONFIG_LIBMP3LAME
+#if CONFIG_LIBMP3LAME
     CODEC_ID_MP3,
 #else
     CODEC_ID_MP2,
diff --git a/libavformat/au.c b/libavformat/au.c
index 7d151cf..caa7f4d 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -47,7 +47,7 @@ static const AVCodecTag codec_au_tags[] = {
     { 0, 0 },
 };
 
-#ifdef CONFIG_AU_MUXER
+#if CONFIG_AU_MUXER
 /* AUDIO_FILE header */
 static int put_au_header(ByteIOContext *pb, AVCodecContext *enc)
 {
@@ -177,7 +177,7 @@ static int au_read_packet(AVFormatContext *s,
     return 0;
 }
 
-#ifdef CONFIG_AU_DEMUXER
+#if CONFIG_AU_DEMUXER
 AVInputFormat au_demuxer = {
     "au",
     NULL_IF_CONFIG_SMALL("SUN AU format"),
@@ -191,7 +191,7 @@ AVInputFormat au_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_AU_MUXER
+#if CONFIG_AU_MUXER
 AVOutputFormat au_muxer = {
     "au",
     NULL_IF_CONFIG_SMALL("SUN AU format"),
diff --git a/libavformat/avc.c b/libavformat/avc.c
index 0c180c8..6ecea38 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "avio.h"
 
@@ -58,24 +60,34 @@ const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end)
     return end + 3;
 }
 
-int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size)
+int ff_avc_parse_nal_units(ByteIOContext *pb, const uint8_t *buf_in, int size)
 {
-    ByteIOContext *pb;
     const uint8_t *p = buf_in;
-    const uint8_t *end = p + *size;
+    const uint8_t *end = p + size;
     const uint8_t *nal_start, *nal_end;
-    int ret = url_open_dyn_buf(&pb);
-    if(ret < 0)
-        return ret;
 
+    size = 0;
     nal_start = ff_avc_find_startcode(p, end);
     while (nal_start < end) {
         while(!*(nal_start++));
         nal_end = ff_avc_find_startcode(nal_start, end);
         put_be32(pb, nal_end - nal_start);
         put_buffer(pb, nal_start, nal_end - nal_start);
+        size += 4 + nal_end - nal_start;
         nal_start = nal_end;
     }
+    return size;
+}
+
+int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
+{
+    ByteIOContext *pb;
+    int ret = url_open_dyn_buf(&pb);
+    if(ret < 0)
+        return ret;
+
+    ff_avc_parse_nal_units(pb, buf_in, *size);
+
     av_freep(buf);
     *size = url_close_dyn_buf(pb, buf);
     return 0;
@@ -85,12 +97,13 @@ int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len)
 {
     if (len > 6) {
         /* check for h264 start code */
-        if (AV_RB32(data) == 0x00000001) {
+        if (AV_RB32(data) == 0x00000001 ||
+            AV_RB24(data) == 0x000001) {
             uint8_t *buf=NULL, *end, *start;
             uint32_t sps_size=0, pps_size=0;
             uint8_t *sps=0, *pps=0;
 
-            int ret = ff_avc_parse_nal_units(data, &buf, &len);
+            int ret = ff_avc_parse_nal_units_buf(data, &buf, &len);
             if (ret < 0)
                 return ret;
             start = buf;
diff --git a/libavformat/avc.h b/libavformat/avc.h
index 2ea938c..2deb77d 100644
--- a/libavformat/avc.h
+++ b/libavformat/avc.h
@@ -25,7 +25,8 @@
 #include <stdint.h>
 #include "avio.h"
 
-int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size);
+int ff_avc_parse_nal_units(ByteIOContext *s, const uint8_t *buf, int size);
+int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size);
 int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len);
 const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end);
 
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index e8b7100..1bd67b6 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -22,7 +22,7 @@
 #define AVFORMAT_AVFORMAT_H
 
 #define LIBAVFORMAT_VERSION_MAJOR 52
-#define LIBAVFORMAT_VERSION_MINOR 23
+#define LIBAVFORMAT_VERSION_MINOR 24
 #define LIBAVFORMAT_VERSION_MICRO  1
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -67,7 +67,7 @@ unsigned avformat_version(void);
  *    A demuxer should set a default if it sets any translated tag.
  */
 
-#define AV_METADATA_IGNORE_CASE     1
+#define AV_METADATA_MATCH_CASE      1
 #define AV_METADATA_IGNORE_SUFFIX   2
 
 typedef struct {
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 14f0ebd..693bdc2 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -18,6 +18,9 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/bswap.h"
 #include "avformat.h"
 #include "avi.h"
 #include "dv.h"
@@ -233,7 +236,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
     AVIContext *avi = s->priv_data;
     ByteIOContext *pb = s->pb;
-    uint32_t tag, tag1, handler;
+    unsigned int tag, tag1, handler;
     int codec_type, stream_index, frame_period, bit_rate;
     unsigned int size, nb_frames;
     int i;
@@ -348,7 +351,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
                 av_freep(&s->streams[0]->codec->extradata);
                 av_freep(&s->streams[0]);
                 s->nb_streams = 0;
-                if (ENABLE_DV_DEMUXER) {
+                if (CONFIG_DV_DEMUXER) {
                     avi->dv_demux = dv_init_demux(s);
                     if (!avi->dv_demux)
                         goto fail;
@@ -515,7 +518,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
                         st->need_parsing = AVSTREAM_PARSE_NONE;
                     /* AVI files with Xan DPCM audio (wrongly) declare PCM
                      * audio in the header but have Axan as stream_code_tag. */
-                    if (st->codec->stream_codec_tag == ff_get_fourcc("Axan")){
+                    if (st->codec->stream_codec_tag == AV_RL32("Axan")){
                         st->codec->codec_id  = CODEC_ID_XAN_DPCM;
                         st->codec->codec_tag = 0;
                     }
@@ -634,7 +637,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
     int64_t i, sync;
     void* dstr;
 
-    if (ENABLE_DV_DEMUXER && avi->dv_demux) {
+    if (CONFIG_DV_DEMUXER && avi->dv_demux) {
         size = dv_get_packet(avi->dv_demux, pkt);
         if (size >= 0)
             return size;
@@ -719,7 +722,7 @@ resync:
                 memcpy(pkt->data + pkt->size - 4*256, ast->pal, 4*256);
         }
 
-        if (ENABLE_DV_DEMUXER && avi->dv_demux) {
+        if (CONFIG_DV_DEMUXER && avi->dv_demux) {
             dstr = pkt->destruct;
             size = dv_produce_packet(avi->dv_demux, pkt,
                                     pkt->data, pkt->size);
@@ -1010,7 +1013,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
 
 //    av_log(NULL, AV_LOG_DEBUG, "XX %"PRId64" %d %"PRId64"\n", timestamp, index, st->index_entries[index].timestamp);
 
-    if (ENABLE_DV_DEMUXER && avi->dv_demux) {
+    if (CONFIG_DV_DEMUXER && avi->dv_demux) {
         /* One and only one real stream for DV in AVI, and it has video  */
         /* offsets. Calling with other stream indexes should have failed */
         /* the av_index_search_timestamp call above.                     */
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index cea513f..7c8a1bb 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -27,7 +27,7 @@
  *  - fill all fields if non streamed (nb_frames for example)
  */
 
-#ifdef CONFIG_AVI_MUXER
+#if CONFIG_AVI_MUXER
 typedef struct AVIIentry {
     unsigned int flags, pos, len;
 } AVIIentry;
@@ -105,9 +105,9 @@ static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *s
 
 static void avi_write_info_tag2(AVFormatContext *s, const char *fourcc, const char *key1, const char *key2)
 {
-    AVMetadataTag *tag= av_metadata_get(s->metadata, key1, NULL, AV_METADATA_IGNORE_CASE);
+    AVMetadataTag *tag= av_metadata_get(s->metadata, key1, NULL, 0);
     if(!tag && key2)
-        tag= av_metadata_get(s->metadata, key2, NULL, AV_METADATA_IGNORE_CASE);
+        tag= av_metadata_get(s->metadata, key2, NULL, 0);
     if(tag)
         avi_write_info_tag(s->pb, fourcc, tag->value);
 }
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index d1dc09b..93efd65 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "avio.h"
 #include <stdarg.h>
@@ -160,12 +161,12 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
     } else {
         int64_t res = AVERROR(EPIPE);
 
-#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
+#if CONFIG_MUXERS || CONFIG_NETWORK
         if (s->write_flag) {
             flush_buffer(s);
             s->must_flush = 1;
         }
-#endif /* defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK) */
+#endif /* CONFIG_MUXERS || CONFIG_NETWORK */
         if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
             return res;
         if (!s->write_flag)
@@ -624,7 +625,7 @@ URLContext *url_fileno(ByteIOContext *s)
     return s->opaque;
 }
 
-#ifdef CONFIG_MUXERS
+#if CONFIG_MUXERS
 int url_fprintf(ByteIOContext *s, const char *fmt, ...)
 {
     va_list ap;
@@ -688,8 +689,8 @@ int64_t av_url_read_fseek(ByteIOContext *s, int stream_index,
 }
 
 /* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response
- * back to the server even if CONFIG_MUXERS is not set. */
-#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
+ * back to the server even if CONFIG_MUXERS is false. */
+#if CONFIG_MUXERS || CONFIG_NETWORK
 /* buffer handling */
 int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags)
 {
@@ -740,7 +741,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
     if (new_allocated_size > d->allocated_size) {
         d->buffer = av_realloc(d->buffer, new_allocated_size);
         if(d->buffer == NULL)
-             return -1234;
+             return AVERROR(ENOMEM);
         d->allocated_size = new_allocated_size;
     }
     memcpy(d->buffer + d->pos, buf, buf_size);
@@ -756,10 +757,7 @@ static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
     int ret;
 
     /* packetized write: output the header */
-    buf1[0] = (buf_size >> 24);
-    buf1[1] = (buf_size >> 16);
-    buf1[2] = (buf_size >> 8);
-    buf1[3] = (buf_size);
+    AV_WB32(buf1, buf_size);
     ret= dyn_buf_write(opaque, buf1, 4);
     if(ret < 0)
         return ret;
@@ -785,28 +783,20 @@ static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
 static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size)
 {
     DynBuffer *d;
-    int io_buffer_size, ret;
-
-    if (max_packet_size)
-        io_buffer_size = max_packet_size;
-    else
-        io_buffer_size = 1024;
+    int ret;
+    unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
 
     if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
         return -1;
-    d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+    d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
     if (!d)
-        return -1;
+        return AVERROR(ENOMEM);
     *s = av_mallocz(sizeof(ByteIOContext));
     if(!*s) {
         av_free(d);
         return AVERROR(ENOMEM);
     }
     d->io_buffer_size = io_buffer_size;
-    d->buffer = NULL;
-    d->pos = 0;
-    d->size = 0;
-    d->allocated_size = 0;
     ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
                         1, d, NULL,
                         max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
index a80b105..7fcf651 100644
--- a/libavformat/bethsoftvid.c
+++ b/libavformat/bethsoftvid.c
@@ -27,6 +27,7 @@
  * @sa http://www.svatopluk.com/andux/docs/dfvid.html
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "libavcodec/bethsoftvideo.h"
 
diff --git a/libavformat/bfi.c b/libavformat/bfi.c
index c6efdd4..b08d166 100644
--- a/libavformat/bfi.c
+++ b/libavformat/bfi.c
@@ -26,6 +26,7 @@
  * @sa http://wiki.multimedia.cx/index.php?title=BFI
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 typedef struct BFIContext {
diff --git a/libavformat/daud.c b/libavformat/daud.c
index 2bca947..cdd831b 100644
--- a/libavformat/daud.c
+++ b/libavformat/daud.c
@@ -78,7 +78,7 @@ AVInputFormat daud_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_DAUD_MUXER
+#if CONFIG_DAUD_MUXER
 AVOutputFormat daud_muxer =
 {
     "daud",
diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c
index 945bacb..8e48651 100644
--- a/libavformat/dsicin.c
+++ b/libavformat/dsicin.c
@@ -24,6 +24,7 @@
  * Delphine Software International CIN file demuxer
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 
diff --git a/libavformat/dv.c b/libavformat/dv.c
index a0e07e9..eb02e3b 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -462,7 +462,7 @@ static int dv_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_DV_DEMUXER
+#if CONFIG_DV_DEMUXER
 AVInputFormat dv_demuxer = {
     "dv",
     NULL_IF_CONFIG_SMALL("DV video format"),
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index c8dc5a8..428d4a0 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -359,7 +359,7 @@ void dv_delete_mux(DVMuxContext *c)
         av_fifo_free(&c->audio_data[i]);
 }
 
-#ifdef CONFIG_DV_MUXER
+#if CONFIG_DV_MUXER
 static int dv_write_header(AVFormatContext *s)
 {
     if (!dv_init_mux(s)) {
diff --git a/libavformat/dxa.c b/libavformat/dxa.c
index 18fb529..1ff44cf 100644
--- a/libavformat/dxa.c
+++ b/libavformat/dxa.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "riff.h"
 
diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index 2eb5868..96345cc 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -25,6 +25,7 @@
  * by Robin Kay (komadori at gekkou.co.uk)
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
index 345e62e..e5d98f1 100644
--- a/libavformat/ffmdec.c
+++ b/libavformat/ffmdec.c
@@ -19,9 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "ffm.h"
-#ifdef CONFIG_FFSERVER
+#if CONFIG_FFSERVER
 #include <unistd.h>
 
 int64_t ffm_read_write_index(int fd)
diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c
index 80ec872..4bb28e2 100644
--- a/libavformat/ffmenc.c
+++ b/libavformat/ffmenc.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "ffm.h"
 
diff --git a/libavformat/file.c b/libavformat/file.c
index e50168d..88ac4db 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -22,6 +22,9 @@
 #include "libavutil/avstring.h"
 #include "avformat.h"
 #include <fcntl.h>
+#if HAVE_SETMODE
+#include <io.h>
+#endif
 #include <unistd.h>
 #include <sys/time.h>
 #include <stdlib.h>
@@ -104,7 +107,7 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
             fd = 0;
         }
     }
-#ifdef O_BINARY
+#if HAVE_SETMODE
     setmode(fd, O_BINARY);
 #endif
     h->priv_data = (void *)(size_t)fd;
diff --git a/libavformat/flic.c b/libavformat/flic.c
index 62ea94e..7867f9c 100644
--- a/libavformat/flic.c
+++ b/libavformat/flic.c
@@ -31,6 +31,7 @@
  * handles special FLIs from the PC game "Magic Carpet".
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define FLIC_FILE_MAGIC_1 0xAF11
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index fc9fc1b..3b63eca 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -309,6 +309,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
     FLVContext *flv = s->priv_data;
     unsigned ts;
     int size= pkt->size;
+    uint8_t *data= NULL;
     int flags, flags_size;
 
 //    av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", enc->codec_type, timestamp, size);
@@ -340,14 +341,12 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
         put_byte(pb, FLV_TAG_TYPE_AUDIO);
     }
 
-    if (enc->codec_id == CODEC_ID_H264 &&
+    if (enc->codec_id == CODEC_ID_H264) {
         /* check if extradata looks like mp4 formated */
-        enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
-        if (ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size) < 0)
-            return -1;
-        assert(pkt->size);
-        size = pkt->size;
-        /* cast needed to get negative value */
+        if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
+            if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
+                return -1;
+        }
         if (!flv->delay && pkt->dts < 0)
             flv->delay = -pkt->dts;
     }
@@ -368,11 +367,16 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
         put_byte(pb,1); // AVC NALU
         put_be24(pb,pkt->pts - pkt->dts);
     }
-    put_buffer(pb, pkt->data, size);
+
+    put_buffer(pb, data ? data : pkt->data, size);
+
     put_be32(pb,size+flags_size+11); // previous tag size
     flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
 
     put_flush_packet(pb);
+
+    av_free(data);
+
     return 0;
 }
 
@@ -382,7 +386,7 @@ AVOutputFormat flv_muxer = {
     "video/x-flv",
     "flv",
     sizeof(FLVContext),
-#ifdef CONFIG_LIBMP3LAME
+#if CONFIG_LIBMP3LAME
     CODEC_ID_MP3,
 #else // CONFIG_LIBMP3LAME
     CODEC_ID_ADPCM_SWF,
diff --git a/libavformat/framehook.c b/libavformat/framehook.c
index 90815fb..8dba5bc 100644
--- a/libavformat/framehook.c
+++ b/libavformat/framehook.c
@@ -23,7 +23,7 @@
 #include "avformat.h"
 #include "framehook.h"
 
-#ifdef HAVE_DLFCN_H
+#if HAVE_DLFCN_H
 #include <dlfcn.h>
 #endif
 
diff --git a/libavformat/gif.c b/libavformat/gif.c
index 0c6686f..827570c 100644
--- a/libavformat/gif.c
+++ b/libavformat/gif.c
@@ -40,6 +40,11 @@
  */
 
 #include "avformat.h"
+
+/* The GIF format uses reversed order for bitstreams... */
+/* at least they don't use PDP_ENDIAN :) */
+#define BITSTREAM_WRITER_LE
+
 #include "libavcodec/bitstream.h"
 
 /* bitstream minipacket size */
@@ -101,72 +106,6 @@ static const rgb_triplet gif_clut[216] = {
     { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
 };
 
-/* The GIF format uses reversed order for bitstreams... */
-/* at least they don't use PDP_ENDIAN :) */
-/* so we 'extend' PutBitContext. hmmm, OOP :) */
-/* seems this thing changed slightly since I wrote it... */
-
-#ifdef ALT_BITSTREAM_WRITER
-# error no ALT_BITSTREAM_WRITER support for now
-#endif
-
-static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
-{
-    unsigned int bit_buf;
-    int bit_cnt;
-
-    //    printf("put_bits=%d %x\n", n, value);
-    assert(n == 32 || value < (1U << n));
-
-    bit_buf = s->bit_buf;
-    bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
-
-    //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
-    /* XXX: optimize */
-    if (n < (32-bit_cnt)) {
-        bit_buf |= value << (bit_cnt);
-        bit_cnt+=n;
-    } else {
-        bit_buf |= value << (bit_cnt);
-
-        *s->buf_ptr = bit_buf & 0xff;
-        s->buf_ptr[1] = (bit_buf >> 8) & 0xff;
-        s->buf_ptr[2] = (bit_buf >> 16) & 0xff;
-        s->buf_ptr[3] = (bit_buf >> 24) & 0xff;
-
-        //printf("bitbuf = %08x\n", bit_buf);
-        s->buf_ptr+=4;
-        if (s->buf_ptr >= s->buf_end)
-            abort();
-//            flush_buffer_rev(s);
-        bit_cnt=bit_cnt + n - 32;
-        if (bit_cnt == 0) {
-            bit_buf = 0;
-        } else {
-            bit_buf = value >> (n - bit_cnt);
-        }
-    }
-
-    s->bit_buf = bit_buf;
-    s->bit_left = 32 - bit_cnt;
-}
-
-/* pad the end of the output stream with zeros */
-static void gif_flush_put_bits_rev(PutBitContext *s)
-{
-    while (s->bit_left < 32) {
-        /* XXX: should test end of buffer */
-        *s->buf_ptr++=s->bit_buf & 0xff;
-        s->bit_buf>>=8;
-        s->bit_left+=8;
-    }
-//    flush_buffer_rev(s);
-    s->bit_left=32;
-    s->bit_buf=0;
-}
-
-/* !RevPutBitContext */
-
 /* GIF header */
 static int gif_image_write_header(ByteIOContext *pb,
                                   int width, int height, int loop_count,
@@ -272,7 +211,7 @@ static int gif_image_write_image(ByteIOContext *pb,
     w = width;
     while(left>0) {
 
-        gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
+        put_bits(&p, 9, 0x0100); /* clear code */
 
         for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
             if (pix_fmt == PIX_FMT_RGB24) {
@@ -281,7 +220,7 @@ static int gif_image_write_image(ByteIOContext *pb,
             } else {
                 v = *ptr++;
             }
-            gif_put_bits_rev(&p, 9, v);
+            put_bits(&p, 9, v);
             if (--w == 0) {
                 w = width;
                 buf += linesize;
@@ -290,8 +229,8 @@ static int gif_image_write_image(ByteIOContext *pb,
         }
 
         if(left<=GIF_CHUNKS) {
-            gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
-            gif_flush_put_bits_rev(&p);
+            put_bits(&p, 9, 0x101); /* end of stream */
+            flush_put_bits(&p);
         }
         if(pbBufPtr(&p) - p.buf > 0) {
             put_byte(pb, pbBufPtr(&p) - p.buf); /* byte count of the packet */
diff --git a/libavcodec/h263_parser.h b/libavformat/id3v2.c
similarity index 67%
copy from libavcodec/h263_parser.h
copy to libavformat/id3v2.c
index 565a222..c27443b 100644
--- a/libavcodec/h263_parser.h
+++ b/libavformat/id3v2.c
@@ -1,6 +1,6 @@
 /*
- * H.263 parser
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni at gmx.at>
+ * ID3v2 header parser
+ * Copyright (c) 2003 Fabrice Bellard
  *
  * This file is part of FFmpeg.
  *
@@ -19,11 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_H263_PARSER_H
-#define AVCODEC_H263_PARSER_H
+#include "id3v2.h"
 
-#include "parser.h"
-
-int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size);
-
-#endif /* AVCODEC_H263_PARSER_H */
+int ff_id3v2_match(const uint8_t *buf)
+{
+    return  buf[0] == 'I' &&
+            buf[1] == 'D' &&
+            buf[2] == '3' &&
+            buf[3] != 0xff &&
+            buf[4] != 0xff &&
+            (buf[6] & 0x80) == 0 &&
+            (buf[7] & 0x80) == 0 &&
+            (buf[8] & 0x80) == 0 &&
+            (buf[9] & 0x80) == 0;
+}
diff --git a/libavcodec/aandcttab.h b/libavformat/id3v2.h
similarity index 73%
copy from libavcodec/aandcttab.h
copy to libavformat/id3v2.h
index 03bb8b5..f54e290 100644
--- a/libavcodec/aandcttab.h
+++ b/libavformat/id3v2.h
@@ -1,4 +1,7 @@
 /*
+ * ID3v2 header parser
+ * Copyright (c) 2003 Fabrice Bellard
+ *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -16,17 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/**
- * @file aandcttab.h
- * AAN (Arai Agui Nakajima) (I)DCT tables
- */
-
-#ifndef AVCODEC_AANDCTTAB_H
-#define AVCODEC_AANDCTTAB_H
+#ifndef AVFORMAT_ID3V2_H
+#define AVFORMAT_ID3V2_H
 
 #include <stdint.h>
 
-extern const uint16_t ff_aanscales[64];
-extern const uint16_t ff_inv_aanscales[64];
+#define ID3v2_HEADER_SIZE 10
+
+/**
+ * Detects ID3v2 Header.
+ * @buf must be ID3v2_HEADER_SIZE byte long
+ */
+int ff_id3v2_match(const uint8_t *buf);
 
-#endif /* AVCODEC_AANDCTTAB_H */
+#endif /* AVFORMAT_ID3V2_H */
diff --git a/libavformat/idcin.c b/libavformat/idcin.c
index 55ad28b..a036189 100644
--- a/libavformat/idcin.c
+++ b/libavformat/idcin.c
@@ -68,6 +68,7 @@
  *       transmitting them to the video decoder
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define HUFFMAN_TABLE_SIZE (64 * 1024)
diff --git a/libavformat/idroq.c b/libavformat/idroq.c
index acf2db6..0326140 100644
--- a/libavformat/idroq.c
+++ b/libavformat/idroq.c
@@ -27,6 +27,7 @@
  *   http://www.csse.monash.edu.au/~timf/
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define RoQ_MAGIC_NUMBER 0x1084
diff --git a/libavformat/iff.c b/libavformat/iff.c
index e5158f6..0354779 100644
--- a/libavformat/iff.c
+++ b/libavformat/iff.c
@@ -27,6 +27,7 @@
  * http://wiki.multimedia.cx/index.php?title=IFF
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define ID_8SVX       MKTAG('8','S','V','X')
diff --git a/libavformat/img2.c b/libavformat/img2.c
index c0b5de2..7e17794 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "libavutil/avstring.h"
 #include "avformat.h"
 #include <strings.h>
@@ -305,7 +306,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
     }
 }
 
-#if defined(CONFIG_IMAGE2_MUXER) || defined(CONFIG_IMAGE2PIPE_MUXER)
+#if CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER
 /******************************************************/
 /* image output */
 
@@ -359,6 +360,29 @@ static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
         url_fclose(pb[1]);
         url_fclose(pb[2]);
     }else{
+        if(av_str2id(img_tags, s->filename) == CODEC_ID_JPEG2000){
+            AVStream *st = s->streams[0];
+            if(st->codec->extradata_size > 8 &&
+               AV_RL32(st->codec->extradata+4) == MKTAG('j','p','2','h')){
+                if(pkt->size < 8 || AV_RL32(pkt->data+4) != MKTAG('j','p','2','c'))
+                    goto error;
+                put_be32(pb[0], 12);
+                put_tag (pb[0], "jP  ");
+                put_be32(pb[0], 0x0D0A870A); // signature
+                put_be32(pb[0], 20);
+                put_tag (pb[0], "ftyp");
+                put_tag (pb[0], "jp2 ");
+                put_be32(pb[0], 0);
+                put_tag (pb[0], "jp2 ");
+                put_buffer(pb[0], st->codec->extradata, st->codec->extradata_size);
+            }else if(pkt->size < 8 ||
+                     (!st->codec->extradata_size &&
+                      AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature
+            error:
+                av_log(s, AV_LOG_ERROR, "malformated jpeg2000 codestream\n");
+                return -1;
+            }
+        }
         put_buffer(pb[0], pkt->data, pkt->size);
     }
     put_flush_packet(pb[0]);
@@ -370,10 +394,10 @@ static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-#endif /* defined(CONFIG_IMAGE2_MUXER) || defined(CONFIG_IMAGE2PIPE_MUXER) */
+#endif /* CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER */
 
 /* input */
-#ifdef CONFIG_IMAGE2_DEMUXER
+#if CONFIG_IMAGE2_DEMUXER
 AVInputFormat image2_demuxer = {
     "image2",
     NULL_IF_CONFIG_SMALL("image2 sequence"),
@@ -387,7 +411,7 @@ AVInputFormat image2_demuxer = {
     AVFMT_NOFILE,
 };
 #endif
-#ifdef CONFIG_IMAGE2PIPE_DEMUXER
+#if CONFIG_IMAGE2PIPE_DEMUXER
 AVInputFormat image2pipe_demuxer = {
     "image2pipe",
     NULL_IF_CONFIG_SMALL("piped image2 sequence"),
@@ -399,12 +423,12 @@ AVInputFormat image2pipe_demuxer = {
 #endif
 
 /* output */
-#ifdef CONFIG_IMAGE2_MUXER
+#if CONFIG_IMAGE2_MUXER
 AVOutputFormat image2_muxer = {
     "image2",
     NULL_IF_CONFIG_SMALL("image2 sequence"),
     "",
-    "bmp,jpeg,jpg,ljpg,pam,pbm,pgm,pgmyuv,png,ppm,sgi,tif,tiff",
+    "bmp,jpeg,jpg,ljpg,pam,pbm,pgm,pgmyuv,png,ppm,sgi,tif,tiff,jp2",
     sizeof(VideoData),
     CODEC_ID_NONE,
     CODEC_ID_MJPEG,
@@ -414,7 +438,7 @@ AVOutputFormat image2_muxer = {
     .flags= AVFMT_NOTIMESTAMPS | AVFMT_NOFILE
 };
 #endif
-#ifdef CONFIG_IMAGE2PIPE_MUXER
+#if CONFIG_IMAGE2PIPE_MUXER
 AVOutputFormat image2pipe_muxer = {
     "image2pipe",
     NULL_IF_CONFIG_SMALL("piped image2 sequence"),
diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index 35c61de..71bae33 100644
--- a/libavformat/ipmovie.c
+++ b/libavformat/ipmovie.c
@@ -32,6 +32,7 @@
  * up and sending out the chunks.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 /* debugging support: #define DEBUG_IPMOVIE as non-zero to see extremely
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 7d1da7c..b5e09c5 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -28,6 +28,7 @@
 /* http://www.mp4ra.org */
 /* ordered by muxing preference */
 const AVCodecTag ff_mp4_obj_type[] = {
+    { CODEC_ID_MOV_TEXT  , 0x08 },
     { CODEC_ID_MPEG4     , 0x20 },
     { CODEC_ID_H264      , 0x21 },
     { CODEC_ID_AAC       , 0x40 },
diff --git a/libavformat/iss.c b/libavformat/iss.c
new file mode 100644
index 0000000..4a16318
--- /dev/null
+++ b/libavformat/iss.c
@@ -0,0 +1,130 @@
+/*
+ * ISS (.iss) file demuxer
+ * Copyright (c) 2008 Jaikrishnan Menon <realityman at gmx.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file iss.c
+ * Funcom ISS file demuxer
+ * @author Jaikrishnan Menon
+ * for more information on the .iss file format, visit:
+ * http://wiki.multimedia.cx/index.php?title=FunCom_ISS
+ */
+
+#include "avformat.h"
+#include "libavutil/avstring.h"
+
+#define ISS_SIG "IMA_ADPCM_Sound"
+#define ISS_SIG_LEN 15
+#define MAX_TOKEN_SIZE 20
+
+typedef struct {
+    int packet_size;
+    int sample_start_pos;
+} IssDemuxContext;
+
+static void get_token(ByteIOContext *s, char *buf, int maxlen)
+{
+    int i = 0;
+    char c;
+
+    while ((c = get_byte(s))) {
+        if(c == ' ')
+            break;
+        if (i < maxlen-1)
+            buf[i++] = c;
+    }
+
+    buf[i] = 0; /* Ensure null terminated, but may be truncated */
+}
+
+static int iss_probe(AVProbeData *p)
+{
+    if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
+        return 0;
+
+    return AVPROBE_SCORE_MAX;
+}
+
+static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+    IssDemuxContext *iss = s->priv_data;
+    ByteIOContext *pb = s->pb;
+    AVStream *st;
+    char token[MAX_TOKEN_SIZE];
+    int stereo, rate_divisor;
+
+    get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
+    get_token(pb, token, sizeof(token)); //packet size
+    sscanf(token, "%d", &iss->packet_size);
+    get_token(pb, token, sizeof(token)); //File ID
+    get_token(pb, token, sizeof(token)); //out size
+    get_token(pb, token, sizeof(token)); //stereo
+    sscanf(token, "%d", &stereo);
+    get_token(pb, token, sizeof(token)); //Unknown1
+    get_token(pb, token, sizeof(token)); //RateDivisor
+    sscanf(token, "%d", &rate_divisor);
+    get_token(pb, token, sizeof(token)); //Unknown2
+    get_token(pb, token, sizeof(token)); //Version ID
+    get_token(pb, token, sizeof(token)); //Size
+
+    iss->sample_start_pos = url_ftell(pb);
+
+    st = av_new_stream(s, 0);
+    if (!st)
+        return AVERROR(ENOMEM);
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
+    st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS;
+    st->codec->channels = stereo ? 2 : 1;
+    st->codec->sample_rate = 44100;
+    if(rate_divisor > 0)
+         st->codec->sample_rate /= rate_divisor;
+    st->codec->bits_per_coded_sample = 4;
+    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
+                                      * st->codec->bits_per_coded_sample;
+    st->codec->block_align = iss->packet_size;
+    av_set_pts_info(st, 32, 1, st->codec->sample_rate);
+
+    return 0;
+}
+
+static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    IssDemuxContext *iss = s->priv_data;
+    int ret = av_get_packet(s->pb, pkt, iss->packet_size);
+
+    if(ret < 0)
+        return ret;
+
+    pkt->stream_index = 0;
+    pkt->pts = url_ftell(s->pb) - iss->sample_start_pos;
+    if(s->streams[0]->codec->channels > 0)
+        pkt->pts /= s->streams[0]->codec->channels*2;
+    return 0;
+}
+
+AVInputFormat iss_demuxer = {
+    "ISS",
+    NULL_IF_CONFIG_SMALL("Funcom ISS format"),
+    sizeof(IssDemuxContext),
+    iss_probe,
+    iss_read_header,
+    iss_read_packet,
+};
+
diff --git a/libavformat/libnut.c b/libavformat/libnut.c
index 3f4a69b..a088551 100644
--- a/libavformat/libnut.c
+++ b/libavformat/libnut.c
@@ -44,7 +44,7 @@ static const AVCodecTag nut_tags[] = {
     { 0, 0 },
 };
 
-#ifdef CONFIG_LIBNUT_MUXER
+#if CONFIG_LIBNUT_MUXER
 static int av_write(void * h, size_t len, const uint8_t * buf) {
     ByteIOContext * bc = h;
     put_buffer(bc, buf, len);
diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c
index 7f01124..dc0a901 100644
--- a/libavformat/lmlm4.c
+++ b/libavformat/lmlm4.c
@@ -22,6 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define LMLM4_I_FRAME   0x00
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6478d84..8ee1f6e 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -36,12 +36,13 @@
 #include "matroska.h"
 #include "libavcodec/mpeg4audio.h"
 #include "libavutil/intfloat_readwrite.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/avstring.h"
 #include "libavutil/lzo.h"
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
-#ifdef CONFIG_BZLIB
+#if CONFIG_BZLIB
 #include <bzlib.h>
 #endif
 
@@ -878,7 +879,7 @@ static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
             goto failed;
         pkt_size -= olen;
         break;
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
         z_stream zstream = {0};
         if (inflateInit(&zstream) != Z_OK)
@@ -899,7 +900,7 @@ static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
         break;
     }
 #endif
-#ifdef CONFIG_BZLIB
+#if CONFIG_BZLIB
     case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
         bz_stream bzstream = {0};
         if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
@@ -1075,6 +1076,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
     EbmlList *index_list;
     MatroskaIndex *index;
     int index_scale = 1;
+    uint64_t max_start = 0;
     Ebml ebml = { 0 };
     AVStream *st;
     int i, j;
@@ -1116,6 +1118,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
         uint8_t *extradata = NULL;
         int extradata_size = 0;
         int extradata_offset = 0;
+        ByteIOContext b;
 
         /* Apply some sanity checks. */
         if (track->type != MATROSKA_TRACK_TYPE_VIDEO &&
@@ -1146,10 +1149,10 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
         } else if (encodings_list->nb_elem == 1) {
             if (encodings[0].type ||
                 (encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP &&
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
                  encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB &&
 #endif
-#ifdef CONFIG_BZLIB
+#if CONFIG_BZLIB
                  encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_BZLIB &&
 #endif
                  encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_LZO)) {
@@ -1199,8 +1202,12 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
         } else if (!strcmp(track->codec_id, "A_MS/ACM")
                    && track->codec_priv.size >= 18
                    && track->codec_priv.data != NULL) {
-            uint16_t tag = AV_RL16(track->codec_priv.data);
-            codec_id = codec_get_id(codec_wav_tags, tag);
+            init_put_byte(&b, track->codec_priv.data, track->codec_priv.size,
+                          URL_RDONLY, NULL, NULL, NULL, NULL);
+            get_wav_header(&b, st->codec, track->codec_priv.size);
+            codec_id = st->codec->codec_id;
+            extradata_offset = 18;
+            track->codec_priv.size -= extradata_offset;
         } else if (!strcmp(track->codec_id, "V_QUICKTIME")
                    && (track->codec_priv.size >= 86)
                    && (track->codec_priv.data != NULL)) {
@@ -1237,7 +1244,6 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
             } else
                 extradata_size = 2;
         } else if (codec_id == CODEC_ID_TTA) {
-            ByteIOContext b;
             extradata_size = 30;
             extradata = av_mallocz(extradata_size);
             if (extradata == NULL)
@@ -1259,8 +1265,6 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
             track->audio.channels = 1;
         } else if (codec_id == CODEC_ID_RA_288 || codec_id == CODEC_ID_COOK ||
                    codec_id == CODEC_ID_ATRAC3) {
-            ByteIOContext b;
-
             init_put_byte(&b, track->codec_priv.data,track->codec_priv.size,
                           0, NULL, NULL, NULL, NULL);
             url_fskip(&b, 24);
@@ -1364,10 +1368,13 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
 
     chapters = chapters_list->elem;
     for (i=0; i<chapters_list->nb_elem; i++)
-        if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid)
+        if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid
+            && (max_start==0 || chapters[i].start > max_start)) {
             ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
                            chapters[i].start, chapters[i].end,
                            chapters[i].title);
+            max_start = chapters[i].start;
+        }
 
     index_list = &matroska->index;
     index = index_list->elem;
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a2d7347..fdd2e21 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -24,6 +24,7 @@
 #include "isom.h"
 #include "matroska.h"
 #include "avc.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/md5.h"
 #include "libavcodec/xiph.h"
 #include "libavcodec/mpeg4audio.h"
@@ -559,7 +560,8 @@ static int mkv_write_tracks(AVFormatContext *s)
         else
             put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, "und");
 
-        put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
+        if (st->disposition)
+            put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
 
         // look for a codec ID string specific to mkv to use,
         // if none are found, use AVI codes
@@ -707,6 +709,7 @@ static int mkv_write_header(AVFormatContext *s)
     if (mkv->cues == NULL)
         return AVERROR(ENOMEM);
 
+    put_flush_packet(pb);
     return 0;
 }
 
@@ -784,6 +787,7 @@ static void mkv_write_block(AVFormatContext *s, unsigned int blockid, AVPacket *
 {
     MatroskaMuxContext *mkv = s->priv_data;
     ByteIOContext *pb = s->pb;
+    AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
 
     av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, "
            "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n",
@@ -793,7 +797,14 @@ static void mkv_write_block(AVFormatContext *s, unsigned int blockid, AVPacket *
     put_byte(pb, 0x80 | (pkt->stream_index + 1));     // this assumes stream_index is less than 126
     put_be16(pb, pkt->pts - mkv->cluster_pts);
     put_byte(pb, flags);
-    put_buffer(pb, pkt->data, pkt->size);
+    if (codec->codec_id == CODEC_ID_H264 &&
+        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
+        /* from x264 or from bytestream h264 */
+        /* nal reformating needed */
+        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+    } else {
+        put_buffer(pb, pkt->data, pkt->size);
+    }
 }
 
 static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
@@ -821,16 +832,6 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
         av_md5_update(mkv->md5_ctx, pkt->data, FFMIN(200, pkt->size));
     }
 
-    if (codec->codec_id == CODEC_ID_H264 &&
-        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
-        /* from x264 or from bytestream h264 */
-        /* nal reformating needed */
-        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
-        if (ret < 0)
-            return ret;
-        assert(pkt->size);
-    }
-
     if (codec->codec_type != CODEC_TYPE_SUBTITLE) {
         mkv_write_block(s, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7);
     } else if (codec->codec_id == CODEC_ID_SSA) {
@@ -889,6 +890,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 
     end_ebml_master(pb, mkv->segment);
     av_free(mkv->md5_ctx);
+    put_flush_packet(pb);
     return 0;
 }
 
diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index 9765e7c..eb545fd 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -33,8 +33,8 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f
 
     for(; i<m->count; i++){
         const char *s= m->elems[i].key;
-        if(flags & AV_METADATA_IGNORE_CASE) for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++);
-        else                                for(j=0;         s[j]  ==         key[j]  && key[j]; j++);
+        if(flags & AV_METADATA_MATCH_CASE) for(j=0;         s[j]  ==         key[j]  && key[j]; j++);
+        else                               for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++);
         if(key[j])
             continue;
         if(s[j] && !(flags & AV_METADATA_IGNORE_SUFFIX))
@@ -47,7 +47,7 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f
 int av_metadata_set(AVMetadata **pm, AVMetadataTag elem)
 {
     AVMetadata *m= *pm;
-    AVMetadataTag *tag= av_metadata_get(m, elem.key, NULL, 0);
+    AVMetadataTag *tag= av_metadata_get(m, elem.key, NULL, AV_METADATA_MATCH_CASE);
 
     if(!m)
         m=*pm= av_mallocz(sizeof(*m));
diff --git a/libavformat/metadata_compat.c b/libavformat/metadata_compat.c
index 7aef938..6cde830 100644
--- a/libavformat/metadata_compat.c
+++ b/libavformat/metadata_compat.c
@@ -18,12 +18,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#if LIBAVFORMAT_VERSION_MAJOR < 53
-
 #include <strings.h>
+#include "avformat.h"
 #include "metadata.h"
 #include "libavutil/avstring.h"
 
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+
 #define SIZE_OFFSET(x) sizeof(((AVFormatContext*)0)->x),offsetof(AVFormatContext,x)
 
 static const struct {
@@ -104,8 +105,7 @@ void ff_metadata_demux_compat(AVFormatContext *ctx)
 
 
 #define FILL_METADATA(s, key, value) {                                        \
-    if (value && *value &&                                                    \
-        !av_metadata_get(s->metadata, #key, NULL, AV_METADATA_IGNORE_CASE))   \
+    if (value && *value && !av_metadata_get(s->metadata, #key, NULL, 0))      \
         av_metadata_set(&s->metadata, (const AVMetadataTag){#key, value});    \
     }
 #define FILL_METADATA_STR(s, key)  FILL_METADATA(s, key, s->key)
diff --git a/libavformat/mm.c b/libavformat/mm.c
index 347d8eb..c6467e1 100644
--- a/libavformat/mm.c
+++ b/libavformat/mm.c
@@ -31,6 +31,7 @@
  *  http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define MM_PREAMBLE_SIZE    6
diff --git a/libavformat/mmf.c b/libavformat/mmf.c
index 5e6d4eb..7c2f4bf 100644
--- a/libavformat/mmf.c
+++ b/libavformat/mmf.c
@@ -36,7 +36,7 @@ static int mmf_rate(int code)
     return mmf_rates[code];
 }
 
-#ifdef CONFIG_MMF_MUXER
+#if CONFIG_MMF_MUXER
 static int mmf_rate_code(int rate)
 {
     int i;
@@ -290,7 +290,7 @@ static int mmf_read_packet(AVFormatContext *s,
     return ret;
 }
 
-#ifdef CONFIG_MMF_DEMUXER
+#if CONFIG_MMF_DEMUXER
 AVInputFormat mmf_demuxer = {
     "mmf",
     NULL_IF_CONFIG_SMALL("mmf format"),
@@ -302,7 +302,7 @@ AVInputFormat mmf_demuxer = {
     pcm_read_seek,
 };
 #endif
-#ifdef CONFIG_MMF_MUXER
+#if CONFIG_MMF_MUXER
 AVOutputFormat mmf_muxer = {
     "mmf",
     NULL_IF_CONFIG_SMALL("mmf format"),
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c0c057a..b510d7c 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -23,6 +23,7 @@
 
 //#define DEBUG
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "riff.h"
 #include "isom.h"
@@ -30,7 +31,7 @@
 #include "libavcodec/mpeg4audio.h"
 #include "libavcodec/mpegaudiodata.h"
 
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
 #include <zlib.h>
 #endif
 
@@ -134,6 +135,8 @@ typedef struct MOVStreamContext {
     MOVDref *drefs;
     int dref_id;
     int wrong_dts; ///< dts are wrong due to negative ctts
+    int width;  ///< tkhd width
+    int height; ///< tkhd height
 } MOVStreamContext;
 
 typedef struct MOVContext {
@@ -977,7 +980,13 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
                 sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
             }
         } else if(st->codec->codec_type==CODEC_TYPE_SUBTITLE){
+            // ttxt stsd contains display flags, justification, background
+            // color, fonts, and default styles, so fake an atom to read it
+            MOVAtom fake_atom = { .size = size - (url_ftell(pb) - start_pos) };
+            mov_read_glbl(c, pb, fake_atom);
             st->codec->codec_id= id;
+            st->codec->width = sc->width;
+            st->codec->height = sc->height;
         } else {
             /* other codec type, just skip (rtp, mp4s, tmcd ...) */
             url_fskip(pb, size - (url_ftell(pb) - start_pos));
@@ -996,7 +1005,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 
     /* special codec parameters handling */
     switch (st->codec->codec_id) {
-#ifdef CONFIG_DV_DEMUXER
+#if CONFIG_DV_DEMUXER
     case CODEC_ID_DVAUDIO:
         c->dv_fctx = av_alloc_format_context();
         c->dv_demux = dv_init_demux(c->dv_fctx);
@@ -1163,7 +1172,7 @@ static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
         sc->stts_data[i].count= sample_count;
         sc->stts_data[i].duration= sample_duration;
 
-        sc->time_rate= ff_gcd(sc->time_rate, sample_duration);
+        sc->time_rate= av_gcd(sc->time_rate, sample_duration);
 
         dprintf(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
 
@@ -1206,7 +1215,7 @@ static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
         sc->ctts_data[i].count   = count;
         sc->ctts_data[i].duration= duration;
 
-        sc->time_rate= ff_gcd(sc->time_rate, FFABS(duration));
+        sc->time_rate= av_gcd(sc->time_rate, FFABS(duration));
     }
     return 0;
 }
@@ -1333,6 +1342,7 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
     st->priv_data = sc;
     st->codec->codec_type = CODEC_TYPE_DATA;
     st->start_time = 0; /* XXX: check */
+    sc->ffindex = st->index;
 
     if ((ret = mov_read_default(c, pb, atom)) < 0)
         return ret;
@@ -1359,7 +1369,7 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
         assert(st->duration % sc->time_rate == 0);
         st->duration /= sc->time_rate;
     }
-    sc->ffindex = st->index;
+
     mov_build_index(c, st);
 
     if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
@@ -1370,13 +1380,13 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
         sc->pb = c->fc->pb;
 
     switch (st->codec->codec_id) {
-#ifdef CONFIG_H261_DECODER
+#if CONFIG_H261_DECODER
     case CODEC_ID_H261:
 #endif
-#ifdef CONFIG_H263_DECODER
+#if CONFIG_H263_DECODER
     case CODEC_ID_H263:
 #endif
-#ifdef CONFIG_MPEG4_DECODER
+#if CONFIG_MPEG4_DECODER
     case CODEC_ID_MPEG4:
 #endif
         st->codec->width= 0; /* let decoder init width/height */
@@ -1466,6 +1476,7 @@ static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
     int64_t disp_transform[2];
     int display_matrix[3][2];
     AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+    MOVStreamContext *sc = st->priv_data;
     int version = get_byte(pb);
 
     get_be24(pb); /* flags */
@@ -1507,6 +1518,8 @@ static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 
     width = get_be32(pb);       // 16.16 fixed point track width
     height = get_be32(pb);      // 16.16 fixed point track height
+    sc->width = width >> 16;
+    sc->height = height >> 16;
 
     //transform the display width/height according to the matrix
     // skip this if the display matrix is the default identity matrix
@@ -1678,7 +1691,7 @@ static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 
 static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 {
-#ifdef CONFIG_ZLIB
+#if CONFIG_ZLIB
     ByteIOContext ctx;
     uint8_t *cmov_data;
     uint8_t *moov_data; /* uncompressed data */
@@ -1926,7 +1939,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
         return -1;
     }
     av_get_packet(sc->pb, pkt, sample->size);
-#ifdef CONFIG_DV_DEMUXER
+#if CONFIG_DV_DEMUXER
     if (mov->dv_demux && sc->dv_audio_container) {
         dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
         av_free(pkt->data);
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 6ddbed1..e07ded3 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -550,6 +550,7 @@ static const AVCodecTag codec_3gp_tags[] = {
     { CODEC_ID_AAC,    MKTAG('m','p','4','a') },
     { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') },
     { CODEC_ID_AMR_WB, MKTAG('s','a','w','b') },
+    { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
     { CODEC_ID_NONE, 0 },
 };
 
@@ -567,6 +568,7 @@ static const AVCodecTag codec_ipod_tags[] = {
     { CODEC_ID_AAC,    MKTAG('m','p','4','a') },
     { CODEC_ID_ALAC,   MKTAG('a','l','a','c') },
     { CODEC_ID_AC3,    MKTAG('a','c','-','3') },
+    { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
     { CODEC_ID_NONE, 0 },
 };
 
@@ -579,6 +581,7 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
         if      (track->enc->codec_id == CODEC_ID_H264)      tag = MKTAG('a','v','c','1');
         else if (track->enc->codec_id == CODEC_ID_AC3)       tag = MKTAG('a','c','-','3');
         else if (track->enc->codec_id == CODEC_ID_DIRAC)     tag = MKTAG('d','r','a','c');
+        else if (track->enc->codec_id == CODEC_ID_MOV_TEXT)  tag = MKTAG('t','x','3','g');
         else if (track->enc->codec_type == CODEC_TYPE_VIDEO) tag = MKTAG('m','p','4','v');
         else if (track->enc->codec_type == CODEC_TYPE_AUDIO) tag = MKTAG('m','p','4','a');
     } else if (track->mode == MODE_IPOD) {
@@ -621,6 +624,8 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
                                "the file may be unplayable!\n");
                     }
                 }
+            } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
+                tag = codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id);
             }
         }
     }
@@ -643,6 +648,21 @@ static int mov_write_uuid_tag_ipod(ByteIOContext *pb)
     return 28;
 }
 
+static int mov_write_subtitle_tag(ByteIOContext *pb, MOVTrack *track)
+{
+    int64_t pos = url_ftell(pb);
+    put_be32(pb, 0);    /* size */
+    put_le32(pb, track->tag); // store it byteswapped
+    put_be32(pb, 0);    /* Reserved */
+    put_be16(pb, 0);    /* Reserved */
+    put_be16(pb, 1);    /* Data-reference index */
+
+    if (track->enc->extradata_size)
+        put_buffer(pb, track->enc->extradata, track->enc->extradata_size);
+
+    return updateSize(pb, pos);
+}
+
 static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track)
 {
     int64_t pos = url_ftell(pb);
@@ -718,6 +738,8 @@ static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack *track)
         mov_write_video_tag(pb, track);
     else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
         mov_write_audio_tag(pb, track);
+    else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE)
+        mov_write_subtitle_tag(pb, track);
     return updateSize(pb, pos);
 }
 
@@ -838,6 +860,30 @@ static int mov_write_dinf_tag(ByteIOContext *pb)
     return updateSize(pb, pos);
 }
 
+static int mov_write_nmhd_tag(ByteIOContext *pb)
+{
+    put_be32(pb, 12);
+    put_tag(pb, "nmhd");
+    put_be32(pb, 0);
+    return 12;
+}
+
+static int mov_write_gmhd_tag(ByteIOContext *pb)
+{
+    put_be32(pb, 0x20);   /* size */
+    put_tag(pb, "gmhd");
+    put_be32(pb, 0x18);   /* gmin size */
+    put_tag(pb, "gmin");  /* generic media info */
+    put_be32(pb, 0);      /* version & flags */
+    put_be16(pb, 0x40);   /* graphics mode = */
+    put_be16(pb, 0x8000); /* opColor (r?) */
+    put_be16(pb, 0x8000); /* opColor (g?) */
+    put_be16(pb, 0x8000); /* opColor (b?) */
+    put_be16(pb, 0);      /* balance */
+    put_be16(pb, 0);      /* reserved */
+    return 0x20;
+}
+
 static int mov_write_smhd_tag(ByteIOContext *pb)
 {
     put_be32(pb, 16); /* size */
@@ -859,7 +905,7 @@ static int mov_write_vmhd_tag(ByteIOContext *pb)
 
 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track)
 {
-    const char *descr, *hdlr, *hdlr_type;
+    const char *hdlr, *descr = NULL, *hdlr_type = NULL;
     int64_t pos = url_ftell(pb);
 
     if (!track) { /* no media --> data handler */
@@ -871,9 +917,13 @@ static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track)
         if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
             hdlr_type = "vide";
             descr = "VideoHandler";
-        } else {
+        } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) {
             hdlr_type = "soun";
             descr = "SoundHandler";
+        } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
+            if (track->mode == MODE_IPOD) hdlr_type = "sbtl";
+            else                          hdlr_type = "text";
+            descr = "SubtitleHandler";
         }
     }
 
@@ -897,8 +947,12 @@ static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack *track)
     put_tag(pb, "minf");
     if(track->enc->codec_type == CODEC_TYPE_VIDEO)
         mov_write_vmhd_tag(pb);
-    else
+    else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
         mov_write_smhd_tag(pb);
+    else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
+        if (track->mode == MODE_MOV) mov_write_gmhd_tag(pb);
+        else                         mov_write_nmhd_tag(pb);
+    }
     if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
         mov_write_hdlr_tag(pb, NULL);
     mov_write_dinf_tag(pb);
@@ -989,7 +1043,8 @@ static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
     put_be32(pb, 0x40000000); /* reserved */
 
     /* Track width and height, for visual only */
-    if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
+    if(track->enc->codec_type == CODEC_TYPE_VIDEO ||
+       track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
         double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
         if(!sample_aspect_ratio) sample_aspect_ratio = 1;
         put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
@@ -1624,6 +1679,9 @@ static int mov_write_header(AVFormatContext *s)
                        i, track->enc->sample_rate);
                 return -1;
             }
+        }else if(st->codec->codec_type == CODEC_TYPE_SUBTITLE){
+            track->timescale = st->codec->time_base.den;
+            av_set_pts_info(st, 64, 1, st->codec->time_base.den);
         }
     }
 
@@ -1677,12 +1735,12 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
         /* from x264 or from bytestream h264 */
         /* nal reformating needed */
-        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
-        if (ret < 0)
-            return ret;
-        assert(pkt->size);
-        size = pkt->size;
-    } else if ((enc->codec_id == CODEC_ID_DNXHD ||
+        size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+    } else {
+        put_buffer(pb, pkt->data, size);
+    }
+
+    if ((enc->codec_id == CODEC_ID_DNXHD ||
                 enc->codec_id == CODEC_ID_AC3) && !trk->vosLen) {
         /* copy frame to create needed atoms */
         trk->vosLen = size;
@@ -1698,7 +1756,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             return -1;
     }
 
-    trk->cluster[trk->entry].pos = url_ftell(pb);
+    trk->cluster[trk->entry].pos = url_ftell(pb) - size;
     trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
     trk->cluster[trk->entry].size = size;
     trk->cluster[trk->entry].entries = samplesInChunk;
@@ -1719,8 +1777,6 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     trk->sampleCount += samplesInChunk;
     mov->mdat_size += size;
 
-    put_buffer(pb, pkt->data, size);
-
     put_flush_packet(pb);
     return 0;
 }
@@ -1761,7 +1817,7 @@ static int mov_write_trailer(AVFormatContext *s)
     return res;
 }
 
-#ifdef CONFIG_MOV_MUXER
+#if CONFIG_MOV_MUXER
 AVOutputFormat mov_muxer = {
     "mov",
     NULL_IF_CONFIG_SMALL("MOV format"),
@@ -1777,7 +1833,7 @@ AVOutputFormat mov_muxer = {
     .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
 };
 #endif
-#ifdef CONFIG_TGP_MUXER
+#if CONFIG_TGP_MUXER
 AVOutputFormat tgp_muxer = {
     "3gp",
     NULL_IF_CONFIG_SMALL("3GP format"),
@@ -1793,7 +1849,7 @@ AVOutputFormat tgp_muxer = {
     .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
 };
 #endif
-#ifdef CONFIG_MP4_MUXER
+#if CONFIG_MP4_MUXER
 AVOutputFormat mp4_muxer = {
     "mp4",
     NULL_IF_CONFIG_SMALL("MP4 format"),
@@ -1809,7 +1865,7 @@ AVOutputFormat mp4_muxer = {
     .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
 };
 #endif
-#ifdef CONFIG_PSP_MUXER
+#if CONFIG_PSP_MUXER
 AVOutputFormat psp_muxer = {
     "psp",
     NULL_IF_CONFIG_SMALL("PSP MP4 format"),
@@ -1825,7 +1881,7 @@ AVOutputFormat psp_muxer = {
     .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
 };
 #endif
-#ifdef CONFIG_TG2_MUXER
+#if CONFIG_TG2_MUXER
 AVOutputFormat tg2_muxer = {
     "3g2",
     NULL_IF_CONFIG_SMALL("3GP2 format"),
@@ -1841,7 +1897,7 @@ AVOutputFormat tg2_muxer = {
     .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
 };
 #endif
-#ifdef CONFIG_IPOD_MUXER
+#if CONFIG_IPOD_MUXER
 AVOutputFormat ipod_muxer = {
     "ipod",
     NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index a4eb49c..9909541 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -24,8 +24,8 @@
 #include "libavcodec/mpegaudio.h"
 #include "libavcodec/mpegaudiodecheader.h"
 #include "avformat.h"
+#include "id3v2.h"
 
-#define ID3v2_HEADER_SIZE 10
 #define ID3v1_TAG_SIZE 128
 
 #define ID3v1_GENRE_MAX 125
@@ -159,20 +159,6 @@ static const char * const id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
     [125] = "Dance Hall",
 };
 
-/* buf must be ID3v2_HEADER_SIZE byte long */
-static int id3v2_match(const uint8_t *buf)
-{
-    return  buf[0] == 'I' &&
-            buf[1] == 'D' &&
-            buf[2] == '3' &&
-            buf[3] != 0xff &&
-            buf[4] != 0xff &&
-            (buf[6] & 0x80) == 0 &&
-            (buf[7] & 0x80) == 0 &&
-            (buf[8] & 0x80) == 0 &&
-            (buf[9] & 0x80) == 0;
-}
-
 static unsigned int id3v2_get_size(ByteIOContext *s, int len)
 {
     int v=0;
@@ -371,7 +357,7 @@ static int mp3_read_probe(AVProbeData *p)
     uint8_t *buf, *buf2, *end;
     AVCodecContext avctx;
 
-    if(id3v2_match(p->buf))
+    if(ff_id3v2_match(p->buf))
         return AVPROBE_SCORE_MAX/2+1; // this must be less than mpeg-ps because some retards put id3v2 tags before mpeg-ps files
 
     max_frames = 0;
@@ -487,7 +473,7 @@ static int mp3_read_header(AVFormatContext *s,
     ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
     if (ret != ID3v2_HEADER_SIZE)
         return -1;
-    if (id3v2_match(buf)) {
+    if (ff_id3v2_match(buf)) {
         /* parse ID3v2 header */
         len = ((buf[6] & 0x7f) << 21) |
             ((buf[7] & 0x7f) << 14) |
@@ -527,7 +513,7 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
     return ret;
 }
 
-#if defined(CONFIG_MP2_MUXER) || defined(CONFIG_MP3_MUXER)
+#if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
 static void id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
 {
     int v, i;
@@ -645,9 +631,9 @@ static int mp3_write_trailer(struct AVFormatContext *s)
     }
     return 0;
 }
-#endif /* defined(CONFIG_MP2_MUXER) || defined(CONFIG_MP3_MUXER) */
+#endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */
 
-#ifdef CONFIG_MP3_DEMUXER
+#if CONFIG_MP3_DEMUXER
 AVInputFormat mp3_demuxer = {
     "mp3",
     NULL_IF_CONFIG_SMALL("MPEG audio"),
@@ -659,12 +645,12 @@ AVInputFormat mp3_demuxer = {
     .extensions = "mp2,mp3,m2a", /* XXX: use probe */
 };
 #endif
-#ifdef CONFIG_MP2_MUXER
+#if CONFIG_MP2_MUXER
 AVOutputFormat mp2_muxer = {
     "mp2",
     NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
     "audio/x-mpeg",
-#ifdef CONFIG_LIBMP3LAME
+#if CONFIG_LIBMP3LAME
     "mp2,m2a",
 #else
     "mp2,mp3,m2a",
@@ -677,7 +663,7 @@ AVOutputFormat mp2_muxer = {
     mp3_write_trailer,
 };
 #endif
-#ifdef CONFIG_MP3_MUXER
+#if CONFIG_MP3_MUXER
 AVOutputFormat mp3_muxer = {
     "mp3",
     NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 4b86f20..69063a8 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -297,12 +297,12 @@ static int mpeg_mux_init(AVFormatContext *ctx)
     int video_bitrate;
 
     s->packet_number = 0;
-    s->is_vcd =    (ENABLE_MPEG1VCD_MUXER  && ctx->oformat == &mpeg1vcd_muxer);
-    s->is_svcd =   (ENABLE_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer);
-    s->is_mpeg2 = ((ENABLE_MPEG2VOB_MUXER  && ctx->oformat == &mpeg2vob_muxer) ||
-                   (ENABLE_MPEG2DVD_MUXER  && ctx->oformat == &mpeg2dvd_muxer) ||
-                   (ENABLE_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer));
-    s->is_dvd =    (ENABLE_MPEG2DVD_MUXER  && ctx->oformat == &mpeg2dvd_muxer);
+    s->is_vcd =    (CONFIG_MPEG1VCD_MUXER  && ctx->oformat == &mpeg1vcd_muxer);
+    s->is_svcd =   (CONFIG_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer);
+    s->is_mpeg2 = ((CONFIG_MPEG2VOB_MUXER  && ctx->oformat == &mpeg2vob_muxer) ||
+                   (CONFIG_MPEG2DVD_MUXER  && ctx->oformat == &mpeg2dvd_muxer) ||
+                   (CONFIG_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer));
+    s->is_dvd =    (CONFIG_MPEG2DVD_MUXER  && ctx->oformat == &mpeg2dvd_muxer);
 
     if(ctx->packet_size)
         s->packet_size = ctx->packet_size;
@@ -1219,7 +1219,7 @@ static int mpeg_mux_end(AVFormatContext *ctx)
     return 0;
 }
 
-#ifdef CONFIG_MPEG1SYSTEM_MUXER
+#if CONFIG_MPEG1SYSTEM_MUXER
 AVOutputFormat mpeg1system_muxer = {
     "mpeg",
     NULL_IF_CONFIG_SMALL("MPEG-1 System format"),
@@ -1233,7 +1233,7 @@ AVOutputFormat mpeg1system_muxer = {
     mpeg_mux_end,
 };
 #endif
-#ifdef CONFIG_MPEG1VCD_MUXER
+#if CONFIG_MPEG1VCD_MUXER
 AVOutputFormat mpeg1vcd_muxer = {
     "vcd",
     NULL_IF_CONFIG_SMALL("MPEG-1 System format (VCD)"),
@@ -1247,7 +1247,7 @@ AVOutputFormat mpeg1vcd_muxer = {
     mpeg_mux_end,
 };
 #endif
-#ifdef CONFIG_MPEG2VOB_MUXER
+#if CONFIG_MPEG2VOB_MUXER
 AVOutputFormat mpeg2vob_muxer = {
     "vob",
     NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"),
@@ -1263,7 +1263,7 @@ AVOutputFormat mpeg2vob_muxer = {
 #endif
 
 /* Same as mpeg2vob_mux except that the pack size is 2324 */
-#ifdef CONFIG_MPEG2SVCD_MUXER
+#if CONFIG_MPEG2SVCD_MUXER
 AVOutputFormat mpeg2svcd_muxer = {
     "svcd",
     NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"),
@@ -1279,7 +1279,7 @@ AVOutputFormat mpeg2svcd_muxer = {
 #endif
 
 /*  Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */
-#ifdef CONFIG_MPEG2DVD_MUXER
+#if CONFIG_MPEG2DVD_MUXER
 AVOutputFormat mpeg2dvd_muxer = {
     "dvd",
     NULL_IF_CONFIG_SMALL("MPEG-2 PS format (DVD VOB)"),
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 00ce336..ac7737e 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "mpegts.h"
 #include "internal.h"
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index fadbb0c..acadc28 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -19,7 +19,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/bswap.h"
 #include "libavutil/crc.h"
+#include "libavcodec/mpegvideo.h"
 #include "avformat.h"
 #include "mpegts.h"
 
@@ -35,9 +37,35 @@ typedef struct MpegTSSection {
     void *opaque;
 } MpegTSSection;
 
+typedef struct MpegTSService {
+    MpegTSSection pmt; /* MPEG2 pmt table context */
+    int sid;           /* service ID */
+    char *name;
+    char *provider_name;
+    int pcr_pid;
+    int pcr_packet_count;
+    int pcr_packet_freq;
+} MpegTSService;
+
+typedef struct MpegTSWrite {
+    MpegTSSection pat; /* MPEG2 pat table */
+    MpegTSSection sdt; /* MPEG2 sdt table context */
+    MpegTSService **services;
+    int sdt_packet_count;
+    int sdt_packet_freq;
+    int pat_packet_count;
+    int pat_packet_freq;
+    int nb_services;
+    int onid;
+    int tsid;
+    uint64_t cur_pcr;
+    int mux_rate;
+} MpegTSWrite;
+
 /* NOTE: 4 bytes must be left at the end for the crc32 */
 static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
 {
+    MpegTSWrite *ts = ((AVFormatContext*)s->opaque)->priv_data;
     unsigned int crc;
     unsigned char packet[TS_PACKET_SIZE];
     const unsigned char *buf_ptr;
@@ -79,6 +107,8 @@ static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
 
         buf_ptr += len1;
         len -= len1;
+
+        ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate;
     }
 }
 
@@ -148,29 +178,6 @@ typedef struct MpegTSWriteStream {
     uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
 } MpegTSWriteStream;
 
-typedef struct MpegTSService {
-    MpegTSSection pmt; /* MPEG2 pmt table context */
-    int sid;           /* service ID */
-    char *name;
-    char *provider_name;
-    int pcr_pid;
-    int pcr_packet_count;
-    int pcr_packet_freq;
-} MpegTSService;
-
-typedef struct MpegTSWrite {
-    MpegTSSection pat; /* MPEG2 pat table */
-    MpegTSSection sdt; /* MPEG2 sdt table context */
-    MpegTSService **services;
-    int sdt_packet_count;
-    int sdt_packet_freq;
-    int pat_packet_count;
-    int pat_packet_freq;
-    int nb_services;
-    int onid;
-    int tsid;
-} MpegTSWrite;
-
 static void mpegts_write_pat(AVFormatContext *s)
 {
     MpegTSWrite *ts = s->priv_data;
@@ -378,6 +385,7 @@ static int mpegts_write_header(AVFormatContext *s)
     AVStream *st;
     int i, total_bit_rate;
     const char *service_name;
+    uint64_t sdt_size, pat_pmt_size, pos;
 
     ts->tsid = DEFAULT_TSID;
     ts->onid = DEFAULT_ONID;
@@ -433,18 +441,39 @@ static int mpegts_write_header(AVFormatContext *s)
         (TS_PACKET_SIZE * 8 * 1000);
     ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
         (TS_PACKET_SIZE * 8 * 1000);
-#if 0
-    printf("%d %d %d\n",
-           total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
-#endif
+
+    ts->mux_rate = 1; // avoid div by 0
 
     /* write info at the start of the file, so that it will be fast to
        find them */
+    pos = url_ftell(s->pb);
     mpegts_write_sdt(s);
+    sdt_size = url_ftell(s->pb) - pos;
+    pos = url_ftell(s->pb);
     mpegts_write_pat(s);
     for(i = 0; i < ts->nb_services; i++) {
         mpegts_write_pmt(s, ts->services[i]);
     }
+    pat_pmt_size = url_ftell(s->pb) - pos;
+
+    total_bit_rate +=
+        total_bit_rate * 25 / (8 * DEFAULT_PES_PAYLOAD_SIZE) + /* PES header size */
+        total_bit_rate * 4 / (8 * TS_PACKET_SIZE) +            /* TS  header size */
+        SDT_RETRANS_TIME * sdt_size +                          /* SDT size */
+        PAT_RETRANS_TIME * pat_pmt_size +                      /* PAT+PMT size */
+        PCR_RETRANS_TIME * 8;                                  /* PCR size */
+
+    av_log(s, AV_LOG_DEBUG, "muxrate %d freq sdt %d pat %d\n",
+           total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
+
+    if (s->mux_rate)
+        ts->mux_rate = s->mux_rate;
+    else
+        ts->mux_rate = total_bit_rate;
+
+    // adjust pcr
+    ts->cur_pcr /= ts->mux_rate;
+
     put_flush_packet(s->pb);
 
     return 0;
@@ -496,6 +525,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
                              int64_t pts, int64_t dts)
 {
     MpegTSWriteStream *ts_st = st->priv_data;
+    MpegTSWrite *ts = s->priv_data;
     uint8_t buf[TS_PACKET_SIZE];
     uint8_t *q;
     int val, is_start, len, header_len, write_pcr, private_code, flags;
@@ -513,9 +543,6 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
                 ts_st->service->pcr_packet_freq) {
                 ts_st->service->pcr_packet_count = 0;
                 write_pcr = 1;
-                /* XXX: this is incorrect, but at least we have a PCR
-                   value */
-                pcr = pts;
             }
         }
 
@@ -530,6 +557,10 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
         *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0);
         ts_st->cc = (ts_st->cc + 1) & 0xf;
         if (write_pcr) {
+            // add 11, pcr references the last byte of program clock reference base
+            pcr = ts->cur_pcr + (4+7)*8*90000LL / ts->mux_rate;
+            if (dts != AV_NOPTS_VALUE && dts < pcr)
+                av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
             *q++ = 7; /* AFC length */
             *q++ = 0x10; /* flags: PCR present */
             *q++ = pcr >> 25;
@@ -567,7 +598,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
                 header_len += 5;
                 flags |= 0x80;
             }
-            if (dts != AV_NOPTS_VALUE) {
+            if (dts != AV_NOPTS_VALUE && dts != pts) {
                 header_len += 5;
                 flags |= 0x40;
             }
@@ -600,7 +631,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
                 write_pts(q, flags >> 6, pts);
                 q += 5;
             }
-            if (dts != AV_NOPTS_VALUE) {
+            if (dts != AV_NOPTS_VALUE && dts != pts) {
                 write_pts(q, 1, dts);
                 q += 5;
             }
@@ -650,6 +681,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
         payload += len;
         payload_size -= len;
         put_buffer(s->pb, buf, TS_PACKET_SIZE);
+        ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate;
     }
     put_flush_packet(s->pb);
 }
@@ -659,21 +691,68 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
     AVStream *st = s->streams[pkt->stream_index];
     int size= pkt->size;
     uint8_t *buf= pkt->data;
+    uint8_t *data= NULL;
     MpegTSWriteStream *ts_st = st->priv_data;
     int len, max_payload_size;
+    const uint8_t *access_unit_index = NULL;
+    const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
+    int64_t dts = AV_NOPTS_VALUE, pts = AV_NOPTS_VALUE;
+
+    if (pkt->pts != AV_NOPTS_VALUE)
+        pts = pkt->pts + delay;
+    if (pkt->dts != AV_NOPTS_VALUE)
+        dts = pkt->dts + delay;
 
     if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
         /* for subtitle, a single PES packet must be generated */
-        mpegts_write_pes(s, st, buf, size, pkt->pts, AV_NOPTS_VALUE);
+        mpegts_write_pes(s, st, buf, size, pts, AV_NOPTS_VALUE);
         return 0;
     }
 
     if (st->codec->codec_id == CODEC_ID_DIRAC) {
         /* for Dirac, a single PES packet must be generated */
-        mpegts_write_pes(s, st, buf, size, pkt->pts, pkt->dts);
+        mpegts_write_pes(s, st, buf, size, pts, dts);
         return 0;
     }
     max_payload_size = DEFAULT_PES_PAYLOAD_SIZE;
+    if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO ||
+        st->codec->codec_id == CODEC_ID_MPEG1VIDEO) {
+        const uint8_t *p = pkt->data;
+        const uint8_t *end = pkt->data+pkt->size;
+        uint32_t state = -1;
+        while (p < end) {
+            p = ff_find_start_code(p, end, &state);
+            if (state == PICTURE_START_CODE) {
+                access_unit_index = p - 4;
+                break;
+            }
+        }
+    } if (st->codec->codec_id == CODEC_ID_H264) {
+        if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
+            av_log(s, AV_LOG_ERROR, "h264 bitstream malformated\n");
+            return -1;
+        }
+        if (pkt->data[4] != 0x09) { // AUD NAL
+            data = av_malloc(pkt->size+6);
+            if (!data)
+                return -1;
+            memcpy(data+6, pkt->data, pkt->size);
+            AV_WB32(data, 0x00000001);
+            data[4] = 0x09;
+            data[5] = 0xe0; // any slice type
+            buf  = data;
+            size = pkt->size+6;
+        }
+        access_unit_index = buf;
+    } else {
+        access_unit_index = pkt->data;
+    }
+
+    if (!access_unit_index) {
+        av_log(s, AV_LOG_ERROR, "error, could not find access unit start\n");
+        return -1;
+    }
+
     while (size > 0) {
         len = max_payload_size - ts_st->payload_index;
         if (len > size)
@@ -682,18 +761,24 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
         buf += len;
         size -= len;
         ts_st->payload_index += len;
-        if (ts_st->payload_pts == AV_NOPTS_VALUE)
-            ts_st->payload_pts = pkt->pts;
-        if (ts_st->payload_dts == AV_NOPTS_VALUE)
-            ts_st->payload_dts = pkt->dts;
+        if (access_unit_index && access_unit_index < buf &&
+            ts_st->payload_pts == AV_NOPTS_VALUE &&
+            ts_st->payload_dts == AV_NOPTS_VALUE) {
+            ts_st->payload_dts = dts;
+            ts_st->payload_pts = pts;
+        }
         if (ts_st->payload_index >= max_payload_size) {
             mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
                              ts_st->payload_pts, ts_st->payload_dts);
             ts_st->payload_pts = AV_NOPTS_VALUE;
             ts_st->payload_dts = AV_NOPTS_VALUE;
             ts_st->payload_index = 0;
+            access_unit_index = NULL; // unset access unit to avoid setting pts/dts again
         }
     }
+
+    av_free(data);
+
     return 0;
 }
 
diff --git a/libavformat/network.h b/libavformat/network.h
index a5904d9..ef08b55 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -21,7 +21,7 @@
 #ifndef AVFORMAT_NETWORK_H
 #define AVFORMAT_NETWORK_H
 
-#ifdef HAVE_WINSOCK2_H
+#if HAVE_WINSOCK2_H
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
@@ -38,7 +38,7 @@
 #define FF_NETERROR(err) err
 #endif
 
-#ifdef HAVE_ARPA_INET_H
+#if HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
 
@@ -46,7 +46,7 @@ int ff_socket_nonblock(int socket, int enable);
 
 static inline int ff_network_init(void)
 {
-#ifdef HAVE_WINSOCK2_H
+#if HAVE_WINSOCK2_H
     WSADATA wsaData;
     if (WSAStartup(MAKEWORD(1,1), &wsaData))
         return 0;
@@ -56,12 +56,12 @@ static inline int ff_network_init(void)
 
 static inline void ff_network_close(void)
 {
-#ifdef HAVE_WINSOCK2_H
+#if HAVE_WINSOCK2_H
     WSACleanup();
 #endif
 }
 
-#if !defined(HAVE_INET_ATON)
+#if !HAVE_INET_ATON
 /* in os_support.c */
 int inet_aton (const char * str, struct in_addr * add);
 #endif
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 098bc84..02d828a 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -21,6 +21,7 @@
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/bswap.h"
 #include "libavutil/tree.h"
 #include "nut.h"
 
@@ -205,7 +206,7 @@ static int decode_main_header(NUTContext *nut){
     for(i=0; i<nut->time_base_count; i++){
         GET_V(nut->time_base[i].num, tmp>0 && tmp<(1ULL<<31))
         GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))
-        if(ff_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
+        if(av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
             av_log(s, AV_LOG_ERROR, "time base invalid\n");
             return -1;
         }
@@ -905,7 +906,7 @@ static int nut_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_NUT_DEMUXER
+#if CONFIG_NUT_DEMUXER
 AVInputFormat nut_demuxer = {
     "nut",
     NULL_IF_CONFIG_SMALL("NUT format"),
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 54d4b07..1e5f733 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "libavutil/tree.h"
 #include "libavcodec/mpegaudiodata.h"
 #include "nut.h"
@@ -808,9 +809,9 @@ AVOutputFormat nut_muxer = {
     "video/x-nut",
     "nut",
     sizeof(NUTContext),
-#ifdef CONFIG_LIBVORBIS
+#if   CONFIG_LIBVORBIS
     CODEC_ID_VORBIS,
-#elif defined(CONFIG_LIBMP3LAME)
+#elif CONFIG_LIBMP3LAME
     CODEC_ID_MP3,
 #else
     CODEC_ID_MP2,
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index 7a01e68..747f238 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -18,6 +18,8 @@
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "riff.h"
 
diff --git a/libavformat/options.c b/libavformat/options.c
new file mode 100644
index 0000000..057de7e
--- /dev/null
+++ b/libavformat/options.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "libavcodec/opt.h"
+
+/**
+ * @file options.c
+ * Options definition for AVFormatContext.
+ */
+
+static const char* format_to_name(void* ptr)
+{
+    AVFormatContext* fc = (AVFormatContext*) ptr;
+    if(fc->iformat) return fc->iformat->name;
+    else if(fc->oformat) return fc->oformat->name;
+    else return "NULL";
+}
+
+#define OFFSET(x) offsetof(AVFormatContext,x)
+#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
+//these names are too long to be readable
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[]={
+{"probesize", NULL, OFFSET(probesize), FF_OPT_TYPE_INT, 32000, 32, INT_MAX, D}, /* 32000 from mpegts.c: 1.0 second at 24Mbit/s */
+{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
+{"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
+{"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"},
+{"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"},
+{"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_GENPTS, INT_MIN, INT_MAX, D, "fflags"},
+{"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
+{"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
+{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D},
+{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D},
+{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D},
+{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
+{"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, E|D, "fdebug"},
+{"ts", NULL, 0, FF_OPT_TYPE_CONST, FF_FDEBUG_TS, INT_MIN, INT_MAX, E|D, "fdebug"},
+{NULL},
+};
+
+#undef E
+#undef D
+#undef DEFAULT
+
+static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options };
+
+static void avformat_get_context_defaults(AVFormatContext *s)
+{
+    memset(s, 0, sizeof(AVFormatContext));
+
+    s->av_class = &av_format_context_class;
+
+    av_opt_set_defaults(s);
+}
+
+AVFormatContext *av_alloc_format_context(void)
+{
+    AVFormatContext *ic;
+    ic = av_malloc(sizeof(AVFormatContext));
+    if (!ic) return ic;
+    avformat_get_context_defaults(ic);
+    ic->av_class = &av_format_context_class;
+    return ic;
+}
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index e6dbc30..6763e39 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -30,18 +30,18 @@
 #include <sys/time.h>
 #include "os_support.h"
 
-#ifdef CONFIG_NETWORK
-#ifndef HAVE_POLL_H
-#ifdef HAVE_WINSOCK2_H
+#if CONFIG_NETWORK
+#if !HAVE_POLL_H
+#if HAVE_WINSOCK2_H
 #include <winsock2.h>
-#elif defined (HAVE_SYS_SELECT_H)
+#elif HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 #endif
 
 #include "network.h"
 
-#if !defined(HAVE_INET_ATON)
+#if !HAVE_INET_ATON
 #include <stdlib.h>
 #include <strings.h>
 
@@ -58,7 +58,7 @@ int inet_aton (const char * str, struct in_addr * add)
 
     return 1;
 }
-#endif /* !defined(HAVE_INET_ATON) */
+#endif /* !HAVE_INET_ATON */
 
 /* resolve host with also IP address parsing */
 int resolve_host(struct in_addr *sin_addr, const char *hostname)
@@ -76,7 +76,7 @@ int resolve_host(struct in_addr *sin_addr, const char *hostname)
 
 int ff_socket_nonblock(int socket, int enable)
 {
-#ifdef HAVE_WINSOCK2_H
+#if HAVE_WINSOCK2_H
    return ioctlsocket(socket, FIONBIO, &enable);
 #else
    if (enable)
@@ -87,8 +87,8 @@ int ff_socket_nonblock(int socket, int enable)
 }
 #endif /* CONFIG_NETWORK */
 
-#ifdef CONFIG_FFSERVER
-#ifndef HAVE_POLL_H
+#if CONFIG_FFSERVER
+#if !HAVE_POLL_H
 int poll(struct pollfd *fds, nfds_t numfds, int timeout)
 {
     fd_set read_set;
@@ -98,7 +98,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     int n;
     int rc;
 
-#ifdef HAVE_WINSOCK2_H
+#if HAVE_WINSOCK2_H
     if (numfds >= FD_SETSIZE) {
         errno = EINVAL;
         return -1;
@@ -113,7 +113,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     for(i = 0; i < numfds; i++) {
         if (fds[i].fd < 0)
             continue;
-#ifndef HAVE_WINSOCK2_H
+#if !HAVE_WINSOCK2_H
         if (fds[i].fd >= FD_SETSIZE) {
             errno = EINVAL;
             return -1;
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 0b6a292..165dc23 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -34,7 +34,7 @@
 
 static inline int is_dos_path(const char *path)
 {
-#ifdef HAVE_DOS_PATHS
+#if HAVE_DOS_PATHS
     if (path[0] && path[1] == ':')
         return 1;
 #endif
@@ -58,18 +58,18 @@ static inline int is_dos_path(const char *path)
 #  endif
 #endif
 
-#ifdef CONFIG_NETWORK
-#ifndef HAVE_SOCKLEN_T
+#if CONFIG_NETWORK
+#if !HAVE_SOCKLEN_T
 typedef int socklen_t;
 #endif
 
 /* most of the time closing a socket is just closing an fd */
-#ifndef HAVE_CLOSESOCKET
+#if !HAVE_CLOSESOCKET
 #define closesocket close
 #endif
 
-#ifdef CONFIG_FFSERVER
-#ifndef HAVE_POLL_H
+#if CONFIG_FFSERVER
+#if !HAVE_POLL_H
 typedef unsigned long nfds_t;
 
 struct pollfd {
diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index 469a2c4..583b87f 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -29,6 +29,7 @@
  * RIFF headers, followed by CD sectors.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
diff --git a/libavformat/raw.c b/libavformat/raw.c
index b93cdcc..f3214ac 100644
--- a/libavformat/raw.c
+++ b/libavformat/raw.c
@@ -28,7 +28,7 @@
 #include "raw.h"
 
 /* simple formats */
-#ifdef CONFIG_FLAC_MUXER
+#if CONFIG_FLAC_MUXER
 static int flac_write_header(struct AVFormatContext *s)
 {
     static const uint8_t header[8] = {
@@ -61,7 +61,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
 }
 #endif
 
-#ifdef CONFIG_ROQ_MUXER
+#if CONFIG_ROQ_MUXER
 static int roq_write_header(struct AVFormatContext *s)
 {
     static const uint8_t header[] = {
@@ -75,14 +75,14 @@ static int roq_write_header(struct AVFormatContext *s)
 }
 #endif
 
-#ifdef CONFIG_NULL_MUXER
+#if CONFIG_NULL_MUXER
 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
     return 0;
 }
 #endif
 
-#ifdef CONFIG_MUXERS
+#if CONFIG_MUXERS
 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
     put_buffer(s->pb, pkt->data, pkt->size);
@@ -91,7 +91,7 @@ static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 }
 #endif
 
-#ifdef CONFIG_DEMUXERS
+#if CONFIG_DEMUXERS
 /* raw input */
 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
@@ -182,7 +182,7 @@ static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
 }
 #endif
 
-#ifdef CONFIG_RAWVIDEO_DEMUXER
+#if CONFIG_RAWVIDEO_DEMUXER
 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int packet_size, ret, width, height;
@@ -208,7 +208,7 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
 }
 #endif
 
-#ifdef CONFIG_INGENIENT_DEMUXER
+#if CONFIG_INGENIENT_DEMUXER
 // http://www.artificis.hu/files/texts/ingenient.txt
 static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
@@ -246,7 +246,7 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
 }
 #endif
 
-#ifdef CONFIG_DEMUXERS
+#if CONFIG_DEMUXERS
 int pcm_read_seek(AVFormatContext *s,
                   int stream_index, int64_t timestamp, int flags)
 {
@@ -320,7 +320,7 @@ static int video_read_header(AVFormatContext *s,
 }
 #endif
 
-#ifdef CONFIG_MPEGVIDEO_DEMUXER
+#if CONFIG_MPEGVIDEO_DEMUXER
 #define SEQ_START_CODE          0x000001b3
 #define GOP_START_CODE          0x000001b8
 #define PICTURE_START_CODE      0x00000100
@@ -354,7 +354,7 @@ static int mpegvideo_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_M4V_DEMUXER
+#if CONFIG_M4V_DEMUXER
 #define VISUAL_OBJECT_START_CODE       0x000001b5
 #define VOP_START_CODE                 0x000001b6
 
@@ -383,7 +383,7 @@ static int mpeg4video_probe(AVProbeData *probe_packet)
 }
 #endif
 
-#ifdef CONFIG_H264_DEMUXER
+#if CONFIG_H264_DEMUXER
 static int h264_probe(AVProbeData *p)
 {
     uint32_t code= -1;
@@ -430,7 +430,7 @@ static int h264_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_H263_DEMUXER
+#if CONFIG_H263_DEMUXER
 static int h263_probe(AVProbeData *p)
 {
     int code;
@@ -445,7 +445,7 @@ static int h263_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_H261_DEMUXER
+#if CONFIG_H261_DEMUXER
 static int h261_probe(AVProbeData *p)
 {
     int code;
@@ -460,7 +460,7 @@ static int h261_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_DTS_DEMUXER
+#if CONFIG_DTS_DEMUXER
 #define DCA_MARKER_14B_BE 0x1FFFE800
 #define DCA_MARKER_14B_LE 0xFF1F00E8
 #define DCA_MARKER_RAW_BE 0x7FFE8001
@@ -495,7 +495,7 @@ static int dts_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_DIRAC_DEMUXER
+#if CONFIG_DIRAC_DEMUXER
 static int dirac_probe(AVProbeData *p)
 {
     if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
@@ -505,7 +505,7 @@ static int dirac_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_DNXHD_DEMUXER
+#if CONFIG_DNXHD_DEMUXER
 static int dnxhd_probe(AVProbeData *p)
 {
     static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01};
@@ -516,7 +516,7 @@ static int dnxhd_probe(AVProbeData *p)
 }
 #endif
 
-#if defined(CONFIG_AC3_DEMUXER) || defined(CONFIG_EAC3_DEMUXER)
+#if CONFIG_AC3_DEMUXER || CONFIG_EAC3_DEMUXER
 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
 {
     int max_frames, first_frames = 0, frames;
@@ -555,21 +555,21 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
 }
 #endif
 
-#ifdef CONFIG_AC3_DEMUXER
+#if CONFIG_AC3_DEMUXER
 static int ac3_probe(AVProbeData *p)
 {
     return ac3_eac3_probe(p, CODEC_ID_AC3);
 }
 #endif
 
-#ifdef CONFIG_EAC3_DEMUXER
+#if CONFIG_EAC3_DEMUXER
 static int eac3_probe(AVProbeData *p)
 {
     return ac3_eac3_probe(p, CODEC_ID_EAC3);
 }
 #endif
 
-#ifdef CONFIG_FLAC_DEMUXER
+#if CONFIG_FLAC_DEMUXER
 static int flac_probe(AVProbeData *p)
 {
     if(memcmp(p->buf, "fLaC", 4)) return 0;
@@ -577,7 +577,7 @@ static int flac_probe(AVProbeData *p)
 }
 #endif
 
-#ifdef CONFIG_AAC_DEMUXER
+#if CONFIG_AAC_DEMUXER
 static int adts_aac_probe(AVProbeData *p)
 {
     int max_frames = 0, first_frames = 0;
@@ -612,7 +612,7 @@ static int adts_aac_probe(AVProbeData *p)
 
 /* Note: Do not forget to add new entries to the Makefile as well. */
 
-#ifdef CONFIG_AAC_DEMUXER
+#if CONFIG_AAC_DEMUXER
 AVInputFormat aac_demuxer = {
     "aac",
     NULL_IF_CONFIG_SMALL("ADTS AAC"),
@@ -626,7 +626,7 @@ AVInputFormat aac_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_AC3_DEMUXER
+#if CONFIG_AC3_DEMUXER
 AVInputFormat ac3_demuxer = {
     "ac3",
     NULL_IF_CONFIG_SMALL("raw AC-3"),
@@ -640,7 +640,7 @@ AVInputFormat ac3_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_AC3_MUXER
+#if CONFIG_AC3_MUXER
 AVOutputFormat ac3_muxer = {
     "ac3",
     NULL_IF_CONFIG_SMALL("raw AC-3"),
@@ -655,7 +655,7 @@ AVOutputFormat ac3_muxer = {
 };
 #endif
 
-#ifdef CONFIG_DIRAC_DEMUXER
+#if CONFIG_DIRAC_DEMUXER
 AVInputFormat dirac_demuxer = {
     "dirac",
     NULL_IF_CONFIG_SMALL("raw Dirac"),
@@ -668,7 +668,7 @@ AVInputFormat dirac_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_DIRAC_MUXER
+#if CONFIG_DIRAC_MUXER
 AVOutputFormat dirac_muxer = {
     "dirac",
     NULL_IF_CONFIG_SMALL("raw Dirac"),
@@ -683,7 +683,7 @@ AVOutputFormat dirac_muxer = {
 };
 #endif
 
-#ifdef CONFIG_DNXHD_DEMUXER
+#if CONFIG_DNXHD_DEMUXER
 AVInputFormat dnxhd_demuxer = {
     "dnxhd",
     NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
@@ -696,7 +696,7 @@ AVInputFormat dnxhd_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_DNXHD_MUXER
+#if CONFIG_DNXHD_MUXER
 AVOutputFormat dnxhd_muxer = {
     "dnxhd",
     NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
@@ -711,7 +711,7 @@ AVOutputFormat dnxhd_muxer = {
 };
 #endif
 
-#ifdef CONFIG_DTS_DEMUXER
+#if CONFIG_DTS_DEMUXER
 AVInputFormat dts_demuxer = {
     "dts",
     NULL_IF_CONFIG_SMALL("raw DTS"),
@@ -725,7 +725,7 @@ AVInputFormat dts_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_DTS_MUXER
+#if CONFIG_DTS_MUXER
 AVOutputFormat dts_muxer = {
     "dts",
     NULL_IF_CONFIG_SMALL("raw DTS"),
@@ -740,7 +740,7 @@ AVOutputFormat dts_muxer = {
 };
 #endif
 
-#ifdef CONFIG_EAC3_DEMUXER
+#if CONFIG_EAC3_DEMUXER
 AVInputFormat eac3_demuxer = {
     "eac3",
     NULL_IF_CONFIG_SMALL("raw E-AC-3"),
@@ -754,7 +754,7 @@ AVInputFormat eac3_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_EAC3_MUXER
+#if CONFIG_EAC3_MUXER
 AVOutputFormat eac3_muxer = {
     "eac3",
     NULL_IF_CONFIG_SMALL("raw E-AC-3"),
@@ -769,7 +769,7 @@ AVOutputFormat eac3_muxer = {
 };
 #endif
 
-#ifdef CONFIG_FLAC_DEMUXER
+#if CONFIG_FLAC_DEMUXER
 AVInputFormat flac_demuxer = {
     "flac",
     NULL_IF_CONFIG_SMALL("raw FLAC"),
@@ -783,7 +783,7 @@ AVInputFormat flac_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_FLAC_MUXER
+#if CONFIG_FLAC_MUXER
 AVOutputFormat flac_muxer = {
     "flac",
     NULL_IF_CONFIG_SMALL("raw FLAC"),
@@ -799,7 +799,7 @@ AVOutputFormat flac_muxer = {
 };
 #endif
 
-#ifdef CONFIG_GSM_DEMUXER
+#if CONFIG_GSM_DEMUXER
 AVInputFormat gsm_demuxer = {
     "gsm",
     NULL_IF_CONFIG_SMALL("GSM"),
@@ -813,7 +813,7 @@ AVInputFormat gsm_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_H261_DEMUXER
+#if CONFIG_H261_DEMUXER
 AVInputFormat h261_demuxer = {
     "h261",
     NULL_IF_CONFIG_SMALL("raw H.261"),
@@ -827,7 +827,7 @@ AVInputFormat h261_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_H261_MUXER
+#if CONFIG_H261_MUXER
 AVOutputFormat h261_muxer = {
     "h261",
     NULL_IF_CONFIG_SMALL("raw H.261"),
@@ -842,7 +842,7 @@ AVOutputFormat h261_muxer = {
 };
 #endif
 
-#ifdef CONFIG_H263_DEMUXER
+#if CONFIG_H263_DEMUXER
 AVInputFormat h263_demuxer = {
     "h263",
     NULL_IF_CONFIG_SMALL("raw H.263"),
@@ -856,7 +856,7 @@ AVInputFormat h263_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_H263_MUXER
+#if CONFIG_H263_MUXER
 AVOutputFormat h263_muxer = {
     "h263",
     NULL_IF_CONFIG_SMALL("raw H.263"),
@@ -871,7 +871,7 @@ AVOutputFormat h263_muxer = {
 };
 #endif
 
-#ifdef CONFIG_H264_DEMUXER
+#if CONFIG_H264_DEMUXER
 AVInputFormat h264_demuxer = {
     "h264",
     NULL_IF_CONFIG_SMALL("raw H.264 video format"),
@@ -885,7 +885,7 @@ AVInputFormat h264_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_H264_MUXER
+#if CONFIG_H264_MUXER
 AVOutputFormat h264_muxer = {
     "h264",
     NULL_IF_CONFIG_SMALL("raw H.264 video format"),
@@ -900,7 +900,7 @@ AVOutputFormat h264_muxer = {
 };
 #endif
 
-#ifdef CONFIG_INGENIENT_DEMUXER
+#if CONFIG_INGENIENT_DEMUXER
 AVInputFormat ingenient_demuxer = {
     "ingenient",
     NULL_IF_CONFIG_SMALL("Ingenient MJPEG"),
@@ -914,7 +914,7 @@ AVInputFormat ingenient_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_M4V_DEMUXER
+#if CONFIG_M4V_DEMUXER
 AVInputFormat m4v_demuxer = {
     "m4v",
     NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
@@ -928,7 +928,7 @@ AVInputFormat m4v_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_M4V_MUXER
+#if CONFIG_M4V_MUXER
 AVOutputFormat m4v_muxer = {
     "m4v",
     NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
@@ -943,7 +943,7 @@ AVOutputFormat m4v_muxer = {
 };
 #endif
 
-#ifdef CONFIG_MJPEG_DEMUXER
+#if CONFIG_MJPEG_DEMUXER
 AVInputFormat mjpeg_demuxer = {
     "mjpeg",
     NULL_IF_CONFIG_SMALL("MJPEG video"),
@@ -957,7 +957,7 @@ AVInputFormat mjpeg_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_MJPEG_MUXER
+#if CONFIG_MJPEG_MUXER
 AVOutputFormat mjpeg_muxer = {
     "mjpeg",
     NULL_IF_CONFIG_SMALL("MJPEG video"),
@@ -972,7 +972,7 @@ AVOutputFormat mjpeg_muxer = {
 };
 #endif
 
-#ifdef CONFIG_MLP_DEMUXER
+#if CONFIG_MLP_DEMUXER
 AVInputFormat mlp_demuxer = {
     "mlp",
     NULL_IF_CONFIG_SMALL("raw MLP"),
@@ -986,7 +986,7 @@ AVInputFormat mlp_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_MPEG1VIDEO_MUXER
+#if CONFIG_MPEG1VIDEO_MUXER
 AVOutputFormat mpeg1video_muxer = {
     "mpeg1video",
     NULL_IF_CONFIG_SMALL("MPEG video"),
@@ -1001,7 +1001,7 @@ AVOutputFormat mpeg1video_muxer = {
 };
 #endif
 
-#ifdef CONFIG_MPEG2VIDEO_MUXER
+#if CONFIG_MPEG2VIDEO_MUXER
 AVOutputFormat mpeg2video_muxer = {
     "mpeg2video",
     NULL_IF_CONFIG_SMALL("MPEG-2 video"),
@@ -1016,7 +1016,7 @@ AVOutputFormat mpeg2video_muxer = {
 };
 #endif
 
-#ifdef CONFIG_MPEGVIDEO_DEMUXER
+#if CONFIG_MPEGVIDEO_DEMUXER
 AVInputFormat mpegvideo_demuxer = {
     "mpegvideo",
     NULL_IF_CONFIG_SMALL("MPEG video"),
@@ -1029,7 +1029,7 @@ AVInputFormat mpegvideo_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_NULL_MUXER
+#if CONFIG_NULL_MUXER
 AVOutputFormat null_muxer = {
     "null",
     NULL_IF_CONFIG_SMALL("null video format"),
@@ -1048,7 +1048,7 @@ AVOutputFormat null_muxer = {
 };
 #endif
 
-#ifdef CONFIG_RAWVIDEO_DEMUXER
+#if CONFIG_RAWVIDEO_DEMUXER
 AVInputFormat rawvideo_demuxer = {
     "rawvideo",
     NULL_IF_CONFIG_SMALL("raw video format"),
@@ -1062,7 +1062,7 @@ AVInputFormat rawvideo_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_RAWVIDEO_MUXER
+#if CONFIG_RAWVIDEO_MUXER
 AVOutputFormat rawvideo_muxer = {
     "rawvideo",
     NULL_IF_CONFIG_SMALL("raw video format"),
@@ -1077,7 +1077,7 @@ AVOutputFormat rawvideo_muxer = {
 };
 #endif
 
-#ifdef CONFIG_ROQ_MUXER
+#if CONFIG_ROQ_MUXER
 AVOutputFormat roq_muxer =
 {
     "RoQ",
@@ -1092,7 +1092,7 @@ AVOutputFormat roq_muxer =
 };
 #endif
 
-#ifdef CONFIG_SHORTEN_DEMUXER
+#if CONFIG_SHORTEN_DEMUXER
 AVInputFormat shorten_demuxer = {
     "shn",
     NULL_IF_CONFIG_SMALL("raw Shorten"),
@@ -1106,7 +1106,7 @@ AVInputFormat shorten_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_VC1_DEMUXER
+#if CONFIG_VC1_DEMUXER
 AVInputFormat vc1_demuxer = {
     "vc1",
     NULL_IF_CONFIG_SMALL("raw VC-1"),
@@ -1151,13 +1151,13 @@ AVOutputFormat pcm_ ## name ## _muxer = {\
 };
 
 
-#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
+#if  !CONFIG_MUXERS && CONFIG_DEMUXERS
 #define PCMDEF(name, long_name, ext, codec) \
         PCMINPUTDEF(name, long_name, ext, codec)
-#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
+#elif CONFIG_MUXERS && !CONFIG_DEMUXERS
 #define PCMDEF(name, long_name, ext, codec) \
         PCMOUTPUTDEF(name, long_name, ext, codec)
-#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
+#elif CONFIG_MUXERS && CONFIG_DEMUXERS
 #define PCMDEF(name, long_name, ext, codec) \
         PCMINPUTDEF(name, long_name, ext, codec)\
         PCMOUTPUTDEF(name, long_name, ext, codec)
diff --git a/libavformat/riff.c b/libavformat/riff.c
index 0f9b177..73ebc91 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -117,6 +117,7 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_MJPEG,        MKTAG('A', 'V', 'R', 'n') },
     { CODEC_ID_MJPEG,        MKTAG('A', 'C', 'D', 'V') },
     { CODEC_ID_MJPEG,        MKTAG('Q', 'I', 'V', 'G') },
+    { CODEC_ID_MJPEG,        MKTAG('S', 'L', 'M', 'J') }, /* SL M-JPEG */
     { CODEC_ID_MJPEG,        MKTAG('C', 'J', 'P', 'G') }, /* Creative Webcam JPEG */
     { CODEC_ID_HUFFYUV,      MKTAG('H', 'F', 'Y', 'U') },
     { CODEC_ID_FFVHUFF,      MKTAG('F', 'F', 'V', 'H') },
@@ -145,6 +146,7 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_VCR1,         MKTAG('V', 'C', 'R', '1') },
     { CODEC_ID_FFV1,         MKTAG('F', 'F', 'V', '1') },
     { CODEC_ID_XAN_WC4,      MKTAG('X', 'x', 'a', 'n') },
+    { CODEC_ID_MIMIC,        MKTAG('L', 'M', '2', '0') },
     { CODEC_ID_MSRLE,        MKTAG('m', 'r', 'l', 'e') },
     { CODEC_ID_MSRLE,        MKTAG( 1 ,  0 ,  0 ,  0 ) },
     { CODEC_ID_MSRLE,        MKTAG( 2 ,  0 ,  0 ,  0 ) },
@@ -247,7 +249,7 @@ const AVCodecTag codec_wav_tags[] = {
     { 0, 0 },
 };
 
-#ifdef CONFIG_MUXERS
+#if CONFIG_MUXERS
 int64_t start_tag(ByteIOContext *pb, const char *tag)
 {
     put_tag(pb, tag);
@@ -378,7 +380,7 @@ void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *ta
 }
 #endif //CONFIG_MUXERS
 
-#ifdef CONFIG_DEMUXERS
+#if CONFIG_DEMUXERS
 /* We could be given one of the three possible structures here:
  * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
  * is an expansion of the previous one with the fields added
@@ -464,7 +466,7 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz
         *au_scale= stream->block_align ? stream->block_align*8 : 8;
         *au_rate = stream->bit_rate ? stream->bit_rate : 8*stream->sample_rate;
     }
-    gcd= ff_gcd(*au_scale, *au_rate);
+    gcd= av_gcd(*au_scale, *au_rate);
     *au_scale /= gcd;
     *au_rate /= gcd;
 }
diff --git a/libavformat/rl2.c b/libavformat/rl2.c
index 5bab85b..fd211bf 100644
--- a/libavformat/rl2.c
+++ b/libavformat/rl2.c
@@ -33,6 +33,7 @@
  * optional background_frame
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define EXTRADATA1_SIZE (6 + 256 * 3) ///< video base, clr, palette
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index fc066df..de81446 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "rm.h"
 
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index b78c759..1933ab0 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -32,7 +32,7 @@
 #include "network.h"
 #include "os_support.h"
 #include <fcntl.h>
-#ifdef HAVE_SYS_SELECT_H
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 464cffe..46a7159 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -23,10 +23,11 @@
 #define _SVID_SOURCE
 
 #include "libavutil/avstring.h"
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #include <sys/time.h>
-#ifdef HAVE_SYS_SELECT_H
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 #include <strings.h>
@@ -441,17 +442,13 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             } else {
                 av_strlcpy(rtsp_st->control_url, p,   sizeof(rtsp_st->control_url));
             }
-        } else if (av_strstart(p, "rtpmap:", &p)) {
+        } else if (av_strstart(p, "rtpmap:", &p) && s->nb_streams > 0) {
             /* NOTE: rtpmap is only supported AFTER the 'm=' tag */
             get_word(buf1, sizeof(buf1), &p);
             payload_type = atoi(buf1);
-            for(i = 0; i < s->nb_streams;i++) {
-                st = s->streams[i];
-                rtsp_st = st->priv_data;
-                if (rtsp_st->sdp_payload_type == payload_type) {
-                    sdp_parse_rtpmap(st->codec, rtsp_st, payload_type, p);
-                }
-            }
+            st = s->streams[s->nb_streams - 1];
+            rtsp_st = st->priv_data;
+            sdp_parse_rtpmap(st->codec, rtsp_st, payload_type, p);
         } else if (av_strstart(p, "fmtp:", &p)) {
             /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */
             get_word(buf1, sizeof(buf1), &p);
@@ -510,10 +507,11 @@ static int sdp_parse(AVFormatContext *s, const char *content)
 {
     const char *p;
     int letter;
-    /* Some SDP lines, particularly for Realmedia or ASF RTSP streams, contain long SDP
-     * lines containing complete ASF Headers (several kB) or arrays of MDPR (RM stream
-     * descriptor) headers plus "rulebooks" describing their properties. Therefore, the
-     * SDP line buffer is large. */
+    /* Some SDP lines, particularly for Realmedia or ASF RTSP streams,
+     * contain long SDP lines containing complete ASF Headers (several
+     * kB) or arrays of MDPR (RM stream descriptor) headers plus
+     * "rulebooks" describing their properties. Therefore, the SDP line
+     * buffer is large. */
     char buf[8192], *q;
     SDPParseState sdp_parse_state, *s1 = &sdp_parse_state;
 
@@ -1504,7 +1502,7 @@ static int rtsp_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_RTSP_DEMUXER
+#if CONFIG_RTSP_DEMUXER
 AVInputFormat rtsp_demuxer = {
     "rtsp",
     NULL_IF_CONFIG_SMALL("RTSP input format"),
@@ -1597,7 +1595,7 @@ static int sdp_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_SDP_DEMUXER
+#if CONFIG_SDP_DEMUXER
 AVInputFormat sdp_demuxer = {
     "sdp",
     NULL_IF_CONFIG_SMALL("SDP"),
@@ -1609,7 +1607,7 @@ AVInputFormat sdp_demuxer = {
 };
 #endif
 
-#ifdef CONFIG_REDIR_DEMUXER
+#if CONFIG_REDIR_DEMUXER
 /* dummy redirector format (used directly in av_open_input_file now) */
 static int redir_probe(AVProbeData *pd)
 {
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index d22f516..09541e3 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -25,7 +25,7 @@
 #include "avc.h"
 #include "rtp.h"
 
-#ifdef CONFIG_RTP_MUXER
+#if CONFIG_RTP_MUXER
 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2)
 
 struct sdp_session_level {
diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 1ec8c28..462d658 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -27,6 +27,7 @@
  *   http://www.pcisys.net/~melanson/codecs/
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define FILM_TAG MKBETAG('F', 'I', 'L', 'M')
diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c
index 1e15a22..83262f8 100644
--- a/libavformat/sierravmd.c
+++ b/libavformat/sierravmd.c
@@ -27,6 +27,7 @@
  *   http://www.pcisys.net/~melanson/codecs/
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define VMD_HEADER_SIZE 0x0330
diff --git a/libavformat/siff.c b/libavformat/siff.c
index 63fe80d..9e6c85d 100644
--- a/libavformat/siff.c
+++ b/libavformat/siff.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 enum SIFFTags{
diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 3aa08bd..eeab64f 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -24,6 +24,7 @@
  */
 
 #include "libavutil/bswap.h"
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define SMACKER_PAL 0x01
diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index d899b2d..dc85c27 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "swf.h"
 
 static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 52e3c72..1431daf 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -503,7 +503,7 @@ static int swf_write_trailer(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_SWF_MUXER
+#if CONFIG_SWF_MUXER
 AVOutputFormat swf_muxer = {
     "swf",
     NULL_IF_CONFIG_SMALL("Flash format"),
@@ -517,7 +517,7 @@ AVOutputFormat swf_muxer = {
     swf_write_trailer,
 };
 #endif
-#ifdef CONFIG_AVM2_MUXER
+#if CONFIG_AVM2_MUXER
 AVOutputFormat avm2_muxer = {
     "avm2",
     NULL_IF_CONFIG_SMALL("Flash 9 (AVM2) format"),
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 0584451..d7eede6 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -22,7 +22,7 @@
 #include <unistd.h>
 #include "network.h"
 #include "os_support.h"
-#ifdef HAVE_SYS_SELECT_H
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 #include <sys/time.h>
diff --git a/libavformat/thp.c b/libavformat/thp.c
index 434bc29..e258720 100644
--- a/libavformat/thp.c
+++ b/libavformat/thp.c
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 typedef struct ThpDemuxContext {
diff --git a/libavformat/tta.c b/libavformat/tta.c
index 884664c..bf0f7e3 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -41,7 +41,7 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
     int i, channels, bps, samplerate, datalen, framelen;
     uint64_t framepos;
 
-    if (get_le32(s->pb) != ff_get_fourcc("TTA1"))
+    if (get_le32(s->pb) != AV_RL32("TTA1"))
         return -1; // not tta file
 
     url_fskip(s->pb, 2); // FIXME: flags
diff --git a/libavformat/txd.c b/libavformat/txd.c
index d2c3996..3403938 100644
--- a/libavformat/txd.c
+++ b/libavformat/txd.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define TXD_FILE            0x16
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 1101ffc..f433e07 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -29,7 +29,7 @@
 #include <unistd.h>
 #include "network.h"
 #include "os_support.h"
-#ifdef HAVE_SYS_SELECT_H
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 #include <sys/time.h>
@@ -52,7 +52,7 @@ typedef struct {
     int is_multicast;
     int local_port;
     int reuse_socket;
-#ifndef CONFIG_IPV6
+#if !CONFIG_IPV6
     struct sockaddr_in dest_addr;
 #else
     struct sockaddr_storage dest_addr;
@@ -72,7 +72,7 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr
         }
     }
 #endif
-#ifdef CONFIG_IPV6
+#if CONFIG_IPV6
     if (addr->sa_family == AF_INET6) {
         if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) {
             av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
@@ -96,7 +96,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) {
         }
     }
 #endif
-#ifdef CONFIG_IPV6
+#if CONFIG_IPV6
     if (addr->sa_family == AF_INET6) {
         struct ipv6_mreq mreq6;
 
@@ -124,7 +124,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) {
         }
     }
 #endif
-#ifdef CONFIG_IPV6
+#if CONFIG_IPV6
     if (addr->sa_family == AF_INET6) {
         struct ipv6_mreq mreq6;
 
@@ -139,7 +139,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) {
     return 0;
 }
 
-#ifdef CONFIG_IPV6
+#if CONFIG_IPV6
 static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) {
     struct addrinfo hints, *res = 0;
     int error;
@@ -342,7 +342,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
     int is_output;
     const char *p;
     char buf[256];
-#ifndef CONFIG_IPV6
+#if !CONFIG_IPV6
     struct sockaddr_in my_addr;
 #else
     struct sockaddr_storage my_addr;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9c3acfb..d3374b8 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -153,6 +153,24 @@ int match_ext(const char *filename, const char *extensions)
     return 0;
 }
 
+static int match_format(const char *name, const char *names)
+{
+    const char *p;
+    int len, namelen;
+
+    if (!name || !names)
+        return 0;
+
+    namelen = strlen(name);
+    while ((p = strchr(names, ','))) {
+        len = FFMAX(p - names, namelen);
+        if (!strncasecmp(name, names, len))
+            return 1;
+        names = p+1;
+    }
+    return !strcasecmp(name, names);
+}
+
 AVOutputFormat *guess_format(const char *short_name, const char *filename,
                              const char *mime_type)
 {
@@ -160,7 +178,7 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename,
     int score_max, score;
 
     /* specific test for image sequences */
-#ifdef CONFIG_IMAGE2_MUXER
+#if CONFIG_IMAGE2_MUXER
     if (!short_name && filename &&
         av_filename_number_test(filename) &&
         av_guess_image2_codec(filename) != CODEC_ID_NONE) {
@@ -214,7 +232,7 @@ enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
     if(type == CODEC_TYPE_VIDEO){
         enum CodecID codec_id= CODEC_ID_NONE;
 
-#ifdef CONFIG_IMAGE2_MUXER
+#if CONFIG_IMAGE2_MUXER
         if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){
             codec_id= av_guess_image2_codec(filename);
         }
@@ -232,7 +250,7 @@ AVInputFormat *av_find_input_format(const char *short_name)
 {
     AVInputFormat *fmt;
     for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) {
-        if (!strcmp(fmt->name, short_name))
+        if (match_format(short_name, fmt->name))
             return fmt;
     }
     return NULL;
@@ -381,63 +399,6 @@ static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
 /**
  * Open a media file from an IO stream. 'fmt' must be specified.
  */
-static const char* format_to_name(void* ptr)
-{
-    AVFormatContext* fc = (AVFormatContext*) ptr;
-    if(fc->iformat) return fc->iformat->name;
-    else if(fc->oformat) return fc->oformat->name;
-    else return "NULL";
-}
-
-#define OFFSET(x) offsetof(AVFormatContext,x)
-#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
-//these names are too long to be readable
-#define E AV_OPT_FLAG_ENCODING_PARAM
-#define D AV_OPT_FLAG_DECODING_PARAM
-
-static const AVOption options[]={
-{"probesize", NULL, OFFSET(probesize), FF_OPT_TYPE_INT, 32000, 32, INT_MAX, D}, /* 32000 from mpegts.c: 1.0 second at 24Mbit/s */
-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
-{"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
-{"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"},
-{"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"},
-{"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_GENPTS, INT_MIN, INT_MAX, D, "fflags"},
-{"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
-{"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
-{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D},
-{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D},
-{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D},
-{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
-{"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, E|D, "fdebug"},
-{"ts", NULL, 0, FF_OPT_TYPE_CONST, FF_FDEBUG_TS, INT_MIN, INT_MAX, E|D, "fdebug"},
-{NULL},
-};
-
-#undef E
-#undef D
-#undef DEFAULT
-
-static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options };
-
-static void avformat_get_context_defaults(AVFormatContext *s)
-{
-    memset(s, 0, sizeof(AVFormatContext));
-
-    s->av_class = &av_format_context_class;
-
-    av_opt_set_defaults(s);
-}
-
-AVFormatContext *av_alloc_format_context(void)
-{
-    AVFormatContext *ic;
-    ic = av_malloc(sizeof(AVFormatContext));
-    if (!ic) return ic;
-    avformat_get_context_defaults(ic);
-    ic->av_class = &av_format_context_class;
-    return ic;
-}
-
 int av_open_input_stream(AVFormatContext **ic_ptr,
                          ByteIOContext *pb, const char *filename,
                          AVInputFormat *fmt, AVFormatParameters *ap)
@@ -752,6 +713,7 @@ static int is_intra_only(AVCodecContext *enc){
         case CODEC_ID_ASV2:
         case CODEC_ID_VCR1:
         case CODEC_ID_DNXHD:
+        case CODEC_ID_JPEG2000:
             return 1;
         default: break;
         }
@@ -2003,8 +1965,8 @@ static int get_std_framerate(int i){
 static int tb_unreliable(AVCodecContext *c){
     if(   c->time_base.den >= 101L*c->time_base.num
        || c->time_base.den <    5L*c->time_base.num
-/*       || c->codec_tag == ff_get_fourcc("DIVX")
-       || c->codec_tag == ff_get_fourcc("XVID")*/
+/*       || c->codec_tag == AV_RL32("DIVX")
+       || c->codec_tag == AV_RL32("XVID")*/
        || c->codec_id == CODEC_ID_MPEG2VIDEO)
         return 1;
     return 0;
@@ -2784,7 +2746,7 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out
     char buf[256];
     int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
     AVStream *st = ic->streams[i];
-    int g = ff_gcd(st->time_base.num, st->time_base.den);
+    int g = av_gcd(st->time_base.num, st->time_base.den);
     avcodec_string(buf, sizeof(buf), st->codec, is_output);
     av_log(NULL, AV_LOG_INFO, "    Stream #%d.%d", index, i);
     /* the pid is an important information, so we display it */
@@ -3249,7 +3211,7 @@ char *ff_data_to_hex(char *buff, const uint8_t *src, int s)
 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
                      int pts_num, int pts_den)
 {
-    unsigned int gcd= ff_gcd(pts_num, pts_den);
+    unsigned int gcd= av_gcd(pts_num, pts_den);
     s->pts_wrap_bits = pts_wrap_bits;
     s->time_base.num = pts_num/gcd;
     s->time_base.den = pts_den/gcd;
diff --git a/libavformat/vc1test.c b/libavformat/vc1test.c
index 7601ea9..9c06f43 100644
--- a/libavformat/vc1test.c
+++ b/libavformat/vc1test.c
@@ -26,6 +26,7 @@
  * Format specified in SMPTE standard 421 Annex L
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define VC1_EXTRADATA_SIZE 4
diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c
index 8ad6909..430f131 100644
--- a/libavformat/vocdec.c
+++ b/libavformat/vocdec.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "voc.h"
 
 
diff --git a/libavformat/wav.c b/libavformat/wav.c
index 01923d5..7aec532 100644
--- a/libavformat/wav.c
+++ b/libavformat/wav.c
@@ -30,7 +30,7 @@ typedef struct {
     int last_duration;
 } WAVContext;
 
-#ifdef CONFIG_WAV_MUXER
+#if CONFIG_WAV_MUXER
 static int wav_write_header(AVFormatContext *s)
 {
     WAVContext *wav = s->priv_data;
@@ -256,7 +256,7 @@ static int wav_read_seek(AVFormatContext *s,
     return pcm_read_seek(s, stream_index, timestamp, flags);
 }
 
-#ifdef CONFIG_WAV_DEMUXER
+#if CONFIG_WAV_DEMUXER
 AVInputFormat wav_demuxer = {
     "wav",
     NULL_IF_CONFIG_SMALL("WAV format"),
@@ -270,7 +270,7 @@ AVInputFormat wav_demuxer = {
     .codec_tag= (const AVCodecTag* const []){codec_wav_tags, 0},
 };
 #endif
-#ifdef CONFIG_WAV_MUXER
+#if CONFIG_WAV_MUXER
 AVOutputFormat wav_muxer = {
     "wav",
     NULL_IF_CONFIG_SMALL("WAV format"),
diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index df207ef..01fb617 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -27,6 +27,7 @@
  *   http://www.pcisys.net/~melanson/codecs/
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define WC3_PREAMBLE_SIZE 8
diff --git a/libavformat/westwood.c b/libavformat/westwood.c
index d88199d..753daca 100644
--- a/libavformat/westwood.c
+++ b/libavformat/westwood.c
@@ -33,6 +33,7 @@
  * qualify a file. Refer to wsaud_probe() for the precise parameters.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define AUD_HEADER_SIZE 12
@@ -370,7 +371,7 @@ static int wsvqa_read_packet(AVFormatContext *s,
     return ret;
 }
 
-#ifdef CONFIG_WSAUD_DEMUXER
+#if CONFIG_WSAUD_DEMUXER
 AVInputFormat wsaud_demuxer = {
     "wsaud",
     NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
@@ -380,7 +381,7 @@ AVInputFormat wsaud_demuxer = {
     wsaud_read_packet,
 };
 #endif
-#ifdef CONFIG_WSVQA_DEMUXER
+#if CONFIG_WSVQA_DEMUXER
 AVInputFormat wsvqa_demuxer = {
     "wsvqa",
     NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
diff --git a/libavformat/wv.c b/libavformat/wv.c
index c9f71f9..2fc6115 100644
--- a/libavformat/wv.c
+++ b/libavformat/wv.c
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavutil/bswap.h"
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 // specs say that maximum block size is 1Mb
@@ -100,10 +100,6 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb)
         av_log(ctx, AV_LOG_ERROR, "Floating point data is not supported\n");
         return -1;
     }
-    if(wc->flags & WV_HYBRID){
-        av_log(ctx, AV_LOG_ERROR, "Hybrid coding mode is not supported\n");
-        return -1;
-    }
 
     bpp = ((wc->flags & 3) + 1) << 3;
     chan = 1 + !(wc->flags & WV_MONO);
diff --git a/libavformat/xa.c b/libavformat/xa.c
index 3ea2aae..9c0df89 100644
--- a/libavformat/xa.c
+++ b/libavformat/xa.c
@@ -27,6 +27,7 @@
  *   http://wiki.multimedia.cx/index.php?title=Maxis_XA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define XA00_TAG MKTAG('X', 'A', 0, 0)
diff --git a/libavformat/yuv4mpeg.c b/libavformat/yuv4mpeg.c
index bc6c781..6a5e8ee 100644
--- a/libavformat/yuv4mpeg.c
+++ b/libavformat/yuv4mpeg.c
@@ -29,7 +29,7 @@ struct frame_attributes {
     int top_field_first;
 };
 
-#ifdef CONFIG_YUV4MPEGPIPE_MUXER
+#if CONFIG_YUV4MPEGPIPE_MUXER
 static int yuv4_generate_header(AVFormatContext *s, char* buf)
 {
     AVStream *st;
@@ -382,7 +382,7 @@ static int yuv4_probe(AVProbeData *pd)
         return 0;
 }
 
-#ifdef CONFIG_YUV4MPEGPIPE_DEMUXER
+#if CONFIG_YUV4MPEGPIPE_DEMUXER
 AVInputFormat yuv4mpegpipe_demuxer = {
     "yuv4mpegpipe",
     NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
diff --git a/libavutil/Makefile b/libavutil/Makefile
index be2f3e1..284f874 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -43,6 +43,8 @@ OBJS = adler32.o                                                        \
 
 TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 pca random sha1 softfloat tree)
 
+DIRS = arm bfin sh4 x86
+
 include $(SUBDIR)../subdir.mak
 
 $(SUBDIR)lzo-test$(EXESUF): EXTRALIBS += -llzo2
diff --git a/libavutil/adler32.c b/libavutil/adler32.c
index 148664e..dad8dab 100644
--- a/libavutil/adler32.c
+++ b/libavutil/adler32.c
@@ -35,7 +35,7 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigne
     unsigned long s2 = adler >> 16;
 
     while (len>0) {
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
         while(len>4 && s2 < (1U<<31)){
             DO4(buf); len-=4;
 #else
diff --git a/libavutil/aes.c b/libavutil/aes.c
index 5030dac..1631cb6 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -39,7 +39,7 @@ static const uint8_t rcon[10] = {
 
 static uint8_t     sbox[256];
 static uint8_t inv_sbox[256];
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
 static uint32_t enc_multbl[1][256];
 static uint32_t dec_multbl[1][256];
 #else
@@ -62,7 +62,7 @@ static void subshift(uint8_t s0[2][16], int s, uint8_t *box){
 }
 
 static inline int mix_core(uint32_t multbl[4][256], int a, int b, int c, int d){
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
 #define ROT(x,s) ((x<<s)|(x>>(32-s)))
     return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
 #else
@@ -114,7 +114,7 @@ static void init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *al
         int x= sbox[i>>2];
         if(x) tbl[i]= alog8[ log8[x] + log8[c[i&3]] ];
     }
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     for(j=256; j<1024; j++)
         for(i=0; i<4; i++)
             tbl[4*j+i]= tbl[4*j + ((i-1)&3) - 1024];
diff --git a/libavutil/arm/bswap.h b/libavutil/arm/bswap.h
index deb7394..65c73c5 100644
--- a/libavutil/arm/bswap.h
+++ b/libavutil/arm/bswap.h
@@ -23,7 +23,7 @@
 #include "config.h"
 #include "libavutil/common.h"
 
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
 #define bswap_16 bswap_16
 static av_always_inline av_const uint16_t bswap_16(uint16_t x)
 {
@@ -35,7 +35,7 @@ static av_always_inline av_const uint16_t bswap_16(uint16_t x)
 #define bswap_32 bswap_32
 static av_always_inline av_const uint32_t bswap_32(uint32_t x)
 {
-#ifdef HAVE_ARMV6
+#if HAVE_ARMV6
     __asm__("rev %0, %0" : "+r"(x));
 #else
     uint32_t t;
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 7366718..fdbce40 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -35,7 +35,7 @@
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
 
 #define LIBAVUTIL_VERSION_MAJOR 49
-#define LIBAVUTIL_VERSION_MINOR 12
+#define LIBAVUTIL_VERSION_MINOR 14
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -122,6 +122,8 @@ enum PixelFormat {
     PIX_FMT_YUVJ440P,  ///< Planar YUV 4:4:0 full scale (jpeg)
     PIX_FMT_YUVA420P,  ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
     PIX_FMT_VDPAU_H264,///< H264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    PIX_FMT_VDPAU_MPEG1,///< MPEG1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    PIX_FMT_VDPAU_MPEG2,///< MPEG2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
     PIX_FMT_NB,        ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
 };
 
diff --git a/libavutil/bswap.h b/libavutil/bswap.h
index 100ed1c..41e98d4 100644
--- a/libavutil/bswap.h
+++ b/libavutil/bswap.h
@@ -30,13 +30,13 @@
 #include "config.h"
 #include "common.h"
 
-#if defined(ARCH_ARM)
+#if   ARCH_ARM
 #   include "arm/bswap.h"
-#elif defined(ARCH_BFIN)
+#elif ARCH_BFIN
 #   include "bfin/bswap.h"
-#elif defined(ARCH_SH4)
+#elif ARCH_SH4
 #   include "sh4/bswap.h"
-#elif defined(ARCH_X86)
+#elif ARCH_X86
 #   include "x86/bswap.h"
 #endif
 
diff --git a/libavutil/common.h b/libavutil/common.h
index d66120f..f701d23 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -151,47 +151,6 @@ static inline av_const int av_log2_16bit(unsigned int v)
     return n;
 }
 
-/* median of 3 */
-static inline av_const int mid_pred(int a, int b, int c)
-{
-#ifdef HAVE_CMOV
-    int i=b;
-    __asm__ volatile(
-        "cmp    %2, %1 \n\t"
-        "cmovg  %1, %0 \n\t"
-        "cmovg  %2, %1 \n\t"
-        "cmp    %3, %1 \n\t"
-        "cmovl  %3, %1 \n\t"
-        "cmp    %1, %0 \n\t"
-        "cmovg  %1, %0 \n\t"
-        :"+&r"(i), "+&r"(a)
-        :"r"(b), "r"(c)
-    );
-    return i;
-#elif 0
-    int t= (a-b)&((a-b)>>31);
-    a-=t;
-    b+=t;
-    b-= (b-c)&((b-c)>>31);
-    b+= (a-b)&((a-b)>>31);
-
-    return b;
-#else
-    if(a>b){
-        if(c>b){
-            if(c>a) b=a;
-            else    b=c;
-        }
-    }else{
-        if(b>c){
-            if(c>a) b=c;
-            else    b=a;
-        }
-    }
-    return b;
-#endif
-}
-
 /**
  * clip a signed integer value into the amin-amax range
  * @param a value to clip
@@ -242,20 +201,6 @@ static inline av_const float av_clipf(float a, float amin, float amax)
     else               return a;
 }
 
-/* math */
-int64_t av_const ff_gcd(int64_t a, int64_t b);
-
-/**
- * converts fourcc string to int
- */
-static inline av_pure int ff_get_fourcc(const char *s){
-#ifdef HAVE_AV_CONFIG_H
-    assert( strlen(s)==4 );
-#endif
-
-    return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
-}
-
 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
 
@@ -323,88 +268,4 @@ static inline av_pure int ff_get_fourcc(const char *s){
         }\
     }
 
-#if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_BFIN)
-#define AV_READ_TIME read_time
-#if defined(ARCH_X86)
-static inline uint64_t read_time(void)
-{
-    uint32_t a, d;
-    __asm__ volatile("rdtsc\n\t"
-                 : "=a" (a), "=d" (d));
-    return ((uint64_t)d << 32) + a;
-}
-#elif ARCH_BFIN
-static inline uint64_t read_time(void)
-{
-    union {
-        struct {
-            unsigned lo;
-            unsigned hi;
-        } p;
-        unsigned long long c;
-    } t;
-    __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
-    return t.c;
-}
-#else //FIXME check ppc64
-static inline uint64_t read_time(void)
-{
-    uint32_t tbu, tbl, temp;
-
-     /* from section 2.2.1 of the 32-bit PowerPC PEM */
-     __asm__ volatile(
-         "1:\n"
-         "mftbu  %2\n"
-         "mftb   %0\n"
-         "mftbu  %1\n"
-         "cmpw   %2,%1\n"
-         "bne    1b\n"
-     : "=r"(tbl), "=r"(tbu), "=r"(temp)
-     :
-     : "cc");
-
-     return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
-}
-#endif
-#elif defined(HAVE_GETHRTIME)
-#define AV_READ_TIME gethrtime
-#endif
-
-#ifdef AV_READ_TIME
-#define START_TIMER \
-uint64_t tend;\
-uint64_t tstart= AV_READ_TIME();\
-
-#define STOP_TIMER(id) \
-tend= AV_READ_TIME();\
-{\
-    static uint64_t tsum=0;\
-    static int tcount=0;\
-    static int tskip_count=0;\
-    if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
-        tsum+= tend - tstart;\
-        tcount++;\
-    }else\
-        tskip_count++;\
-    if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
-        av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
-               tsum*10/tcount, id, tcount, tskip_count);\
-    }\
-}
-#else
-#define START_TIMER
-#define STOP_TIMER(id) {}
-#endif
-
-/**
- * Returns NULL if CONFIG_SMALL is defined otherwise the argument
- * without modifications, used to disable the definition of strings
- * (for example AVCodec long_names).
- */
-#ifdef CONFIG_SMALL
-#   define NULL_IF_CONFIG_SMALL(x) NULL
-#else
-#   define NULL_IF_CONFIG_SMALL(x) x
-#endif
-
 #endif /* AVUTIL_COMMON_H */
diff --git a/libavutil/crc.c b/libavutil/crc.c
index bc21f5b..8b8a90e 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -18,10 +18,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "common.h"
+#include "config.h"
+#include "bswap.h"
 #include "crc.h"
 
-#ifdef CONFIG_HARDCODED_TABLES
+#if CONFIG_HARDCODED_TABLES
 #include "crc_data.h"
 #else
 static struct {
@@ -74,7 +75,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
         }
     }
     ctx[256]=1;
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     if(ctx_size >= sizeof(AVCRC)*1024)
         for (i = 0; i < 256; i++)
             for(j=0; j<3; j++)
@@ -90,7 +91,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
  * @return a pointer to the CRC table or NULL on failure
  */
 const AVCRC *av_crc_get_table(AVCRCId crc_id){
-#ifndef CONFIG_HARDCODED_TABLES
+#if !CONFIG_HARDCODED_TABLES
     if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id])-1])
         if (av_crc_init(av_crc_table[crc_id],
                         av_crc_table_params[crc_id].le,
@@ -112,7 +113,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id){
 uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){
     const uint8_t *end= buffer+length;
 
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     if(!ctx[256])
         while(buffer<end-3){
             crc ^= le2me_32(*(const uint32_t*)buffer); buffer+=4;
diff --git a/libavutil/des.c b/libavutil/des.c
index 43a14f6..51d73a3 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -74,7 +74,7 @@ static const uint8_t PC2_shuffle[] = {
 };
 #undef T
 
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
 static const uint8_t S_boxes[8][32] = {
     {
     0x0e, 0xf4, 0x7d, 0x41, 0xe2, 0x2f, 0xdb, 0x18, 0xa3, 0x6a, 0xc6, 0xbc, 0x95, 0x59, 0x30, 0x87,
@@ -218,7 +218,7 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
     // apply S-boxes, those compress the data again from 8 * 6 to 8 * 4 bits
     for (i = 7; i >= 0; i--) {
         uint8_t tmp = (r ^ k) & 0x3f;
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
         uint8_t v = S_boxes[i][tmp >> 1];
         if (tmp & 1) v >>= 4;
         out = (out >> 4) | (v << 28);
@@ -229,7 +229,7 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
         r = (r >> 4) | (r << 28);
         k >>= 6;
     }
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     out = shuffle(out, P_shuffle, sizeof(P_shuffle));
 #endif
     return out;
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 37338ca..93756e9 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -25,6 +25,7 @@
 #define AVUTIL_FIFO_H
 
 #include <stdint.h>
+#include "avutil.h"
 #include "common.h"
 
 typedef struct AVFifoBuffer {
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 251cc33..ef1233d 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -34,6 +34,7 @@
 #include <stddef.h>
 #include <assert.h>
 #include "common.h"
+#include "timer.h"
 
 #ifndef attribute_align_arg
 #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,2)
@@ -96,15 +97,13 @@
 #endif
 
 #include "config.h"
-#include "intreadwrite.h"
-#include "bswap.h"
 
 #ifndef offsetof
 #    define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
 #endif
 
 // Use rip-relative addressing if compiling PIC code on x86-64.
-#if defined(ARCH_X86_64) && defined(PIC)
+#if ARCH_X86_64 && defined(PIC)
 #    define LOCAL_MANGLE(a) #a "(%%rip)"
 #else
 #    define LOCAL_MANGLE(a) #a
@@ -127,7 +126,7 @@
 
 extern const uint32_t ff_inverse[256];
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 #    define FASTDIV(a,b) \
     ({\
         int ret,dmy;\
@@ -138,7 +137,7 @@ extern const uint32_t ff_inverse[256];
             );\
         ret;\
     })
-#elif defined(HAVE_ARMV6)
+#elif HAVE_ARMV6
 static inline av_const int FASTDIV(int a, int b)
 {
     int r, t;
@@ -149,7 +148,7 @@ static inline av_const int FASTDIV(int a, int b)
                      : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse));
     return r;
 }
-#elif defined(ARCH_ARM)
+#elif ARCH_ARM
 static inline av_const int FASTDIV(int a, int b)
 {
     int r, t;
@@ -157,7 +156,7 @@ static inline av_const int FASTDIV(int a, int b)
                       : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
     return r;
 }
-#elif defined(CONFIG_FASTDIV)
+#elif CONFIG_FASTDIV
 #    define FASTDIV(a,b)   ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
 #else
 #    define FASTDIV(a,b)   ((a)/(b))
@@ -173,7 +172,7 @@ static inline av_const unsigned int ff_sqrt(unsigned int a)
 
     if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
     else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
     else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
     else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ]   ;
 #endif
@@ -187,7 +186,7 @@ static inline av_const unsigned int ff_sqrt(unsigned int a)
     return b - (a<b*b);
 }
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 #define MASK_ABS(mask, level)\
             __asm__ volatile(\
                 "cltd                   \n\t"\
@@ -201,7 +200,7 @@ static inline av_const unsigned int ff_sqrt(unsigned int a)
             level= (level^mask)-mask;
 #endif
 
-#ifdef HAVE_CMOV
+#if HAVE_CMOV
 #define COPY3_IF_LT(x,y,a,b,c,d)\
 __asm__ volatile (\
     "cmpl %0, %3        \n\t"\
@@ -261,39 +260,57 @@ if((y)<(x)){\
     }\
 }
 
-#ifndef HAVE_LLRINT
+#if !HAVE_LLRINT
 static av_always_inline av_const long long llrint(double x)
 {
     return rint(x);
 }
 #endif /* HAVE_LLRINT */
 
-#ifndef HAVE_LRINT
+#if !HAVE_LRINT
 static av_always_inline av_const long int lrint(double x)
 {
     return rint(x);
 }
 #endif /* HAVE_LRINT */
 
-#ifndef HAVE_LRINTF
+#if !HAVE_LRINTF
 static av_always_inline av_const long int lrintf(float x)
 {
     return (int)(rint(x));
 }
 #endif /* HAVE_LRINTF */
 
-#ifndef HAVE_ROUND
+#if !HAVE_ROUND
 static av_always_inline av_const double round(double x)
 {
     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
 }
 #endif /* HAVE_ROUND */
 
-#ifndef HAVE_ROUNDF
+#if !HAVE_ROUNDF
 static av_always_inline av_const float roundf(float x)
 {
     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
 }
 #endif /* HAVE_ROUNDF */
 
+#if !HAVE_TRUNCF
+static av_always_inline av_const float truncf(float x)
+{
+    return (x > 0) ? floor(x) : ceil(x);
+}
+#endif /* HAVE_TRUNCF */
+
+/**
+ * Returns NULL if CONFIG_SMALL is true otherwise the argument
+ * without modifications, used to disable the definition of strings
+ * (for example AVCodec long_names).
+ */
+#if CONFIG_SMALL
+#   define NULL_IF_CONFIG_SMALL(x) NULL
+#else
+#   define NULL_IF_CONFIG_SMALL(x) x
+#endif
+
 #endif /* AVUTIL_INTERNAL_H */
diff --git a/libavutil/intreadwrite.h b/libavutil/intreadwrite.h
index 535fdd2..7c5909e 100644
--- a/libavutil/intreadwrite.h
+++ b/libavutil/intreadwrite.h
@@ -66,7 +66,7 @@ struct unaligned_16 { uint16_t l; } __attribute__((packed));
 #define AV_RL8(x)     AV_RB8(x)
 #define AV_WL8(p, d)  AV_WB8(p, d)
 
-#ifdef HAVE_FAST_UNALIGNED
+#if HAVE_FAST_UNALIGNED
 # ifdef WORDS_BIGENDIAN
 #  define AV_RB16(x)    AV_RN16(x)
 #  define AV_WB16(p, d) AV_WN16(p, d)
diff --git a/libavutil/log.h b/libavutil/log.h
index 152e773..8c93f9c 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -22,6 +22,7 @@
 #define AVUTIL_LOG_H
 
 #include <stdarg.h>
+#include "avutil.h"
 
 /**
  * Describes the class of an AVClass context structure, that is an
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index ef93ba4..eed2241 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -48,8 +48,8 @@ const uint8_t ff_log2_tab[256]={
         7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
 };
 
-int64_t ff_gcd(int64_t a, int64_t b){
-    if(b) return ff_gcd(b, a%b);
+int64_t av_gcd(int64_t a, int64_t b){
+    if(b) return av_gcd(b, a%b);
     else  return a;
 }
 
diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h
index 7438527..3098862 100644
--- a/libavutil/mathematics.h
+++ b/libavutil/mathematics.h
@@ -49,6 +49,8 @@ enum AVRounding {
     AV_ROUND_NEAR_INF = 5, ///< round to nearest and halfway cases away from zero
 };
 
+int64_t av_const av_gcd(int64_t a, int64_t b);
+
 /**
  * rescale a 64bit integer with rounding to nearest.
  * a simple a*b/c isn't possible as it can overflow
diff --git a/libavutil/md5.c b/libavutil/md5.c
index d7c4f30..289fa56 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -30,8 +30,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "common.h"
 #include <string.h>
+#include "bswap.h"
 #include "md5.h"
 
 typedef struct AVMD5{
@@ -98,7 +98,7 @@ static void body(uint32_t ABCD[4], uint32_t X[16]){
         X[i]= bswap_32(X[i]);
 #endif
 
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     for( i = 0; i < 64; i++ ){
         CORE(i,a,b,c,d)
         t=d; d=c; c=b; b=a; a=t;
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 328bef7..95299a1 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -32,7 +32,7 @@
 #undef realloc
 
 #include <stdlib.h>
-#ifdef HAVE_MALLOC_H
+#if HAVE_MALLOC_H
 #include <malloc.h>
 #endif
 
@@ -43,7 +43,7 @@
 void *av_malloc(unsigned int size)
 {
     void *ptr = NULL;
-#ifdef CONFIG_MEMALIGN_HACK
+#if CONFIG_MEMALIGN_HACK
     long diff;
 #endif
 
@@ -51,16 +51,16 @@ void *av_malloc(unsigned int size)
     if(size > (INT_MAX-16) )
         return NULL;
 
-#ifdef CONFIG_MEMALIGN_HACK
+#if CONFIG_MEMALIGN_HACK
     ptr = malloc(size+16);
     if(!ptr)
         return ptr;
     diff= ((-(long)ptr - 1)&15) + 1;
     ptr = (char*)ptr + diff;
     ((char*)ptr)[-1]= diff;
-#elif defined (HAVE_POSIX_MEMALIGN)
+#elif HAVE_POSIX_MEMALIGN
     posix_memalign(&ptr,16,size);
-#elif defined (HAVE_MEMALIGN)
+#elif HAVE_MEMALIGN
     ptr = memalign(16,size);
     /* Why 64?
        Indeed, we should align it:
@@ -96,7 +96,7 @@ void *av_malloc(unsigned int size)
 
 void *av_realloc(void *ptr, unsigned int size)
 {
-#ifdef CONFIG_MEMALIGN_HACK
+#if CONFIG_MEMALIGN_HACK
     int diff;
 #endif
 
@@ -104,7 +104,7 @@ void *av_realloc(void *ptr, unsigned int size)
     if(size > (INT_MAX-16) )
         return NULL;
 
-#ifdef CONFIG_MEMALIGN_HACK
+#if CONFIG_MEMALIGN_HACK
     //FIXME this isn't aligned correctly, though it probably isn't needed
     if(!ptr) return av_malloc(size);
     diff= ((char*)ptr)[-1];
@@ -118,7 +118,7 @@ void av_free(void *ptr)
 {
     /* XXX: this test should not be needed on most libcs */
     if (ptr)
-#ifdef CONFIG_MEMALIGN_HACK
+#if CONFIG_MEMALIGN_HACK
         free((char*)ptr - ((char*)ptr)[-1]);
 #else
         free(ptr);
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 3ea9858..ec6e3b7 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -37,7 +37,7 @@
 #elif defined(_MSC_VER)
     #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
     #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
-#elif defined(HAVE_INLINE_ASM)
+#elif HAVE_INLINE_ASM
     #error The asm code needs alignment, but we do not know how to do it for this compiler.
 #else
     #define DECLARE_ALIGNED(n,t,v)      t v
diff --git a/libavutil/random.c b/libavutil/random.c
index 7991988..bafdf7a 100644
--- a/libavutil/random.c
+++ b/libavutil/random.c
@@ -36,7 +36,7 @@ see http://en.wikipedia.org/wiki/Mersenne_twister for an explanation of this alg
 #define LOWER_MASK 0x7fffffff /* least significant r bits */
 
 /** initializes mt[AV_RANDOM_N] with a seed */
-void av_init_random(unsigned int seed, AVRandomState *state)
+void av_random_init(AVRandomState *state, unsigned int seed)
 {
     int index;
 
@@ -55,6 +55,11 @@ void av_init_random(unsigned int seed, AVRandomState *state)
     state->index= index; // will cause it to generate untempered numbers the first iteration
 }
 
+void av_init_random(unsigned int seed, AVRandomState *state)
+{
+    av_random_init(state, seed);
+}
+
 /** generate AV_RANDOM_N words at one time (which will then be tempered later) (av_random calls this; you shouldn't) */
 void av_random_generate_untempered_numbers(AVRandomState *state)
 {
diff --git a/libavutil/random.h b/libavutil/random.h
index f243676..0bedcd5 100644
--- a/libavutil/random.h
+++ b/libavutil/random.h
@@ -26,13 +26,16 @@
 
 #define AV_RANDOM_N 624
 
+#include "common.h"
+
 typedef struct {
     unsigned int mt[AV_RANDOM_N]; ///< the array for the state vector
     int index; ///< Current untempered value we use as the base.
 } AVRandomState;
 
 
-void av_init_random(unsigned int seed, AVRandomState *state); ///< To be inlined, the struct must be visible. So it does not make sense to try and keep it opaque with malloc/free-like calls.
+attribute_deprecated void av_init_random(unsigned int seed, AVRandomState *state);
+void av_random_init(AVRandomState *state, unsigned int seed); ///< To be inlined, the struct must be visible. So it does not make sense to try and keep it opaque with malloc/free-like calls.
 void av_random_generate_untempered_numbers(AVRandomState *state); ///< Regenerate the untempered numbers (must be done every 624 iterations, or it will loop).
 
 /**
diff --git a/libavutil/rational.c b/libavutil/rational.c
index cac3ff5..4c0216e 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -35,7 +35,7 @@
 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
     AVRational a0={0,1}, a1={1,0};
     int sign= (nom<0) ^ (den<0);
-    int64_t gcd= ff_gcd(FFABS(nom), FFABS(den));
+    int64_t gcd= av_gcd(FFABS(nom), FFABS(den));
 
     if(gcd){
         nom = FFABS(nom)/gcd;
@@ -66,7 +66,7 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max)
         nom= den;
         den= next_den;
     }
-    assert(ff_gcd(a1.num, a1.den) <= 1U);
+    assert(av_gcd(a1.num, a1.den) <= 1U);
 
     *dst_nom = sign ? -a1.num : a1.num;
     *dst_den = a1.den;
diff --git a/libavutil/sha1.c b/libavutil/sha1.c
index 61ad38d..72c2726 100644
--- a/libavutil/sha1.c
+++ b/libavutil/sha1.c
@@ -54,7 +54,7 @@ static void transform(uint32_t state[5], const uint8_t buffer[64]){
     c = state[2];
     d = state[3];
     e = state[4];
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     for(i=0; i<80; i++){
         int t;
         if(i<16) t= be2me_32(((uint32_t*)buffer)[i]);
@@ -110,7 +110,7 @@ void av_sha1_update(AVSHA1* ctx, const uint8_t* data, unsigned int len){
 
     j = ctx->count & 63;
     ctx->count += len;
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
     for( i = 0; i < len; i++ ){
         ctx->buffer[ j++ ] = data[i];
         if( 64 == j ){
diff --git a/libavutil/timer.h b/libavutil/timer.h
new file mode 100644
index 0000000..6d11fe2
--- /dev/null
+++ b/libavutil/timer.h
@@ -0,0 +1,104 @@
+/**
+ * @file timer.h
+ * high precision timer, useful to profile code
+ *
+ * copyright (c) 2006 Michael Niedermayer <michaelni at gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_TIMER_H
+#define AVUTIL_TIMER_H
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "config.h"
+
+#if ARCH_X86 || ARCH_PPC || ARCH_BFIN
+#define AV_READ_TIME read_time
+#if ARCH_X86
+static inline uint64_t read_time(void)
+{
+    uint32_t a, d;
+    __asm__ volatile("rdtsc\n\t"
+                 : "=a" (a), "=d" (d));
+    return ((uint64_t)d << 32) + a;
+}
+#elif ARCH_BFIN
+static inline uint64_t read_time(void)
+{
+    union {
+        struct {
+            unsigned lo;
+            unsigned hi;
+        } p;
+        unsigned long long c;
+    } t;
+    __asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
+    return t.c;
+}
+#else //FIXME check ppc64
+static inline uint64_t read_time(void)
+{
+    uint32_t tbu, tbl, temp;
+
+     /* from section 2.2.1 of the 32-bit PowerPC PEM */
+     __asm__ volatile(
+         "1:\n"
+         "mftbu  %2\n"
+         "mftb   %0\n"
+         "mftbu  %1\n"
+         "cmpw   %2,%1\n"
+         "bne    1b\n"
+     : "=r"(tbl), "=r"(tbu), "=r"(temp)
+     :
+     : "cc");
+
+     return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
+}
+#endif
+#elif HAVE_GETHRTIME
+#define AV_READ_TIME gethrtime
+#endif
+
+#ifdef AV_READ_TIME
+#define START_TIMER \
+uint64_t tend;\
+uint64_t tstart= AV_READ_TIME();\
+
+#define STOP_TIMER(id) \
+tend= AV_READ_TIME();\
+{\
+    static uint64_t tsum=0;\
+    static int tcount=0;\
+    static int tskip_count=0;\
+    if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
+        tsum+= tend - tstart;\
+        tcount++;\
+    }else\
+        tskip_count++;\
+    if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
+        av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
+               tsum*10/tcount, id, tcount, tskip_count);\
+    }\
+}
+#else
+#define START_TIMER
+#define STOP_TIMER(id) {}
+#endif
+
+#endif /* AVUTIL_TIMER_H */
diff --git a/libavutil/x86/bswap.h b/libavutil/x86/bswap.h
index c52b529..0ff8a93 100644
--- a/libavutil/x86/bswap.h
+++ b/libavutil/x86/bswap.h
@@ -38,7 +38,7 @@ static av_always_inline av_const uint16_t bswap_16(uint16_t x)
 #define bswap_32 bswap_32
 static av_always_inline av_const uint32_t bswap_32(uint32_t x)
 {
-#ifdef HAVE_BSWAP
+#if HAVE_BSWAP
     __asm__("bswap   %0" : "+r" (x));
 #else
     __asm__("rorw    $8,  %w0 \n\t"
@@ -49,7 +49,7 @@ static av_always_inline av_const uint32_t bswap_32(uint32_t x)
     return x;
 }
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #define bswap_64 bswap_64
 static inline uint64_t av_const bswap_64(uint64_t x)
 {
diff --git a/libavutil/x86_cpu.h b/libavutil/x86_cpu.h
index 4b5f105..d29b7d8 100644
--- a/libavutil/x86_cpu.h
+++ b/libavutil/x86_cpu.h
@@ -24,7 +24,7 @@
 #include <stdint.h>
 #include "config.h"
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #    define REG_a "rax"
 #    define REG_b "rbx"
 #    define REG_c "rcx"
@@ -64,15 +64,10 @@ typedef int32_t x86_reg;
 #    define REGSP   esp
 #endif
 
-#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(HAVE_EBX_AVAILABLE) && defined(HAVE_EBP_AVAILABLE))
-#    define HAVE_7REGS 1
-#endif
-
-#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && (defined(HAVE_EBX_AVAILABLE) || defined(HAVE_EBP_AVAILABLE)))
-#    define HAVE_6REGS 1
-#endif
+#define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))
+#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE))
 
-#if defined(ARCH_X86_64) && defined(PIC)
+#if ARCH_X86_64 && defined(PIC)
 #    define BROKEN_RELOCATIONS 1
 #endif
 
diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index b2f5bad..a41f28b 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -92,7 +92,7 @@ unsigned postproc_version(void)
     return LIBPOSTPROC_VERSION_INT;
 }
 
-#ifdef HAVE_ALTIVEC_H
+#if HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
 
@@ -102,7 +102,7 @@ unsigned postproc_version(void)
 #define TEMP_STRIDE 8
 //#define NUM_BLOCKS_AT_ONCE 16 //not used yet
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 DECLARE_ASM_CONST(8, uint64_t, w05)= 0x0005000500050005LL;
 DECLARE_ASM_CONST(8, uint64_t, w04)= 0x0004000400040004LL;
 DECLARE_ASM_CONST(8, uint64_t, w20)= 0x0020002000200020LL;
@@ -150,7 +150,7 @@ static const char *replaceTable[]=
 };
 
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 static inline void prefetchnta(void *p)
 {
     __asm__ volatile(   "prefetchnta (%0)\n\t"
@@ -554,45 +554,47 @@ static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride,
 
 //Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
 //Plain C versions
-#if !(defined (HAVE_MMX) || defined (HAVE_ALTIVEC)) || defined (RUNTIME_CPUDETECT)
+#if !(HAVE_MMX || HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT)
 #define COMPILE_C
 #endif
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
 #define COMPILE_ALTIVEC
 #endif //HAVE_ALTIVEC
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 
-#if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
+#if (HAVE_MMX && !HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
 #define COMPILE_MMX
 #endif
 
-#if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
+#if HAVE_MMX2 || defined (RUNTIME_CPUDETECT)
 #define COMPILE_MMX2
 #endif
 
-#if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
+#if (HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
 #define COMPILE_3DNOW
 #endif
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
 
 #undef HAVE_MMX
+#define HAVE_MMX 0
 #undef HAVE_MMX2
+#define HAVE_MMX2 0
 #undef HAVE_3DNOW
+#define HAVE_3DNOW 0
 #undef HAVE_ALTIVEC
+#define HAVE_ALTIVEC 0
 
 #ifdef COMPILE_C
-#undef HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
 #define RENAME(a) a ## _C
 #include "postprocess_template.c"
 #endif
 
 #ifdef COMPILE_ALTIVEC
 #undef RENAME
-#define HAVE_ALTIVEC
+#undef HAVE_ALTIVEC
+#define HAVE_ALTIVEC 1
 #define RENAME(a) a ## _altivec
 #include "postprocess_altivec_template.c"
 #include "postprocess_template.c"
@@ -601,9 +603,8 @@ static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride,
 //MMX versions
 #ifdef COMPILE_MMX
 #undef RENAME
-#define HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
+#undef HAVE_MMX
+#define HAVE_MMX 1
 #define RENAME(a) a ## _MMX
 #include "postprocess_template.c"
 #endif
@@ -611,9 +612,10 @@ static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride,
 //MMX2 versions
 #ifdef COMPILE_MMX2
 #undef RENAME
-#define HAVE_MMX
-#define HAVE_MMX2
-#undef HAVE_3DNOW
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#define HAVE_MMX 1
+#define HAVE_MMX2 1
 #define RENAME(a) a ## _MMX2
 #include "postprocess_template.c"
 #endif
@@ -621,9 +623,12 @@ static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride,
 //3DNOW versions
 #ifdef COMPILE_3DNOW
 #undef RENAME
-#define HAVE_MMX
+#undef HAVE_MMX
 #undef HAVE_MMX2
-#define HAVE_3DNOW
+#undef HAVE_3DNOW
+#define HAVE_MMX 1
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 1
 #define RENAME(a) a ## _3DNow
 #include "postprocess_template.c"
 #endif
@@ -641,7 +646,7 @@ static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[]
     // difference would not be measurable here but it is much better because
     // someone might exchange the CPU whithout restarting MPlayer ;)
 #ifdef RUNTIME_CPUDETECT
-#if defined(ARCH_X86)
+#if ARCH_X86
     // ordered per speed fastest first
     if(c->cpuCaps & PP_CPU_CAPS_MMX2)
         postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
@@ -652,7 +657,7 @@ static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[]
     else
         postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
 #else
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     if(c->cpuCaps & PP_CPU_CAPS_ALTIVEC)
             postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
     else
@@ -660,13 +665,13 @@ static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[]
             postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
 #endif
 #else //RUNTIME_CPUDETECT
-#ifdef HAVE_MMX2
+#if   HAVE_MMX2
             postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_3DNOW)
+#elif HAVE_3DNOW
             postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
             postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_ALTIVEC)
+#elif HAVE_ALTIVEC
             postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
 #else
             postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
diff --git a/libpostproc/postprocess_template.c b/libpostproc/postprocess_template.c
index 05dc837..3d9b811 100644
--- a/libpostproc/postprocess_template.c
+++ b/libpostproc/postprocess_template.c
@@ -31,32 +31,32 @@
 #undef PMINUB
 #undef PMAXUB
 
-#ifdef HAVE_MMX2
+#if   HAVE_MMX2
 #define REAL_PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
-#elif defined (HAVE_3DNOW)
+#elif HAVE_3DNOW
 #define REAL_PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
 #endif
 #define PAVGB(a,b)  REAL_PAVGB(a,b)
 
-#ifdef HAVE_MMX2
+#if   HAVE_MMX2
 #define PMINUB(a,b,t) "pminub " #a ", " #b " \n\t"
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
 #define PMINUB(b,a,t) \
     "movq " #a ", " #t " \n\t"\
     "psubusb " #b ", " #t " \n\t"\
     "psubb " #t ", " #a " \n\t"
 #endif
 
-#ifdef HAVE_MMX2
+#if   HAVE_MMX2
 #define PMAXUB(a,b) "pmaxub " #a ", " #b " \n\t"
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
 #define PMAXUB(a,b) \
     "psubusb " #a ", " #b " \n\t"\
     "paddb " #a ", " #b " \n\t"
 #endif
 
 //FIXME? |255-0| = 1 (should not be a problem ...)
-#ifdef HAVE_MMX
+#if HAVE_MMX
 /**
  * Check if the middle 8x8 Block in the given 8x16 block is flat
  */
@@ -136,7 +136,7 @@ static inline int RENAME(vertClassify)(uint8_t src[], int stride, PPContext *c){
         "psubusb %%mm3, %%mm4                   \n\t"
 
         "                                       \n\t"
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "pxor %%mm7, %%mm7                      \n\t"
         "psadbw %%mm7, %%mm0                    \n\t"
 #else
@@ -176,10 +176,10 @@ static inline int RENAME(vertClassify)(uint8_t src[], int stride, PPContext *c){
  * Do a vertical low pass filter on the 8x16 block (only write to the 8x8 block in the middle)
  * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16
  */
-#ifndef HAVE_ALTIVEC
+#if !HAVE_ALTIVEC
 static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= stride*3;
     __asm__ volatile(        //"movv %0 %1 %2\n\t"
         "movq %2, %%mm0                         \n\t"  // QP,..., QP
@@ -306,7 +306,7 @@ static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
         : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb)
         : "%"REG_a, "%"REG_c
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     const int l1= stride;
     const int l2= stride + l1;
     const int l3= stride + l2;
@@ -345,7 +345,7 @@ static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
 
         src++;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 #endif //HAVE_ALTIVEC
 
@@ -364,7 +364,7 @@ static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
  */
 static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= stride*3;
 // FIXME rounding
     __asm__ volatile(
@@ -426,7 +426,7 @@ static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
         : "r" (src), "r" ((x86_reg)stride)
         : "%"REG_a, "%"REG_c
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     const int l1= stride;
     const int l2= stride + l1;
     const int l3= stride + l2;
@@ -449,7 +449,7 @@ static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
         }
     }
 
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 #endif //0
 
@@ -462,7 +462,7 @@ static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
  */
 static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= stride*3;
 
     __asm__ volatile(
@@ -548,7 +548,7 @@ static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
         : "r" (src), "r" ((x86_reg)stride), "m" (co->pQPb)
         : "%"REG_a, "%"REG_c
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
 
     const int l1= stride;
     const int l2= stride + l1;
@@ -582,13 +582,13 @@ static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
         }
         src++;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 
-#ifndef HAVE_ALTIVEC
+#if !HAVE_ALTIVEC
 static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext *c)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
 /*
     uint8_t tmp[16];
     const int l1= stride;
@@ -869,7 +869,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
     }
 }
 */
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
     src+= stride*4;
     __asm__ volatile(
         "pxor %%mm7, %%mm7                      \n\t"
@@ -978,7 +978,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
         "movq (%%"REG_c"), %%mm2                \n\t" // 2L0 - 5L1 + 5L2 - 2L3
         "movq 8(%%"REG_c"), %%mm3               \n\t" // 2H0 - 5H1 + 5H2 - 2H3
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "movq %%mm7, %%mm6                      \n\t" // 0
         "psubw %%mm0, %%mm6                     \n\t"
         "pmaxsw %%mm6, %%mm0                    \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
@@ -1010,7 +1010,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
         "psubw %%mm6, %%mm3                     \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "pminsw %%mm2, %%mm0                    \n\t"
         "pminsw %%mm3, %%mm1                    \n\t"
 #else
@@ -1074,7 +1074,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
         "pand %%mm2, %%mm4                      \n\t"
         "pand %%mm3, %%mm5                      \n\t"
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "pminsw %%mm0, %%mm4                    \n\t"
         "pminsw %%mm1, %%mm5                    \n\t"
 #else
@@ -1101,7 +1101,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
         : "r" ((x86_reg)stride), "m" (c->pQPb)
         : "%"REG_a, "%"REG_c
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     const int l1= stride;
     const int l2= stride + l1;
     const int l3= stride + l2;
@@ -1139,14 +1139,14 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
         }
         src++;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 #endif //HAVE_ALTIVEC
 
-#ifndef HAVE_ALTIVEC
+#if !HAVE_ALTIVEC
 static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     __asm__ volatile(
         "pxor %%mm6, %%mm6                      \n\t"
         "pcmpeqb %%mm7, %%mm7                   \n\t"
@@ -1164,7 +1164,7 @@ static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
 //        %0        eax        eax+%1        eax+2%1        %0+4%1        edx        edx+%1        edx+2%1        %0+8%1        edx+4%1
 
 #undef FIND_MIN_MAX
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define REAL_FIND_MIN_MAX(addr)\
         "movq " #addr ", %%mm0                  \n\t"\
         "pminub %%mm0, %%mm7                    \n\t"\
@@ -1191,7 +1191,7 @@ FIND_MIN_MAX((%0, %1, 8))
 
         "movq %%mm7, %%mm4                      \n\t"
         "psrlq $8, %%mm7                        \n\t"
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "pminub %%mm4, %%mm7                    \n\t" // min of pixels
         "pshufw $0xF9, %%mm7, %%mm4             \n\t"
         "pminub %%mm4, %%mm7                    \n\t" // min of pixels
@@ -1216,7 +1216,7 @@ FIND_MIN_MAX((%0, %1, 8))
 
         "movq %%mm6, %%mm4                      \n\t"
         "psrlq $8, %%mm6                        \n\t"
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "pmaxub %%mm4, %%mm6                    \n\t" // max of pixels
         "pshufw $0xF9, %%mm6, %%mm4             \n\t"
         "pmaxub %%mm4, %%mm6                    \n\t"
@@ -1370,7 +1370,7 @@ DERING_CORE((%0, %1, 8)    ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,
         : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2)
         : "%"REG_a, "%"REG_d, "%"REG_c
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     int y;
     int min=255;
     int max=0;
@@ -1487,7 +1487,7 @@ DERING_CORE((%0, %1, 8)    ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,
 //        src[0] = src[7]=src[stride*7]=src[stride*7 + 7]=255;
     }
 #endif
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 #endif //HAVE_ALTIVEC
 
@@ -1499,7 +1499,7 @@ DERING_CORE((%0, %1, 8)    ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,
  */
 static inline void RENAME(deInterlaceInterpolateLinear)(uint8_t src[], int stride)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= 4*stride;
     __asm__ volatile(
         "lea (%0, %1), %%"REG_a"                \n\t"
@@ -1552,7 +1552,7 @@ static inline void RENAME(deInterlaceInterpolateLinear)(uint8_t src[], int strid
  */
 static inline void RENAME(deInterlaceInterpolateCubic)(uint8_t src[], int stride)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= stride*3;
     __asm__ volatile(
         "lea (%0, %1), %%"REG_a"                \n\t"
@@ -1594,7 +1594,7 @@ DEINT_CUBIC((%%REGd, %1), (%0, %1, 8) , (%%REGd, %1, 4), (%%REGc)    , (%%REGc,
         : : "r" (src), "r" ((x86_reg)stride)
         : "%"REG_a, "%"REG_d, "%"REG_c
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     int x;
     src+= stride*3;
     for(x=0; x<8; x++){
@@ -1604,7 +1604,7 @@ DEINT_CUBIC((%%REGd, %1), (%0, %1, 8) , (%%REGd, %1, 4), (%%REGc)    , (%%REGc,
         src[stride*9] = CLIP((-src[stride*6] + 9*src[stride*8] + 9*src[stride*10] - src[stride*12])>>4);
         src++;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 
 /**
@@ -1616,7 +1616,7 @@ DEINT_CUBIC((%%REGd, %1), (%0, %1, 8) , (%%REGd, %1, 4), (%%REGc)    , (%%REGc,
  */
 static inline void RENAME(deInterlaceFF)(uint8_t src[], int stride, uint8_t *tmp)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= stride*4;
     __asm__ volatile(
         "lea (%0, %1), %%"REG_a"                \n\t"
@@ -1665,7 +1665,7 @@ DEINT_FF((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
         : : "r" (src), "r" ((x86_reg)stride), "r"(tmp)
         : "%"REG_a, "%"REG_d
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     int x;
     src+= stride*4;
     for(x=0; x<8; x++){
@@ -1683,7 +1683,7 @@ DEINT_FF((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
 
         src++;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 
 /**
@@ -1695,7 +1695,7 @@ DEINT_FF((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
  */
 static inline void RENAME(deInterlaceL5)(uint8_t src[], int stride, uint8_t *tmp, uint8_t *tmp2)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= stride*4;
     __asm__ volatile(
         "lea (%0, %1), %%"REG_a"                \n\t"
@@ -1755,7 +1755,7 @@ DEINT_L5(%%mm1, %%mm0, (%%REGd, %1, 2), (%0, %1, 8)    , (%%REGd, %1, 4))
         : : "r" (src), "r" ((x86_reg)stride), "r"(tmp), "r"(tmp2)
         : "%"REG_a, "%"REG_d
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     int x;
     src+= stride*4;
     for(x=0; x<8; x++){
@@ -1784,7 +1784,7 @@ DEINT_L5(%%mm1, %%mm0, (%%REGd, %1, 2), (%0, %1, 8)    , (%%REGd, %1, 4))
 
         src++;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 
 /**
@@ -1796,7 +1796,7 @@ DEINT_L5(%%mm1, %%mm0, (%%REGd, %1, 2), (%0, %1, 8)    , (%%REGd, %1, 4))
  */
 static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uint8_t *tmp)
 {
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     src+= 4*stride;
     __asm__ volatile(
         "lea (%0, %1), %%"REG_a"                \n\t"
@@ -1843,7 +1843,7 @@ static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uin
         : : "r" (src), "r" ((x86_reg)stride), "r" (tmp)
         : "%"REG_a, "%"REG_d
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
     int a, b, c, x;
     src+= 4*stride;
 
@@ -1886,7 +1886,7 @@ static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uin
         src += 4;
         tmp += 4;
     }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 
 /**
@@ -1897,9 +1897,9 @@ static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uin
  */
 static inline void RENAME(deInterlaceMedian)(uint8_t src[], int stride)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     src+= 4*stride;
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
     __asm__ volatile(
         "lea (%0, %1), %%"REG_a"                \n\t"
         "lea (%%"REG_a", %1, 4), %%"REG_d"      \n\t"
@@ -2012,7 +2012,7 @@ MEDIAN((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8))
 #endif //HAVE_MMX
 }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 /**
  * transposes and shift the given 8x8 Block into dst1 and dst2
  */
@@ -2180,7 +2180,7 @@ static inline void RENAME(transpose2)(uint8_t *dst, int dstStride, uint8_t *src)
 #endif //HAVE_MMX
 //static long test=0;
 
-#ifndef HAVE_ALTIVEC
+#if !HAVE_ALTIVEC
 static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
                                     uint8_t *tempBlurred, uint32_t *tempBlurredPast, int *maxNoise)
 {
@@ -2191,7 +2191,7 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
 
 #define FAST_L2_DIFF
 //#define L1_DIFF //u should change the thresholds too if u try that one
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
     __asm__ volatile(
         "lea (%2, %2, 2), %%"REG_a"             \n\t" // 3*stride
         "lea (%2, %2, 4), %%"REG_d"             \n\t" // 5*stride
@@ -2479,7 +2479,7 @@ L2_DIFF_CORE((%0, %%REGc)  , (%1, %%REGc))
         :: "r" (src), "r" (tempBlurred), "r"((x86_reg)stride), "m" (tempBlurredPast)
         : "%"REG_a, "%"REG_d, "%"REG_c, "memory"
     );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#else //HAVE_MMX2 || HAVE_3DNOW
 {
     int y;
     int d=0;
@@ -2562,11 +2562,11 @@ Switch between
         }
     }
 }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#endif //HAVE_MMX2 || HAVE_3DNOW
 }
 #endif //HAVE_ALTIVEC
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 /**
  * accurate deblock filter
  */
@@ -2970,7 +2970,7 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
             "movq (%%"REG_c"), %%mm2                \n\t" // 2L0 - 5L1 + 5L2 - 2L3
             "movq 8(%%"REG_c"), %%mm3               \n\t" // 2H0 - 5H1 + 5H2 - 2H3
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
             "movq %%mm7, %%mm6                      \n\t" // 0
             "psubw %%mm0, %%mm6                     \n\t"
             "pmaxsw %%mm6, %%mm0                    \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
@@ -3002,7 +3002,7 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
             "psubw %%mm6, %%mm3                     \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
             "pminsw %%mm2, %%mm0                    \n\t"
             "pminsw %%mm3, %%mm1                    \n\t"
 #else
@@ -3066,7 +3066,7 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
             "pand %%mm2, %%mm4                      \n\t"
             "pand %%mm3, %%mm5                      \n\t"
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
             "pminsw %%mm0, %%mm4                    \n\t"
             "pminsw %%mm1, %%mm5                    \n\t"
 #else
@@ -3116,18 +3116,18 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
 static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, const uint8_t src[], int srcStride,
                                      int levelFix, int64_t *packedOffsetAndScale)
 {
-#ifndef HAVE_MMX
+#if !HAVE_MMX
     int i;
 #endif
     if(levelFix){
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
         "movq (%%"REG_a"), %%mm2        \n\t" // packedYOffset
         "movq 8(%%"REG_a"), %%mm3       \n\t" // packedYScale
         "lea (%2,%4), %%"REG_a"         \n\t"
         "lea (%3,%5), %%"REG_d"         \n\t"
         "pxor %%mm4, %%mm4              \n\t"
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define REAL_SCALED_CPY(src1, src2, dst1, dst2)                                                \
         "movq " #src1 ", %%mm0          \n\t"\
         "movq " #src1 ", %%mm5          \n\t"\
@@ -3203,7 +3203,7 @@ SCALED_CPY((%%REGa, %4), (%%REGa, %4, 2), (%%REGd, %5), (%%REGd, %5, 2))
                 &(src[srcStride*i]), BLOCK_SIZE);
 #endif //HAVE_MMX
     }else{
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
         "lea (%0,%2), %%"REG_a"                 \n\t"
         "lea (%1,%3), %%"REG_d"                 \n\t"
@@ -3243,7 +3243,7 @@ SIMPLE_CPY((%%REGa, %2), (%%REGa, %2, 2), (%%REGd, %3), (%%REGd, %3, 2))
  */
 static inline void RENAME(duplicate)(uint8_t src[], int stride)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
         "movq (%0), %%mm0               \n\t"
         "add %1, %0                     \n\t"
@@ -3280,7 +3280,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
     int QPCorrecture= 256*256;
 
     int copyAhead;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     int i;
 #endif
 
@@ -3293,7 +3293,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
     uint8_t * const tempDst= dstStride > 0 ? c.tempDst : c.tempDst - 23*dstStride;
     //const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
     for(i=0; i<57; i++){
         int offset= ((i*c.ppMode.baseDcDiff)>>8) + 1;
         int threshold= offset*2 + 1;
@@ -3351,7 +3351,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
 
         scale= (double)(c.ppMode.maxAllowedY - c.ppMode.minAllowedY) / (double)(white-black);
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         c.packedYScale= (uint16_t)(scale*256.0 + 0.5);
         c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
 #else
@@ -3384,7 +3384,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
         // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
         for(x=0; x<width; x+=BLOCK_SIZE){
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 /*
             prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
             prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
@@ -3411,7 +3411,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
                 : "%"REG_a, "%"REG_d
             );
 
-#elif defined(HAVE_3DNOW)
+#elif HAVE_3DNOW
 //FIXME check if this is faster on an 3dnow chip or if it is faster without the prefetch or ...
 /*          prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
             prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
@@ -3457,7 +3457,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
         //1% speedup if these are here instead of the inner loop
         const uint8_t *srcBlock= &(src[y*srcStride]);
         uint8_t *dstBlock= &(dst[y*dstStride]);
-#ifdef HAVE_MMX
+#if HAVE_MMX
         uint8_t *tempBlock1= c.tempBlocks;
         uint8_t *tempBlock2= c.tempBlocks + 8;
 #endif
@@ -3493,7 +3493,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
         // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
         for(x=0; x<width; x+=BLOCK_SIZE){
             const int stride= dstStride;
-#ifdef HAVE_MMX
+#if HAVE_MMX
             uint8_t *tmpXchg;
 #endif
             if(isColor){
@@ -3507,7 +3507,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
                 yHistogram[ srcBlock[srcStride*12 + 4] ]++;
             }
             c.QP= QP;
-#ifdef HAVE_MMX
+#if HAVE_MMX
             __asm__ volatile(
                 "movd %1, %%mm7         \n\t"
                 "packuswb %%mm7, %%mm7  \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
@@ -3520,7 +3520,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
 #endif
 
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 /*
             prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
             prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
@@ -3547,7 +3547,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
                 : "%"REG_a, "%"REG_d
             );
 
-#elif defined(HAVE_3DNOW)
+#elif HAVE_3DNOW
 //FIXME check if this is faster on an 3dnow chip or if it is faster without the prefetch or ...
 /*          prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
             prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
@@ -3591,12 +3591,12 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
                 }
             }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
             RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
 #endif
             /* check if we have a previous block to deblock it with dstBlock */
             if(x - 8 >= 0){
-#ifdef HAVE_MMX
+#if HAVE_MMX
                 if(mode & H_X1_FILTER)
                         RENAME(vertX1Filter)(tempBlock1, 16, &c);
                 else if(mode & H_DEBLOCK){
@@ -3617,7 +3617,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
                 if(mode & H_X1_FILTER)
                     horizX1Filter(dstBlock-4, stride, QP);
                 else if(mode & H_DEBLOCK){
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
                     DECLARE_ALIGNED(16, unsigned char, tempBlock[272]);
                     transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride);
 
@@ -3659,7 +3659,7 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
             dstBlock+=8;
             srcBlock+=8;
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
             tmpXchg= tempBlock1;
             tempBlock1= tempBlock2;
             tempBlock2 = tmpXchg;
@@ -3699,9 +3699,9 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[
                 + dstBlock[x +14*dstStride] + dstBlock[x +15*dstStride];
         }*/
     }
-#ifdef HAVE_3DNOW
+#if   HAVE_3DNOW
     __asm__ volatile("femms");
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
     __asm__ volatile("emms");
 #endif
 
diff --git a/libswscale/.svnrevision b/libswscale/.svnrevision
new file mode 100644
index 0000000..d0e7cce
--- /dev/null
+++ b/libswscale/.svnrevision
@@ -0,0 +1 @@
+28341
diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c
index ac452a0..5b79fea 100644
--- a/libswscale/rgb2rgb.c
+++ b/libswscale/rgb2rgb.c
@@ -88,7 +88,7 @@ void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *sr
                      long srcStride1, long srcStride2,
                      long srcStride3, long dstStride);
 
-#if defined(ARCH_X86) && defined(CONFIG_GPL)
+#if ARCH_X86 && CONFIG_GPL
 DECLARE_ASM_CONST(8, uint64_t, mmx_null)     = 0x0000000000000000ULL;
 DECLARE_ASM_CONST(8, uint64_t, mmx_one)      = 0xFFFFFFFFFFFFFFFFULL;
 DECLARE_ASM_CONST(8, uint64_t, mask32b)      = 0x000000FF000000FFULL;
@@ -122,7 +122,7 @@ DECLARE_ASM_CONST(8, uint64_t, blue_16mask)  = 0x0000001f0000001fULL;
 DECLARE_ASM_CONST(8, uint64_t, red_15mask)   = 0x00007c0000007c00ULL;
 DECLARE_ASM_CONST(8, uint64_t, green_15mask) = 0x000003e0000003e0ULL;
 DECLARE_ASM_CONST(8, uint64_t, blue_15mask)  = 0x0000001f0000001fULL;
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
 
 #define RGB2YUV_SHIFT 8
 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
@@ -141,35 +141,35 @@ DECLARE_ASM_CONST(8, uint64_t, blue_15mask)  = 0x0000001f0000001fULL;
 #undef HAVE_MMX2
 #undef HAVE_3DNOW
 #undef HAVE_SSE2
+#define HAVE_MMX 0
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 0
+#define HAVE_SSE2 0
 #define RENAME(a) a ## _C
 #include "rgb2rgb_template.c"
 
-#if defined(ARCH_X86) && defined(CONFIG_GPL)
+#if ARCH_X86 && CONFIG_GPL
 
 //MMX versions
 #undef RENAME
-#define HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#undef HAVE_SSE2
+#undef HAVE_MMX
+#define HAVE_MMX 1
 #define RENAME(a) a ## _MMX
 #include "rgb2rgb_template.c"
 
 //MMX2 versions
 #undef RENAME
-#define HAVE_MMX
-#define HAVE_MMX2
-#undef HAVE_3DNOW
-#undef HAVE_SSE2
+#undef HAVE_MMX2
+#define HAVE_MMX2 1
 #define RENAME(a) a ## _MMX2
 #include "rgb2rgb_template.c"
 
 //3DNOW versions
 #undef RENAME
-#define HAVE_MMX
 #undef HAVE_MMX2
-#define HAVE_3DNOW
-#undef HAVE_SSE2
+#undef HAVE_3DNOW
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 1
 #define RENAME(a) a ## _3DNOW
 #include "rgb2rgb_template.c"
 
@@ -183,7 +183,7 @@ DECLARE_ASM_CONST(8, uint64_t, blue_15mask)  = 0x0000001f0000001fULL;
 */
 
 void sws_rgb2rgb_init(int flags){
-#if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX))  && defined(CONFIG_GPL)
+#if (HAVE_MMX2 || HAVE_3DNOW || HAVE_MMX)  && CONFIG_GPL
     if (flags & SWS_CPU_CAPS_MMX2)
         rgb2rgb_init_MMX2();
     else if (flags & SWS_CPU_CAPS_3DNOW)
@@ -191,7 +191,7 @@ void sws_rgb2rgb_init(int flags){
     else if (flags & SWS_CPU_CAPS_MMX)
         rgb2rgb_init_MMX();
     else
-#endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */
+#endif /* HAVE_MMX2 || HAVE_3DNOW || HAVE_MMX */
         rgb2rgb_init_C();
 }
 
diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c
index ce76c5e..b988ca0 100644
--- a/libswscale/rgb2rgb_template.c
+++ b/libswscale/rgb2rgb_template.c
@@ -37,17 +37,17 @@
 #undef PREFETCHW
 #undef PAVGB
 
-#ifdef HAVE_SSE2
+#if HAVE_SSE2
 #define MMREG_SIZE 16
 #else
 #define MMREG_SIZE 8
 #endif
 
-#ifdef HAVE_3DNOW
+#if HAVE_3DNOW
 #define PREFETCH  "prefetch"
 #define PREFETCHW "prefetchw"
 #define PAVGB     "pavgusb"
-#elif defined (HAVE_MMX2)
+#elif HAVE_MMX2
 #define PREFETCH "prefetchnta"
 #define PREFETCHW "prefetcht0"
 #define PAVGB     "pavgb"
@@ -56,14 +56,14 @@
 #define PREFETCHW " # nop"
 #endif
 
-#ifdef HAVE_3DNOW
+#if HAVE_3DNOW
 /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */
 #define EMMS     "femms"
 #else
 #define EMMS     "emms"
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define MOVNTQ "movntq"
 #define SFENCE "sfence"
 #else
@@ -76,11 +76,11 @@ static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long s
     uint8_t *dest = dst;
     const uint8_t *s = src;
     const uint8_t *end;
-    #ifdef HAVE_MMX
+    #if HAVE_MMX
         const uint8_t *mm_end;
     #endif
     end = s + src_size;
-    #ifdef HAVE_MMX
+    #if HAVE_MMX
         __asm__ volatile(PREFETCH"    %0"::"m"(*s):"memory");
         mm_end = end - 23;
         __asm__ volatile("movq        %0, %%mm7"::"m"(mask32):"memory");
@@ -136,11 +136,11 @@ static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long s
     uint8_t *dest = dst;
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s):"memory");
     mm_end = end - 31;
     while (s < mm_end)
@@ -230,7 +230,7 @@ static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_
     register const uint8_t *end;
     const uint8_t *mm_end;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s));
     __asm__ volatile("movq        %0, %%mm4"::"m"(mask15s));
     mm_end = end - 15;
@@ -279,7 +279,7 @@ static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_
     register const uint8_t *end;
     const uint8_t *mm_end;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s));
     __asm__ volatile("movq        %0, %%mm7"::"m"(mask15rg));
     __asm__ volatile("movq        %0, %%mm6"::"m"(mask15b));
@@ -332,12 +332,12 @@ static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     mm_end = end - 15;
 #if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster)
     __asm__ volatile(
@@ -430,12 +430,12 @@ static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long s
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*src):"memory");
     __asm__ volatile(
         "movq          %0, %%mm7    \n\t"
@@ -491,12 +491,12 @@ static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     mm_end = end - 15;
 #if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster)
     __asm__ volatile(
@@ -589,12 +589,12 @@ static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long s
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*src):"memory");
     __asm__ volatile(
         "movq          %0, %%mm7    \n\t"
@@ -650,12 +650,12 @@ static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long s
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*src):"memory");
     __asm__ volatile(
         "movq         %0, %%mm7     \n\t"
@@ -713,12 +713,12 @@ static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*src):"memory");
     __asm__ volatile(
         "movq         %0, %%mm7     \n\t"
@@ -776,12 +776,12 @@ static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long s
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*src):"memory");
     __asm__ volatile(
         "movq          %0, %%mm7    \n\t"
@@ -839,12 +839,12 @@ static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_
 {
     const uint8_t *s = src;
     const uint8_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint8_t *mm_end;
 #endif
     uint16_t *d = (uint16_t *)dst;
     end = s + src_size;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*src):"memory");
     __asm__ volatile(
         "movq         %0, %%mm7     \n\t"
@@ -922,13 +922,13 @@ static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_
 static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
 {
     const uint16_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint16_t *mm_end;
 #endif
     uint8_t *d = dst;
     const uint16_t *s = (const uint16_t*)src;
     end = s + src_size/2;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s):"memory");
     mm_end = end - 7;
     while (s < mm_end)
@@ -1064,13 +1064,13 @@ static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long s
 static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
 {
     const uint16_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint16_t *mm_end;
 #endif
     uint8_t *d = (uint8_t *)dst;
     const uint16_t *s = (const uint16_t *)src;
     end = s + src_size/2;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s):"memory");
     mm_end = end - 7;
     while (s < mm_end)
@@ -1205,13 +1205,13 @@ static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long s
 static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size)
 {
     const uint16_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint16_t *mm_end;
 #endif
     uint8_t *d = dst;
     const uint16_t *s = (const uint16_t *)src;
     end = s + src_size/2;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s):"memory");
     __asm__ volatile("pxor    %%mm7,%%mm7    \n\t":::"memory");
     mm_end = end - 3;
@@ -1283,13 +1283,13 @@ static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_
 static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size)
 {
     const uint16_t *end;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     const uint16_t *mm_end;
 #endif
     uint8_t *d = dst;
     const uint16_t *s = (const uint16_t*)src;
     end = s + src_size/2;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(PREFETCH"    %0"::"m"(*s):"memory");
     __asm__ volatile("pxor    %%mm7,%%mm7    \n\t":::"memory");
     mm_end = end - 3;
@@ -1357,7 +1357,7 @@ static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long s
     long idx = 15 - src_size;
     const uint8_t *s = src-idx;
     uint8_t *d = dst-idx;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
     "test          %0, %0           \n\t"
     "jns           2f               \n\t"
@@ -1371,7 +1371,7 @@ static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long s
     PREFETCH"     32(%1, %0)        \n\t"
     "movq           (%1, %0), %%mm0 \n\t"
     "movq          8(%1, %0), %%mm1 \n\t"
-# ifdef HAVE_MMX2
+# if HAVE_MMX2
     "pshufw      $177, %%mm0, %%mm3 \n\t"
     "pshufw      $177, %%mm1, %%mm5 \n\t"
     "pand       %%mm7, %%mm0        \n\t"
@@ -1419,7 +1419,7 @@ static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long s
 static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
 {
     unsigned i;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     long mmx_size= 23 - src_size;
     __asm__ volatile (
     "test             %%"REG_a", %%"REG_a"          \n\t"
@@ -1494,7 +1494,7 @@ static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *u
     const long chromWidth= width>>1;
     for (y=0; y<height; y++)
     {
-#ifdef HAVE_MMX
+#if HAVE_MMX
 //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
         __asm__ volatile(
         "xor                 %%"REG_a", %%"REG_a"   \n\t"
@@ -1531,7 +1531,7 @@ static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *u
         );
 #else
 
-#if defined ARCH_ALPHA && defined HAVE_MVI
+#if ARCH_ALPHA && HAVE_MVI
 #define pl2yuy2(n)                  \
     y1 = yc[n];                     \
     y2 = yc2[n];                    \
@@ -1619,7 +1619,7 @@ static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *u
         ysrc += lumStride;
         dst  += dstStride;
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
 __asm__(    EMMS"       \n\t"
         SFENCE"     \n\t"
         :::"memory");
@@ -1646,7 +1646,7 @@ static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *u
     const long chromWidth= width>>1;
     for (y=0; y<height; y++)
     {
-#ifdef HAVE_MMX
+#if HAVE_MMX
 //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
         __asm__ volatile(
         "xor                %%"REG_a", %%"REG_a"    \n\t"
@@ -1725,7 +1725,7 @@ static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *u
         ysrc += lumStride;
         dst += dstStride;
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
 __asm__(    EMMS"       \n\t"
         SFENCE"     \n\t"
         :::"memory");
@@ -1776,7 +1776,7 @@ static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t
     const long chromWidth= width>>1;
     for (y=0; y<height; y+=2)
     {
-#ifdef HAVE_MMX
+#if HAVE_MMX
         __asm__ volatile(
         "xor                 %%"REG_a", %%"REG_a"   \n\t"
         "pcmpeqw                 %%mm7, %%mm7       \n\t"
@@ -1881,7 +1881,7 @@ static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t
         ydst += lumStride;
         src  += srcStride;
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
 __asm__ volatile(   EMMS"       \n\t"
                 SFENCE"     \n\t"
                 :::"memory");
@@ -1914,7 +1914,7 @@ static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, long srcWi
         dst+= dstStride;
 
     for (y=1; y<srcHeight; y++){
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
         const long mmxSize= srcWidth&~15;
         __asm__ volatile(
         "mov           %4, %%"REG_a"            \n\t"
@@ -1993,7 +1993,7 @@ static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, long srcWi
     }
 #endif
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 __asm__ volatile(   EMMS"       \n\t"
                 SFENCE"     \n\t"
                 :::"memory");
@@ -2014,7 +2014,7 @@ static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t
     const long chromWidth= width>>1;
     for (y=0; y<height; y+=2)
     {
-#ifdef HAVE_MMX
+#if HAVE_MMX
         __asm__ volatile(
         "xor                 %%"REG_a", %%"REG_a"   \n\t"
         "pcmpeqw             %%mm7, %%mm7   \n\t"
@@ -2119,7 +2119,7 @@ static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t
         ydst += lumStride;
         src  += srcStride;
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
 __asm__ volatile(   EMMS"       \n\t"
                 SFENCE"     \n\t"
                 :::"memory");
@@ -2139,7 +2139,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
 {
     long y;
     const long chromWidth= width>>1;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     for (y=0; y<height-2; y+=2)
     {
         long i;
@@ -2229,7 +2229,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
         "1:                                         \n\t"
         PREFETCH"    64(%0, %%"REG_d")              \n\t"
         PREFETCH"    64(%1, %%"REG_d")              \n\t"
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
         "movq          (%0, %%"REG_d"), %%mm0       \n\t"
         "movq          (%1, %%"REG_d"), %%mm1       \n\t"
         "movq         6(%0, %%"REG_d"), %%mm2       \n\t"
@@ -2290,7 +2290,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
         "packssdw                %%mm1, %%mm0       \n\t" // V1 V0 U1 U0
         "psraw                      $7, %%mm0       \n\t"
 
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+#if HAVE_MMX2 || HAVE_3DNOW
         "movq        12(%0, %%"REG_d"), %%mm4       \n\t"
         "movq        12(%1, %%"REG_d"), %%mm1       \n\t"
         "movq        18(%0, %%"REG_d"), %%mm2       \n\t"
@@ -2438,8 +2438,8 @@ static void RENAME(interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dest,
     {
         long w;
 
-#ifdef HAVE_MMX
-#ifdef HAVE_SSE2
+#if HAVE_MMX
+#if HAVE_SSE2
         __asm__(
         "xor              %%"REG_a", %%"REG_a"  \n\t"
         "1:                                     \n\t"
@@ -2501,7 +2501,7 @@ static void RENAME(interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dest,
                 src1 += src1Stride;
                 src2 += src2Stride;
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__(
         EMMS"       \n\t"
         SFENCE"     \n\t"
@@ -2518,7 +2518,7 @@ static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
 {
     long y,x,w,h;
     w=width/2; h=height/2;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
     PREFETCH" %0    \n\t"
     PREFETCH" %1    \n\t"
@@ -2528,7 +2528,7 @@ static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
     const uint8_t* s1=src1+srcStride1*(y>>1);
     uint8_t* d=dst1+dstStride1*y;
     x=0;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     for (;x<w-31;x+=32)
     {
         __asm__ volatile(
@@ -2568,7 +2568,7 @@ static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
     const uint8_t* s2=src2+srcStride2*(y>>1);
     uint8_t* d=dst2+dstStride2*y;
     x=0;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     for (;x<w-31;x+=32)
     {
         __asm__ volatile(
@@ -2604,7 +2604,7 @@ static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
 #endif
     for (;x<w;x++) d[2*x]=d[2*x+1]=s2[x];
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__(
         EMMS"       \n\t"
         SFENCE"     \n\t"
@@ -2627,7 +2627,7 @@ static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2
     const uint8_t* vp=src3+srcStride3*(y>>2);
     uint8_t* d=dst+dstStride*y;
     x=0;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     for (;x<w-7;x+=8)
     {
         __asm__ volatile(
@@ -2695,7 +2695,7 @@ static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2
         d[8*x+7] = vp[x];
     }
     }
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__(
         EMMS"       \n\t"
         SFENCE"     \n\t"
diff --git a/libswscale/swscale-example.c b/libswscale/swscale-example.c
index d1189b2..90c3ce3 100644
--- a/libswscale/swscale-example.c
+++ b/libswscale/swscale-example.c
@@ -118,7 +118,7 @@ static int doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcFormat
     sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride);
     sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride);
 
-#if defined(ARCH_X86)
+#if ARCH_X86
     __asm__ volatile ("emms\n\t");
 #endif
 
@@ -208,7 +208,7 @@ int main(int argc, char **argv){
     }
     sws_scale(sws, rgb_src, rgb_stride, 0, H, src, stride);
 
-#if defined(ARCH_X86)
+#if ARCH_X86
     __asm__ volatile ("emms\n\t");
 #endif
 
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index cfa3580..52b709a 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -62,7 +62,7 @@ untested special converters
 #include <unistd.h>
 #include "config.h"
 #include <assert.h>
-#ifdef HAVE_SYS_MMAN_H
+#if HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
 #define MAP_ANONYMOUS MAP_ANON
@@ -202,7 +202,7 @@ add BGR4 output support
 write special BGR->BGR scaler
 */
 
-#if defined(ARCH_X86) && defined (CONFIG_GPL)
+#if ARCH_X86 && CONFIG_GPL
 DECLARE_ASM_CONST(8, uint64_t, bF8)=       0xF8F8F8F8F8F8F8F8LL;
 DECLARE_ASM_CONST(8, uint64_t, bFC)=       0xFCFCFCFCFCFCFCFCLL;
 DECLARE_ASM_CONST(8, uint64_t, w10)=       0x0010001000100010LL;
@@ -257,7 +257,7 @@ DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV[2][4]) = {
 
 DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUVOffset)= 0x0040400000404000ULL;
 
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
 
 // clipping helper table for C implementations:
 static unsigned char clip_table[768];
@@ -454,6 +454,10 @@ const char *sws_format_name(enum PixelFormat format)
             return "yuv440p";
         case PIX_FMT_VDPAU_H264:
             return "vdpau_h264";
+        case PIX_FMT_VDPAU_MPEG1:
+            return "vdpau_mpeg1";
+        case PIX_FMT_VDPAU_MPEG2:
+            return "vdpau_mpeg2";
         default:
             return "Unknown format";
     }
@@ -947,27 +951,27 @@ static inline void yuv2rgbXinC_full(SwsContext *c, int16_t *lumFilter, int16_t *
 
 //Note: we have C, X86, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
 //Plain C versions
-#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT) || !defined(CONFIG_GPL)
+#if !HAVE_MMX || defined (RUNTIME_CPUDETECT) || !CONFIG_GPL
 #define COMPILE_C
 #endif
 
-#ifdef ARCH_PPC
-#if (defined (HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#if ARCH_PPC
+#if (HAVE_ALTIVEC || defined (RUNTIME_CPUDETECT)) && CONFIG_GPL
 #define COMPILE_ALTIVEC
 #endif //HAVE_ALTIVEC
 #endif //ARCH_PPC
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 
-#if ((defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#if ((HAVE_MMX && !HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)) && CONFIG_GPL
 #define COMPILE_MMX
 #endif
 
-#if (defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#if (HAVE_MMX2 || defined (RUNTIME_CPUDETECT)) && CONFIG_GPL
 #define COMPILE_MMX2
 #endif
 
-#if ((defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#if ((HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)) && CONFIG_GPL
 #define COMPILE_3DNOW
 #endif
 #endif //ARCH_X86 || ARCH_X86_64
@@ -975,24 +979,26 @@ static inline void yuv2rgbXinC_full(SwsContext *c, int16_t *lumFilter, int16_t *
 #undef HAVE_MMX
 #undef HAVE_MMX2
 #undef HAVE_3DNOW
+#undef HAVE_ALTIVEC
+#define HAVE_MMX 0
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 0
+#define HAVE_ALTIVEC 0
 
 #ifdef COMPILE_C
-#undef HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#undef HAVE_ALTIVEC
 #define RENAME(a) a ## _C
 #include "swscale_template.c"
 #endif
 
 #ifdef COMPILE_ALTIVEC
 #undef RENAME
-#define HAVE_ALTIVEC
+#undef HAVE_ALTIVEC
+#define HAVE_ALTIVEC 1
 #define RENAME(a) a ## _altivec
 #include "swscale_template.c"
 #endif
 
-#if defined(ARCH_X86)
+#if ARCH_X86
 
 //X86 versions
 /*
@@ -1007,9 +1013,12 @@ static inline void yuv2rgbXinC_full(SwsContext *c, int16_t *lumFilter, int16_t *
 //MMX versions
 #ifdef COMPILE_MMX
 #undef RENAME
-#define HAVE_MMX
+#undef HAVE_MMX
 #undef HAVE_MMX2
 #undef HAVE_3DNOW
+#define HAVE_MMX 1
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 0
 #define RENAME(a) a ## _MMX
 #include "swscale_template.c"
 #endif
@@ -1017,9 +1026,12 @@ static inline void yuv2rgbXinC_full(SwsContext *c, int16_t *lumFilter, int16_t *
 //MMX2 versions
 #ifdef COMPILE_MMX2
 #undef RENAME
-#define HAVE_MMX
-#define HAVE_MMX2
+#undef HAVE_MMX
+#undef HAVE_MMX2
 #undef HAVE_3DNOW
+#define HAVE_MMX 1
+#define HAVE_MMX2 1
+#define HAVE_3DNOW 0
 #define RENAME(a) a ## _MMX2
 #include "swscale_template.c"
 #endif
@@ -1027,9 +1039,12 @@ static inline void yuv2rgbXinC_full(SwsContext *c, int16_t *lumFilter, int16_t *
 //3DNOW versions
 #ifdef COMPILE_3DNOW
 #undef RENAME
-#define HAVE_MMX
+#undef HAVE_MMX
 #undef HAVE_MMX2
-#define HAVE_3DNOW
+#undef HAVE_3DNOW
+#define HAVE_MMX 1
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 1
 #define RENAME(a) a ## _3DNow
 #include "swscale_template.c"
 #endif
@@ -1061,7 +1076,7 @@ static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outF
     int64_t *filter2=NULL;
     const int64_t fone= 1LL<<54;
     int ret= -1;
-#if defined(ARCH_X86)
+#if ARCH_X86
     if (flags & SWS_CPU_CAPS_MMX)
         __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
 #endif
@@ -1617,8 +1632,8 @@ static void globalInit(void){
 
 static SwsFunc getSwsFunc(int flags){
 
-#if defined(RUNTIME_CPUDETECT) && defined (CONFIG_GPL)
-#if defined(ARCH_X86)
+#if defined(RUNTIME_CPUDETECT) && CONFIG_GPL
+#if ARCH_X86
     // ordered per speed fastest first
     if (flags & SWS_CPU_CAPS_MMX2)
         return swScale_MMX2;
@@ -1630,22 +1645,22 @@ static SwsFunc getSwsFunc(int flags){
         return swScale_C;
 
 #else
-#ifdef ARCH_PPC
+#if ARCH_PPC
     if (flags & SWS_CPU_CAPS_ALTIVEC)
         return swScale_altivec;
     else
         return swScale_C;
 #endif
     return swScale_C;
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
 #else //RUNTIME_CPUDETECT
-#ifdef HAVE_MMX2
+#if   HAVE_MMX2
     return swScale_MMX2;
-#elif defined (HAVE_3DNOW)
+#elif HAVE_3DNOW
     return swScale_3DNow;
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
     return swScale_MMX;
-#elif defined (HAVE_ALTIVEC)
+#elif HAVE_ALTIVEC
     return swScale_altivec;
 #else
     return swScale_C;
@@ -2169,22 +2184,22 @@ SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int d
     int unscaled, needsDither;
     int srcRange, dstRange;
     SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
-#if defined(ARCH_X86)
+#if ARCH_X86
     if (flags & SWS_CPU_CAPS_MMX)
         __asm__ volatile("emms\n\t"::: "memory");
 #endif
 
-#if !defined(RUNTIME_CPUDETECT) || !defined (CONFIG_GPL) //ensure that the flags match the compiled variant if cpudetect is off
+#if !defined(RUNTIME_CPUDETECT) || !CONFIG_GPL //ensure that the flags match the compiled variant if cpudetect is off
     flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC|SWS_CPU_CAPS_BFIN);
-#ifdef HAVE_MMX2
+#if   HAVE_MMX2
     flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2;
-#elif defined (HAVE_3DNOW)
+#elif HAVE_3DNOW
     flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_3DNOW;
-#elif defined (HAVE_MMX)
+#elif HAVE_MMX
     flags |= SWS_CPU_CAPS_MMX;
-#elif defined (HAVE_ALTIVEC)
+#elif HAVE_ALTIVEC
     flags |= SWS_CPU_CAPS_ALTIVEC;
-#elif defined (ARCH_BFIN)
+#elif ARCH_BFIN
     flags |= SWS_CPU_CAPS_BFIN;
 #endif
 #endif /* RUNTIME_CPUDETECT */
@@ -2311,7 +2326,7 @@ SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int d
         {
             c->swScale= PlanarToNV12Wrapper;
         }
-#ifdef CONFIG_GPL
+#if CONFIG_GPL
         /* yuv2bgr */
         if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat))
             && !(flags & SWS_ACCURATE_RND) && !(dstH&1))
@@ -2410,7 +2425,7 @@ SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int d
             c->swScale= gray16swap;
         }
 
-#ifdef ARCH_BFIN
+#if ARCH_BFIN
         if (flags & SWS_CPU_CAPS_BFIN)
             ff_bfin_get_unscaled_swscale (c);
 #endif
@@ -2518,7 +2533,7 @@ SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int d
                    (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
                    srcFilter->chrV, dstFilter->chrV, c->param);
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
         c->vYCoeffsBank = av_malloc(sizeof (vector signed short)*c->vLumFilterSize*c->dstH);
         c->vCCoeffsBank = av_malloc(sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH);
 
@@ -2648,7 +2663,7 @@ SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int d
         }
         else
         {
-#if defined(ARCH_X86)
+#if ARCH_X86
             av_log(c, AV_LOG_VERBOSE, "using X86-Asm scaler for horizontal scaling\n");
 #else
             if (flags & SWS_FAST_BILINEAR)
@@ -3115,7 +3130,7 @@ void sws_freeContext(SwsContext *c){
     av_freep(&c->vChrFilter);
     av_freep(&c->hLumFilter);
     av_freep(&c->hChrFilter);
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     av_freep(&c->vYCoeffsBank);
     av_freep(&c->vCCoeffsBank);
 #endif
@@ -3125,7 +3140,7 @@ void sws_freeContext(SwsContext *c){
     av_freep(&c->hLumFilterPos);
     av_freep(&c->hChrFilterPos);
 
-#if defined(ARCH_X86) && defined(CONFIG_GPL)
+#if ARCH_X86 && CONFIG_GPL
 #ifdef MAP_ANONYMOUS
     if (c->funnyYCode) munmap(c->funnyYCode, MAX_FUNNY_CODE_SIZE);
     if (c->funnyUVCode) munmap(c->funnyUVCode, MAX_FUNNY_CODE_SIZE);
@@ -3135,7 +3150,7 @@ void sws_freeContext(SwsContext *c){
 #endif
     c->funnyYCode=NULL;
     c->funnyUVCode=NULL;
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
 
     av_freep(&c->lumMmx2Filter);
     av_freep(&c->chrMmx2Filter);
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 4899557..b2505c0 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -23,7 +23,7 @@
 
 #include "config.h"
 
-#ifdef HAVE_ALTIVEC_H
+#if HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
 
@@ -42,7 +42,7 @@
 #define ALT32_CORR   1
 #endif
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 #   define APCK_PTR2 8
 #   define APCK_COEF 16
 #   define APCK_SIZE 24
@@ -175,7 +175,7 @@ typedef struct SwsContext{
     uint64_t u_temp       __attribute__((aligned(8)));
     uint64_t v_temp       __attribute__((aligned(8)));
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
 
   vector signed short   CY;
   vector signed short   CRV;
@@ -189,7 +189,7 @@ typedef struct SwsContext{
 #endif
 
 
-#ifdef ARCH_BFIN
+#if ARCH_BFIN
     uint32_t oy           __attribute__((aligned(4)));
     uint32_t oc           __attribute__((aligned(4)));
     uint32_t zero         __attribute__((aligned(4)));
@@ -203,7 +203,7 @@ typedef struct SwsContext{
     uint32_t gmask        __attribute__((aligned(4)));
 #endif
 
-#ifdef HAVE_VIS
+#if HAVE_VIS
     uint64_t sparc_coeffs[10] __attribute__((aligned(8)));
 #endif
 
diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c
index 4c8bc6e..2144b5a 100644
--- a/libswscale/swscale_template.c
+++ b/libswscale/swscale_template.c
@@ -29,17 +29,17 @@
 #undef EMMS
 #undef SFENCE
 
-#ifdef HAVE_3DNOW
+#if HAVE_3DNOW
 /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */
 #define EMMS     "femms"
 #else
 #define EMMS     "emms"
 #endif
 
-#ifdef HAVE_3DNOW
+#if HAVE_3DNOW
 #define PREFETCH  "prefetch"
 #define PREFETCHW "prefetchw"
-#elif defined (HAVE_MMX2)
+#elif HAVE_MMX2
 #define PREFETCH "prefetchnta"
 #define PREFETCHW "prefetcht0"
 #else
@@ -47,26 +47,26 @@
 #define PREFETCHW " # nop"
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define SFENCE "sfence"
 #else
 #define SFENCE " # nop"
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
-#elif defined (HAVE_3DNOW)
+#elif HAVE_3DNOW
 #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
 #else
 #define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
 #endif
 #define MOVNTQ(a,b)  REAL_MOVNTQ(a,b)
 
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
 #include "swscale_altivec_template.c"
 #endif
 
@@ -865,7 +865,7 @@
     "cmp  "#dstw", "#index"     \n\t"\
     " jb       1b               \n\t"
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #undef WRITEBGR24
 #define WRITEBGR24(dst, dstw, index)  WRITEBGR24MMX2(dst, dstw, index)
 #else
@@ -895,7 +895,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, int16_t *lumFilter, int16_t *
                                     int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     if(!(c->flags & SWS_BITEXACT)){
         if (c->flags & SWS_ACCURATE_RND){
             if (uDest){
@@ -915,7 +915,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, int16_t *lumFilter, int16_t *
         return;
     }
 #endif
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
 yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize,
                       chrFilter, chrSrc, chrFilterSize,
                       dest, uDest, vDest, dstW, chrDstW);
@@ -939,7 +939,7 @@ static inline void RENAME(yuv2yuv1)(SwsContext *c, int16_t *lumSrc, int16_t *chr
                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW)
 {
     int i;
-#ifdef HAVE_MMX
+#if HAVE_MMX
     if(!(c->flags & SWS_BITEXACT)){
         long p= uDest ? 3 : 1;
         uint8_t *src[3]= {lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW};
@@ -1006,7 +1006,7 @@ static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_
                                        int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
                                        uint8_t *dest, long dstW, long dstY)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     long dummy=0;
     if(!(c->flags & SWS_BITEXACT)){
         if (c->flags & SWS_ACCURATE_RND){
@@ -1133,7 +1133,7 @@ static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_
         }
     }
 #endif /* HAVE_MMX */
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     /* The following list of supported dstFormat values should
        match what's found in the body of altivec_yuv2packedX() */
     if (c->dstFormat==PIX_FMT_ABGR  || c->dstFormat==PIX_FMT_BGRA  ||
@@ -1159,7 +1159,7 @@ static inline void RENAME(yuv2packed2)(SwsContext *c, uint16_t *buf0, uint16_t *
     int uvalpha1=4095-uvalpha;
     int i;
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
     if(!(c->flags & SWS_BITEXACT)){
         switch(c->dstFormat)
         {
@@ -1270,7 +1270,7 @@ static inline void RENAME(yuv2packed1)(SwsContext *c, uint16_t *buf0, uint16_t *
         return;
     }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
     if(!(flags & SWS_BITEXACT)){
         if (uvalpha < 2048) // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
         {
@@ -1464,7 +1464,7 @@ static inline void RENAME(yuv2packed1)(SwsContext *c, uint16_t *buf0, uint16_t *
 
 static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
     "movq "MANGLE(bm01010101)", %%mm2           \n\t"
     "mov                    %0, %%"REG_a"       \n\t"
@@ -1489,7 +1489,7 @@ static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, long width, uint3
 
 static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
     "movq "MANGLE(bm01010101)", %%mm4           \n\t"
     "mov                    %0, %%"REG_a"       \n\t"
@@ -1526,7 +1526,7 @@ static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1,
  * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
 static inline void RENAME(uyvyToY)(uint8_t *dst, uint8_t *src, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
     "mov                  %0, %%"REG_a"         \n\t"
     "1:                                         \n\t"
@@ -1550,7 +1550,7 @@ static inline void RENAME(uyvyToY)(uint8_t *dst, uint8_t *src, long width, uint3
 
 static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(
     "movq "MANGLE(bm01010101)", %%mm4           \n\t"
     "mov                    %0, %%"REG_a"       \n\t"
@@ -1643,7 +1643,7 @@ BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RU<<10, GU<<5, BU
 BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RU    , GU<<5, BU<<11, RV    , GV<<5, BV<<11, RGB2YUV_SHIFT+8)
 BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU    , GU<<5, BU<<10, RV    , GV<<5, BV<<10, RGB2YUV_SHIFT+7)
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, uint8_t *src, long width, int srcFormat)
 {
 
@@ -1758,7 +1758,7 @@ static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, uint8_t *
 
 static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
 #else
     int i;
@@ -1775,7 +1775,7 @@ static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, long width, uint
 
 static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
 #else
     int i;
@@ -1809,7 +1809,7 @@ static inline void RENAME(bgr24ToUV_half)(uint8_t *dstU, uint8_t *dstV, uint8_t
 
 static inline void RENAME(rgb24ToY)(uint8_t *dst, uint8_t *src, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
 #else
     int i;
@@ -1826,7 +1826,7 @@ static inline void RENAME(rgb24ToY)(uint8_t *dst, uint8_t *src, long width, uint
 
 static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width, uint32_t *unused)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     assert(src1==src2);
     RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
 #else
@@ -1908,7 +1908,7 @@ static inline void RENAME(monoblack2Y)(uint8_t *dst, uint8_t *src, long width, u
 static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc,
                                   int16_t *filter, int16_t *filterPos, long filterSize)
 {
-#ifdef HAVE_MMX
+#if HAVE_MMX
     assert(filterSize % 4 == 0 && filterSize>0);
     if (filterSize==4) // Always true for upscaling, sometimes for down, too.
     {
@@ -2064,7 +2064,7 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW
         );
     }
 #else
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize);
 #else
     int i;
@@ -2169,7 +2169,7 @@ static inline void RENAME(hyscale)(SwsContext *c, uint16_t *dst, long dstWidth,
         src= formatConvBuffer;
     }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
     // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
     if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
 #else
@@ -2180,8 +2180,8 @@ static inline void RENAME(hyscale)(SwsContext *c, uint16_t *dst, long dstWidth,
     }
     else // fast bilinear upscale / crap downscale
     {
-#if defined(ARCH_X86)
-#ifdef HAVE_MMX2
+#if ARCH_X86
+#if HAVE_MMX2
         int i;
 #if defined(PIC)
         uint64_t ebxsave __attribute__((aligned(8)));
@@ -2202,7 +2202,7 @@ static inline void RENAME(hyscale)(SwsContext *c, uint16_t *dst, long dstWidth,
             PREFETCH"      32(%%"REG_c")            \n\t"
             PREFETCH"      64(%%"REG_c")            \n\t"
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 
 #define FUNNY_Y_CODE \
             "movl            (%%"REG_b"), %%esi     \n\t"\
@@ -2292,7 +2292,7 @@ FUNNY_Y_CODE
         :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask)
         : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi"
         );
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         } //if MMX2 can't be used
 #endif
 #else
@@ -2305,7 +2305,7 @@ FUNNY_Y_CODE
             dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
             xpos+=xInc;
         }
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
     }
 
     if(c->srcRange != c->dstRange && !(isRGB(c->dstFormat) || isBGR(c->dstFormat))){
@@ -2441,7 +2441,7 @@ inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth,
         src2= formatConvBuffer+VOFW;
     }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
     // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
     if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
 #else
@@ -2453,8 +2453,8 @@ inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth,
     }
     else // fast bilinear upscale / crap downscale
     {
-#if defined(ARCH_X86)
-#ifdef HAVE_MMX2
+#if ARCH_X86
+#if HAVE_MMX2
         int i;
 #if defined(PIC)
         uint64_t ebxsave __attribute__((aligned(8)));
@@ -2475,7 +2475,7 @@ inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth,
             PREFETCH" 32(%%"REG_c")             \n\t"
             PREFETCH" 64(%%"REG_c")             \n\t"
 
-#ifdef ARCH_X86_64
+#if ARCH_X86_64
 
 #define FUNNY_UV_CODE \
             "movl       (%%"REG_b"), %%esi      \n\t"\
@@ -2573,7 +2573,7 @@ FUNNY_UV_CODE
 
 /* GCC 3.3 makes MPlayer crash on IA-32 machines when using "g" operand here,
    which is needed to support GCC 4.0. */
-#if defined(ARCH_X86_64) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if ARCH_X86_64 && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
             :: "m" (src1), "m" (dst), "g" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
 #else
             :: "m" (src1), "m" (dst), "m" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
@@ -2581,7 +2581,7 @@ FUNNY_UV_CODE
             "r" (src2)
             : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi"
             );
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         } //if MMX2 can't be used
 #endif
 #else
@@ -2599,7 +2599,7 @@ FUNNY_UV_CODE
             */
             xpos+=xInc;
         }
-#endif /* defined(ARCH_X86) */
+#endif /* ARCH_X86 */
     }
     if(c->srcRange != c->dstRange && !(isRGB(c->dstFormat) || isBGR(c->dstFormat))){
         int i;
@@ -2821,7 +2821,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s
             break; //we can't output a dstY line so let's try with the next slice
         }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
         c->blueDither= ff_dither8[dstY&1];
         if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555)
             c->greenDither= ff_dither8[dstY&1];
@@ -2833,7 +2833,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s
         {
             int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
             int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
-#ifdef HAVE_MMX
+#if HAVE_MMX
             int i;
         if (flags & SWS_ACCURATE_RND){
             int s= APCK_SIZE / 8;
@@ -2987,7 +2987,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s
         }
     }
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
     __asm__ volatile(SFENCE:::"memory");
     __asm__ volatile(EMMS:::"memory");
 #endif
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index d19430f..9dedd2a 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -45,28 +45,26 @@ extern const uint8_t dither_8x8_32[8][8];
 extern const uint8_t dither_8x8_73[8][8];
 extern const uint8_t dither_8x8_220[8][8];
 
-#ifdef HAVE_MMX
+#if HAVE_MMX
 
 /* hope these constant values are cache line aligned */
 DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw)   = 0x00ff00ff00ff00ffULL;
 DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
 DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
 
-#undef HAVE_MMX
-
 //MMX versions
 #undef RENAME
-#define HAVE_MMX
 #undef HAVE_MMX2
 #undef HAVE_3DNOW
+#define HAVE_MMX2 0
+#define HAVE_3DNOW 0
 #define RENAME(a) a ## _MMX
 #include "yuv2rgb_template.c"
 
 //MMX2 versions
 #undef RENAME
-#define HAVE_MMX
-#define HAVE_MMX2
-#undef HAVE_3DNOW
+#undef HAVE_MMX2
+#define HAVE_MMX2 1
 #define RENAME(a) a ## _MMX2
 #include "yuv2rgb_template.c"
 
@@ -485,7 +483,7 @@ EPILOG(1)
 
 SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
 {
-#if defined(HAVE_MMX2) || defined(HAVE_MMX)
+#if HAVE_MMX2 || HAVE_MMX
     if (c->flags & SWS_CPU_CAPS_MMX2){
         switch(c->dstFormat){
         case PIX_FMT_RGB32:  return yuv420_rgb32_MMX2;
@@ -503,19 +501,19 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
         }
     }
 #endif
-#ifdef HAVE_VIS
+#if HAVE_VIS
     {
         SwsFunc t= yuv2rgb_init_vis(c);
         if (t) return t;
     }
 #endif
-#ifdef CONFIG_MLIB
+#if CONFIG_MLIB
     {
         SwsFunc t= yuv2rgb_init_mlib(c);
         if (t) return t;
     }
 #endif
-#ifdef HAVE_ALTIVEC
+#if HAVE_ALTIVEC
     if (c->flags & SWS_CPU_CAPS_ALTIVEC)
     {
         SwsFunc t = yuv2rgb_init_altivec(c);
@@ -523,7 +521,7 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
     }
 #endif
 
-#ifdef ARCH_BFIN
+#if ARCH_BFIN
     if (c->flags & SWS_CPU_CAPS_BFIN)
     {
         SwsFunc t = ff_bfin_yuv2rgb_get_func_ptr (c);
diff --git a/libswscale/yuv2rgb_template.c b/libswscale/yuv2rgb_template.c
index e8b6ff3..c66f24e 100644
--- a/libswscale/yuv2rgb_template.c
+++ b/libswscale/yuv2rgb_template.c
@@ -30,14 +30,14 @@
 #undef EMMS
 #undef SFENCE
 
-#ifdef HAVE_3DNOW
+#if HAVE_3DNOW
 /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */
 #define EMMS     "femms"
 #else
 #define EMMS     "emms"
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define MOVNTQ "movntq"
 #define SFENCE "sfence"
 #else
@@ -335,7 +335,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr
         "1:             \n\t"
 YUV2RGB
         /* mm0=B, %%mm2=G, %%mm1=R */
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "movq "MANGLE(ff_M24A)", %%mm4     \n\t"
         "movq "MANGLE(ff_M24C)", %%mm7     \n\t"
         "pshufw $0x50, %%mm0, %%mm5     \n\t" /* B3 B2 B3 B2  B1 B0 B1 B0 */
diff --git a/tests/ffmpeg.regression.ref b/tests/ffmpeg.regression.ref
index 7102ecb..df19c03 100644
--- a/tests/ffmpeg.regression.ref
+++ b/tests/ffmpeg.regression.ref
@@ -237,12 +237,12 @@ stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
 1058444 ./tests/data/a-pcm_s16le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
-5a2c3500cf180e8f5fa47f725d635767 *./tests/data/a-pcm_s16be.mkv
-1066121 ./tests/data/a-pcm_s16be.mkv
+60594366d252826f839d527fb61fd31b *./tests/data/a-pcm_s16be.mkv
+1066118 ./tests/data/a-pcm_s16be.mkv
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
-2cc0a1fb4553d29cccfa99d8f4f2d6e8 *./tests/data/a-pcm_s16le.mkv
-1066121 ./tests/data/a-pcm_s16le.mkv
+73172ccaabfc945a6908955951ead16b *./tests/data/a-pcm_s16le.mkv
+1066118 ./tests/data/a-pcm_s16le.mkv
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
 4bc4cd19722f6456fd0e9b51ee0c30cf *./tests/data/a-pcm_s24be.mov
diff --git a/tests/libav.regression.ref b/tests/libav.regression.ref
index 22c1c40..1826b89 100644
--- a/tests/libav.regression.ref
+++ b/tests/libav.regression.ref
@@ -9,8 +9,8 @@ c351132527ccb1e8cab06cc0822fde23 *./tests/data/b-libav.rm
 bdb7484c68db722f66ba1630cf79844c *./tests/data/b-libav.mpg
 378880 ./tests/data/b-libav.mpg
 ./tests/data/b-libav.mpg CRC=0x2b71a386
-447b005e527cf495ec13092e788f028d *./tests/data/b-libav.ts
-471692 ./tests/data/b-libav.ts
+c0cc2ae4df6a8b3df84986929a393116 *./tests/data/b-libav.ts
+471316 ./tests/data/b-libav.ts
 ./tests/data/b-libav.ts CRC=0xcc4948e1
 1b28a16652bb8ac528b33f7478ca18b6 *./tests/data/b-libav.swf
 335771 ./tests/data/b-libav.swf
@@ -33,8 +33,8 @@ af78858062599fcbba049e4a02588a15 *./tests/data/b-libav.mov
 66a6584f9e83e8ea3af822a3ba71fbbe *./tests/data/b-libav.nut
 329264 ./tests/data/b-libav.nut
 ./tests/data/b-libav.nut CRC=0x400c29e9
-eae326ecf213a6f2ffb71a8a7afc5ef1 *./tests/data/b-libav.mkv
-329803 ./tests/data/b-libav.mkv
+6f4e64d21325f6721cdbddca2626e5df *./tests/data/b-libav.mkv
+329797 ./tests/data/b-libav.mkv
 ./tests/data/b-libav.mkv CRC=0x400c29e9
 af195c31e8f49de61e3851ccde4c3ebd *./tests/data/b-pbmpipe.pbm
 317075 ./tests/data/b-pbmpipe.pbm
diff --git a/tests/rotozoom.regression.ref b/tests/rotozoom.regression.ref
index 1390ea2..9507a51 100644
--- a/tests/rotozoom.regression.ref
+++ b/tests/rotozoom.regression.ref
@@ -237,12 +237,12 @@ stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
 1058444 ./tests/data/a-pcm_s16le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
-5a2c3500cf180e8f5fa47f725d635767 *./tests/data/a-pcm_s16be.mkv
-1066121 ./tests/data/a-pcm_s16be.mkv
+60594366d252826f839d527fb61fd31b *./tests/data/a-pcm_s16be.mkv
+1066118 ./tests/data/a-pcm_s16be.mkv
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
-2cc0a1fb4553d29cccfa99d8f4f2d6e8 *./tests/data/a-pcm_s16le.mkv
-1066121 ./tests/data/a-pcm_s16le.mkv
+73172ccaabfc945a6908955951ead16b *./tests/data/a-pcm_s16le.mkv
+1066118 ./tests/data/a-pcm_s16le.mkv
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
 4bc4cd19722f6456fd0e9b51ee0c30cf *./tests/data/a-pcm_s24be.mov
diff --git a/tests/seek.regression.ref b/tests/seek.regression.ref
index 90181f8..c173300 100644
--- a/tests/seek.regression.ref
+++ b/tests/seek.regression.ref
@@ -2954,59 +2954,59 @@ ret: 0 st:-1 ts:-0.645825 flags:1
 ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:748 size:55076 flags:1
 ----------------
 tests/data/b-libav.mkv
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st:-1 ts:-1.000000 flags:0
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st:-1 ts:1.894167 flags:1
-ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301387 size:27897 flags:1
+ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301381 size:27897 flags:1
 ret: 0 st: 0 ts:0.788000 flags:0
-ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:259121 size:10844 flags:0
+ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:259115 size:10844 flags:0
 ret: 0 st: 0 ts:-0.317000 flags:1
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st: 1 ts:2.577000 flags:0
 ret:-5
 ret: 0 st: 1 ts:1.471000 flags:1
-ret: 0 st: 1 dts:0.993000 pts:0.993000 pos:329507 size:209 flags:1
+ret: 0 st: 1 dts:0.993000 pts:0.993000 pos:329501 size:209 flags:1
 ret: 0 st:-1 ts:0.365002 flags:0
-ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:128834 size:9787 flags:0
+ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:128828 size:9787 flags:0
 ret: 0 st:-1 ts:-0.740831 flags:1
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st: 0 ts:2.153000 flags:0
 ret:-5
 ret: 0 st: 0 ts:1.048000 flags:1
-ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301387 size:27897 flags:1
+ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301381 size:27897 flags:1
 ret: 0 st: 1 ts:-0.058000 flags:0
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st: 1 ts:2.836000 flags:1
-ret: 0 st: 1 dts:0.993000 pts:0.993000 pos:329507 size:209 flags:1
+ret: 0 st: 1 dts:0.993000 pts:0.993000 pos:329501 size:209 flags:1
 ret: 0 st:-1 ts:1.730004 flags:0
 ret:-5
 ret: 0 st:-1 ts:0.624171 flags:1
-ret: 0 st: 0 dts:0.600000 pts:0.600000 pos:200763 size:11166 flags:0
+ret: 0 st: 0 dts:0.600000 pts:0.600000 pos:200757 size:11166 flags:0
 ret: 0 st: 0 ts:-0.482000 flags:0
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st: 0 ts:2.413000 flags:1
-ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301387 size:27897 flags:1
+ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301381 size:27897 flags:1
 ret: 0 st: 1 ts:1.307000 flags:0
 ret:-5
 ret: 0 st: 1 ts:0.201000 flags:1
-ret: 0 st: 1 dts:0.183000 pts:0.183000 pos:72878 size:209 flags:1
+ret: 0 st: 1 dts:0.183000 pts:0.183000 pos:72872 size:209 flags:1
 ret: 0 st:-1 ts:-0.904994 flags:0
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st:-1 ts:1.989173 flags:1
-ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301387 size:27897 flags:1
+ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:301381 size:27897 flags:1
 ret: 0 st: 0 ts:0.883000 flags:0
-ret: 0 st: 0 dts:0.920000 pts:0.920000 pos:290768 size:10395 flags:0
+ret: 0 st: 0 dts:0.920000 pts:0.920000 pos:290762 size:10395 flags:0
 ret: 0 st: 0 ts:-0.222000 flags:1
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ret: 0 st: 1 ts:2.672000 flags:0
 ret:-5
 ret: 0 st: 1 ts:1.566000 flags:1
-ret: 0 st: 1 dts:0.993000 pts:0.993000 pos:329507 size:209 flags:1
+ret: 0 st: 1 dts:0.993000 pts:0.993000 pos:329501 size:209 flags:1
 ret: 0 st:-1 ts:0.460008 flags:0
-ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149431 size:27412 flags:1
+ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149425 size:27412 flags:1
 ret: 0 st:-1 ts:-0.645825 flags:1
-ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:511 size:28088 flags:1
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1
 ----------------
 tests/data/b-libav.mmf
 ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:4096 flags:1
@@ -3420,59 +3420,59 @@ ret:-1 st:-1 ts:0.460008 flags:0
 ret:-1 st:-1 ts:-0.645825 flags:1
 ----------------
 tests/data/b-libav.ts
-ret: 0 st: 0 dts:-102481911520608.625000 pts:-102481911520608.625000 pos:-1 size:24921 flags:1
+ret: 0 st: 0 dts:0.660000 pts:0.700000 pos:-1 size:24921 flags:1
 ret: 0 st:-1 ts:-1.000000 flags:0
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st:-1 ts:1.894167 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.887078 pts:-102481911520608.625000 pos:-1 size:7907 flags:1
 ret: 0 st: 0 ts:0.788333 flags:0
-ret: 0 st: 0 dts:0.760000 pts:0.800000 pos:-1 size:12351 flags:1
+ret: 0 st: 0 dts:0.795878 pts:-102481911520608.625000 pos:-1 size:9043 flags:1
 ret: 0 st: 0 ts:-0.317500 flags:1
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st: 1 ts:2.576667 flags:0
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:2.580444 pts:-102481911520608.625000 pos:-1 size:5727 flags:1
 ret: 0 st: 1 ts:1.470833 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.466511 pts:-102481911520608.625000 pos:-1 size:10244 flags:1
 ret: 0 st:-1 ts:0.365002 flags:0
-ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:-1 size:208 flags:1
+ret: 0 st: 0 dts:0.379100 pts:-102481911520608.625000 pos:-1 size:7376 flags:1
 ret: 0 st:-1 ts:-0.740831 flags:1
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st: 0 ts:2.153333 flags:0
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:2.156089 pts:-102481911520608.625000 pos:-1 size:8674 flags:1
 ret: 0 st: 0 ts:1.047500 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.042156 pts:-102481911520608.625000 pos:-1 size:11942 flags:1
 ret: 0 st: 1 ts:-0.058333 flags:0
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st: 1 ts:2.835833 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:2.822933 pts:-102481911520608.625000 pos:-1 size:10429 flags:1
 ret: 0 st:-1 ts:1.730004 flags:0
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.731733 pts:-102481911520608.625000 pos:-1 size:13769 flags:1
 ret: 0 st:-1 ts:0.624171 flags:1
-ret: 0 st: 0 dts:0.600000 pts:0.640000 pos:-1 size:14233 flags:1
+ret: 0 st: 0 dts:0.617800 pts:-102481911520608.625000 pos:-1 size:14905 flags:1
 ret: 0 st: 0 ts:-0.481667 flags:0
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st: 0 ts:2.412500 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:2.406156 pts:-102481911520608.625000 pos:-1 size:13938 flags:1
 ret: 0 st: 1 ts:1.306667 flags:0
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.314956 pts:-102481911520608.625000 pos:-1 size:3107 flags:1
 ret: 0 st: 1 ts:0.200844 flags:1
-ret: 0 st: 0 dts:0.200000 pts:0.240000 pos:-1 size:13938 flags:1
+ret: 0 st: 0 dts:0.193444 pts:-102481911520608.625000 pos:-1 size:16166 flags:1
 ret: 0 st:-1 ts:-0.904994 flags:0
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st:-1 ts:1.989173 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.981800 pts:-102481911520608.625000 pos:-1 size:2039 flags:1
 ret: 0 st: 0 ts:0.883344 flags:0
-ret: 0 st: 0 dts:0.920000 pts:-102481911520608.625000 pos:-1 size:7258 flags:1
+ret: 0 st: 0 dts:0.890600 pts:-102481911520608.625000 pos:-1 size:3175 flags:1
 ret: 0 st: 0 ts:-0.222489 flags:1
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ret: 0 st: 1 ts:2.671678 flags:0
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:2.682744 pts:-102481911520608.625000 pos:-1 size:2253 flags:1
 ret: 0 st: 1 ts:1.565844 flags:1
-ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1
+ret: 0 st: 0 dts:1.557444 pts:-102481911520608.625000 pos:-1 size:5682 flags:1
 ret: 0 st:-1 ts:0.460008 flags:0
-ret: 0 st: 0 dts:0.440000 pts:0.480000 pos:-1 size:21317 flags:1
+ret: 0 st: 0 dts:0.466244 pts:-102481911520608.625000 pos:-1 size:4446 flags:1
 ret: 0 st:-1 ts:-0.645825 flags:1
-ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
 ----------------
 tests/data/b-libav.ul
 ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:1024 flags:1

-- 
FFmpeg packaging



More information about the pkg-multimedia-commits mailing list