Merge commit 'be039278b5ebd8075d90a3508db2aed5adf59e02'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 17 Mar 2014 12:23:48 +0000 (13:23 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 17 Mar 2014 12:23:48 +0000 (13:23 +0100)
* commit 'be039278b5ebd8075d90a3508db2aed5adf59e02':
  mpegvideo: move ff_draw_horiz_band() to mpegutils.c

Conflicts:
libavcodec/Makefile

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
configure
libavcodec/Makefile
libavcodec/mpegutils.c
libavcodec/mpegutils.h
libavcodec/mpegvideo.c
libavcodec/mpegvideo.h

diff --combined configure
+++ b/configure
@@@ -1,6 -1,6 +1,6 @@@
  #!/bin/sh
  #
 -# Libav configure script
 +# FFmpeg configure script
  #
  # Copyright (c) 2000-2002 Fabrice Bellard
  # Copyright (c) 2005-2008 Diego Biurrun
@@@ -44,9 -44,9 +44,9 @@@ if test "$E1" != 0 || test "$E2" = 0; t
      echo "No compatible shell script interpreter found."
      echo "This configure script requires a POSIX-compatible shell"
      echo "such as bash or ksh."
 -    echo "THIS IS NOT A BUG IN LIBAV, DO NOT REPORT IT AS SUCH."
 +    echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
      echo "Instead, install a working POSIX-compatible shell."
 -    echo "Disabling this configure test will create a broken Libav."
 +    echo "Disabling this configure test will create a broken FFmpeg."
      if test "$BASH_VERSION" = '2.04.0(1)-release'; then
          echo "This bash version ($BASH_VERSION) is broken on your platform."
          echo "Upgrade to a later version if available."
@@@ -78,17 -78,14 +78,17 @@@ Help options
  Standard options:
    --logfile=FILE           log tests and output to FILE [config.log]
    --disable-logging        do not log configure debug information
 +  --fatal-warnings         fail if any configure warning is generated
    --prefix=PREFIX          install in PREFIX [$prefix]
    --bindir=DIR             install binaries in DIR [PREFIX/bin]
 -  --datadir=DIR            install data files in DIR [PREFIX/share/avconv]
 -  --docdir=DIR             install documentation in DIR [PREFIX/share/doc/libav]
 +  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
 +  --docdir=DIR             install documentation in DIR [PREFIX/share/doc/ffmpeg]
    --libdir=DIR             install libs in DIR [PREFIX/lib]
    --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]
    --incdir=DIR             install includes in DIR [PREFIX/include]
    --mandir=DIR             install man page in DIR [PREFIX/share/man]
 +  --enable-rpath           use rpath to allow installing libraries in paths
 +                           not part of the dynamic linker search path
  
  Licensing options:
    --enable-gpl             allow use of GPL code, the resulting libs
@@@ -101,44 -98,31 +101,44 @@@ Configuration options
    --disable-static         do not build static libraries [no]
    --enable-shared          build shared libraries [no]
    --enable-small           optimize for size instead of speed
 -  --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
 +  --disable-runtime-cpudetect disable detecting cpu capabilities at runtime (smaller binary)
    --enable-gray            enable full grayscale support (slower color)
    --disable-swscale-alpha  disable alpha channel support in swscale
    --disable-all            disable building components, libraries and programs
 +  --enable-incompatible-libav-abi enable incompatible Libav fork ABI [no]
 +  --enable-incompatible-fork-abi  enable incompatible Libav fork ABI (deprecated) [no]
 +  --enable-raise-major     increase major version numbers in sonames [no]
  
  Program options:
    --disable-programs       do not build command line programs
 -  --disable-avconv         disable avconv build
 -  --disable-avplay         disable avplay build
 -  --disable-avprobe        disable avprobe build
 -  --disable-avserver       disable avserver build
 +  --disable-ffmpeg         disable ffmpeg build
 +  --disable-ffplay         disable ffplay build
 +  --disable-ffprobe        disable ffprobe build
 +  --disable-ffserver       disable ffserver build
  
 -Component options:
 +Documentation options:
    --disable-doc            do not build documentation
 +  --disable-htmlpages      do not build HTML documentation pages
 +  --disable-manpages       do not build man documentation pages
 +  --disable-podpages       do not build POD documentation pages
 +  --disable-txtpages       do not build text documentation pages
 +
 +Component options:
    --disable-avdevice       disable libavdevice build
    --disable-avcodec        disable libavcodec build
    --disable-avformat       disable libavformat build
    --disable-avutil         disable libavutil build
 +  --disable-swresample     disable libswresample build
    --disable-swscale        disable libswscale build
 -  --disable-avfilter       disable video filter support [no]
 -  --disable-avresample     disable libavresample build [no]
 +  --disable-postproc       disable libpostproc build
 +  --disable-avfilter       disable libavfilter build
 +  --enable-avresample      enable libavresample build [no]
    --disable-pthreads       disable pthreads [auto]
    --disable-w32threads     disable Win32 threads [auto]
 +  --disable-os2threads     disable OS/2 threads [auto]
    --disable-network        disable network support [no]
    --disable-dct            disable DCT code
 +  --disable-dwt            disable DWT code
    --disable-error-resilience disable error resilience code
    --disable-lsp            disable LSP code
    --disable-lzo            disable LZO decoder code
    --disable-fft            disable FFT code
  
  Hardware accelerators:
 -  --enable-dxva2           enable DXVA2 code
 -  --enable-vaapi           enable VAAPI code
 +  --disable-dxva2          disable DXVA2 code [autodetect]
 +  --disable-vaapi          disable VAAPI code [autodetect]
    --enable-vda             enable VDA code
 -  --enable-vdpau           enable VDPAU code
 +  --disable-vdpau          disable VDPAU code [autodetect]
  
  Individual component options:
    --disable-everything     disable all components listed below
  
  External library support:
    --enable-avisynth        enable reading of AviSynth script files [no]
 -  --enable-bzlib           enable bzlib [autodetect]
 +  --disable-bzlib          disable bzlib [autodetect]
 +  --enable-fontconfig      enable fontconfig
    --enable-frei0r          enable frei0r video filtering
    --enable-gnutls          enable gnutls [no]
 +  --disable-iconv          disable iconv [autodetect]
 +  --enable-ladspa          enable LADSPA audio filtering
 +  --enable-libaacplus      enable AAC+ encoding via libaacplus [no]
 +  --enable-libass          enable libass subtitles rendering [no]
 +  --enable-libbluray       enable BluRay reading using libbluray [no]
 +  --enable-libcaca         enable textual display using libcaca
 +  --enable-libcelt         enable CELT decoding via libcelt [no]
    --enable-libcdio         enable audio CD grabbing with libcdio
    --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                             and libraw1394 [no]
    --enable-libfaac         enable AAC encoding via libfaac [no]
    --enable-libfdk-aac      enable AAC de/encoding via libfdk-aac [no]
 +  --enable-libflite        enable flite (voice synthesis) support via libflite [no]
    --enable-libfreetype     enable libfreetype [no]
 +  --enable-libgme          enable Game Music Emu via libgme [no]
    --enable-libgsm          enable GSM de/encoding via libgsm [no]
 +  --enable-libiec61883     enable iec61883 via libiec61883 [no]
    --enable-libilbc         enable iLBC de/encoding via libilbc [no]
 +  --enable-libmodplug      enable ModPlug via libmodplug [no]
    --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
 +  --enable-libnut          enable NUT (de)muxing via libnut,
 +                           native (de)muxer exists [no]
    --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
    --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
    --enable-libopencv       enable video filtering via libopencv [no]
    --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
    --enable-libopus         enable Opus decoding via libopus [no]
    --enable-libpulse        enable Pulseaudio input via libpulse [no]
 +  --enable-libquvi         enable quvi input via libquvi [no]
    --enable-librtmp         enable RTMP[E] support via librtmp [no]
    --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
 +  --enable-libshine        enable fixed-point MP3 encoding via libshine [no]
 +  --enable-libsoxr         enable Include libsoxr resampling [no]
    --enable-libspeex        enable Speex de/encoding via libspeex [no]
 +  --enable-libssh          enable SFTP protocol via libssh [no]
 +  --enable-libstagefright-h264  enable H.264 decoding via libstagefright [no]
    --enable-libtheora       enable Theora encoding via libtheora [no]
 +  --enable-libtwolame      enable MP2 encoding via libtwolame [no]
 +  --enable-libutvideo      enable Ut Video encoding and decoding via libutvideo [no]
 +  --enable-libv4l2         enable libv4l2/v4l-utils [no]
 +  --enable-libvidstab      enable video stabilization using vid.stab [no]
    --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
    --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
 -  --enable-libvorbis       enable Vorbis encoding via libvorbis [no]
 +  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,
 +                           native implementation exists [no]
    --enable-libvpx          enable VP8 and VP9 de/encoding via libvpx [no]
    --enable-libwavpack      enable wavpack encoding via libwavpack [no]
    --enable-libwebp         enable WebP encoding via libwebp [no]
    --enable-libxavs         enable AVS encoding via xavs [no]
    --enable-libxvid         enable Xvid encoding via xvidcore,
                             native MPEG-4/Xvid encoder exists [no]
 +  --enable-libzmq          enable message passing via libzmq [no]
 +  --enable-libzvbi         enable teletext support via libzvbi [no]
 +  --enable-decklink        enable Blackmagick DeckLink output [no]
 +  --enable-openal          enable OpenAL 1.1 capture support [no]
 +  --enable-opencl          enable OpenCL code
 +  --enable-opengl          enable OpenGL rendering [no]
    --enable-openssl         enable openssl [no]
    --enable-x11grab         enable X11 grabbing [no]
 -  --enable-zlib            enable zlib [autodetect]
 +  --disable-xlib           disable xlib [autodetect]
 +  --disable-zlib           disable zlib [autodetect]
  
  Toolchain options:
    --arch=ARCH              select architecture [$arch]
    --cpu=CPU                select the minimum required CPU (affects
                             instruction selection, may crash on older CPUs)
    --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]
 +  --progs-suffix=SUFFIX    program name suffix []
    --enable-cross-compile   assume a cross-compiler is used
    --sysroot=PATH           root of cross-build tree
    --sysinclude=PATH        location of cross-build system headers
    --target-exec=CMD        command to run executables on target
    --target-path=DIR        path to view of build directory on target
    --target-samples=DIR     path to samples directory on target
 +  --tempprefix=PATH        force fixed dir/prefix instead of mktemp for checks
    --toolchain=NAME         set tool defaults according to NAME
    --pkg-config=PKGCONFIG   use pkg-config tool PKGCONFIG [$pkg_config_default]
 -  --nm=NM                  use nm tool
 +  --nm=NM                  use nm tool NM [$nm_default]
    --ar=AR                  use archive tool AR [$ar_default]
    --as=AS                  use assembler AS [$as_default]
 +  --windres=WINDRES        use windows resource compiler WINDRES [$windres_default]
 +  --yasmexe=EXE            use yasm-compatible assembler EXE [$yasmexe_default]
    --cc=CC                  use C compiler CC [$cc_default]
 +  --cxx=CXX                use C compiler CXX [$cxx_default]
    --dep-cc=DEPCC           use dependency generator DEPCC [$cc_default]
 -  --ld=LD                  use linker LD
 +  --ld=LD                  use linker LD [$ld_default]
    --pkg-config=PKGCONF     use pkg-config PKGCONF [$pkg_config_default]
    --pkg-config-flags=FLAGS pass additional flags to pkgconf []
    --host-cc=HOSTCC         use host C compiler HOSTCC
    --host-libs=HLIBS        use libs HLIBS when linking for host
    --host-os=OS             compiler host OS [$target_os]
    --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]
 +  --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS [$CXXFLAGS]
    --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
    --extra-libs=ELIBS       add ELIBS [$ELIBS]
    --extra-version=STRING   version string suffix []
@@@ -339,27 -286,14 +339,27 @@@ Optimization options (experts only)
    --disable-neon           disable NEON optimizations
    --disable-inline-asm     disable use of inline assembler
    --disable-yasm           disable use of yasm assembler
 +  --disable-mips32r2       disable MIPS32R2 optimizations
 +  --disable-mipsdspr1      disable MIPS DSP ASE R1 optimizations
 +  --disable-mipsdspr2      disable MIPS DSP ASE R2 optimizations
 +  --disable-mipsfpu        disable floating point MIPS optimizations
 +  --disable-fast-unaligned consider unaligned accesses slow
  
 -Developer options (useful when working on Libav itself):
 +Developer options (useful when working on FFmpeg itself):
    --disable-debug          disable debugging symbols
    --enable-debug=LEVEL     set the debug level [$debuglevel]
    --disable-optimizations  disable compiler optimizations
    --enable-extra-warnings  enable more compiler warnings
 +  --disable-stripping      disable stripping of executables and shared libraries
 +  --assert-level=level     0(default), 1 or 2, amount of assertion testing,
 +                           2 causes a slowdown at runtime.
 +  --enable-memory-poisoning fill heap uninitialized allocated space with arbitrary data
 +  --valgrind=VALGRIND      run "make fate" tests through valgrind to detect memory
 +                           leaks and errors, using the specified valgrind binary.
 +                           Cannot be combined with --target-exec
 +  --enable-ftrapv          Trap arithmetic overflows
    --samples=PATH           location of test samples for FATE, if not set use
 -                           \$LIBAV_SAMPLES at make invocation time.
 +                           \$FATE_SAMPLES at make invocation time.
    --enable-neon-clobber-test check NEON registers for clobbering (should be
                             used only for debugging purposes)
    --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
@@@ -406,7 -340,7 +406,7 @@@ die()
  
  If you think configure made a mistake, make sure you are using the latest
  version from Git.  If the latest version fails, report the problem to the
 -libav-tools@libav.org mailing list or IRC #libav on irc.freenode.net.
 +ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
  EOF
      if disabled logging; then
          cat <<EOF
@@@ -442,7 -376,7 +442,7 @@@ sh_quote()
  }
  
  cleanws(){
 -    echo "$@" | sed 's/^ *//;s/  */ /g;s/ *$//'
 +    echo "$@" | sed 's/^ *//;s/  */ /g;s/ *$//;s/\r//g'
  }
  
  filter(){
@@@ -694,12 -628,6 +694,12 @@@ print_config()
                  } else if (file ~ /\\.mak\$/) {
                      n = -v ? \"\" : \"!\";
                      printf(\"%s%s=yes\\n\", n, c) >>file;
 +                } else if (file ~ /\\.texi\$/) {
 +                    pre = -v ? \"\" : \"@c \";
 +                    yesno = \$2;
 +                    c2 = tolower(c);
 +                    gsub(/_/, \"-\", c2);
 +                    printf(\"%s@set %s %s\\n\", pre, c2, yesno) >>file;
                  }
              }
          }"
@@@ -733,10 -661,6 +733,10 @@@ add_cflags()
      append CFLAGS $($cflags_filter "$@")
  }
  
 +add_cxxflags(){
 +    append CXXFLAGS $($cflags_filter "$@")
 +}
 +
  add_asflags(){
      append ASFLAGS $($asflags_filter "$@")
  }
@@@ -746,7 -670,7 +746,7 @@@ add_ldflags()
  }
  
  add_stripflags(){
 -    append STRIPFLAGS "$@"
 +    append ASMSTRIPFLAGS "$@"
  }
  
  add_extralibs(){
@@@ -791,13 -715,6 +791,13 @@@ check_cc()
      check_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC
  }
  
 +check_cxx(){
 +    log check_cxx "$@"
 +    cat > $TMPCPP
 +    log_file $TMPCPP
 +    check_cmd $cxx $CPPFLAGS $CFLAGS $CXXFLAGS "$@" $CXX_C -o $TMPO $TMPCPP
 +}
 +
  check_cpp(){
      log check_cpp "$@"
      cat > $TMPC
@@@ -838,7 -755,7 +838,7 @@@ check_yasm()
      echo "$1" > $TMPS
      log_file $TMPS
      shift 1
 -    check_cmd $yasmexe $YASMFLAGS "$@" -o $TMPO $TMPS
 +    check_cmd $yasmexe $YASMFLAGS -Werror "$@" -o $TMPO $TMPS
  }
  
  ld_o(){
  
  check_ld(){
      log check_ld "$@"
 -    flags=$(filter_out '-l*' "$@")
 -    libs=$(filter '-l*' "$@")
 -    check_cc $($cflags_filter $flags) || return
 +    type=$1
 +    shift 1
 +    flags=$(filter_out '-l*|*.so' $@)
 +    libs=$(filter '-l*|*.so' $@)
 +    check_$type $($cflags_filter $flags) || return
      flags=$($ldflags_filter $flags)
      libs=$($ldflags_filter $libs)
      check_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs
@@@ -898,17 -813,9 +898,17 @@@ check_cflags()
      test_cflags "$@" && add_cflags "$@"
  }
  
 +check_cxxflags(){
 +    log check_cxxflags "$@"
 +    set -- $($cflags_filter "$@")
 +    check_cxx "$@" <<EOF && append CXXFLAGS "$@"
 +int x;
 +EOF
 +}
 +
  test_ldflags(){
      log test_ldflags "$@"
 -    check_ld "$@" <<EOF
 +    check_ld "cc" "$@" <<EOF
  int main(void){ return 0; }
  EOF
  }
@@@ -924,7 -831,7 +924,7 @@@ test_stripflags()
      check_cc <<EOF
  int main(void) { return 0; }
  EOF
 -    check_cmd $strip $STRIPFLAGS "$@" $TMPO
 +    check_cmd $strip $ASMSTRIPFLAGS "$@" $TMPO
  }
  
  check_stripflags(){
@@@ -948,7 -855,7 +948,7 @@@ check_func()
      func=$1
      shift
      disable $func
 -    check_ld "$@" <<EOF && enable $func
 +    check_ld "cc" "$@" <<EOF && enable $func
  extern int $func();
  int main(void){ $func(); }
  EOF
@@@ -961,10 -868,10 +961,10 @@@ check_mathfunc()
      shift 2
      test $narg = 2 && args="f, g" || args="f"
      disable $func
 -    check_ld "$@" <<EOF && enable $func
 +    check_ld "cc" "$@" <<EOF && enable $func
  #include <math.h>
  float foo(float f, float g) { return $func($args); }
 -int main(void){ return 0; }
 +int main(void){ return (int) foo; }
  EOF
  }
  
@@@ -981,26 -888,7 +981,26 @@@ check_func_headers()
              echo "long check_$func(void) { return (long) $func; }"
          done
          echo "int main(void) { return 0; }"
 -    } | check_ld "$@" && enable $funcs && enable_safe $headers
 +    } | check_ld "cc" "$@" && enable $funcs && enable_safe $headers
 +}
 +
 +check_class_headers_cpp(){
 +    log check_class_headers_cpp "$@"
 +    headers=$1
 +    classes=$2
 +    shift 2
 +    {
 +        for hdr in $headers; do
 +            echo "#include <$hdr>"
 +        done
 +        echo "int main(void) { "
 +        i=1
 +        for class in $classes; do
 +            echo "$class obj$i;"
 +            i=$(expr $i + 1)
 +        done
 +        echo "return 0; }"
 +    } | check_ld "cxx" "$@" && enable $funcs && enable_safe $headers
  }
  
  check_cpp_condition(){
@@@ -1032,22 -920,13 +1032,22 @@@ check_lib2()
      check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@"
  }
  
 +check_lib_cpp(){
 +    log check_lib_cpp "$@"
 +    headers="$1"
 +    classes="$2"
 +    shift 2
 +    check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@"
 +}
 +
  check_pkg_config(){
      log check_pkg_config "$@"
 -    pkg="$1"
 +    pkgandversion="$1"
 +    pkg="${1%% *}"
      headers="$2"
      funcs="$3"
      shift 3
 -    check_cmd $pkg_config --exists --print-errors $pkg || return
 +    check_cmd $pkg_config --exists --print-errors $pkgandversion || return
      pkg_cflags=$($pkg_config --cflags $pkg_config_flags $pkg)
      pkg_libs=$($pkg_config --libs $pkg_config_flags $pkg)
      check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
  }
  
  check_exec(){
 -    check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
 +    check_ld "cc" "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
  }
  
  check_exec_crash(){
@@@ -1116,7 -995,7 +1116,7 @@@ check_builtin()
      builtin=$3
      shift 3
      disable "$name"
 -    check_code ld "$headers" "$builtin" "$@" && enable "$name"
 +    check_code ld "$headers" "$builtin" "cc" "$@" && enable "$name"
  }
  
  check_compile_assert(){
@@@ -1145,14 -1024,6 +1145,14 @@@ require2()
      check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
  }
  
 +require_cpp(){
 +    name="$1"
 +    headers="$2"
 +    classes="$3"
 +    shift 3
 +    check_lib_cpp "$headers" "$classes" "$@" || die "ERROR: $name not found"
 +}
 +
  require_pkg_config(){
      pkg="$1"
      check_pkg_config "$@" || die "ERROR: $pkg not found"
      add_extralibs $(get_safe ${pkg}_libs)
  }
  
 +require_libfreetype(){
 +    log require_libfreetype "$@"
 +    pkg="freetype2"
 +    check_cmd $pkg_config --exists --print-errors $pkg \
 +      || die "ERROR: $pkg not found"
 +    pkg_cflags=$($pkg_config --cflags $pkg)
 +    pkg_libs=$($pkg_config --libs $pkg)
 +    {
 +        echo "#include <ft2build.h>"
 +        echo "#include FT_FREETYPE_H"
 +        echo "long check_func(void) { return (long) FT_Init_FreeType; }"
 +        echo "int main(void) { return 0; }"
 +    } | check_ld "cc" $pkg_cflags $pkg_libs \
 +      && set_safe ${pkg}_cflags $pkg_cflags \
 +      && set_safe ${pkg}_libs   $pkg_libs \
 +      || die "ERROR: $pkg not found"
 +    add_cflags    $(get_safe ${pkg}_cflags)
 +    add_extralibs $(get_safe ${pkg}_libs)
 +}
 +
  hostcc_e(){
      eval printf '%s\\n' $HOSTCC_E
  }
@@@ -1260,67 -1111,36 +1260,67 @@@ COMPONENT_LIST=
  "
  
  EXAMPLE_LIST="
 +    avio_reading_example
      avcodec_example
 +    demuxing_decoding_example
      filter_audio_example
 +    filtering_audio_example
 +    filtering_video_example
      metadata_example
 -    output_example
 +    muxing_example
 +    remuxing_example
 +    resampling_audio_example
 +    scaling_video_example
      transcode_aac_example
  "
  
  EXTERNAL_LIBRARY_LIST="
      avisynth
      bzlib
 +    crystalhd
 +    decklink
 +    fontconfig
      frei0r
      gnutls
 +    iconv
 +    ladspa
 +    libaacplus
 +    libass
 +    libbluray
 +    libcaca
      libcdio
 +    libcelt
      libdc1394
      libfaac
      libfdk_aac
 +    libflite
      libfreetype
 +    libgme
      libgsm
 +    libiec61883
      libilbc
 +    libmodplug
      libmp3lame
 +    libnut
      libopencore_amrnb
      libopencore_amrwb
      libopencv
      libopenjpeg
      libopus
      libpulse
 +    libquvi
      librtmp
      libschroedinger
 +    libshine
 +    libsoxr
      libspeex
 +    libssh
 +    libstagefright_h264
      libtheora
 +    libtwolame
 +    libutvideo
 +    libv4l2
 +    libvidstab
      libvo_aacenc
      libvo_amrwbenc
      libvorbis
      libx265
      libxavs
      libxvid
 +    libzmq
 +    libzvbi
 +    openal
 +    opencl
 +    opengl
      openssl
      x11grab
 +    xlib
      zlib
  "
  
 +DOCUMENT_LIST="
 +    doc
 +    htmlpages
 +    manpages
 +    podpages
 +    txtpages
 +"
 +
  FEATURE_LIST="
 +    ftrapv
      gray
      hardcoded_tables
      runtime_cpudetect
@@@ -1368,7 -1173,6 +1368,7 @@@ HWACCEL_LIST=
      vaapi
      vda
      vdpau
 +    xvmc
  "
  
  LIBRARY_LIST="
      avformat
      avresample
      avutil
 +    postproc
 +    swresample
      swscale
  "
  
@@@ -1390,17 -1192,16 +1390,17 @@@ LICENSE_LIST=
  "
  
  PROGRAM_LIST="
 -    avconv
 -    avplay
 -    avprobe
 -    avserver
 +    ffplay
 +    ffprobe
 +    ffserver
 +    ffmpeg
  "
  
  SUBSYSTEM_LIST="
      dct
 -    doc
 +    dwt
      error_resilience
 +    fast_unaligned
      fft
      lsp
      lzo
  
  CONFIG_LIST="
      $COMPONENT_LIST
 +    $DOCUMENT_LIST
      $EXAMPLE_LIST
      $EXTERNAL_LIBRARY_LIST
      $FEATURE_LIST
      $LIBRARY_LIST
      $PROGRAM_LIST
      $SUBSYSTEM_LIST
 +    incompatible_libav_abi
 +    incompatible_fork_abi
      memalign_hack
 +    memory_poisoning
      neon_clobber_test
      pic
      pod2man
 -    texi2html
 +    raise_major
      thumb
      xmm_clobber_test
  "
  
  THREADS_LIST="
      pthreads
 +    os2threads
      w32threads
  "
  
@@@ -1480,13 -1276,6 +1480,13 @@@ ARCH_EXT_LIST_ARM=
      vfpv3
  "
  
 +ARCH_EXT_LIST_MIPS="
 +    mipsfpu
 +    mips32r2
 +    mipsdspr1
 +    mipsdspr2
 +"
 +
  ARCH_EXT_LIST_X86_SIMD="
      amd3dnow
      amd3dnowext
@@@ -1522,8 -1311,8 +1522,8 @@@ ARCH_EXT_LIST=
      $ARCH_EXT_LIST_ARM
      $ARCH_EXT_LIST_PPC
      $ARCH_EXT_LIST_X86
 +    $ARCH_EXT_LIST_MIPS
      loongson
 -    vis
  "
  
  ARCH_FEATURES="
@@@ -1541,7 -1330,6 +1541,7 @@@ BUILTIN_LIST=
      MemoryBarrier
      mm_empty
      rdtsc
 +    sarestart
      sync_val_compare_and_swap
  "
  HAVE_LIST_CMDLINE="
  HAVE_LIST_PUB="
      bigendian
      fast_unaligned
 +    incompatible_libav_abi
 +    incompatible_fork_abi
  "
  
  HEADERS_LIST="
      alsa_asoundlib_h
      altivec_h
      arpa_inet_h
 +    asm_types_h
      cdio_paranoia_h
      cdio_paranoia_paranoia_h
 +    CL_cl_h
      dev_bktr_ioctl_bt848_h
      dev_bktr_ioctl_meteor_h
      dev_ic_bt8xx_h
      direct_h
      dlfcn_h
      dxva_h
 +    ES2_gl_h
      gsm_h
      io_h
      mach_mach_time_h
      machine_ioctl_bt848_h
      machine_ioctl_meteor_h
      malloc_h
 +    openjpeg_1_5_openjpeg_h
 +    OpenGL_gl3_h
      poll_h
      sndio_h
      soundcard_h
      sys_time_h
      sys_un_h
      sys_videoio_h
 +    termios_h
      unistd_h
      windows_h
      winsock2_h
  MATH_FUNCS="
      atanf
      atan2f
 +    cbrt
      cbrtf
      cosf
      exp2
  "
  
  SYSTEM_FUNCS="
 +    access
      aligned_malloc
 +    clock_gettime
      closesocket
      CommandLineToArgvW
      CryptGenRandom
      getservbyport
      GetSystemTimeAsFileTime
      gettimeofday
 +    glob
 +    glXGetProcAddress
      inet_aton
      isatty
      jack_port_get_latency_range
 +    kbhit
      localtime_r
 +    lzo1x_999_compress
      mach_absolute_time
      MapViewOfFile
      memalign
      mmap
      mprotect
      nanosleep
 +    PeekNamedPipe
      posix_memalign
 +    pthread_cancel
      sched_getaffinity
      SetConsoleTextAttribute
      setmode
      setrlimit
      Sleep
      strerror_r
 -    strptime
      sysconf
      sysctl
      usleep
      VirtualAlloc
 +    wglGetProcAddress
  "
  
  TOOLCHAIN_FEATURES="
      ebp_available
      ebx_available
      gnu_as
 +    gnu_windres
      ibm_asm
      inline_asm_labels
      pragma_deprecated
 +    rsync_contimeout
      symver_asm_label
      symver_gnu_asm
      vfp_args
@@@ -1706,11 -1475,9 +1706,11 @@@ TYPES_LIST=
      struct_ipv6_mreq
      struct_pollfd
      struct_rusage_ru_maxrss
 +    struct_sctp_event_subscribe
      struct_sockaddr_in6
      struct_sockaddr_sa_len
      struct_sockaddr_storage
 +    struct_stat_st_mtim_tv_nsec
      struct_v4l2_frmivalenum_discrete
  "
  
@@@ -1734,11 -1501,7 +1734,11 @@@ HAVE_LIST=
      libc_msvcrt
      libdc1394_1
      libdc1394_2
 +    makeinfo
 +    perl
 +    pod2man
      sdl
 +    texi2html
      threads
      vdpau_x11
      xlib
@@@ -1750,8 -1513,6 +1750,8 @@@ CONFIG_EXTRA=
      ac3dsp
      audio_frame_queue
      dsputil
 +    exif
 +    frame_thread_encoder
      gcrypt
      golomb
      gplv3
      huffman
      intrax8
      lgplv3
 +    llviddsp
      lpc
      mpegaudio
      mpegaudiodsp
@@@ -1793,8 -1553,6 +1793,8 @@@ CMDLINE_SELECT=
      logging
      lto
      optimizations
 +    rpath
 +    stripping
  "
  
  PATHS_LIST="
@@@ -1813,12 -1571,10 +1813,12 @@@ CMDLINE_SET=
      ar
      arch
      as
 +    assert_level
      build_suffix
      cc
      cpu
      cross_prefix
 +    cxx
      dep_cc
      extra_version
      host_cc
      host_ldflags
      host_libs
      host_os
 +    install
      ld
      logfile
      malloc_prefix
      optflags
      pkg_config
      pkg_config_flags
 +    progs_suffix
      random_seed
      samples
 +    strip
      sysinclude
      sysroot
      target_exec
      target_os
      target_path
      target_samples
 +    tempprefix
      toolchain
 +    valgrind
 +    yasmexe
  "
  
  CMDLINE_APPEND="
      extra_cflags
 +    extra_cxxflags
      host_cppflags
  "
  
@@@ -1870,11 -1619,6 +1870,11 @@@ vfpv3_deps="vfp
  
  map 'eval ${v}_inline_deps=inline_asm' $ARCH_EXT_LIST_ARM
  
 +mipsfpu_deps="mips"
 +mips32r2_deps="mips"
 +mipsdspr1_deps="mips"
 +mipsdspr2_deps="mips"
 +
  altivec_deps="ppc"
  ppc4xx_deps="ppc"
  
@@@ -1933,12 -1677,11 +1933,12 @@@ threads_if_any="$THREADS_LIST
  # subsystems
  dct_select="rdft"
  error_resilience_select="dsputil"
 +frame_thread_encoder_deps="encoders threads"
  mdct_select="fft"
  rdft_select="fft"
  mpegaudio_select="mpegaudiodsp"
  mpegaudiodsp_select="dct"
 -mpegvideo_select="dsputil hpeldsp videodsp"
 +mpegvideo_select="dsputil h264chroma hpeldsp videodsp"
  mpegvideoenc_select="dsputil mpegvideo"
  
  # decoders / encoders
@@@ -1953,8 -1696,7 +1953,8 @@@ alac_encoder_select="lpc
  als_decoder_select="dsputil"
  amrnb_decoder_select="lsp"
  amrwb_decoder_select="lsp"
 -amv_decoder_select="sp5x_decoder"
 +amv_decoder_select="sp5x_decoder exif"
 +amv_encoder_select="aandcttables"
  ape_decoder_select="dsputil"
  asv1_decoder_select="dsputil"
  asv1_encoder_select="dsputil"
@@@ -1963,7 -1705,6 +1963,7 @@@ asv2_encoder_select="dsputil
  atrac1_decoder_select="mdct sinewin"
  atrac3_decoder_select="mdct"
  atrac3p_decoder_select="mdct sinewin"
 +avrn_decoder_select="exif"
  bink_decoder_select="dsputil hpeldsp"
  binkaudio_dct_decoder_select="mdct rdft dct sinewin"
  binkaudio_rdft_decoder_select="mdct rdft sinewin"
@@@ -1974,18 -1715,16 +1974,18 @@@ cook_decoder_select="dsputil mdct sinew
  cscd_decoder_select="lzo"
  cscd_decoder_suggest="zlib"
  dca_decoder_select="mdct"
 +dirac_decoder_select="dsputil dwt golomb videodsp"
  dnxhd_decoder_select="dsputil"
  dnxhd_encoder_select="aandcttables dsputil mpegvideoenc"
  dvvideo_decoder_select="dsputil"
  dvvideo_encoder_select="dsputil"
 -dxa_decoder_deps="zlib"
 +dxa_decoder_select="zlib"
  eac3_decoder_select="ac3_decoder"
  eac3_encoder_select="ac3_encoder"
  eamad_decoder_select="aandcttables dsputil mpegvideo"
 -eatgq_decoder_select="aandcttables dsputil"
 +eatgq_decoder_select="aandcttables"
  eatqi_decoder_select="aandcttables dsputil error_resilience mpegvideo"
 +exr_decoder_select="zlib"
  ffv1_decoder_select="golomb rangecoder"
  ffv1_encoder_select="rangecoder"
  ffvhuff_decoder_select="huffyuv_decoder"
@@@ -1993,16 -1732,15 +1993,16 @@@ ffvhuff_encoder_select="huffyuv_encoder
  fic_decoder_select="dsputil golomb"
  flac_decoder_select="golomb"
  flac_encoder_select="dsputil golomb lpc"
 -flashsv_decoder_deps="zlib"
 -flashsv_encoder_deps="zlib"
 -flashsv2_decoder_deps="zlib"
 +flashsv_decoder_select="zlib"
 +flashsv_encoder_select="zlib"
 +flashsv2_encoder_select="zlib"
 +flashsv2_decoder_select="zlib"
  flv_decoder_select="h263_decoder"
  flv_encoder_select="h263_encoder"
  fourxm_decoder_select="dsputil"
  fraps_decoder_select="dsputil huffman"
 -g2m_decoder_deps="zlib"
 -g2m_decoder_select="dsputil"
 +g2m_decoder_select="dsputil zlib"
 +g729_decoder_select="dsputil"
  h261_decoder_select="error_resilience mpegvideo"
  h261_encoder_select="aandcttables mpegvideoenc"
  h263_decoder_select="error_resilience h263_parser h263dsp mpegvideo"
@@@ -2012,8 -1750,8 +2012,8 @@@ h263p_encoder_select="h263_encoder
  h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel videodsp"
  h264_decoder_suggest="error_resilience"
  hevc_decoder_select="dsputil golomb videodsp"
 -huffyuv_decoder_select="dsputil"
 -huffyuv_encoder_select="dsputil huffman"
 +huffyuv_decoder_select="dsputil llviddsp"
 +huffyuv_encoder_select="dsputil huffman llviddsp"
  iac_decoder_select="imc_decoder"
  imc_decoder_select="dsputil fft mdct sinewin"
  indeo3_decoder_select="hpeldsp"
@@@ -2027,7 -1765,7 +2027,7 @@@ loco_decoder_select="golomb
  mdec_decoder_select="dsputil error_resilience mpegvideo"
  metasound_decoder_select="lsp mdct sinewin"
  mimic_decoder_select="dsputil hpeldsp"
 -mjpeg_decoder_select="dsputil hpeldsp"
 +mjpeg_decoder_select="dsputil hpeldsp exif"
  mjpeg_encoder_select="aandcttables mpegvideoenc"
  mjpegb_decoder_select="mjpeg_decoder"
  mlp_decoder_select="mlp_parser"
@@@ -2047,9 -1785,9 +2047,9 @@@ mpc8_decoder_select="mpegaudiodsp
  mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
  mpeg_xvmc_decoder_select="mpeg2video_decoder"
  mpeg1video_decoder_select="error_resilience mpegvideo"
 -mpeg1video_encoder_select="aandcttables mpegvideoenc"
 +mpeg1video_encoder_select="aandcttables mpegvideoenc h263dsp"
  mpeg2video_decoder_select="error_resilience mpegvideo"
 -mpeg2video_encoder_select="aandcttables mpegvideoenc"
 +mpeg2video_encoder_select="aandcttables mpegvideoenc h263dsp"
  mpeg4_decoder_select="h263_decoder mpeg4video_parser"
  mpeg4_encoder_select="h263_encoder"
  msmpeg4v1_decoder_select="h263_decoder"
@@@ -2062,15 -1800,15 +2062,15 @@@ mxpeg_decoder_select="mjpeg_decoder
  nellymoser_decoder_select="mdct sinewin"
  nellymoser_encoder_select="audio_frame_queue mdct sinewin"
  nuv_decoder_select="dsputil lzo"
 -png_decoder_deps="zlib"
 -png_encoder_deps="zlib"
 -png_encoder_select="dsputil"
 +png_decoder_select="zlib"
 +png_encoder_select="dsputil zlib"
  prores_decoder_select="dsputil"
  prores_encoder_select="dsputil"
  qcelp_decoder_select="lsp"
  qdm2_decoder_select="mdct rdft mpegaudiodsp"
  ra_144_encoder_select="audio_frame_queue lpc"
  ralf_decoder_select="golomb"
 +rtjpeg_decoder_select="dsputil"
  rv10_decoder_select="error_resilience h263_decoder h263dsp"
  rv10_encoder_select="h263_encoder"
  rv20_decoder_select="error_resilience h263_decoder h263dsp"
@@@ -2079,25 -1817,20 +2079,25 @@@ rv30_decoder_select="error_resilience g
  rv40_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo videodsp"
  shorten_decoder_select="golomb"
  sipr_decoder_select="lsp"
 +snow_decoder_select="dsputil dwt h264qpel hpeldsp rangecoder"
 +snow_encoder_select="aandcttables dsputil dwt h264qpel hpeldsp mpegvideoenc rangecoder"
 +sonic_decoder_select="golomb rangecoder"
 +sonic_encoder_select="golomb rangecoder"
 +sonic_ls_encoder_select="golomb"
  sp5x_decoder_select="mjpeg_decoder"
  svq1_decoder_select="hpeldsp"
  svq1_encoder_select="aandcttables dsputil hpeldsp mpegvideoenc"
- svq3_decoder_select="h264_decoder hpeldsp mpegvideo"
+ svq3_decoder_select="h264_decoder hpeldsp"
  svq3_decoder_suggest="zlib"
  tak_decoder_select="dsputil"
  theora_decoder_select="vp3_decoder"
  thp_decoder_select="mjpeg_decoder"
  tiff_decoder_suggest="zlib"
  tiff_encoder_suggest="zlib"
 -truehd_decoder_select="mlp_decoder"
 +truehd_decoder_select="mlp_parser"
  truemotion2_decoder_select="dsputil"
  truespeech_decoder_select="dsputil"
 -tscc_decoder_deps="zlib"
 +tscc_decoder_select="zlib"
  twinvq_decoder_select="mdct lsp sinewin"
  utvideo_decoder_select="dsputil"
  utvideo_encoder_select="dsputil huffman"
@@@ -2126,103 -1859,71 +2126,103 @@@ wmv2_decoder_select="h263_decoder intra
  wmv2_encoder_select="h263_encoder"
  wmv3_decoder_select="vc1_decoder"
  wmv3image_decoder_select="wmv3_decoder"
 -zerocodec_decoder_deps="zlib"
 -zlib_decoder_deps="zlib"
 -zlib_encoder_deps="zlib"
 -zmbv_decoder_deps="zlib"
 -zmbv_encoder_deps="zlib"
 +zerocodec_decoder_select="zlib"
 +zlib_decoder_select="zlib"
 +zlib_encoder_select="zlib"
 +zmbv_decoder_select="zlib"
 +zmbv_encoder_select="zlib"
  
  # hardware accelerators
 +crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
  dxva2_deps="dxva2api_h"
  vaapi_deps="va_va_h"
  vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
  vda_extralibs="-framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore"
  vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
 +xvmc_deps="X11_extensions_XvMClib_h"
  
  h263_vaapi_hwaccel_deps="vaapi"
  h263_vaapi_hwaccel_select="h263_decoder"
  h263_vdpau_hwaccel_deps="vdpau"
  h263_vdpau_hwaccel_select="h263_decoder"
 +h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
  h264_dxva2_hwaccel_deps="dxva2"
  h264_dxva2_hwaccel_select="h264_decoder"
  h264_vaapi_hwaccel_deps="vaapi"
  h264_vaapi_hwaccel_select="h264_decoder"
 +h264_vda_decoder_deps="vda"
 +h264_vda_decoder_select="h264_decoder"
  h264_vda_hwaccel_deps="vda"
  h264_vda_hwaccel_select="h264_decoder"
 +h264_vdpau_decoder_deps="vdpau"
 +h264_vdpau_decoder_select="h264_decoder"
  h264_vdpau_hwaccel_deps="vdpau"
  h264_vdpau_hwaccel_select="h264_decoder"
 +mpeg_vdpau_decoder_deps="vdpau"
 +mpeg_vdpau_decoder_select="mpeg2video_decoder"
 +mpeg_xvmc_hwaccel_deps="xvmc"
 +mpeg_xvmc_hwaccel_select="mpeg2video_decoder"
 +mpeg1_vdpau_decoder_deps="vdpau"
 +mpeg1_vdpau_decoder_select="mpeg1video_decoder"
  mpeg1_vdpau_hwaccel_deps="vdpau"
  mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
 +mpeg1_xvmc_hwaccel_deps="xvmc"
 +mpeg1_xvmc_hwaccel_select="mpeg1video_decoder"
 +mpeg2_crystalhd_decoder_select="crystalhd"
  mpeg2_dxva2_hwaccel_deps="dxva2"
  mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
  mpeg2_vaapi_hwaccel_deps="vaapi"
  mpeg2_vaapi_hwaccel_select="mpeg2video_decoder"
  mpeg2_vdpau_hwaccel_deps="vdpau"
  mpeg2_vdpau_hwaccel_select="mpeg2video_decoder"
 +mpeg2_xvmc_hwaccel_deps="xvmc"
 +mpeg2_xvmc_hwaccel_select="mpeg2video_decoder"
 +mpeg4_crystalhd_decoder_select="crystalhd"
  mpeg4_vaapi_hwaccel_deps="vaapi"
  mpeg4_vaapi_hwaccel_select="mpeg4_decoder"
 +mpeg4_vdpau_decoder_deps="vdpau"
 +mpeg4_vdpau_decoder_select="mpeg4_decoder"
  mpeg4_vdpau_hwaccel_deps="vdpau"
  mpeg4_vdpau_hwaccel_select="mpeg4_decoder"
 +msmpeg4_crystalhd_decoder_select="crystalhd"
 +vc1_crystalhd_decoder_select="crystalhd"
  vc1_dxva2_hwaccel_deps="dxva2"
  vc1_dxva2_hwaccel_select="vc1_decoder"
  vc1_vaapi_hwaccel_deps="vaapi"
  vc1_vaapi_hwaccel_select="vc1_decoder"
 +vc1_vdpau_decoder_deps="vdpau"
 +vc1_vdpau_decoder_select="vc1_decoder"
  vc1_vdpau_hwaccel_deps="vdpau"
  vc1_vdpau_hwaccel_select="vc1_decoder"
 +wmv3_crystalhd_decoder_select="crystalhd"
  wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
  wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
 +wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
  wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
  
  # parsers
  h264_parser_select="golomb h264chroma h264dsp h264pred h264qpel videodsp"
 +hevc_parser_select="hevc_decoder"
  mpeg4video_parser_select="error_resilience h263dsp mpegvideo"
  mpegvideo_parser_select="error_resilience mpegvideo"
  vc1_parser_select="mpegvideo"
  
  # external libraries
 +libaacplus_encoder_deps="libaacplus"
 +libcelt_decoder_deps="libcelt"
  libfaac_encoder_deps="libfaac"
  libfaac_encoder_select="audio_frame_queue"
  libfdk_aac_decoder_deps="libfdk_aac"
  libfdk_aac_encoder_deps="libfdk_aac"
  libfdk_aac_encoder_select="audio_frame_queue"
 +libgme_demuxer_deps="libgme"
  libgsm_decoder_deps="libgsm"
  libgsm_encoder_deps="libgsm"
  libgsm_ms_decoder_deps="libgsm"
  libgsm_ms_encoder_deps="libgsm"
  libilbc_decoder_deps="libilbc"
  libilbc_encoder_deps="libilbc"
 +libmodplug_demuxer_deps="libmodplug"
  libmp3lame_encoder_deps="libmp3lame"
  libmp3lame_encoder_select="audio_frame_queue"
  libopencore_amrnb_decoder_deps="libopencore_amrnb"
@@@ -2234,21 -1935,15 +2234,21 @@@ libopenjpeg_encoder_deps="libopenjpeg
  libopus_decoder_deps="libopus"
  libopus_encoder_deps="libopus"
  libopus_encoder_select="audio_frame_queue"
 +libquvi_demuxer_deps="libquvi"
  libschroedinger_decoder_deps="libschroedinger"
  libschroedinger_encoder_deps="libschroedinger"
 +libshine_encoder_deps="libshine"
 +libshine_encoder_select="audio_frame_queue"
  libspeex_decoder_deps="libspeex"
  libspeex_encoder_deps="libspeex"
  libspeex_encoder_select="audio_frame_queue"
 +libstagefright_h264_decoder_deps="libstagefright_h264"
  libtheora_encoder_deps="libtheora"
 +libtwolame_encoder_deps="libtwolame"
  libvo_aacenc_encoder_deps="libvo_aacenc"
  libvo_aacenc_encoder_select="audio_frame_queue"
  libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
 +libvorbis_decoder_deps="libvorbis"
  libvorbis_encoder_deps="libvorbis"
  libvorbis_encoder_select="audio_frame_queue"
  libvpx_vp8_decoder_deps="libvpx"
@@@ -2258,13 -1953,9 +2258,13 @@@ libvpx_vp9_encoder_deps="libvpx
  libwavpack_encoder_deps="libwavpack"
  libwebp_encoder_deps="libwebp"
  libx264_encoder_deps="libx264"
 +libx264rgb_encoder_deps="libx264"
  libx265_encoder_deps="libx265"
  libxavs_encoder_deps="libxavs"
  libxvid_encoder_deps="libxvid"
 +libutvideo_decoder_deps="libutvideo"
 +libutvideo_encoder_deps="libutvideo"
 +libzvbi_teletext_decoder_deps="libzvbi"
  
  # demuxers / muxers
  ac3_demuxer_select="ac3_parser"
@@@ -2277,8 -1968,6 +2277,8 @@@ avisynth_demuxer_deps="avisynth
  avisynth_demuxer_select="riffdec"
  caf_demuxer_select="riffdec"
  dirac_demuxer_select="dirac_parser"
 +dts_demuxer_select="dca_parser"
 +dtshd_demuxer_select="dca_parser"
  dxa_demuxer_select="riffdec"
  eac3_demuxer_select="ac3_parser"
  f4v_muxer_select="mov_muxer"
@@@ -2287,8 -1976,6 +2287,8 @@@ hds_muxer_select="flv_muxer
  hls_muxer_select="mpegts_muxer"
  ipod_muxer_select="mov_muxer"
  ismv_muxer_select="mov_muxer"
 +libnut_demuxer_deps="libnut"
 +libnut_muxer_deps="libnut"
  matroska_audio_muxer_select="matroska_muxer"
  matroska_demuxer_select="riffdec"
  matroska_demuxer_suggest="bzlib lzo zlib"
@@@ -2318,14 -2005,11 +2318,14 @@@ spdif_muxer_select="aac_parser
  tak_demuxer_select="tak_parser"
  tg2_muxer_select="mov_muxer"
  tgp_muxer_select="mov_muxer"
 +vobsub_demuxer_select="mpegps_demuxer"
  w64_demuxer_select="wav_demuxer"
 +w64_muxer_select="wav_muxer"
  wav_demuxer_select="riffdec"
  wav_muxer_select="riffenc"
  webm_muxer_select="riffenc"
  wtv_demuxer_select="riffdec"
 +wtv_muxer_select="riffenc"
  xmv_demuxer_select="riffdec"
  xwma_demuxer_select="riffdec"
  
  alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
  alsa_outdev_deps="alsa_asoundlib_h"
  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
 +caca_outdev_deps="libcaca"
 +decklink_outdev_deps="decklink pthreads"
 +decklink_outdev_extralibs="-lstdc++"
 +dshow_indev_deps="IBaseFilter"
 +dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid"
  dv1394_indev_deps="dv1394"
  dv1394_indev_select="dv_demuxer"
  fbdev_indev_deps="linux_fb_h"
 -jack_indev_deps="jack_jack_h pthreads"
 +fbdev_outdev_deps="linux_fb_h"
 +iec61883_indev_deps="libiec61883"
 +jack_indev_deps="jack_jack_h sem_timedwait"
 +lavfi_indev_deps="avfilter"
  libcdio_indev_deps="libcdio"
  libdc1394_indev_deps="libdc1394"
 +libv4l2_indev_deps="libv4l2"
 +openal_indev_deps="openal"
 +opengl_outdev_deps="opengl"
  oss_indev_deps_any="soundcard_h sys_soundcard_h"
  oss_outdev_deps_any="soundcard_h sys_soundcard_h"
  pulse_indev_deps="libpulse"
 +pulse_outdev_deps="libpulse"
 +sdl_outdev_deps="sdl"
  sndio_indev_deps="sndio_h"
  sndio_outdev_deps="sndio_h"
 +v4l_indev_deps="linux_videodev_h"
  v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
 +v4l2_outdev_deps_any="linux_videodev2_h sys_videoio_h"
  vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines"
  vfwcap_indev_extralibs="-lavicap32"
 -x11grab_indev_deps="x11grab XShmCreateImage"
 +xv_outdev_deps="X11_extensions_Xvlib_h XvGetPortAttribute"
 +xv_outdev_extralibs="-lXv -lX11 -lXext"
 +x11grab_indev_deps="x11grab"
  
  # protocols
 +bluray_protocol_deps="libbluray"
  ffrtmpcrypt_protocol_deps="!librtmp_protocol"
  ffrtmpcrypt_protocol_deps_any="gcrypt nettle openssl"
  ffrtmpcrypt_protocol_select="tcp_protocol"
  ffrtmphttp_protocol_deps="!librtmp_protocol"
  ffrtmphttp_protocol_select="http_protocol"
 +ftp_protocol_select="tcp_protocol"
  gopher_protocol_select="network"
  http_protocol_select="tcp_protocol"
  httpproxy_protocol_select="tcp_protocol"
@@@ -2383,7 -2048,6 +2383,7 @@@ librtmpe_protocol_deps="librtmp
  librtmps_protocol_deps="librtmp"
  librtmpt_protocol_deps="librtmp"
  librtmpte_protocol_deps="librtmp"
 +libssh_protocol_deps="libssh"
  mmsh_protocol_select="http_protocol"
  mmst_protocol_select="network"
  rtmp_protocol_deps="!librtmp_protocol"
@@@ -2406,82 -2070,27 +2406,82 @@@ unix_protocol_deps="sys_un_h
  unix_protocol_select="network"
  
  # filters
 +aconvert_filter_deps="swresample"
 +amovie_filter_deps="avcodec avformat"
 +aresample_filter_deps="swresample"
 +ass_filter_deps="libass"
 +asyncts_filter_deps="avresample"
 +atempo_filter_deps="avcodec"
 +atempo_filter_select="rdft"
 +azmq_filter_deps="libzmq"
  blackframe_filter_deps="gpl"
  boxblur_filter_deps="gpl"
 +colormatrix_filter_deps="gpl"
  cropdetect_filter_deps="gpl"
 +dctdnoiz_filter_deps="avcodec"
 +dctdnoiz_filter_select="dct"
  delogo_filter_deps="gpl"
 +deshake_filter_deps="avcodec"
 +deshake_filter_select="dsputil"
  drawtext_filter_deps="libfreetype"
 +ebur128_filter_deps="gpl"
 +flite_filter_deps="libflite"
  frei0r_filter_deps="frei0r dlopen"
  frei0r_filter_extralibs='$ldl'
  frei0r_src_filter_deps="frei0r dlopen"
  frei0r_src_filter_extralibs='$ldl'
 +geq_filter_deps="gpl"
 +histeq_filter_deps="gpl"
  hqdn3d_filter_deps="gpl"
  interlace_filter_deps="gpl"
 +kerndeint_filter_deps="gpl"
 +ladspa_filter_deps="ladspa dlopen"
 +mcdeint_filter_deps="avcodec gpl"
 +movie_filter_deps="avcodec avformat"
 +mp_filter_deps="gpl avcodec swscale inline_asm"
 +mpdecimate_filter_deps="gpl avcodec"
 +mptestsrc_filter_deps="gpl"
 +negate_filter_deps="lut_filter"
 +perspective_filter_deps="gpl"
  ocv_filter_deps="libopencv"
 +owdenoise_filter_deps="gpl"
 +pan_filter_deps="swresample"
 +phase_filter_deps="gpl"
 +pp_filter_deps="gpl postproc"
 +pullup_filter_deps="gpl"
 +removelogo_filter_deps="avcodec avformat swscale"
  resample_filter_deps="avresample"
 +sab_filter_deps="gpl swscale"
  scale_filter_deps="swscale"
 +smartblur_filter_deps="gpl swscale"
 +showspectrum_filter_deps="avcodec"
 +showspectrum_filter_select="rdft"
 +spp_filter_deps="gpl avcodec"
 +spp_filter_select="fft"
 +stereo3d_filter_deps="gpl"
 +subtitles_filter_deps="avformat avcodec libass"
 +super2xsai_filter_deps="gpl"
 +tinterlace_filter_deps="gpl"
 +vidstabdetect_filter_deps="libvidstab"
 +vidstabtransform_filter_deps="libvidstab"
 +pixfmts_super2xsai_test_deps="super2xsai_filter"
 +tinterlace_merge_test_deps="tinterlace_filter"
 +tinterlace_pad_test_deps="tinterlace_filter"
 +zmq_filter_deps="libzmq"
  
  # examples
 +avio_reading="avformat avcodec avutil"
  avcodec_example_deps="avcodec avutil"
 +demuxing_decoding_example_deps="avcodec avformat avutil"
  filter_audio_example_deps="avfilter avutil"
 +filtering_audio_example_deps="avfilter avcodec avformat avutil"
 +filtering_video_example_deps="avfilter avcodec avformat avutil"
  metadata_example_deps="avformat avutil"
 -output_example_deps="avcodec avformat avutil swscale"
 -transcode_aac_example_deps="avcodec avformat avresample"
 +muxing_example_deps="avcodec avformat avutil swscale"
 +remuxing_example_deps="avcodec avformat avutil"
 +resampling_audio_example_deps="avutil swresample"
 +scaling_video_example_deps="avutil swscale"
 +transcode_aac_example_deps="avcodec avformat swresample"
  
  # libraries
  avcodec_deps="avutil"
@@@ -2489,27 -2098,23 +2489,27 @@@ avdevice_deps="avutil avcodec avformat
  avfilter_deps="avutil"
  avformat_deps="avutil avcodec"
  avresample_deps="avutil"
 +postproc_deps="avutil gpl"
  swscale_deps="avutil"
  
  # programs
 -avconv_deps="avcodec avfilter avformat avresample swscale"
 -avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter format_filter
 -               fps_filter null_filter resample_filter scale_filter
 +ffmpeg_deps="avcodec avfilter avformat swresample"
 +ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter
 +               null_filter
                 setpts_filter trim_filter"
 -avplay_deps="avcodec avformat avresample swscale sdl"
 -avplay_libs='$sdl_libs'
 -avplay_select="rdft"
 -avprobe_deps="avcodec avformat"
 -avserver_deps="avformat fork !shared"
 -avserver_select="ffm_muxer rtp_protocol rtsp_demuxer"
 +ffplay_deps="avcodec avformat swscale swresample sdl"
 +ffplay_libs='$sdl_libs'
 +ffplay_select="rdft crop_filter"
 +ffprobe_deps="avcodec avformat"
 +ffserver_deps="avformat fork sarestart"
 +ffserver_select="ffm_muxer rtp_protocol rtsp_demuxer"
  
  # documentation
 -pod2man_deps="doc"
 -texi2html_deps="doc"
 +podpages_deps="perl"
 +manpages_deps="perl pod2man"
 +htmlpages_deps="perl texi2html"
 +txtpages_deps="perl makeinfo"
 +doc_deps_any="manpages htmlpages podpages txtpages"
  
  # default parameters
  
@@@ -2518,8 -2123,8 +2518,8 @@@ logfile="config.log
  # installation paths
  prefix_default="/usr/local"
  bindir_default='${prefix}/bin'
 -datadir_default='${prefix}/share/avconv'
 -docdir_default='${prefix}/share/doc/libav'
 +datadir_default='${prefix}/share/ffmpeg'
 +docdir_default='${prefix}/share/doc/ffmpeg'
  incdir_default='${prefix}/include'
  libdir_default='${prefix}/lib'
  mandir_default='${prefix}/share/man'
@@@ -2528,52 -2133,39 +2528,52 @@@ shlibdir_default="$libdir_default
  # toolchain
  ar_default="ar"
  cc_default="gcc"
 +cxx_default="g++"
  host_cc_default="gcc"
  cp_f="cp -f"
 +install="install"
  ln_s="ln -s -f"
  nm_default="nm -g"
  objformat="elf"
  pkg_config_default=pkg-config
  ranlib="ranlib"
 -strip="strip"
 -yasmexe="yasm"
 +strip_default="strip"
 +yasmexe_default="yasm"
 +windres_default="windres"
  
  nogas=":"
  
 -# machine
 -arch_default=$(uname -m)
 -cpu="generic"
 -
  # OS
  target_os_default=$(tolower $(uname -s))
  host_os=$target_os_default
  
 +# machine
 +if test "$target_os_default" = aix; then
 +    arch_default=$(uname -p)
 +else
 +    arch_default=$(uname -m)
 +fi
 +cpu="generic"
 +
  # configurable options
 -enable $EXAMPLE_LIST $LIBRARY_LIST $PROGRAM_LIST
 +enable $PROGRAM_LIST
 +enable $DOCUMENT_LIST
 +enable $EXAMPLE_LIST
 +enable $(filter_out avresample $LIBRARY_LIST)
 +enable stripping
  
  enable asm
  enable debug
  enable doc
  enable optimizations
 +enable runtime_cpudetect
  enable safe_bitstream_reader
  enable static
  enable swscale_alpha
  
 -# By default, enable only those hwaccels that have no external dependencies.
 -enable dxva2 vdpau
 +# Enable hwaccels by default.
 +enable dxva2 vaapi vdpau xvmc
 +enable xlib
  
  # build settings
  SHFLAGS='-shared -Wl,-soname,$$(@F)'
@@@ -2599,8 -2191,6 +2599,8 @@@ AS_O='-o $@
  CC_C='-c'
  CC_E='-E -o $@'
  CC_O='-o $@'
 +CXX_C='-c'
 +CXX_O='-o $@'
  LD_O='-o $@'
  LD_LIB='-l%'
  LD_PATH='-L'
@@@ -2635,7 -2225,7 +2635,7 @@@ for v in "$@"; d
      r=${v#*=}
      l=${v%"$r"}
      r=$(sh_quote "$r")
 -    LIBAV_CONFIGURATION="${LIBAV_CONFIGURATION# } ${l}${r}"
 +    FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
  done
  
  find_things(){
@@@ -2755,9 -2345,7 +2755,9 @@@ for opt d
              is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt"
              eval list=\$$(toupper $thing)_LIST
              name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing}
 -            $action $(filter "$name" $list)
 +            list=$(filter "$name" $list)
 +            [ "$list" = "" ] && warn "Option $opt did not match anything"
 +            $action $list
          ;;
          --enable-?*|--disable-?*)
              eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
          ;;
          --help|-h) show_help
          ;;
 +        --fatal-warnings) enable fatal_warnings
 +        ;;
          *)
              optname="${opt%%=*}"
              optname="${optname#--}"
@@@ -2797,7 -2383,7 +2797,7 @@@ don
  
  disabled logging && logfile=/dev/null
  
 -echo "# $0 $LIBAV_CONFIGURATION" > $logfile
 +echo "# $0 $FFMPEG_CONFIGURATION" > $logfile
  set >> $logfile
  
  test -n "$cross_prefix" && enable cross_compile
  
  ar_default="${cross_prefix}${ar_default}"
  cc_default="${cross_prefix}${cc_default}"
 +cxx_default="${cross_prefix}${cxx_default}"
  nm_default="${cross_prefix}${nm_default}"
  pkg_config_default="${cross_prefix}${pkg_config_default}"
  ranlib="${cross_prefix}${ranlib}"
 -strip="${cross_prefix}${strip}"
 +strip_default="${cross_prefix}${strip_default}"
 +windres_default="${cross_prefix}${windres_default}"
  
  sysinclude_default="${sysroot}/usr/include"
  
 +test -n "$valgrind" && toolchain="valgrind-memcheck"
 +
  case "$toolchain" in
      clang-asan)
          cc_default="clang"
          add_ldflags -fsanitize=undefined
      ;;
      valgrind-massif)
 -        target_exec_default="valgrind"
 -        target_exec_args="--alloc-fn=av_malloc --alloc-fn=av_mallocz"
 +        target_exec_default=${valgrind:-"valgrind"}
 +        target_exec_args="--tool=massif --alloc-fn=av_malloc --alloc-fn=av_mallocz --alloc-fn=av_calloc --alloc-fn=av_fast_padded_malloc --alloc-fn=av_fast_malloc --alloc-fn=av_realloc_f --alloc-fn=av_fast_realloc --alloc-fn=av_realloc"
      ;;
      valgrind-memcheck)
 -        target_exec_default="valgrind"
 -        target_exec_args="--track-origins=yes --leak-check=full"
 +        target_exec_default=${valgrind:-"valgrind"}
 +        target_exec_args="--error-exitcode=1 --malloc-fill=0x2a --track-origins=yes --leak-check=full --gen-suppressions=all --suppressions=$source_path/tests/fate-valgrind.supp"
      ;;
      msvc)
          # Check whether the current MSVC version needs the C99 converter.
          # From MSVC 2013 (compiler major version 18) onwards, it does actually
 -        # support enough of C99 to build libav. Default to the new
 +        # support enough of C99 to build ffmpeg. Default to the new
          # behaviour if the regexp was unable to match anything, since this
          # successfully parses the version number of existing supported
          # versions that require the converter (MSVC 2010 and 2012).
      ;;
  esac
  
 -set_default arch cc pkg_config sysinclude target_exec target_os
 +set_default arch cc cxx pkg_config strip sysinclude target_exec target_os yasmexe
  enabled cross_compile || host_cc_default=$cc
  set_default host_cc
  
@@@ -2926,11 -2508,7 +2926,11 @@@ HOSTEXESUF=$(exesuf $host_os
  : ${TMPDIR:=$TMP}
  : ${TMPDIR:=/tmp}
  
 -if ! check_cmd mktemp -u XXXXXX; then
 +if [ -n "$tempprefix" ] ; then
 +    mktemp(){
 +        echo $tempprefix.${HOSTNAME}.${UID}
 +    }
 +elif ! check_cmd mktemp -u XXXXXX; then
      # simple replacement for missing mktemp
      # NOT SAFE FOR GENERAL USE
      mktemp(){
@@@ -2950,7 -2528,6 +2950,7 @@@ trap 'rm -f -- $TMPFILES' EXI
  
  tmpfile TMPASM .asm
  tmpfile TMPC   .c
 +tmpfile TMPCPP .cpp
  tmpfile TMPE   $EXESUF
  tmpfile TMPH   .h
  tmpfile TMPO   .o
@@@ -3038,7 -2615,6 +3038,7 @@@ msvc_flags()
              -Wall)                echo -W4 -wd4244 -wd4127 -wd4018 -wd4389     \
                                         -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \
                                         -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \
 +                                       -wd4554 \
                                         -wd4273 ;;
          esac
      done
@@@ -3086,8 -2662,7 +3086,8 @@@ suncc_flags()
                      core2)              echo -xarch=ssse3 -xchip=core2   ;;
                      corei7)           echo -xarch=sse4_2 -xchip=nehalem  ;;
                      corei7-avx)       echo -xarch=avx -xchip=sandybridge ;;
 -                    amdfam10|barcelona|bdver*) echo -xarch=sse4_1        ;;
 +                    amdfam10|barcelona)        echo -xtarget=barcelona   ;;
 +                    bdver*)                    echo -xarch=avx           ;;
                      athlon-4|athlon-[mx]p)     echo -xarch=ssea          ;;
                      k8|opteron|athlon64|athlon-fx)
                                                 echo -xarch=sse2a         ;;
@@@ -3143,9 -2718,7 +3143,9 @@@ probe_cc()
      unset _depflags _DEPCMD _DEPFLAGS
      _flags_filter=echo
  
 -    if $_cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
 +    if $_cc --version 2>&1 | grep -q '^GNU assembler'; then
 +        true # no-op to avoid reading stdin in following checks
 +    elif $_cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
          _type=llvm_gcc
          gcc_extra_ver=$(expr "$($_cc --version | head -n1)" : '.*\((.*)\)')
          _ident="llvm-gcc $($_cc -dumpversion) $gcc_extra_ver"
          opt_common='-alias=ansi -Mdse -Mlre -Mpre'
          _cflags_speed="-O3 -Mautoinline -Munroll=c:4 $opt_common"
          _cflags_size="-O2 -Munroll=c:1 $opt_common"
 -        _cflags_noopt="-O1"
 +        _cflags_noopt="-O"
          _flags_filter=pgi_flags
      elif $_cc 2>&1 | grep -q Microsoft; then
          _type=msvc
          if [ $pfx = hostcc ]; then
              append _cflags -Dsnprintf=_snprintf
          fi
 +        disable stripping
      elif $_cc 2>&1 | grep -q Intel; then
          _type=icl
          _ident=$($cc 2>&1 | head -n1)
@@@ -3343,7 -2915,7 +3343,7 @@@ test -n "$cc_type" && enable $cc_type |
  : ${dep_cc_default:=$cc}
  : ${ld_default:=$cc}
  : ${host_ld_default:=$host_cc}
 -set_default ar as dep_cc ld host_ld
 +set_default ar as dep_cc ld host_ld windres
  
  probe_cc as "$as"
  asflags_filter=$_flags_filter
@@@ -3385,7 -2957,6 +3385,7 @@@ els
  fi
  
  add_cflags $extra_cflags
 +add_cxxflags $extra_cxxflags
  add_asflags $extra_cflags
  
  if test -n "$sysroot"; then
@@@ -3428,7 -2999,7 +3428,7 @@@ case "$arch" i
      aarch64|arm64)
          arch="aarch64"
      ;;
 -    arm*)
 +    arm*|iPad*|iPhone*)
          arch="arm"
      ;;
      mips*|IP*)
      tilegx|tile-gx)
          arch="tilegx"
      ;;
 -    i[3-6]86|i86pc|BePC|x86pc|x86_64|amd64)
 +    i[3-6]86|i86pc|BePC|x86pc|x86_64|x86_32|amd64)
          arch="x86"
      ;;
  esac
@@@ -3562,28 -3133,6 +3562,28 @@@ elif enabled mips; the
  
      cpuflags="-march=$cpu"
  
 +    case $cpu in
 +        24kc)
 +            disable mipsfpu
 +            disable mipsdspr1
 +            disable mipsdspr2
 +        ;;
 +        24kf*)
 +            disable mipsdspr1
 +            disable mipsdspr2
 +        ;;
 +        24kec|34kc|1004kc)
 +            disable mipsfpu
 +            disable mipsdspr2
 +        ;;
 +        24kef*|34kf*|1004kf*)
 +            disable mipsdspr2
 +        ;;
 +        74kc)
 +            disable mipsfpu
 +        ;;
 +    esac
 +
  elif enabled ppc; then
  
      case $(tolower $cpu) in
@@@ -3691,7 -3240,6 +3691,7 @@@ if test "$?" != 0; the
  fi
  
  add_cppflags -D_ISOC99_SOURCE
 +add_cxxflags -D__STDC_CONSTANT_MACROS
  check_cflags -std=c99
  check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
  #include <stdlib.h>
@@@ -3743,11 -3291,6 +3743,11 @@@ case "$arch" i
              spic=$shared
          fi
      ;;
 +    ppc)
 +        check_cc <<EOF && subarch="ppc64"
 +        int test[(int)sizeof(char*) - 7];
 +EOF
 +    ;;
  esac
  
  enable $subarch
@@@ -3783,7 -3326,6 +3783,7 @@@ case $target_os i
          disable symver
          oss_indev_extralibs="-lossaudio"
          oss_outdev_extralibs="-lossaudio"
 +        enabled gcc || check_ldflags -Wl,-zmuldefs
          ;;
      openbsd|bitrig)
          disable symver
          ;;
      bsd/os)
          add_extralibs -lpoll -lgnugetopt
 +        strip="strip -d"
          ;;
      darwin)
          gas="gas-preprocessor.pl $cc"
          enabled ppc && add_asflags -force_cpusubtype_ALL
          SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
          enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
 +        strip="${strip} -x"
          add_ldflags -Wl,-dynamic,-search_paths_first
          SLIBSUF=".dylib"
          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
          elif enabled arm; then
              LIBTARGET=arm-wince
          fi
 +        enabled shared && ! enabled small && check_cmd $windres --version && enable gnu_windres
          check_ldflags -Wl,--nxcompat
          check_ldflags -Wl,--dynamicbase
          shlibdir_default="$bindir_default"
          SLIBSUF=".dll"
          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
          SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
 -        SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
 +        dlltool="${cross_prefix}dlltool"
 +        if check_cmd lib.exe -list; then
 +            SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
 +            if enabled x86_64; then
 +                LIBTARGET=x64
 +            fi
 +        elif check_cmd $dlltool --version; then
 +            SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
 +        fi
          SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
          SLIB_INSTALL_LINKS=
          SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
          SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
          SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.orig.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
          objformat="win32"
 -        dlltool="${cross_prefix}dlltool"
          ranlib=:
          enable dos_paths
          ;;
          SHFLAGS='-shared -Wl,--out-implib,$(SUBDIR)lib$(FULLNAME).dll.a'
          objformat="win32"
          enable dos_paths
 +        enabled shared && ! enabled small && check_cmd $windres --version && enable gnu_windres
          ;;
      *-dos|freedos|opendos)
          network_extralibs="-lsocket"
          ranlib="echo ignoring ranlib"
          ;;
      os/2*)
 +        strip="lxlite -CS"
          ln_s="cp -f"
          objformat="aout"
          add_cppflags -D_GNU_SOURCE
              emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
          SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib'
          enable dos_paths
 +        enable_weak os2threads
          ;;
      gnu/kfreebsd)
          add_cppflags -D_BSD_SOURCE
          add_compat strtod.o strtod=avpriv_strtod
          network_extralibs='-lbsd'
          exeobjs=compat/plan9/main.o
 -        disable avserver
 +        disable ffserver
          cp_f='cp'
          ;;
      none)
@@@ -3995,10 -3524,6 +3995,10 @@@ probe_libc()
      # MinGW64 is backwards compatible with MinGW32, so check for it first.
      elif check_${pfx}cpp_condition _mingw.h "defined __MINGW64_VERSION_MAJOR"; then
          eval ${pfx}libc_type=mingw64
 +        if check_${pfx}cpp_condition _mingw.h "__MINGW64_VERSION_MAJOR < 3"; then
 +            add_compat msvcrt/snprintf.o
 +            add_cflags "-include $source_path/compat/msvcrt/snprintf.h"
 +        fi
          add_${pfx}cppflags -U__STRICT_ANSI__ -D__USE_MINGW_ANSI_STDIO=1
          eval test \$${pfx_no_}cc_type = "gcc" &&
              add_${pfx}cppflags -D__printf__=__gnu_printf__
@@@ -4069,7 -3594,7 +4069,7 @@@ esc()
      echo "$*" | sed 's/%/%25/g;s/:/%3a/g'
  }
  
 -echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $LIBAV_CONFIGURATION)" >config.fate
 +echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $FFMPEG_CONFIGURATION)" >config.fate
  
  check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic
  
      exit 1;
  fi
  
 +# backward compatibility layer for incompatible_libav/fork_abi
 +enabled incompatible_fork_abi  && enable incompatible_libav_abi
 +enabled incompatible_libav_abi && enable incompatible_fork_abi
 +
  die_license_disabled() {
      enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; }
  }
  
 +die_license_disabled_gpl() {
 +    enabled $1 || { enabled $2 && die "$2 is incompatible with the gpl and --enable-$1 is not specified."; }
 +}
 +
 +die_license_disabled gpl frei0r
  die_license_disabled gpl libcdio
 +die_license_disabled gpl libutvideo
 +die_license_disabled gpl libvidstab
  die_license_disabled gpl libx264
  die_license_disabled gpl libx265
  die_license_disabled gpl libxavs
  die_license_disabled gpl libxvid
 +die_license_disabled gpl libzvbi
  die_license_disabled gpl x11grab
  
 +die_license_disabled nonfree libaacplus
  die_license_disabled nonfree libfaac
 -die_license_disabled nonfree libfdk_aac
 -die_license_disabled nonfree openssl
 +enabled gpl && die_license_disabled_gpl nonfree libfdk_aac
 +enabled gpl && die_license_disabled_gpl nonfree openssl
  
  die_license_disabled version3 libopencore_amrnb
  die_license_disabled version3 libopencore_amrwb
@@@ -4189,10 -3701,7 +4189,10 @@@ elif enabled alpha; the
  
  elif enabled arm; then
  
 -    check_cpp_condition stddef.h "defined __thumb__" && enable_weak thumb
 +    check_cpp_condition stddef.h "defined __thumb__" && check_cc <<EOF && enable_weak thumb
 +float func(float a, float b){ return a+b; }
 +EOF
 +
      enabled thumb && check_cflags -mthumb || check_cflags -marm
      nogas=die
  
      elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then
          case "${cross_prefix:-$cc}" in
              *hardfloat*)         enable vfp_args;   fpabi=vfp ;;
 -            *) check_ld <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
 +            *) check_ld "cc" <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
  __asm__ (".eabi_attribute 28, 1");
  int main(void) { return 0; }
  EOF
  elif enabled mips; then
  
      check_inline_asm loongson '"dmult.g $1, $2, $3"'
 +    enabled mips32r2  && add_cflags "-mips32r2" && add_asflags "-mips32r2" &&
 +     check_inline_asm mips32r2  '"rotr $t0, $t1, 1"'
 +    enabled mipsdspr1 && add_cflags "-mdsp" && add_asflags "-mdsp" &&
 +     check_inline_asm mipsdspr1 '"addu.qb $t0, $t1, $t2"'
 +    enabled mipsdspr2 && add_cflags "-mdspr2" && add_asflags "-mdspr2" &&
 +     check_inline_asm mipsdspr2 '"absq_s.qb $t0, $t1"'
 +    enabled mipsfpu   && add_cflags "-mhard-float" && add_asflags "-mhard-float" &&
 +     check_inline_asm mipsfpu   '"madd.d $f0, $f2, $f4, $f6"'
  
  elif enabled parisc; then
  
@@@ -4248,17 -3749,14 +4248,17 @@@ elif enabled ppc; the
  
      enable local_aligned_8 local_aligned_16
  
 -    check_inline_asm dcbzl     '"dcbzl 0, %0" :: "r"(0)'
 +    [ $cpu != e500 -a $cpu != e500v2 ] &&
 +     check_inline_asm dcbzl    '"dcbzl 0, %0" :: "r"(0)'
      check_inline_asm ibm_asm   '"add 0, 0, 0"'
      check_inline_asm ppc4xx    '"maclhw r10, r11, r12"'
      check_inline_asm xform_asm '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)'
  
      # AltiVec flags: The FSF version of GCC differs from the Apple version
      if enabled altivec; then
 -        nogas=warn
 +        if ! enabled_any pic ppc64; then
 +            nogas=warn
 +        fi
          check_cflags -maltivec -mabi=altivec &&
          { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
          check_cflags -faltivec
@@@ -4324,8 -3822,6 +4324,8 @@@ EO
  
          check_yasm "movbe ecx, [5]" && enable yasm ||
              die "yasm/nasm not found or too old. Use --disable-yasm for a crippled build."
 +        check_yasm "vextractf128 xmm0, ymm0, 0"      || disable avx_external avresample
 +        check_yasm "vextracti128 xmm0, ymm0, 0"      || disable avx2_external
          check_yasm "vpmacsdd xmm0, xmm1, xmm2, xmm3" || disable xop_external
          check_yasm "vfmadd132ps ymm0, ymm1, ymm2"    || disable fma3_external
          check_yasm "vfmaddps ymm0, ymm1, ymm2, ymm3" || disable fma4_external
  check_builtin atomic_cas_ptr atomic.h "void **ptr; void *oldval, *newval; atomic_cas_ptr(ptr, oldval, newval)"
  check_builtin machine_rw_barrier mbarrier.h "__machine_rw_barrier()"
  check_builtin MemoryBarrier windows.h "MemoryBarrier()"
 +check_builtin sarestart signal.h "SA_RESTART"
  check_builtin sync_val_compare_and_swap "" "int *ptr; int oldval, newval; __sync_val_compare_and_swap(ptr, oldval, newval)"
  
  check_func_headers malloc.h _aligned_malloc     && enable aligned_malloc
  check_func  ${malloc_prefix}memalign            && enable memalign
  check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
  
 +check_func  access
 +check_func  clock_gettime || { check_func clock_gettime -lrt && add_extralibs -lrt; }
  check_func  fcntl
  check_func  fork
  check_func  gethrtime
@@@ -4427,36 -3920,28 +4427,36 @@@ check_func  mprotec
  check_func  nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; }
  check_func  sched_getaffinity
  check_func  setrlimit
 +check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE
  check_func  strerror_r
 -check_func  strptime
  check_func  sysconf
  check_func  sysctl
  check_func  usleep
  
 +check_func_headers conio.h kbhit
  check_func_headers io.h setmode
 +check_func_headers lzo/lzo1x.h lzo1x_999_compress
  check_func_headers stdlib.h getenv
  
  check_func_headers windows.h GetProcessAffinityMask
  check_func_headers windows.h GetProcessTimes
  check_func_headers windows.h GetSystemTimeAsFileTime
  check_func_headers windows.h MapViewOfFile
 +check_func_headers windows.h PeekNamedPipe
  check_func_headers windows.h SetConsoleTextAttribute
  check_func_headers windows.h Sleep
  check_func_headers windows.h VirtualAlloc
 +check_func_headers glob.h glob
 +enabled xlib &&
 +    check_func_headers "X11/Xlib.h X11/extensions/Xvlib.h" XvGetPortAttribute -lXv -lX11 -lXext
  
 +check_header cl/cl.h
  check_header direct.h
  check_header dlfcn.h
  check_header dxva.h
 -check_header dxva2api.h
 +check_header dxva2api.h -D_WIN32_WINNT=0x0600
  check_header io.h
 +check_header libcrystalhd/libcrystalhd_if.h
  check_header mach/mach_time.h
  check_header malloc.h
  check_header poll.h
@@@ -4466,14 -3951,12 +4466,14 @@@ check_header sys/resource.
  check_header sys/select.h
  check_header sys/time.h
  check_header sys/un.h
 +check_header termios.h
  check_header unistd.h
  check_header vdpau/vdpau.h
  check_header vdpau/vdpau_x11.h
  check_header VideoDecodeAcceleration/VDADecoder.h
  check_header windows.h
  check_header X11/extensions/XvMClib.h
 +check_header asm/types.h
  
  check_lib2 "windows.h shellapi.h" CommandLineToArgvW -lshell32
  check_lib2 "windows.h wincrypt.h" CryptGenRandom -ladvapi32
  
  # check for some common methods of building with pthread support
  # do this before the optional library checks as some of them require pthreads
 -if ! disabled pthreads && ! enabled w32threads; then
 +if ! disabled pthreads && ! enabled w32threads && ! enabled os2threads; then
      enable pthreads
 -    if check_func pthread_join -pthread; then
 +    if check_func pthread_join -pthread && check_func pthread_create -pthread; then
          add_cflags -pthread
          add_extralibs -pthread
 -    elif check_func pthread_join -pthreads; then
 +    elif check_func pthread_join -pthreads && check_func pthread_create -pthreads; then
          add_cflags -pthreads
          add_extralibs -pthreads
 -    elif check_func pthread_join -lpthreadGC2; then
 +    elif check_func pthread_join -lpthreadGC2 && check_func pthread_create -lpthreadGC2; then
          add_extralibs -lpthreadGC2
 -    elif check_lib pthread.h pthread_join -lpthread; then
 +    elif check_lib pthread.h pthread_join -lpthread && check_lib pthread.h pthread_create -lpthread; then
          :
 -    elif ! check_func pthread_join; then
 +    elif ! check_func pthread_join && ! check_func pthread_create; then
          disable pthreads
      fi
 +    check_code cc "pthread.h" "static pthread_mutex_t atomic_lock = PTHREAD_MUTEX_INITIALIZER" || disable pthreads
 +fi
 +
 +
 +if enabled pthreads; then
 +  check_func pthread_cancel
  fi
  
  disabled  zlib || check_lib   zlib.h      zlibVersion -lz   || disable  zlib
  disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
  
  check_lib math.h sin -lm && LIBM="-lm"
 -enabled vaapi && require vaapi va/va.h vaInitialize -lva
 +disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersion -lcrystalhd || disable crystalhd
  
  atan2f_args=2
  ldexpf_args=2
@@@ -4526,101 -4003,50 +4526,101 @@@ for func in $MATH_FUNCS; d
  done
  
  # these are off by default, so fail if requested and not available
 -enabled avisynth          && { { check_header "avisynth/avisynth_c.h" && check_lib2 "windows.h" LoadLibrary; } ||
 -                               { check_header "avxsynth/avxsynth_c.h" && check_lib2 "dlfcn.h" dlopen -ldl; } ||
 -                               die "ERROR: LoadLibrary/dlopen not found, or avisynth header not found"; }
 +enabled avisynth          && { { check_lib2 "windows.h" LoadLibrary; } ||
 +                               { check_lib2 "dlfcn.h" dlopen -ldl; } ||
 +                               die "ERROR: LoadLibrary/dlopen not found for avisynth"; }
 +enabled decklink          && { check_header DeckLinkAPI.h || die "ERROR: DeckLinkAPI.h header not found"; }
 +enabled fontconfig        && require_pkg_config fontconfig "fontconfig/fontconfig.h" FcInit
  enabled frei0r            && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
  enabled gnutls            && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
 +enabled ladspa            && { check_header ladspa.h || die "ERROR: ladspa.h header not found"; }
 +enabled libiec61883       && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
 +enabled libaacplus        && require "libaacplus >= 2.0.0" aacplus.h aacplusEncOpen -laacplus
 +enabled libass            && require_pkg_config libass ass/ass.h ass_library_init
 +enabled libbluray         && require_pkg_config libbluray libbluray/bluray.h bd_open
 +enabled libcelt           && require libcelt celt/celt.h celt_decode -lcelt0 &&
 +                             { check_lib celt/celt.h celt_decoder_create_custom -lcelt0 ||
 +                               die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
 +enabled libcaca           && require_pkg_config caca caca.h caca_create_canvas
  enabled libfaac           && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
  enabled libfdk_aac        && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac
 -enabled libfreetype       && require_pkg_config freetype2 "ft2build.h FT_FREETYPE_H" FT_Init_FreeType
 +flite_libs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lflite_cmu_us_kal16 -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish -lflite_cmulex -lflite"
 +enabled libflite          && require2 libflite "flite/flite.h" flite_init $flite_libs
 +enabled libfreetype       && require_libfreetype
 +enabled libgme            && require  libgme gme/gme.h gme_new_emu -lgme -lstdc++
  enabled libgsm            && { for gsm_hdr in "gsm.h" "gsm/gsm.h"; do
                                     check_lib "${gsm_hdr}" gsm_create -lgsm && break;
                                 done || die "ERROR: libgsm not found"; }
  enabled libilbc           && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc
 +enabled libmodplug        && require libmodplug libmodplug/modplug.h ModPlug_Load -lmodplug
  enabled libmp3lame        && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
 +enabled libnut            && require libnut libnut.h nut_demuxer_init -lnut
  enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
  enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
 -enabled libopencv         && require_pkg_config opencv opencv/cv.h cvCreateImageHeader
 -enabled libopenjpeg       && { { check_header openjpeg.h && check_lib2 openjpeg.h opj_version -lopenjpeg; } ||
 -                               { require_pkg_config libopenjpeg1 openjpeg.h opj_version; } }
 +enabled libopencv         && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
 +enabled libopenjpeg       && { check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg ||
 +                               check_lib openjpeg.h opj_version -lopenjpeg ||
 +                               die "ERROR: libopenjpeg not found"; }
  enabled libopus           && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
  enabled libpulse          && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new
 +enabled libquvi           && require_pkg_config libquvi quvi/quvi.h quvi_init
  enabled librtmp           && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
  enabled libschroedinger   && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
 +enabled libshine          && require_pkg_config shine shine/layer3.h shine_encode_buffer
 +enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr
 +enabled libssh            && require_pkg_config libssh libssh/sftp.h sftp_init
  enabled libspeex          && require libspeex speex/speex.h speex_decoder_init -lspeex
 +enabled libstagefright_h264 && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h
 +    media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h
 +    media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder -lgnustl_static
  enabled libtheora         && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
 +enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame &&
 +                             { check_lib twolame.h twolame_encode_buffer_float32_interleaved -ltwolame ||
 +                               die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
 +enabled libutvideo        && require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++
 +enabled libv4l2           && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
 +enabled libvidstab        && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
  enabled libvo_aacenc      && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
  enabled libvo_amrwbenc    && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
  enabled libvorbis         && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
  enabled libvpx            && {
      enabled libvpx_vp8_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
                                      die "ERROR: libvpx decoder version must be >=0.9.1"; }
 -    enabled libvpx_vp8_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx ||
 -                                    die "ERROR: libvpx encoder version must be >=0.9.6"; }
 +    enabled libvpx_vp8_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VP8E_SET_MAX_INTRA_BITRATE_PCT" -lvpx ||
 +                                    die "ERROR: libvpx encoder version must be >=0.9.7"; }
      enabled libvpx_vp9_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" "vpx_codec_vp9_dx" -lvpx || disable libvpx_vp9_decoder; }
 -    enabled libvpx_vp9_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_vp9_cx" -lvpx || disable libvpx_vp9_encoder; } }
 +    enabled libvpx_vp9_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_vp9_cx VP9E_SET_SVC" -lvpx || disable libvpx_vp9_encoder; } }
  enabled libwavpack        && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput  -lwavpack
  enabled libwebp           && require_pkg_config libwebp webp/encode.h WebPGetEncoderVersion
  enabled libx264           && require libx264 x264.h x264_encoder_encode -lx264 &&
                               { check_cpp_condition x264.h "X264_BUILD >= 118" ||
 -                               die "ERROR: libx264 version must be >= 0.118."; }
 +                               die "ERROR: libx264 must be installed and version must be >= 0.118."; }
  enabled libx265           && require_pkg_config x265 x265.h x265_encoder_encode &&
                               { check_cpp_condition x265.h "X265_BUILD >= 9" ||
                                 die "ERROR: libx265 version must be >= 9."; }
  enabled libxavs           && require libxavs xavs.h xavs_encoder_encode -lxavs
  enabled libxvid           && require libxvid xvid.h xvid_global -lxvidcore
 +enabled libzmq            && require_pkg_config libzmq zmq.h zmq_ctx_new
 +enabled libzvbi           && require libzvbi libzvbi.h vbi_decoder_new -lzvbi
 +enabled openal            && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
 +                               check_lib 'AL/al.h' alGetError "${al_libs}" && break; done } ||
 +                               die "ERROR: openal not found"; } &&
 +                             { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
 +                               die "ERROR: openal must be installed and version must be 1.1 or compatible"; }
 +enabled opencl            && { check_lib2 OpenCL/cl.h clEnqueueNDRangeKernel -Wl,-framework,OpenCL ||
 +                               check_lib2 CL/cl.h clEnqueueNDRangeKernel -lOpenCL ||
 +                               die "ERROR: opencl not found"; } &&
 +                             { ! enabled_any w32threads os2threads ||
 +                               die "opencl currently needs --enable-pthreads or --disable-w32threads"; } &&
 +                             { check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" ||
 +                               check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ||
 +                               die "ERROR: opencl must be installed and version must be 1.2 or compatible"; }
 +enabled opengl            && { check_lib GL/glx.h glXGetProcAddress "-lGL" ||
 +                               check_lib2 windows.h wglGetProcAddress "-lopengl32 -lgdi32" ||
 +                               check_lib2 OpenGL/gl3.h glGetError "-Wl,-framework,OpenGL" ||
 +                               check_lib2 ES2/gl.h glGetError "-isysroot=${sysroot} -Wl,-framework,OpenGLES" ||
 +                               die "ERROR: opengl not found."
 +                             }
  enabled openssl           && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
                                 check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                                 check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
@@@ -4640,33 -4066,18 +4640,33 @@@ if enabled libdc1394; the
      die "ERROR: No version of libdc1394 found "
  fi
  
 +SDL_CONFIG="${cross_prefix}sdl-config"
  if check_pkg_config sdl SDL_events.h SDL_PollEvent; then
      check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
      check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x010300" $sdl_cflags &&
      enable sdl
 +else
 +  if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
 +    sdl_cflags=$("${SDL_CONFIG}" --cflags)
 +    sdl_libs=$("${SDL_CONFIG}" --libs)
 +    check_func_headers SDL_version.h SDL_Linked_Version $sdl_cflags $sdl_libs &&
 +    check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
 +    check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x010300" $sdl_cflags &&
 +    enable sdl
 +  fi
  fi
 +enabled sdl && add_cflags $sdl_cflags && add_extralibs $sdl_libs
  
 +texi2html --help 2> /dev/null | grep -q 'init-file' && enable texi2html || disable texi2html
 +makeinfo --version > /dev/null 2>&1 && enable makeinfo  || disable makeinfo
 +perl -v            > /dev/null 2>&1 && enable perl      || disable perl
  pod2man --help     > /dev/null 2>&1 && enable pod2man   || disable pod2man
 -texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
 +rsync --help 2> /dev/null | grep -q 'contimeout' && enable rsync_contimeout || disable rsync_contimeout
  
  check_header linux/fb.h
 +check_header linux/videodev.h
  check_header linux/videodev2.h
 -check_struct linux/videodev2.h "struct v4l2_frmivalenum" discrete
 +check_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_safe struct_v4l2_frmivalenum_discrete
  
  check_header sys/videoio.h
  
@@@ -4675,8 -4086,6 +4675,8 @@@ check_func_headers "windows.h vfw.h" ca
  # w32api 3.12 had it defined wrong
  check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines
  
 +check_type "dshow.h" IBaseFilter
 +
  # check for ioctl_meteor.h, ioctl_bt848.h and alternatives
  { check_header dev/bktr/ioctl_meteor.h &&
    check_header dev/bktr/ioctl_bt848.h; } ||
  check_header dev/ic/bt8xx.h
  
  check_header sndio.h
 -check_header sys/soundcard.h
 +if check_struct sys/soundcard.h audio_buf_info bytes; then
 +    enable_safe sys/soundcard.h
 +else
 +    check_cc -D__BSD_VISIBLE -D__XSI_VISIBLE <<EOF && add_cppflags -D__BSD_VISIBLE -D__XSI_VISIBLE && enable_safe sys/soundcard.h
 +    #include <sys/soundcard.h>
 +    audio_buf_info abc;
 +EOF
 +fi
  check_header soundcard.h
  
  enabled_any alsa_indev alsa_outdev &&
      check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
  
 -enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack &&
 +enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait &&
      check_func jack_port_get_latency_range -ljack
  
  enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
  
  if enabled libcdio; then
      check_lib2 "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio ||
 -    check_lib2 "cdio/paranoia/cdda.h cdio/paranoia/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio
 +    check_lib2 "cdio/paranoia/cdda.h cdio/paranoia/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio ||
 +    die "ERROR: libcdio-paranoia not found"
  fi
  
 -check_lib X11/Xlib.h XOpenDisplay -lX11 && enable xlib
 +enabled xlib &&
 +    check_lib X11/Xlib.h XOpenDisplay -lX11 || disable xlib
  
  enabled x11grab                                           &&
  require Xext X11/extensions/XShm.h XShmCreateImage -lXext &&
  require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes &&
  { enabled xlib || die "ERROR: Xlib not found"; }
  
 +enabled vaapi &&
 +    check_lib va/va.h vaInitialize -lva ||
 +    disable vaapi
 +
  enabled vdpau &&
      check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
      disable vdpau
  
  enabled vdpau && enabled xlib &&
      check_func_headers "vdpau/vdpau.h vdpau/vdpau_x11.h" vdp_device_create_x11 -lvdpau &&
 -    prepend avconv_libs $($ldflags_filter "-lvdpau") &&
 +    prepend ffmpeg_libs $($ldflags_filter "-lvdpau") &&
      enable vdpau_x11
  
 +# Funny iconv installations are not unusual, so check it after all flags have been set
 +disabled iconv || check_func_headers iconv.h iconv || check_lib2 iconv.h iconv -liconv || disable iconv
 +
  enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
  
  # add some useful compiler flags if supported
@@@ -4743,11 -4136,11 +4743,11 @@@ check_cflags -Wal
  check_cflags -Wdisabled-optimization
  check_cflags -Wpointer-arith
  check_cflags -Wredundant-decls
 -check_cflags -Wcast-qual
  check_cflags -Wwrite-strings
  check_cflags -Wtype-limits
  check_cflags -Wundef
  check_cflags -Wmissing-prototypes
 +check_cflags -Wno-pointer-to-int-cast
  check_cflags -Wstrict-prototypes
  enabled extra_warnings && check_cflags -Winline
  
@@@ -4763,13 -4156,12 +4763,13 @@@ check_disable_warning -Wno-pointer-sig
  
  # add some linker flags
  check_ldflags -Wl,--warn-common
 -check_ldflags -Wl,-rpath-link=libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample
 +check_ldflags -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample
 +enabled rpath && add_ldflags -Wl,-rpath=$libdir
  test_ldflags -Wl,-Bsymbolic && append SHFLAGS -Wl,-Bsymbolic
  
  # add some strip flags
  # -wN '..@*' is more selective than -x, but not available everywhere.
 -check_stripflags -wN \'..@*\' || check_stripflags -x || strip='true'
 +check_stripflags -wN \'..@*\' || check_stripflags -x
  
  enabled neon_clobber_test &&
      check_ldflags -Wl,--wrap,avcodec_open2              \
                    -Wl,--wrap,avcodec_encode_audio2      \
                    -Wl,--wrap,avcodec_encode_video2      \
                    -Wl,--wrap,avcodec_encode_subtitle    \
 +                  -Wl,--wrap,swr_convert                \
                    -Wl,--wrap,avresample_convert ||
      disable neon_clobber_test
  
@@@ -4789,10 -4180,8 +4789,10 @@@ enabled xmm_clobber_test &
                    -Wl,--wrap,avcodec_decode_video2      \
                    -Wl,--wrap,avcodec_decode_subtitle2   \
                    -Wl,--wrap,avcodec_encode_audio2      \
 +                  -Wl,--wrap,avcodec_encode_video       \
                    -Wl,--wrap,avcodec_encode_video2      \
                    -Wl,--wrap,avcodec_encode_subtitle    \
 +                  -Wl,--wrap,swr_convert                \
                    -Wl,--wrap,avresample_convert         \
                    -Wl,--wrap,sws_scale ||
      disable xmm_clobber_test
@@@ -4836,25 -4225,17 +4836,25 @@@ check_optflags $optflag
  check_optflags -fno-math-errno
  check_optflags -fno-signed-zeros
  
 +enabled ftrapv && check_cflags -ftrapv
 +
 +check_cc -mno-red-zone <<EOF && noredzone_flags="-mno-red-zone"
 +int x;
 +EOF
 +
 +
  if enabled icc; then
      # Just warnings, no remarks
      check_cflags -w1
      # -wd: Disable following warnings
      # 144, 167, 556: -Wno-pointer-sign
 +    # 188: enumerated type mixed with another type
      # 1292: attribute "foo" ignored
      # 1419: external declaration in primary source file
      # 10006: ignoring unknown option -fno-signed-zeros
      # 10148: ignoring unknown option -Wno-parentheses
      # 10156: ignoring option '-W'; no argument required
 -    check_cflags -wd144,167,556,1292,1419,10006,10148,10156
 +    check_cflags -wd144,167,188,556,1292,1419,10006,10148,10156
      # 11030: Warning unknown option --as-needed
      # 10156: ignoring option '-export'; no argument required
      check_ldflags -wd10156,11030
@@@ -4877,6 -4258,7 +4877,6 @@@ elif enabled gcc; the
      check_cflags -Werror=implicit-function-declaration
      check_cflags -Werror=missing-prototypes
      check_cflags -Werror=return-type
 -    check_cflags -Werror=declaration-after-statement
      check_cflags -Werror=vla
      enabled extra_warnings || check_disable_warning -Wno-maybe-uninitialized
  elif enabled llvm_gcc; then
@@@ -4915,7 -4297,6 +4915,7 @@@ elif enabled_any msvc icl; the
              add_cflags -Qansi-alias
          # icl will pass the inline asm tests but inline asm is currently
          # not supported (build will fail)
 +        disabled inline_asm || warn "inline asm disabled due to issues with it in ICL"
          disable inline_asm
      fi
  fi
@@@ -4941,8 -4322,6 +4941,8 @@@ case $target_os i
      ;;
  esac
  
 +enable frame_thread_encoder
 +
  enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
  
  check_deps $CONFIG_LIST       \
             $HAVE_LIST         \
             $ALL_COMPONENTS    \
  
 +enabled threads && ! enabled pthreads && ! enabled atomics_native && die "non pthread threading without atomics not supported, try adding --enable-pthreads or --cpu=i486 or higher if you are on x86"
 +
 +
 +if test $target_os = "haiku"; then
 +    disable memalign
 +    disable posix_memalign
 +fi
 +
  ! enabled_any memalign posix_memalign aligned_malloc &&
      enabled_any $need_memalign && enable memalign_hack
  
 +# add_dep lib dep
 +# -> enable ${lib}_deps_${dep}
 +# -> add $dep to ${lib}_deps only once
 +add_dep() {
 +    lib=$1
 +    dep=$2
 +    enabled "${lib}_deps_${dep}" && return 0
 +    enable  "${lib}_deps_${dep}"
 +    prepend "${lib}_deps" $dep
 +}
 +
 +# merge deps lib components
 +# merge all ${component}_deps into ${lib}_deps and ${lib}_deps_*
 +merge_deps() {
 +    lib=$1
 +    shift
 +    for comp in $*; do
 +        enabled $comp || continue
 +        eval "dep=\"\$${comp}_deps\""
 +        for d in $dep; do
 +            add_dep $lib $d
 +        done
 +    done
 +}
 +
 +merge_deps libavfilter $FILTER_LIST
 +
  for thread in $THREADS_LIST; do
      if enabled $thread; then
          test -n "$thread_type" &&
@@@ -5008,9 -4352,6 +5008,9 @@@ echo "ARCH                      $arch (
  if test "$build_suffix" != ""; then
      echo "build suffix              $build_suffix"
  fi
 +if test "$progs_suffix" != ""; then
 +    echo "progs suffix              $progs_suffix"
 +fi
  if test "$extra_version" != ""; then
      echo "version string suffix     $extra_version"
  fi
@@@ -5043,13 -4384,6 +5043,13 @@@ if enabled arm; the
      echo "ARMv6T2 enabled           ${armv6t2-no}"
      echo "VFP enabled               ${vfp-no}"
      echo "NEON enabled              ${neon-no}"
 +    echo "THUMB enabled             ${thumb-no}"
 +fi
 +if enabled mips; then
 +    echo "MIPS FPU enabled          ${mipsfpu-no}"
 +    echo "MIPS32R2 enabled          ${mips32r2-no}"
 +    echo "MIPS DSP R1 enabled       ${mipsdspr1-no}"
 +    echo "MIPS DSP R2 enabled       ${mipsdspr2-no}"
  fi
  if enabled ppc; then
      echo "AltiVec enabled           ${altivec-no}"
      echo "dcbzl available           ${dcbzl-no}"
  fi
  echo "debug symbols             ${debug-no}"
 +echo "strip symbols             ${stripping-no}"
  echo "optimize for size         ${small-no}"
  echo "optimizations             ${optimizations-no}"
  echo "static                    ${static-no}"
  echo "shared                    ${shared-no}"
 +echo "postprocessing support    ${postproc-no}"
  echo "new filter support        ${avfilter-no}"
  echo "network support           ${network-no}"
  echo "threading support         ${thread_type-no}"
  echo "safe bitstream reader     ${safe_bitstream_reader-no}"
  echo "SDL support               ${sdl-no}"
 +echo "opencl enabled            ${opencl-no}"
 +echo "libzvbi enabled           ${libzvbi-no}"
 +echo "texi2html enabled         ${texi2html-no}"
 +echo "perl enabled              ${perl-no}"
 +echo "pod2man enabled           ${pod2man-no}"
 +echo "makeinfo enabled          ${makeinfo-no}"
  test -n "$random_seed" &&
      echo "random seed               ${random_seed}"
  echo
  
  echo "License: $license"
  
 -echo "Creating config.mak and config.h..."
 +echo "Creating config.mak, config.h, and doc/config.texi..."
  
  test -e Makefile || echo "include $source_path/Makefile" > Makefile
  
 -config_files="$TMPH config.mak"
 +enabled stripping || strip="echo skipping strip"
 +
 +config_files="$TMPH config.mak doc/config.texi"
  
  cat > config.mak <<EOF
  # Automatically generated by configure - do not modify!
 -LIBAV_CONFIGURATION=$LIBAV_CONFIGURATION
 +ifndef FFMPEG_CONFIG_MAK
 +FFMPEG_CONFIG_MAK=1
 +FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION
  prefix=$prefix
  LIBDIR=\$(DESTDIR)$libdir
  SHLIBDIR=\$(DESTDIR)$shlibdir
@@@ -5124,13 -4446,9 +5124,13 @@@ DATADIR=\$(DESTDIR)$datadi
  DOCDIR=\$(DESTDIR)$docdir
  MANDIR=\$(DESTDIR)$mandir
  SRC_PATH=$source_path
 +ifndef MAIN_MAKEFILE
 +SRC_PATH:=\$(SRC_PATH:.%=..%)
 +endif
  CC_IDENT=$cc_ident
  ARCH=$arch
  CC=$cc
 +CXX=$cxx
  AS=$as
  LD=$ld
  DEPCC=$dep_cc
@@@ -5144,31 -4462,24 +5144,31 @@@ ARFLAGS=$arflag
  AR_O=$ar_o
  RANLIB=$ranlib
  STRIP=$strip
 +CP=cp -p
  LN_S=$ln_s
  CPPFLAGS=$CPPFLAGS
  CFLAGS=$CFLAGS
 +CXXFLAGS=$CXXFLAGS
  ASFLAGS=$ASFLAGS
  AS_C=$AS_C
  AS_O=$AS_O
  CC_C=$CC_C
  CC_E=$CC_E
  CC_O=$CC_O
 +CXX_C=$CXX_C
 +CXX_O=$CXX_O
  LD_O=$LD_O
  LD_LIB=$LD_LIB
  LD_PATH=$LD_PATH
  DLLTOOL=$dlltool
 +WINDRES=$windres
 +DEPWINDRES=$dep_cc
  LDFLAGS=$LDFLAGS
  SHFLAGS=$(echo $($ldflags_filter $SHFLAGS))
 -STRIPFLAGS=$STRIPFLAGS
 +ASMSTRIPFLAGS=$ASMSTRIPFLAGS
  YASMFLAGS=$YASMFLAGS
  BUILDSUF=$build_suffix
 +PROGSSUF=$progs_suffix
  FULLNAME=$FULLNAME
  LIBPREF=$LIBPREF
  LIBSUF=$LIBSUF
@@@ -5178,7 -4489,6 +5178,7 @@@ SLIBSUF=$SLIBSU
  EXESUF=$EXESUF
  EXTRA_VERSION=$extra_version
  CCDEP=$CCDEP
 +CXXDEP=$CXXDEP
  CCDEP_FLAGS=$CCDEP_FLAGS
  ASDEP=$ASDEP
  ASDEP_FLAGS=$ASDEP_FLAGS
@@@ -5202,13 -4512,13 +5202,13 @@@ HOSTLD_O=$HOSTLD_
  TARGET_EXEC=$target_exec $target_exec_args
  TARGET_PATH=$target_path
  TARGET_SAMPLES=${target_samples:-\$(SAMPLES)}
 -CFLAGS-avplay=$sdl_cflags
 +CFLAGS-ffplay=$sdl_cflags
  ZLIB=$($ldflags_filter -lz)
  LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
  EXTRALIBS=$extralibs
  COMPAT_OBJS=$compat_objs
  EXEOBJS=$exeobjs
 -INSTALL=install
 +INSTALL=$install
  LIBTARGET=${LIBTARGET}
  SLIBNAME=${SLIBNAME}
  SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}
@@@ -5219,8 -4529,7 +5219,8 @@@ SLIB_INSTALL_NAME=${SLIB_INSTALL_NAME
  SLIB_INSTALL_LINKS=${SLIB_INSTALL_LINKS}
  SLIB_INSTALL_EXTRA_LIB=${SLIB_INSTALL_EXTRA_LIB}
  SLIB_INSTALL_EXTRA_SHLIB=${SLIB_INSTALL_EXTRA_SHLIB}
 -SAMPLES:=${samples:-\$(LIBAV_SAMPLES)}
 +SAMPLES:=${samples:-\$(FATE_SAMPLES)}
 +NOREDZONE_FLAGS=$noredzone_flags
  EOF
  
  get_version(){
      name=$(toupper $lcname)
      file=$source_path/$lcname/version.h
      eval $(awk "/#define ${name}_VERSION_M/ { print \$2 \"=\" \$3 }" "$file")
 +    enabled raise_major && eval ${name}_VERSION_MAJOR=$((${name}_VERSION_MAJOR+100))
      eval ${name}_VERSION=\$${name}_VERSION_MAJOR.\$${name}_VERSION_MINOR.\$${name}_VERSION_MICRO
      eval echo "${lcname}_VERSION=\$${name}_VERSION" >> config.mak
      eval echo "${lcname}_VERSION_MAJOR=\$${name}_VERSION_MAJOR" >> config.mak
@@@ -5246,25 -4554,18 +5246,25 @@@ map 'print_program_libs $v' $PROGRAM_LI
  
  cat > $TMPH <<EOF
  /* Automatically generated by configure - do not modify! */
 -#ifndef LIBAV_CONFIG_H
 -#define LIBAV_CONFIG_H
 -#define LIBAV_CONFIGURATION "$(c_escape $LIBAV_CONFIGURATION)"
 -#define LIBAV_LICENSE "$(c_escape $license)"
 +#ifndef FFMPEG_CONFIG_H
 +#define FFMPEG_CONFIG_H
 +#define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
 +#define FFMPEG_LICENSE "$(c_escape $license)"
 +#define CONFIG_THIS_YEAR 2014
 +#define FFMPEG_DATADIR "$(eval c_escape $datadir)"
  #define AVCONV_DATADIR "$(eval c_escape $datadir)"
  #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
 -#define restrict $_restrict
 +#define av_restrict $_restrict
  #define EXTERN_PREFIX "${extern_prefix}"
  #define EXTERN_ASM ${extern_prefix}
 +#define BUILDSUF "$build_suffix"
  #define SLIBSUF "$SLIBSUF"
 +#define HAVE_MMX2 HAVE_MMXEXT
  EOF
  
 +test -n "$assert_level" &&
 +    echo "#define ASSERT_LEVEL $assert_level" >>$TMPH
 +
  test -n "$malloc_prefix" &&
      echo "#define MALLOC_PREFIX $malloc_prefix" >>$TMPH
  
  
  enabled getenv || echo "#define getenv(x) NULL" >> $TMPH
  
 +
 +mkdir -p doc
 +echo "@c auto-generated by configure" > doc/config.texi
 +
  print_config ARCH_   "$config_files" $ARCH_LIST
  print_config HAVE_   "$config_files" $HAVE_LIST
  print_config CONFIG_ "$config_files" $CONFIG_LIST       \
                                       $CONFIG_EXTRA      \
                                       $ALL_COMPONENTS    \
  
 -echo "#endif /* LIBAV_CONFIG_H */" >> $TMPH
 +echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
 +echo "endif # FFMPEG_CONFIG_MAK" >> config.mak
  
  # Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
  cp_if_changed $TMPH config.h
@@@ -5306,10 -4602,7 +5306,10 @@@ echo "#endif /* AVUTIL_AVCONFIG_H */" >
  
  cp_if_changed $TMPH libavutil/avconfig.h
  
 -test -n "$WARNINGS" && printf "\n$WARNINGS"
 +if test -n "$WARNINGS"; then
 +    printf "\n$WARNINGS"
 +    enabled fatal_warnings && exit 1
 +fi
  
  # build pkg-config files
  
@@@ -5322,7 -4615,7 +5322,7 @@@ pkgconfig_generate()
      requires=$5
      enabled ${name#lib} || return 0
      mkdir -p $name
 -    cat <<EOF > $name/$name.pc
 +    cat <<EOF > $name/$name${build_suffix}.pc
  prefix=$prefix
  exec_prefix=\${prefix}
  libdir=$libdir
@@@ -5334,48 -4627,35 +5334,48 @@@ Version: $versio
  Requires: $(enabled shared || echo $requires)
  Requires.private: $(enabled shared && echo $requires)
  Conflicts:
 -Libs: -L\${libdir} -l${shortname} $(enabled shared || echo $libs)
 +Libs: -L\${libdir} $(enabled rpath && echo "-Wl,-rpath,\${libdir}") -l${shortname} $(enabled shared || echo $libs)
  Libs.private: $(enabled shared && echo $libs)
  Cflags: -I\${includedir}
  EOF
 -    cat <<EOF > $name/$name-uninstalled.pc
 +
 +mkdir -p doc/examples/pc-uninstalled
 +includedir=${source_path}
 +[ "$includedir" = . ] && includedir="\${pcfiledir}/../../.."
 +    cat <<EOF > doc/examples/pc-uninstalled/$name.pc
  prefix=
  exec_prefix=
 -libdir=\${pcfiledir}
 -includedir=${source_path}
 +libdir=\${pcfiledir}/../../../$name
 +includedir=${includedir}
  
  Name: $name
  Description: $comment
  Version: $version
  Requires: $requires
  Conflicts:
 -Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
 +Libs: -L\${libdir} -Wl,-rpath,\${libdir} -l${shortname} $(enabled shared || echo $libs)
  Cflags: -I\${includedir}
  EOF
  }
  
 -lavfi_libs="libavutil = $LIBAVUTIL_VERSION"
 -enabled movie_filter    && prepend lavfi_libs "libavformat >= $LIBAVFORMAT_VERSION, libavcodec >= $LIBAVCODEC_VERSION,"
 -enabled resample_filter && prepend lavfi_libs "libavresample >= $LIBAVRESAMPLE_VERSION,"
 -enabled scale_filter    && prepend lavfi_libs "libswscale >= $LIBSWSCALE_VERSION,"
 -
 -pkgconfig_generate libavutil     "Libav utility library"          "$LIBAVUTIL_VERSION"     "$LIBM"
 -pkgconfig_generate libavcodec    "Libav codec library"            "$LIBAVCODEC_VERSION"    "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
 -pkgconfig_generate libavformat   "Libav container format library" "$LIBAVFORMAT_VERSION"   "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
 -pkgconfig_generate libavdevice   "Libav device handling library"  "$LIBAVDEVICE_VERSION"   "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
 -pkgconfig_generate libavfilter   "Libav video filtering library"  "$LIBAVFILTER_VERSION"   "$extralibs" "$lavfi_libs"
 -pkgconfig_generate libavresample "Libav audio resampling library" "$LIBAVRESAMPLE_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
 -pkgconfig_generate libswscale    "Libav image rescaling library"  "$LIBSWSCALE_VERSION"    "$LIBM"      "libavutil = $LIBAVUTIL_VERSION"
 +lavfi_libs="libavutil${build_suffix} = $LIBAVUTIL_VERSION"
 +enabled libavfilter_deps_avcodec    && prepend lavfi_libs "libavcodec${build_suffix} = $LIBAVCODEC_VERSION,"
 +enabled libavfilter_deps_avformat   && prepend lavfi_libs "libavformat${build_suffix} = $LIBAVFORMAT_VERSION,"
 +enabled libavfilter_deps_avresample && prepend lavfi_libs "libavresample${build_suffix} = $LIBAVRESAMPLE_VERSION,"
 +enabled libavfilter_deps_swscale    && prepend lavfi_libs "libswscale${build_suffix} = $LIBSWSCALE_VERSION,"
 +enabled libavfilter_deps_swresample && prepend lavfi_libs "libswresample${build_suffix} = $LIBSWRESAMPLE_VERSION,"
 +enabled libavfilter_deps_postproc   && prepend lavfi_libs "libpostproc${build_suffix} = $LIBPOSTPROC_VERSION,"
 +lavfi_libs=${lavfi_libs%, }
 +
 +lavd_libs="libavformat${build_suffix} = $LIBAVFORMAT_VERSION"
 +enabled lavfi_indev && prepend lavd_libs "libavfilter${build_suffix} = $LIBAVFILTER_VERSION,"
 +
 +pkgconfig_generate libavutil     "FFmpeg utility library"               "$LIBAVUTIL_VERSION"     "$LIBM"
 +pkgconfig_generate libavcodec    "FFmpeg codec library"                 "$LIBAVCODEC_VERSION"    "$extralibs" "libavutil${build_suffix} = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libavformat   "FFmpeg container format library"      "$LIBAVFORMAT_VERSION"   "$extralibs" "libavcodec${build_suffix} = $LIBAVCODEC_VERSION"
 +pkgconfig_generate libavdevice   "FFmpeg device handling library"       "$LIBAVDEVICE_VERSION"   "$extralibs" "$lavd_libs"
 +pkgconfig_generate libavfilter   "FFmpeg audio/video filtering library" "$LIBAVFILTER_VERSION"   "$extralibs" "$lavfi_libs"
 +pkgconfig_generate libpostproc   "FFmpeg postprocessing library"        "$LIBPOSTPROC_VERSION"   ""           "libavutil${build_suffix} = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libavresample "Libav audio resampling library"       "$LIBAVRESAMPLE_VERSION" "$extralibs" "libavutil${build_suffix} = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libswscale    "FFmpeg image rescaling library"       "$LIBSWSCALE_VERSION"    "$LIBM"      "libavutil${build_suffix} = $LIBAVUTIL_VERSION"
 +pkgconfig_generate libswresample "FFmpeg audio resampling library"      "$LIBSWRESAMPLE_VERSION" "$LIBM"      "libavutil${build_suffix} = $LIBAVUTIL_VERSION"
diff --combined libavcodec/Makefile
@@@ -1,12 -1,9 +1,12 @@@
 +include $(SUBDIR)../config.mak
 +
  NAME = avcodec
  FFLIBS = avutil
  
  HEADERS = avcodec.h                                                     \
            avfft.h                                                       \
            dxva2.h                                                       \
 +          old_codec_ids.h                                               \
            vaapi.h                                                       \
            vda.h                                                         \
            vdpau.h                                                       \
@@@ -14,7 -11,6 +14,7 @@@
            xvmc.h                                                        \
  
  OBJS = allcodecs.o                                                      \
 +       audioconvert.o                                                   \
         avpacket.o                                                       \
         avpicture.o                                                      \
         bitstream.o                                                      \
         codec_desc.o                                                     \
         fmtconvert.o                                                     \
         imgconvert.o                                                     \
 -       log2_tab.o                                                       \
         mathtables.o                                                     \
         options.o                                                        \
         parser.o                                                         \
         raw.o                                                            \
 +       rawdec.o                                                         \
 +       resample.o                                                       \
 +       resample2.o                                                      \
         utils.o                                                          \
  
  # parts needed for many different codecs
  OBJS-$(CONFIG_AANDCTTABLES)            += aandcttab.o
  OBJS-$(CONFIG_AC3DSP)                  += ac3dsp.o
  OBJS-$(CONFIG_AUDIO_FRAME_QUEUE)       += audio_frame_queue.o
 +OBJS-$(CONFIG_CRYSTALHD)               += crystalhd.o
  OBJS-$(CONFIG_DCT)                     += dct.o dct32_fixed.o dct32_float.o
  OBJS-$(CONFIG_DXVA2)                   += dxva2.o
  OBJS-$(CONFIG_DSPUTIL)                 += dsputil.o faanidct.o          \
                                            simple_idct.o jrevdct.o
  OBJS-$(CONFIG_ENCODERS)                += faandct.o jfdctfst.o jfdctint.o
  OBJS-$(CONFIG_ERROR_RESILIENCE)        += error_resilience.o
 +OBJS-$(CONFIG_EXIF)                    += exif.o tiff_common.o
  FFT-OBJS-$(CONFIG_HARDCODED_TABLES)    += cos_tables.o cos_fixed_tables.o
  OBJS-$(CONFIG_FFT)                     += avfft.o fft_fixed.o fft_float.o \
 +                                          fft_fixed_32.o fft_init_table.o \
                                            $(FFT-OBJS-yes)
  OBJS-$(CONFIG_GOLOMB)                  += golomb.o
  OBJS-$(CONFIG_H263DSP)                 += h263dsp.o
@@@ -57,23 -48,22 +57,24 @@@ OBJS-$(CONFIG_HPELDSP)                 
  OBJS-$(CONFIG_HUFFMAN)                 += huffman.o
  OBJS-$(CONFIG_INTRAX8)                 += intrax8.o intrax8dsp.o
  OBJS-$(CONFIG_LIBXVID)                 += libxvid_rc.o
 +OBJS-$(CONFIG_LLVIDDSP)                += lossless_videodsp.o
  OBJS-$(CONFIG_LPC)                     += lpc.o
  OBJS-$(CONFIG_LSP)                     += lsp.o
 -OBJS-$(CONFIG_MDCT)                    += mdct_fixed.o mdct_float.o
 +OBJS-$(CONFIG_MDCT)                    += mdct_fixed.o mdct_float.o mdct_fixed_32.o
  OBJS-$(CONFIG_MPEGAUDIO)               += mpegaudio.o mpegaudiodata.o   \
                                            mpegaudiodecheader.o
  OBJS-$(CONFIG_MPEGAUDIODSP)            += mpegaudiodsp.o                \
                                            mpegaudiodsp_data.o           \
                                            mpegaudiodsp_fixed.o          \
                                            mpegaudiodsp_float.o
- OBJS-$(CONFIG_MPEGVIDEO)               += mpegvideo.o mpegvideo_motion.o
+ OBJS-$(CONFIG_MPEGVIDEO)               += mpegvideo.o mpegvideo_motion.o \
+                                           mpegutils.o
  OBJS-$(CONFIG_MPEGVIDEOENC)            += mpegvideo_enc.o mpeg12data.o  \
                                            motion_est.o ratecontrol.o
  OBJS-$(CONFIG_RANGECODER)              += rangecoder.o
  RDFT-OBJS-$(CONFIG_HARDCODED_TABLES)   += sin_tables.o
  OBJS-$(CONFIG_RDFT)                    += rdft.o $(RDFT-OBJS-yes)
 +OBJS-$(CONFIG_SHARED)                  += log2_tab.o
  OBJS-$(CONFIG_SINEWIN)                 += sinewin.o
  OBJS-$(CONFIG_VAAPI)                   += vaapi.o
  OBJS-$(CONFIG_VDPAU)                   += vdpau.o
@@@ -81,7 -71,6 +82,7 @@@ OBJS-$(CONFIG_VIDEODSP)                
  OBJS-$(CONFIG_VP3DSP)                  += vp3dsp.o
  
  # decoders/encoders
 +OBJS-$(CONFIG_ZERO12V_DECODER)         += 012v.o
  OBJS-$(CONFIG_A64MULTI_ENCODER)        += a64multienc.o elbg.o
  OBJS-$(CONFIG_A64MULTI5_ENCODER)       += a64multienc.o elbg.o
  OBJS-$(CONFIG_AAC_DECODER)             += aacdec.o aactab.o aacsbr.o aacps.o \
@@@ -108,16 -97,10 +109,16 @@@ OBJS-$(CONFIG_AMRWB_DECODER)           
                                            celp_math.o acelp_filters.o \
                                            acelp_vectors.o             \
                                            acelp_pitch_delay.o
 +OBJS-$(CONFIG_AMV_ENCODER)             += mjpegenc.o mjpeg.o           \
 +                                          mpegvideo_enc.o motion_est.o \
 +                                          ratecontrol.o mpeg12data.o   \
 +                                          mpegvideo.o
  OBJS-$(CONFIG_ANM_DECODER)             += anm.o
  OBJS-$(CONFIG_ANSI_DECODER)            += ansi.o cga_data.o
  OBJS-$(CONFIG_APE_DECODER)             += apedec.o
 -OBJS-$(CONFIG_ASS_DECODER)             += assdec.o ass.o
 +OBJS-$(CONFIG_SSA_DECODER)             += assdec.o ass.o ass_split.o
 +OBJS-$(CONFIG_SSA_ENCODER)             += assenc.o ass.o
 +OBJS-$(CONFIG_ASS_DECODER)             += assdec.o ass.o ass_split.o
  OBJS-$(CONFIG_ASS_ENCODER)             += assenc.o ass.o
  OBJS-$(CONFIG_ASV1_DECODER)            += asvdec.o asv.o mpeg12data.o
  OBJS-$(CONFIG_ASV1_ENCODER)            += asvenc.o asv.o mpeg12data.o
@@@ -129,46 -112,32 +130,46 @@@ OBJS-$(CONFIG_ATRAC3P_DECODER)         
                                            atrac3plusdsp.o atrac.o
  OBJS-$(CONFIG_AURA_DECODER)            += cyuv.o
  OBJS-$(CONFIG_AURA2_DECODER)           += aura.o
 +OBJS-$(CONFIG_AVRN_DECODER)            += avrndec.o mjpegdec.o mjpeg.o
 +OBJS-$(CONFIG_AVRP_DECODER)            += r210dec.o
 +OBJS-$(CONFIG_AVRP_ENCODER)            += r210enc.o
  OBJS-$(CONFIG_AVS_DECODER)             += avs.o
 +OBJS-$(CONFIG_AVUI_DECODER)            += avuidec.o
 +OBJS-$(CONFIG_AVUI_ENCODER)            += avuienc.o
 +OBJS-$(CONFIG_AYUV_DECODER)            += v408dec.o
 +OBJS-$(CONFIG_AYUV_ENCODER)            += v408enc.o
  OBJS-$(CONFIG_BETHSOFTVID_DECODER)     += bethsoftvideo.o
  OBJS-$(CONFIG_BFI_DECODER)             += bfi.o
  OBJS-$(CONFIG_BINK_DECODER)            += bink.o binkdsp.o
  OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER)   += binkaudio.o wma.o wma_common.o
  OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER)  += binkaudio.o wma.o wma_common.o
 +OBJS-$(CONFIG_BINTEXT_DECODER)         += bintext.o cga_data.o
  OBJS-$(CONFIG_BMP_DECODER)             += bmp.o msrledec.o
  OBJS-$(CONFIG_BMP_ENCODER)             += bmpenc.o
  OBJS-$(CONFIG_BMV_VIDEO_DECODER)       += bmv.o
  OBJS-$(CONFIG_BMV_AUDIO_DECODER)       += bmv.o
 +OBJS-$(CONFIG_BRENDER_PIX_DECODER)     += brender_pix.o
  OBJS-$(CONFIG_C93_DECODER)             += c93.o
  OBJS-$(CONFIG_CAVS_DECODER)            += cavs.o cavsdec.o cavsdsp.o \
                                            cavsdata.o mpeg12data.o
  OBJS-$(CONFIG_CDGRAPHICS_DECODER)      += cdgraphics.o
  OBJS-$(CONFIG_CDXL_DECODER)            += cdxl.o
  OBJS-$(CONFIG_CINEPAK_DECODER)         += cinepak.o
 +OBJS-$(CONFIG_CINEPAK_ENCODER)         += cinepakenc.o elbg.o
  OBJS-$(CONFIG_CLJR_DECODER)            += cljr.o
  OBJS-$(CONFIG_CLJR_ENCODER)            += cljr.o
  OBJS-$(CONFIG_CLLC_DECODER)            += cllc.o
  OBJS-$(CONFIG_COOK_DECODER)            += cook.o
  OBJS-$(CONFIG_COMFORTNOISE_DECODER)    += cngdec.o celp_filters.o
  OBJS-$(CONFIG_COMFORTNOISE_ENCODER)    += cngenc.o
 +OBJS-$(CONFIG_CPIA_DECODER)            += cpia.o
  OBJS-$(CONFIG_CSCD_DECODER)            += cscd.o
  OBJS-$(CONFIG_CYUV_DECODER)            += cyuv.o
  OBJS-$(CONFIG_DCA_DECODER)             += dcadec.o dca.o dcadsp.o      \
                                            synth_filter.o
 +OBJS-$(CONFIG_DCA_ENCODER)             += dcaenc.o dca.o
 +OBJS-$(CONFIG_DIRAC_DECODER)           += diracdec.o dirac.o diracdsp.o \
 +                                          dirac_arith.o mpeg12data.o dirac_dwt.o
  OBJS-$(CONFIG_DFA_DECODER)             += dfa.o
  OBJS-$(CONFIG_DNXHD_DECODER)           += dnxhddec.o dnxhddata.o
  OBJS-$(CONFIG_DNXHD_ENCODER)           += dnxhdenc.o dnxhddata.o
@@@ -198,17 -167,13 +199,17 @@@ OBJS-$(CONFIG_EIGHTSVX_EXP_DECODER)    
  OBJS-$(CONFIG_EIGHTSVX_FIB_DECODER)    += 8svx.o
  OBJS-$(CONFIG_ESCAPE124_DECODER)       += escape124.o
  OBJS-$(CONFIG_ESCAPE130_DECODER)       += escape130.o
 +OBJS-$(CONFIG_EVRC_DECODER)            += evrcdec.o acelp_vectors.o lsp.o
 +OBJS-$(CONFIG_EXR_DECODER)             += exr.o
  OBJS-$(CONFIG_FFV1_DECODER)            += ffv1dec.o ffv1.o
  OBJS-$(CONFIG_FFV1_ENCODER)            += ffv1enc.o ffv1.o
 +OBJS-$(CONFIG_FFWAVESYNTH_DECODER)     += ffwavesynth.o
  OBJS-$(CONFIG_FIC_DECODER)             += fic.o
  OBJS-$(CONFIG_FLAC_DECODER)            += flacdec.o flacdata.o flac.o flacdsp.o
 -OBJS-$(CONFIG_FLAC_ENCODER)            += flacenc.o flacdata.o flac.o flacdsp.o
 +OBJS-$(CONFIG_FLAC_ENCODER)            += flacenc.o flacdata.o flac.o flacdsp.o vorbis_data.o
  OBJS-$(CONFIG_FLASHSV_DECODER)         += flashsv.o
  OBJS-$(CONFIG_FLASHSV_ENCODER)         += flashsvenc.o
 +OBJS-$(CONFIG_FLASHSV2_ENCODER)        += flashsv2enc.o
  OBJS-$(CONFIG_FLASHSV2_DECODER)        += flashsv.o
  OBJS-$(CONFIG_FLIC_DECODER)            += flicvideo.o
  OBJS-$(CONFIG_FOURXM_DECODER)          += 4xm.o
@@@ -216,9 -181,7 +217,9 @@@ OBJS-$(CONFIG_FRAPS_DECODER)           
  OBJS-$(CONFIG_FRWU_DECODER)            += frwu.o
  OBJS-$(CONFIG_G2M_DECODER)             += g2meet.o mjpeg.o
  OBJS-$(CONFIG_G723_1_DECODER)          += g723_1.o acelp_vectors.o \
 -                                          celp_filters.o
 +                                          celp_filters.o celp_math.o
 +OBJS-$(CONFIG_G723_1_ENCODER)          += g723_1.o acelp_vectors.o celp_math.o
 +OBJS-$(CONFIG_G729_DECODER)            += g729dec.o lsp.o celp_math.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o
  OBJS-$(CONFIG_GIF_DECODER)             += gifdec.o lzw.o
  OBJS-$(CONFIG_GIF_ENCODER)             += gif.o lzwenc.o
  OBJS-$(CONFIG_GSM_DECODER)             += gsmdec.o gsmdec_data.o msgsmdec.o
@@@ -234,7 -197,6 +235,7 @@@ OBJS-$(CONFIG_H264_DECODER)            
                                            h264_loopfilter.o h264_direct.o      \
                                            cabac.o h264_sei.o h264_ps.o         \
                                            h264_refs.o h264_cavlc.o h264_cabac.o
 +OBJS-$(CONFIG_H264_VDA_DECODER)        += vda_h264_dec.o
  OBJS-$(CONFIG_HEVC_DECODER)            += hevc.o hevc_mvs.o hevc_ps.o hevc_sei.o \
                                            hevc_cabac.o hevc_refs.o hevcpred.o    \
                                            hevcdsp.o hevc_filter.o cabac.o
@@@ -242,7 -204,6 +243,7 @@@ OBJS-$(CONFIG_HNM4_VIDEO_DECODER)      
  OBJS-$(CONFIG_HUFFYUV_DECODER)         += huffyuv.o huffyuvdec.o
  OBJS-$(CONFIG_HUFFYUV_ENCODER)         += huffyuv.o huffyuvenc.o
  OBJS-$(CONFIG_IDCIN_DECODER)           += idcinvideo.o
 +OBJS-$(CONFIG_IDF_DECODER)             += bintext.o cga_data.o
  OBJS-$(CONFIG_IFF_BYTERUN1_DECODER)    += iff.o
  OBJS-$(CONFIG_IFF_ILBM_DECODER)        += iff.o
  OBJS-$(CONFIG_IMC_DECODER)             += imc.o
@@@ -252,9 -213,6 +253,9 @@@ OBJS-$(CONFIG_INDEO4_DECODER)          
  OBJS-$(CONFIG_INDEO5_DECODER)          += indeo5.o ivi_common.o ivi_dsp.o
  OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
  OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 +OBJS-$(CONFIG_JACOSUB_DECODER)         += jacosubdec.o ass.o
 +OBJS-$(CONFIG_JPEG2000_ENCODER)        += j2kenc.o mqcenc.o mqc.o jpeg2000.o \
 +                                          jpeg2000dwt.o
  OBJS-$(CONFIG_JPEG2000_DECODER)        += jpeg2000dec.o jpeg2000.o      \
                                            jpeg2000dwt.o mqcdec.o mqc.o
  OBJS-$(CONFIG_JPEGLS_DECODER)          += jpeglsdec.o jpegls.o
@@@ -270,7 -228,6 +271,7 @@@ OBJS-$(CONFIG_MACE6_DECODER)           
  OBJS-$(CONFIG_MDEC_DECODER)            += mdec.o mpeg12.o mpeg12data.o
  OBJS-$(CONFIG_METASOUND_DECODER)       += metasound.o metasound_data.o \
                                            twinvq.o
 +OBJS-$(CONFIG_MICRODVD_DECODER)        += microdvddec.o ass.o
  OBJS-$(CONFIG_MIMIC_DECODER)           += mimic.o
  OBJS-$(CONFIG_MJPEG_DECODER)           += mjpegdec.o mjpeg.o
  OBJS-$(CONFIG_MJPEG_ENCODER)           += mjpegenc.o mjpeg.o
@@@ -278,14 -235,10 +279,14 @@@ OBJS-$(CONFIG_MJPEGB_DECODER)          
  OBJS-$(CONFIG_MLP_DECODER)             += mlpdec.o mlpdsp.o
  OBJS-$(CONFIG_MMVIDEO_DECODER)         += mmvideo.o
  OBJS-$(CONFIG_MOTIONPIXELS_DECODER)    += motionpixels.o
 +OBJS-$(CONFIG_MOVTEXT_DECODER)         += movtextdec.o ass.o
 +OBJS-$(CONFIG_MOVTEXT_ENCODER)         += movtextenc.o ass_split.o
  OBJS-$(CONFIG_MP1_DECODER)             += mpegaudiodec_fixed.o
  OBJS-$(CONFIG_MP1FLOAT_DECODER)        += mpegaudiodec_float.o
  OBJS-$(CONFIG_MP2_DECODER)             += mpegaudiodec_fixed.o
 -OBJS-$(CONFIG_MP2_ENCODER)             += mpegaudioenc.o mpegaudio.o \
 +OBJS-$(CONFIG_MP2_ENCODER)             += mpegaudioenc_float.o mpegaudio.o \
 +                                          mpegaudiodata.o mpegaudiodsp_data.o
 +OBJS-$(CONFIG_MP2FIXED_ENCODER)        += mpegaudioenc_fixed.o mpegaudio.o \
                                            mpegaudiodata.o mpegaudiodsp_data.o
  OBJS-$(CONFIG_MP2FLOAT_DECODER)        += mpegaudiodec_float.o
  OBJS-$(CONFIG_MP3_DECODER)             += mpegaudiodec_fixed.o
@@@ -296,13 -249,11 +297,13 @@@ OBJS-$(CONFIG_MP3ON4_DECODER)          
  OBJS-$(CONFIG_MP3ON4FLOAT_DECODER)     += mpegaudiodec_float.o mpeg4audio.o
  OBJS-$(CONFIG_MPC7_DECODER)            += mpc7.o mpc.o
  OBJS-$(CONFIG_MPC8_DECODER)            += mpc8.o mpc.o
 -OBJS-$(CONFIG_MPEG_XVMC_DECODER)       += mpegvideo_xvmc.o
 +OBJS-$(CONFIG_MPEGVIDEO_DECODER)       += mpeg12.o mpeg12data.o \
 +                                          mpegvideo.o error_resilience.o
  OBJS-$(CONFIG_MPEG1VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
  OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
  OBJS-$(CONFIG_MPEG2VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
  OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
 +OBJS-$(CONFIG_MPL2_DECODER)            += mpl2dec.o ass.o
  OBJS-$(CONFIG_MSMPEG4V1_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o
  OBJS-$(CONFIG_MSMPEG4V2_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o
  OBJS-$(CONFIG_MSMPEG4V2_ENCODER)       += msmpeg4enc.o msmpeg4.o msmpeg4data.o
@@@ -313,17 -264,12 +314,17 @@@ OBJS-$(CONFIG_MSA1_DECODER)            
  OBJS-$(CONFIG_MSS1_DECODER)            += mss1.o mss12.o
  OBJS-$(CONFIG_MSS2_DECODER)            += mss2.o mss12.o mss2dsp.o
  OBJS-$(CONFIG_MSVIDEO1_DECODER)        += msvideo1.o
 +OBJS-$(CONFIG_MSVIDEO1_ENCODER)        += msvideo1enc.o elbg.o
  OBJS-$(CONFIG_MSZH_DECODER)            += lcldec.o
  OBJS-$(CONFIG_MTS2_DECODER)            += mss4.o mss34dsp.o
 +OBJS-$(CONFIG_MVC1_DECODER)            += mvcdec.o
 +OBJS-$(CONFIG_MVC2_DECODER)            += mvcdec.o
  OBJS-$(CONFIG_MXPEG_DECODER)           += mxpegdec.o
  OBJS-$(CONFIG_NELLYMOSER_DECODER)      += nellymoserdec.o nellymoser.o
  OBJS-$(CONFIG_NELLYMOSER_ENCODER)      += nellymoserenc.o nellymoser.o
  OBJS-$(CONFIG_NUV_DECODER)             += nuv.o rtjpeg.o
 +OBJS-$(CONFIG_PAF_VIDEO_DECODER)       += paf.o
 +OBJS-$(CONFIG_PAF_AUDIO_DECODER)       += paf.o
  OBJS-$(CONFIG_PAM_DECODER)             += pnmdec.o pnm.o
  OBJS-$(CONFIG_PAM_ENCODER)             += pamenc.o
  OBJS-$(CONFIG_PBM_DECODER)             += pnmdec.o pnm.o
@@@ -336,16 -282,12 +337,16 @@@ OBJS-$(CONFIG_PGMYUV_DECODER)          
  OBJS-$(CONFIG_PGMYUV_ENCODER)          += pnmenc.o
  OBJS-$(CONFIG_PGSSUB_DECODER)          += pgssubdec.o
  OBJS-$(CONFIG_PICTOR_DECODER)          += pictordec.o cga_data.o
 +OBJS-$(CONFIG_PJS_DECODER)             += textdec.o ass.o
  OBJS-$(CONFIG_PNG_DECODER)             += png.o pngdec.o pngdsp.o
  OBJS-$(CONFIG_PNG_ENCODER)             += png.o pngenc.o
  OBJS-$(CONFIG_PPM_DECODER)             += pnmdec.o pnm.o
  OBJS-$(CONFIG_PPM_ENCODER)             += pnmenc.o
 -OBJS-$(CONFIG_PRORES_DECODER)          += proresdec.o proresdata.o proresdsp.o
 -OBJS-$(CONFIG_PRORES_ENCODER)          += proresenc.o proresdata.o
 +OBJS-$(CONFIG_PRORES_DECODER)          += proresdec2.o proresdsp.o proresdata.o
 +OBJS-$(CONFIG_PRORES_LGPL_DECODER)     += proresdec_lgpl.o proresdsp.o proresdata.o
 +OBJS-$(CONFIG_PRORES_ENCODER)          += proresenc_anatoliy.o
 +OBJS-$(CONFIG_PRORES_AW_ENCODER)       += proresenc_anatoliy.o
 +OBJS-$(CONFIG_PRORES_KS_ENCODER)       += proresenc_kostya.o proresdata.o
  OBJS-$(CONFIG_PTX_DECODER)             += ptx.o
  OBJS-$(CONFIG_QCELP_DECODER)           += qcelpdec.o                     \
                                            celp_filters.o acelp_vectors.o \
@@@ -356,16 -298,13 +357,16 @@@ OBJS-$(CONFIG_QPEG_DECODER)            
  OBJS-$(CONFIG_QTRLE_DECODER)           += qtrle.o
  OBJS-$(CONFIG_QTRLE_ENCODER)           += qtrleenc.o
  OBJS-$(CONFIG_R10K_DECODER)            += r210dec.o
 +OBJS-$(CONFIG_R10K_ENCODER)            += r210enc.o
  OBJS-$(CONFIG_R210_DECODER)            += r210dec.o
 +OBJS-$(CONFIG_R210_ENCODER)            += r210enc.o
  OBJS-$(CONFIG_RA_144_DECODER)          += ra144dec.o ra144.o celp_filters.o
  OBJS-$(CONFIG_RA_144_ENCODER)          += ra144enc.o ra144.o celp_filters.o
  OBJS-$(CONFIG_RA_288_DECODER)          += ra288.o celp_filters.o
  OBJS-$(CONFIG_RALF_DECODER)            += ralf.o
  OBJS-$(CONFIG_RAWVIDEO_DECODER)        += rawdec.o
  OBJS-$(CONFIG_RAWVIDEO_ENCODER)        += rawenc.o
 +OBJS-$(CONFIG_REALTEXT_DECODER)        += realtextdec.o ass.o
  OBJS-$(CONFIG_RL2_DECODER)             += rl2.o
  OBJS-$(CONFIG_ROQ_DECODER)             += roqvideodec.o roqvideo.o
  OBJS-$(CONFIG_ROQ_ENCODER)             += roqvideoenc.o roqvideo.o elbg.o
@@@ -378,13 -317,9 +379,13 @@@ OBJS-$(CONFIG_RV20_DECODER)            
  OBJS-$(CONFIG_RV20_ENCODER)            += rv20enc.o
  OBJS-$(CONFIG_RV30_DECODER)            += rv30.o rv34.o rv30dsp.o rv34dsp.o
  OBJS-$(CONFIG_RV40_DECODER)            += rv40.o rv34.o rv34dsp.o rv40dsp.o
 +OBJS-$(CONFIG_SAMI_DECODER)            += samidec.o ass.o
  OBJS-$(CONFIG_S302M_DECODER)           += s302m.o
 +OBJS-$(CONFIG_S302M_ENCODER)           += s302menc.o
 +OBJS-$(CONFIG_SANM_DECODER)            += sanm.o
  OBJS-$(CONFIG_SGI_DECODER)             += sgidec.o
  OBJS-$(CONFIG_SGI_ENCODER)             += sgienc.o rle.o
 +OBJS-$(CONFIG_SGIRLE_DECODER)          += sgirledec.o
  OBJS-$(CONFIG_SHORTEN_DECODER)         += shorten.o
  OBJS-$(CONFIG_SIPR_DECODER)            += sipr.o acelp_pitch_delay.o \
                                            celp_math.o acelp_vectors.o \
  OBJS-$(CONFIG_SMACKAUD_DECODER)        += smacker.o
  OBJS-$(CONFIG_SMACKER_DECODER)         += smacker.o
  OBJS-$(CONFIG_SMC_DECODER)             += smc.o
 +OBJS-$(CONFIG_SMVJPEG_DECODER)         += smvjpegdec.o
 +OBJS-$(CONFIG_SNOW_DECODER)            += snowdec.o snow.o snow_dwt.o
 +OBJS-$(CONFIG_SNOW_ENCODER)            += snowenc.o snow.o snow_dwt.o             \
 +                                          h263.o ituh263enc.o
  OBJS-$(CONFIG_SOL_DPCM_DECODER)        += dpcm.o
 +OBJS-$(CONFIG_SONIC_DECODER)           += sonic.o
 +OBJS-$(CONFIG_SONIC_ENCODER)           += sonic.o
 +OBJS-$(CONFIG_SONIC_LS_ENCODER)        += sonic.o
  OBJS-$(CONFIG_SP5X_DECODER)            += sp5xdec.o
  OBJS-$(CONFIG_SRT_DECODER)             += srtdec.o ass.o
 +OBJS-$(CONFIG_SRT_ENCODER)             += srtenc.o ass_split.o
 +OBJS-$(CONFIG_SUBRIP_DECODER)          += srtdec.o ass.o
 +OBJS-$(CONFIG_SUBRIP_ENCODER)          += srtenc.o ass_split.o
 +OBJS-$(CONFIG_SUBVIEWER1_DECODER)      += textdec.o ass.o
 +OBJS-$(CONFIG_SUBVIEWER_DECODER)       += subviewerdec.o ass.o
  OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
  OBJS-$(CONFIG_SUNRAST_ENCODER)         += sunrastenc.o
  OBJS-$(CONFIG_SVQ1_DECODER)            += svq1dec.o svq1.o svq13.o h263.o
  OBJS-$(CONFIG_SVQ1_ENCODER)            += svq1enc.o svq1.o    \
                                            h263.o ituh263enc.o
- OBJS-$(CONFIG_SVQ3_DECODER)            += svq3.o svq13.o
+ OBJS-$(CONFIG_SVQ3_DECODER)            += svq3.o svq13.o mpegutils.o
 +OBJS-$(CONFIG_TEXT_DECODER)            += textdec.o ass.o
  OBJS-$(CONFIG_TAK_DECODER)             += takdec.o tak.o
  OBJS-$(CONFIG_TARGA_DECODER)           += targa.o
  OBJS-$(CONFIG_TARGA_ENCODER)           += targaenc.o rle.o
 +OBJS-$(CONFIG_TARGA_Y216_DECODER)      += targa_y216dec.o
  OBJS-$(CONFIG_THEORA_DECODER)          += xiph.o
  OBJS-$(CONFIG_TIERTEXSEQVIDEO_DECODER) += tiertexseqv.o
 -OBJS-$(CONFIG_TIFF_DECODER)            += tiff.o lzw.o faxcompr.o
 -OBJS-$(CONFIG_TIFF_ENCODER)            += tiffenc.o rle.o lzwenc.o
 +OBJS-$(CONFIG_TIFF_DECODER)            += tiff.o lzw.o faxcompr.o tiff_data.o tiff_common.o
 +OBJS-$(CONFIG_TIFF_ENCODER)            += tiffenc.o rle.o lzwenc.o tiff_data.o
  OBJS-$(CONFIG_TMV_DECODER)             += tmv.o cga_data.o
 +OBJS-$(CONFIG_TRUEHD_DECODER)          += mlpdec.o mlpdsp.o
  OBJS-$(CONFIG_TRUEMOTION1_DECODER)     += truemotion1.o
  OBJS-$(CONFIG_TRUEMOTION2_DECODER)     += truemotion2.o
  OBJS-$(CONFIG_TRUESPEECH_DECODER)      += truespeech.o
  OBJS-$(CONFIG_TSCC_DECODER)            += tscc.o msrledec.o
  OBJS-$(CONFIG_TSCC2_DECODER)           += tscc2.o
 -OBJS-$(CONFIG_TTA_DECODER)             += tta.o
 +OBJS-$(CONFIG_TTA_DECODER)             += tta.o ttadata.o ttadsp.o
 +OBJS-$(CONFIG_TTA_ENCODER)             += ttaenc.o ttadata.o
  OBJS-$(CONFIG_TWINVQ_DECODER)          += twinvqdec.o twinvq.o
  OBJS-$(CONFIG_TXD_DECODER)             += txd.o s3tc.o
  OBJS-$(CONFIG_ULTI_DECODER)            += ulti.o
@@@ -439,18 -358,13 +440,18 @@@ OBJS-$(CONFIG_UTVIDEO_DECODER)         
  OBJS-$(CONFIG_UTVIDEO_ENCODER)         += utvideoenc.o utvideo.o
  OBJS-$(CONFIG_V210_DECODER)            += v210dec.o
  OBJS-$(CONFIG_V210_ENCODER)            += v210enc.o
 +OBJS-$(CONFIG_V308_DECODER)            += v308dec.o
 +OBJS-$(CONFIG_V308_ENCODER)            += v308enc.o
 +OBJS-$(CONFIG_V408_DECODER)            += v408dec.o
 +OBJS-$(CONFIG_V408_ENCODER)            += v408enc.o
  OBJS-$(CONFIG_V410_DECODER)            += v410dec.o
  OBJS-$(CONFIG_V410_ENCODER)            += v410enc.o
  OBJS-$(CONFIG_V210X_DECODER)           += v210x.o
  OBJS-$(CONFIG_VB_DECODER)              += vb.o
  OBJS-$(CONFIG_VBLE_DECODER)            += vble.o
  OBJS-$(CONFIG_VC1_DECODER)             += vc1dec.o vc1.o vc1data.o vc1dsp.o \
 -                                          msmpeg4dec.o msmpeg4.o msmpeg4data.o
 +                                          msmpeg4dec.o msmpeg4.o msmpeg4data.o \
 +                                          wmv2dsp.o
  OBJS-$(CONFIG_VCR1_DECODER)            += vcr1.o
  OBJS-$(CONFIG_VMDAUDIO_DECODER)        += vmdav.o
  OBJS-$(CONFIG_VMDVIDEO_DECODER)        += vmdav.o
@@@ -465,14 -379,11 +466,14 @@@ OBJS-$(CONFIG_VP5_DECODER)             
  OBJS-$(CONFIG_VP6_DECODER)             += vp6.o vp56.o vp56data.o vp56dsp.o \
                                            vp6dsp.o vp56rac.o
  OBJS-$(CONFIG_VP8_DECODER)             += vp8.o vp8dsp.o vp56rac.o
 -OBJS-$(CONFIG_VP9_DECODER)             += vp9.o vp9data.o vp9dsp.o \
 -                                          vp9block.o vp9prob.o vp9mvs.o vp56rac.o
 +OBJS-$(CONFIG_VP9_DECODER)             += vp9.o vp9dsp.o vp56rac.o
 +OBJS-$(CONFIG_VPLAYER_DECODER)         += textdec.o ass.o
  OBJS-$(CONFIG_VQA_DECODER)             += vqavideo.o
  OBJS-$(CONFIG_WAVPACK_DECODER)         += wavpack.o
 -OBJS-$(CONFIG_WEBP_DECODER)            += webp.o
 +OBJS-$(CONFIG_WAVPACK_ENCODER)         += wavpackenc.o
 +OBJS-$(CONFIG_WEBP_DECODER)            += vp8.o vp8dsp.o vp56rac.o
 +OBJS-$(CONFIG_WEBP_DECODER)            += webp.o exif.o tiff_common.o
 +OBJS-$(CONFIG_WEBVTT_DECODER)          += webvttdec.o
  OBJS-$(CONFIG_WMALOSSLESS_DECODER)     += wmalosslessdec.o wma_common.o
  OBJS-$(CONFIG_WMAPRO_DECODER)          += wmaprodec.o wma.o wma_common.o
  OBJS-$(CONFIG_WMAV1_DECODER)           += wmadec.o wma.o wma_common.o aactab.o
@@@ -492,21 -403,13 +493,21 @@@ OBJS-$(CONFIG_WS_SND1_DECODER)         
  OBJS-$(CONFIG_XAN_DPCM_DECODER)        += dpcm.o
  OBJS-$(CONFIG_XAN_WC3_DECODER)         += xan.o
  OBJS-$(CONFIG_XAN_WC4_DECODER)         += xxan.o
 +OBJS-$(CONFIG_XBIN_DECODER)            += bintext.o cga_data.o
 +OBJS-$(CONFIG_XBM_DECODER)             += xbmdec.o
  OBJS-$(CONFIG_XBM_ENCODER)             += xbmenc.o
 +OBJS-$(CONFIG_XFACE_DECODER)           += xfacedec.o xface.o
 +OBJS-$(CONFIG_XFACE_ENCODER)           += xfaceenc.o xface.o
  OBJS-$(CONFIG_XL_DECODER)              += xl.o
  OBJS-$(CONFIG_XSUB_DECODER)            += xsubdec.o
  OBJS-$(CONFIG_XSUB_ENCODER)            += xsubenc.o
  OBJS-$(CONFIG_XWD_DECODER)             += xwddec.o
  OBJS-$(CONFIG_XWD_ENCODER)             += xwdenc.o
 +OBJS-$(CONFIG_Y41P_DECODER)            += y41pdec.o
 +OBJS-$(CONFIG_Y41P_ENCODER)            += y41penc.o
  OBJS-$(CONFIG_YOP_DECODER)             += yop.o
 +OBJS-$(CONFIG_YUV4_DECODER)            += yuv4dec.o
 +OBJS-$(CONFIG_YUV4_ENCODER)            += yuv4enc.o
  OBJS-$(CONFIG_ZEROCODEC_DECODER)       += zerocodec.o
  OBJS-$(CONFIG_ZLIB_DECODER)            += lcldec.o
  OBJS-$(CONFIG_ZLIB_ENCODER)            += lclenc.o
@@@ -531,16 -434,12 +532,16 @@@ OBJS-$(CONFIG_PCM_MULAW_DECODER
  OBJS-$(CONFIG_PCM_MULAW_ENCODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S8_DECODER)             += pcm.o
  OBJS-$(CONFIG_PCM_S8_ENCODER)             += pcm.o
 -OBJS-$(CONFIG_PCM_S8_PLANAR_DECODER)      += 8svx.o
 +OBJS-$(CONFIG_PCM_S8_PLANAR_DECODER)      += pcm.o
 +OBJS-$(CONFIG_PCM_S8_PLANAR_ENCODER)      += pcm.o
  OBJS-$(CONFIG_PCM_S16BE_DECODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S16BE_ENCODER)          += pcm.o
 +OBJS-$(CONFIG_PCM_S16BE_PLANAR_DECODER)   += pcm.o
 +OBJS-$(CONFIG_PCM_S16BE_PLANAR_ENCODER)   += pcm.o
  OBJS-$(CONFIG_PCM_S16LE_DECODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S16LE_ENCODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S16LE_PLANAR_DECODER)   += pcm.o
 +OBJS-$(CONFIG_PCM_S16LE_PLANAR_ENCODER)   += pcm.o
  OBJS-$(CONFIG_PCM_S24BE_DECODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S24BE_ENCODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S24DAUD_DECODER)        += pcm.o
@@@ -548,13 -447,11 +549,13 @@@ OBJS-$(CONFIG_PCM_S24DAUD_ENCODER
  OBJS-$(CONFIG_PCM_S24LE_DECODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S24LE_ENCODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S24LE_PLANAR_DECODER)   += pcm.o
 +OBJS-$(CONFIG_PCM_S24LE_PLANAR_ENCODER)   += pcm.o
  OBJS-$(CONFIG_PCM_S32BE_DECODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S32BE_ENCODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S32LE_DECODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S32LE_ENCODER)          += pcm.o
  OBJS-$(CONFIG_PCM_S32LE_PLANAR_DECODER)   += pcm.o
 +OBJS-$(CONFIG_PCM_S32LE_PLANAR_ENCODER)   += pcm.o
  OBJS-$(CONFIG_PCM_U8_DECODER)             += pcm.o
  OBJS-$(CONFIG_PCM_U8_ENCODER)             += pcm.o
  OBJS-$(CONFIG_PCM_U16BE_DECODER)          += pcm.o
@@@ -574,9 -471,7 +575,9 @@@ OBJS-$(CONFIG_PCM_ZORK_DECODER
  OBJS-$(CONFIG_ADPCM_4XM_DECODER)          += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_ADX_DECODER)          += adxdec.o adx.o
  OBJS-$(CONFIG_ADPCM_ADX_ENCODER)          += adxenc.o adx.o
 +OBJS-$(CONFIG_ADPCM_AFC_DECODER)          += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_CT_DECODER)           += adpcm.o adpcm_data.o
 +OBJS-$(CONFIG_ADPCM_DTK_DECODER)          += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_EA_DECODER)           += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER)  += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_EA_R1_DECODER)        += adpcm.o adpcm_data.o
@@@ -587,7 -482,6 +588,7 @@@ OBJS-$(CONFIG_ADPCM_G722_DECODER
  OBJS-$(CONFIG_ADPCM_G722_ENCODER)         += g722.o g722enc.o
  OBJS-$(CONFIG_ADPCM_G726_DECODER)         += g726.o
  OBJS-$(CONFIG_ADPCM_G726_ENCODER)         += g726.o
 +OBJS-$(CONFIG_ADPCM_G726LE_DECODER)       += g726.o
  OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)      += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)      += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER)      += adpcm.o adpcm_data.o
@@@ -595,10 -489,8 +596,10 @@@ OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER
  OBJS-$(CONFIG_ADPCM_IMA_EA_EACS_DECODER)  += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_EA_SEAD_DECODER)  += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_ISS_DECODER)      += adpcm.o adpcm_data.o
 +OBJS-$(CONFIG_ADPCM_IMA_OKI_DECODER)      += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER)       += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER)       += adpcmenc.o adpcm_data.o
 +OBJS-$(CONFIG_ADPCM_IMA_RAD_DECODER)      += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER)   += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER)      += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER)      += adpcmenc.o adpcm_data.o
@@@ -614,25 -506,22 +615,25 @@@ OBJS-$(CONFIG_ADPCM_THP_DECODER
  OBJS-$(CONFIG_ADPCM_XA_DECODER)           += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER)       += adpcm.o adpcm_data.o
  OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER)       += adpcmenc.o adpcm_data.o
 +OBJS-$(CONFIG_VIMA_DECODER)               += vima.o adpcm_data.o
  
  # hardware accelerators
 -OBJS-$(CONFIG_H263_VAAPI_HWACCEL)         += vaapi_mpeg4.o
 +OBJS-$(CONFIG_H263_VAAPI_HWACCEL)         += vaapi_mpeg4.o vaapi_mpeg.o
  OBJS-$(CONFIG_H263_VDPAU_HWACCEL)         += vdpau_mpeg4.o
  OBJS-$(CONFIG_H264_DXVA2_HWACCEL)         += dxva2_h264.o
  OBJS-$(CONFIG_H264_VAAPI_HWACCEL)         += vaapi_h264.o
  OBJS-$(CONFIG_H264_VDA_HWACCEL)           += vda_h264.o
  OBJS-$(CONFIG_H264_VDPAU_HWACCEL)         += vdpau_h264.o
  OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)        += vdpau_mpeg12.o
 +OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL)         += mpegvideo_xvmc.o
  OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)        += dxva2_mpeg2.o
 -OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)        += vaapi_mpeg2.o
 +OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)        += vaapi_mpeg2.o vaapi_mpeg.o
  OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)        += vdpau_mpeg12.o
 -OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)        += vaapi_mpeg4.o
 +OBJS-$(CONFIG_MPEG2_XVMC_HWACCEL)         += mpegvideo_xvmc.o
 +OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)        += vaapi_mpeg4.o vaapi_mpeg.o
  OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)        += vdpau_mpeg4.o
  OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)          += dxva2_vc1.o
 -OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)          += vaapi_vc1.o
 +OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)          += vaapi_vc1.o vaapi_mpeg.o
  OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)          += vdpau_vc1.o
  
  # libavformat dependencies
@@@ -642,48 -531,40 +643,48 @@@ OBJS-$(CONFIG_CAF_DEMUXER)             
                                            ac3tab.o
  OBJS-$(CONFIG_DV_DEMUXER)              += dv_profile.o
  OBJS-$(CONFIG_DV_MUXER)                += dv_profile.o
 -OBJS-$(CONFIG_FLAC_DEMUXER)            += flac.o flacdata.o             \
 +OBJS-$(CONFIG_FLAC_DEMUXER)            += flac.o flacdata.o vorbis_data.o \
                                            vorbis_parser.o xiph.o
 -OBJS-$(CONFIG_FLAC_MUXER)              += flac.o flacdata.o
 +OBJS-$(CONFIG_FLAC_MUXER)              += flac.o flacdata.o vorbis_data.o
  OBJS-$(CONFIG_FLV_DEMUXER)             += mpeg4audio.o
  OBJS-$(CONFIG_GXF_DEMUXER)             += mpeg12data.o
  OBJS-$(CONFIG_IFF_DEMUXER)             += iff.o
  OBJS-$(CONFIG_ISMV_MUXER)              += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_LATM_MUXER)              += mpeg4audio.o
 -OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)    += xiph.o mpeg4audio.o           \
 +OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)    += xiph.o mpeg4audio.o vorbis_data.o \
                                            flac.o flacdata.o
  OBJS-$(CONFIG_MATROSKA_DEMUXER)        += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_MATROSKA_MUXER)          += mpeg4audio.o mpegaudiodata.o  \
 -                                          flac.o flacdata.o xiph.o
 +                                          flac.o flacdata.o vorbis_data.o xiph.o
  OBJS-$(CONFIG_MP2_MUXER)               += mpegaudiodata.o mpegaudiodecheader.o
  OBJS-$(CONFIG_MP3_MUXER)               += mpegaudiodata.o mpegaudiodecheader.o
  OBJS-$(CONFIG_MOV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o ac3tab.o
  OBJS-$(CONFIG_MOV_MUXER)               += mpeg4audio.o mpegaudiodata.o
  OBJS-$(CONFIG_MPEGTS_MUXER)            += mpeg4audio.o
  OBJS-$(CONFIG_MPEGTS_DEMUXER)          += mpeg4audio.o mpegaudiodata.o
 +OBJS-$(CONFIG_MXF_MUXER)               += dnxhddata.o
  OBJS-$(CONFIG_NUT_MUXER)               += mpegaudiodata.o
  OBJS-$(CONFIG_OGG_DEMUXER)             += xiph.o flac.o flacdata.o     \
                                            mpeg12data.o vorbis_parser.o \
 -                                          dirac.o
 -OBJS-$(CONFIG_OGG_MUXER)               += xiph.o flac.o flacdata.o
 +                                          dirac.o vorbis_data.o
 +OBJS-$(CONFIG_OGG_MUXER)               += xiph.o flac.o flacdata.o \
 +                                          vorbis_data.o
  OBJS-$(CONFIG_RTP_MUXER)               += mpeg4audio.o xiph.o
  OBJS-$(CONFIG_RTPDEC)                  += mjpeg.o
  OBJS-$(CONFIG_SPDIF_DEMUXER)           += aacadtsdec.o mpeg4audio.o
  OBJS-$(CONFIG_SPDIF_MUXER)             += dca.o
  OBJS-$(CONFIG_TAK_DEMUXER)             += tak.o
  OBJS-$(CONFIG_WEBM_MUXER)              += mpeg4audio.o mpegaudiodata.o  \
 -                                          xiph.o flac.o flacdata.o
 +                                          xiph.o flac.o flacdata.o \
 +                                          vorbis_data.o
  OBJS-$(CONFIG_WTV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
  
 +# libavfilter dependencies
 +OBJS-$(CONFIG_ELBG_FILTER)             += elbg.o
 +
  # external codec libraries
 +OBJS-$(CONFIG_LIBAACPLUS_ENCODER)         += libaacplus.o
 +OBJS-$(CONFIG_LIBCELT_DECODER)            += libcelt_dec.o
  OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o
  OBJS-$(CONFIG_LIBFDK_AAC_DECODER)         += libfdk-aacdec.o
  OBJS-$(CONFIG_LIBFDK_AAC_ENCODER)         += libfdk-aacenc.o
@@@ -707,19 -588,13 +708,19 @@@ OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER
                                               libschroedinger.o
  OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)    += libschroedingerenc.o \
                                               libschroedinger.o
 +OBJS-$(CONFIG_LIBSHINE_ENCODER)           += libshine.o
  OBJS-$(CONFIG_LIBSPEEX_DECODER)           += libspeexdec.o
  OBJS-$(CONFIG_LIBSPEEX_ENCODER)           += libspeexenc.o
 +OBJS-$(CONFIG_LIBSTAGEFRIGHT_H264_DECODER)+= libstagefright.o
  OBJS-$(CONFIG_LIBTHEORA_ENCODER)          += libtheoraenc.o
 +OBJS-$(CONFIG_LIBTWOLAME_ENCODER)         += libtwolame.o
 +OBJS-$(CONFIG_LIBUTVIDEO_DECODER)         += libutvideodec.o
 +OBJS-$(CONFIG_LIBUTVIDEO_ENCODER)         += libutvideoenc.o
  OBJS-$(CONFIG_LIBVO_AACENC_ENCODER)       += libvo-aacenc.o mpeg4audio.o
  OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER)     += libvo-amrwbenc.o
 -OBJS-$(CONFIG_LIBVORBIS_ENCODER)          += libvorbis.o \
 -                                             vorbis_data.o vorbis_parser.o
 +OBJS-$(CONFIG_LIBVORBIS_DECODER)          += libvorbisdec.o
 +OBJS-$(CONFIG_LIBVORBIS_ENCODER)          += libvorbisenc.o \
 +                                             vorbis_data.o vorbis_parser.o xiph.o
  OBJS-$(CONFIG_LIBVPX_VP8_DECODER)         += libvpxdec.o
  OBJS-$(CONFIG_LIBVPX_VP8_ENCODER)         += libvpxenc.o
  OBJS-$(CONFIG_LIBVPX_VP9_DECODER)         += libvpxdec.o libvpx.o
@@@ -730,7 -605,6 +731,7 @@@ OBJS-$(CONFIG_LIBX264_ENCODER
  OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o
  OBJS-$(CONFIG_LIBXAVS_ENCODER)            += libxavs.o
  OBJS-$(CONFIG_LIBXVID_ENCODER)            += libxvid.o
 +OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER)   += libzvbi-teletextdec.o
  
  # parsers
  OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o \
@@@ -739,18 -613,14 +740,18 @@@ OBJS-$(CONFIG_AAC_LATM_PARSER)         
  OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o \
                                            aac_ac3_parser.o
  OBJS-$(CONFIG_ADX_PARSER)              += adx_parser.o adx.o
 +OBJS-$(CONFIG_BMP_PARSER)              += bmp_parser.o
  OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
  OBJS-$(CONFIG_COOK_PARSER)             += cook_parser.o
  OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o dca.o
  OBJS-$(CONFIG_DIRAC_PARSER)            += dirac_parser.o
  OBJS-$(CONFIG_DNXHD_PARSER)            += dnxhd_parser.o
 +OBJS-$(CONFIG_DPX_PARSER)              += dpx_parser.o
  OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
 +OBJS-$(CONFIG_DVD_NAV_PARSER)          += dvd_nav_parser.o
  OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsub_parser.o
 -OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o
 +OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o \
 +                                          vorbis_data.o
  OBJS-$(CONFIG_GSM_PARSER)              += gsm_parser.o
  OBJS-$(CONFIG_H261_PARSER)             += h261_parser.o
  OBJS-$(CONFIG_H263_PARSER)             += h263_parser.o
@@@ -765,7 -635,6 +766,7 @@@ OBJS-$(CONFIG_MLP_PARSER)              
  OBJS-$(CONFIG_MPEG4VIDEO_PARSER)       += mpeg4video_parser.o h263.o \
                                            mpeg4videodec.o mpeg4video.o \
                                            ituh263dec.o h263dec.o
 +OBJS-$(CONFIG_PNG_PARSER)              += png_parser.o
  OBJS-$(CONFIG_MPEGAUDIO_PARSER)        += mpegaudio_parser.o \
                                            mpegaudiodecheader.o mpegaudiodata.o
  OBJS-$(CONFIG_MPEGVIDEO_PARSER)        += mpegvideo_parser.o    \
@@@ -781,7 -650,6 +782,7 @@@ OBJS-$(CONFIG_VC1_PARSER)              
  OBJS-$(CONFIG_VORBIS_PARSER)           += vorbis_parser.o xiph.o
  OBJS-$(CONFIG_VP3_PARSER)              += vp3_parser.o
  OBJS-$(CONFIG_VP8_PARSER)              += vp8_parser.o
 +OBJS-$(CONFIG_VP9_PARSER)              += vp9_parser.o
  
  # bitstream filters
  OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)          += aac_adtstoasc_bsf.o aacadtsdec.o \
@@@ -793,8 -661,6 +794,8 @@@ OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF
  OBJS-$(CONFIG_MJPEG2JPEG_BSF)             += mjpeg2jpeg_bsf.o mjpeg.o
  OBJS-$(CONFIG_MJPEGA_DUMP_HEADER_BSF)     += mjpega_dump_header_bsf.o
  OBJS-$(CONFIG_MOV2TEXTSUB_BSF)            += movsub_bsf.o
 +OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
 +                                             mpegaudiodata.o
  OBJS-$(CONFIG_NOISE_BSF)                  += noise_bsf.o
  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)       += remove_extradata_bsf.o
  OBJS-$(CONFIG_TEXT2MOVSUB_BSF)            += movsub_bsf.o
  OBJS-$(HAVE_LIBC_MSVCRT)               += file_open.o
  OBJS-$(HAVE_THREADS)                   += pthread.o pthread_slice.o pthread_frame.o
  
 +OBJS-$(CONFIG_FRAME_THREAD_ENCODER)    += frame_thread_encoder.o
 +
 +# Windows resource file
 +SLIBOBJS-$(HAVE_GNU_WINDRES)           += avcodecres.o
 +
  SKIPHEADERS                            += %_tablegen.h                  \
                                            %_tables.h                    \
                                            aac_tablegen_decl.h           \
                                            fft-internal.h                \
 +                                          old_codec_ids.h               \
                                            tableprint.h                  \
                                            $(ARCH)/vp56_arith.h          \
  
  SKIPHEADERS-$(CONFIG_DXVA2)            += dxva2.h dxva2_internal.h
  SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER)  += libschroedinger.h
 -SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h
 +SKIPHEADERS-$(CONFIG_LIBUTVIDEO)       += libutvideo.h
 +SKIPHEADERS-$(CONFIG_XVMC)             += xvmc.h
  SKIPHEADERS-$(CONFIG_VAAPI)            += vaapi_internal.h
  SKIPHEADERS-$(CONFIG_VDA)              += vda.h
  SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h vdpau_internal.h
  
 -TESTPROGS = dct                                                         \
 +TESTPROGS = cabac                                                       \
              fft                                                         \
              fft-fixed                                                   \
 +            fft-fixed32                                                 \
              golomb                                                      \
              iirfilter                                                   \
 +            imgconvert                                                  \
              rangecoder                                                  \
 +            snowenc                                                     \
  
 +TESTPROGS-$(CONFIG_DCT) += dct
 +TESTPROGS-$(HAVE_MMX) += motion
  TESTOBJS = dctref.o
  
 +TOOLS = fourcc2pixfmt
 +
  HOSTPROGS = aac_tablegen                                                \
              aacps_tablegen                                              \
              cbrt_tablegen                                               \
diff --combined libavcodec/mpegutils.c
index 0000000,bc430f0..62cc36a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,80 +1,80 @@@
 - * This file is part of Libav.
+ /*
+  * Mpeg video formats-related defines and utility functions
+  *
 - * Libav is free software; you can redistribute it and/or
++ * This file is part of FFmpeg.
+  *
 - * Libav is distributed in the hope that it will be useful,
++ * 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.
+  *
 - * License along with Libav; if not, write to the Free Software
++ * 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 <stdint.h>
+ #include "libavutil/common.h"
+ #include "libavutil/frame.h"
+ #include "libavutil/pixdesc.h"
+ #include "avcodec.h"
+ #include "mpegutils.h"
+ void ff_draw_horiz_band(AVCodecContext *avctx,
+                         AVFrame *cur, AVFrame *last,
+                         int y, int h, int picture_structure,
+                         int first_field, int low_delay)
+ {
+     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+     int vshift = desc->log2_chroma_h;
+     const int field_pic = picture_structure != PICT_FRAME;
+     if (field_pic) {
+         h <<= 1;
+         y <<= 1;
+     }
+     h = FFMIN(h, avctx->height - y);
+     if (field_pic && first_field &&
+         !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD))
+         return;
+     if (avctx->draw_horiz_band) {
+         AVFrame *src;
+         int offset[AV_NUM_DATA_POINTERS];
+         int i;
+         if (cur->pict_type == AV_PICTURE_TYPE_B || low_delay ||
+            (avctx->slice_flags & SLICE_FLAG_CODED_ORDER))
+             src = cur;
+         else if (last)
+             src = last;
+         else
+             return;
+         if (cur->pict_type == AV_PICTURE_TYPE_B &&
+             picture_structure == PICT_FRAME &&
+             avctx->codec_id != AV_CODEC_ID_SVQ3) {
+             for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
+                 offset[i] = 0;
+         } else {
+             offset[0]= y * src->linesize[0];
+             offset[1]=
+             offset[2]= (y >> vshift) * src->linesize[1];
+             for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
+                 offset[i] = 0;
+         }
+         emms_c();
+         avctx->draw_horiz_band(avctx, src, offset,
+                                y, picture_structure, h);
+     }
+ }
diff --combined libavcodec/mpegutils.h
@@@ -1,28 -1,34 +1,34 @@@
  /*
   * Mpeg video formats-related defines and utility functions
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * 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.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * 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 Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #ifndef AVCODEC_MPEGUTILS_H
  #define AVCODEC_MPEGUTILS_H
  
+ #include <stdint.h>
+ #include "libavutil/frame.h"
+ #include "avcodec.h"
  #include "version.h"
  
  /* picture type */
  #define PICT_TOP_FIELD     1
  #define PICT_BOTTOM_FIELD  2
  
  #define CANDIDATE_MB_TYPE_DIRECT0    (1 << 12)
  
+ /**
+  * Draw a horizontal band if supported.
+  *
+  * @param h is the normal height, this will be reduced automatically if needed
+  */
+ void ff_draw_horiz_band(AVCodecContext *avctx, AVFrame *cur, AVFrame *last,
+                         int y, int h, int picture_structure, int first_field,
+                         int low_delay);
  #endif /* AVCODEC_PICTTYPE_H */
diff --combined libavcodec/mpegvideo.c
@@@ -5,20 -5,20 +5,20 @@@
   *
   * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * 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.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * 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 Libav; if not, write to the Free Software
 + * 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/timer.h"
  #include "avcodec.h"
  #include "dsputil.h"
 +#include "h264chroma.h"
  #include "internal.h"
  #include "mathops.h"
  #include "mpegutils.h"
  #include "mpegvideo.h"
  #include "mjpegenc.h"
  #include "msmpeg4.h"
 -#include "xvmc_internal.h"
  #include "thread.h"
  #include <limits.h>
  
@@@ -118,7 -118,10 +118,7 @@@ static void dct_unquantize_mpeg1_intra_
  
      nCoeffs= s->block_last_index[n];
  
 -    if (n < 4)
 -        block[0] = block[0] * s->y_dc_scale;
 -    else
 -        block[0] = block[0] * s->c_dc_scale;
 +    block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
      /* XXX: only mpeg1 */
      quant_matrix = s->intra_matrix;
      for(i=1;i<=nCoeffs;i++) {
@@@ -177,7 -180,10 +177,7 @@@ static void dct_unquantize_mpeg2_intra_
      if(s->alternate_scan) nCoeffs= 63;
      else nCoeffs= s->block_last_index[n];
  
 -    if (n < 4)
 -        block[0] = block[0] * s->y_dc_scale;
 -    else
 -        block[0] = block[0] * s->c_dc_scale;
 +    block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
      quant_matrix = s->intra_matrix;
      for(i=1;i<=nCoeffs;i++) {
          int j= s->intra_scantable.permutated[i];
@@@ -205,8 -211,10 +205,8 @@@ static void dct_unquantize_mpeg2_intra_
      if(s->alternate_scan) nCoeffs= 63;
      else nCoeffs= s->block_last_index[n];
  
 -    if (n < 4)
 -        block[0] = block[0] * s->y_dc_scale;
 -    else
 -        block[0] = block[0] * s->c_dc_scale;
 +    block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
 +    sum += block[0];
      quant_matrix = s->intra_matrix;
      for(i=1;i<=nCoeffs;i++) {
          int j= s->intra_scantable.permutated[i];
@@@ -263,12 -271,15 +263,12 @@@ static void dct_unquantize_h263_intra_c
      int i, level, qmul, qadd;
      int nCoeffs;
  
 -    assert(s->block_last_index[n]>=0);
 +    av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
  
      qmul = qscale << 1;
  
      if (!s->h263_aic) {
 -        if (n < 4)
 -            block[0] = block[0] * s->y_dc_scale;
 -        else
 -            block[0] = block[0] * s->c_dc_scale;
 +        block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
          qadd = (qscale - 1) | 1;
      }else{
          qadd = 0;
@@@ -297,7 -308,7 +297,7 @@@ static void dct_unquantize_h263_inter_c
      int i, level, qmul, qadd;
      int nCoeffs;
  
 -    assert(s->block_last_index[n]>=0);
 +    av_assert2(s->block_last_index[n]>=0);
  
      qadd = (qscale - 1) | 1;
      qmul = qscale << 1;
@@@ -340,8 -351,7 +340,8 @@@ static void mpeg_er_decode_mb(void *opa
      s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
      s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
  
 -    assert(ref == 0);
 +    if (ref)
 +        av_log(s->avctx, AV_LOG_DEBUG, "Interlaced error concealment is not fully implemented\n");
      ff_MPV_decode_mb(s, s->block);
  }
  
  av_cold int ff_dct_common_init(MpegEncContext *s)
  {
      ff_dsputil_init(&s->dsp, s->avctx);
 +    ff_h264chroma_init(&s->h264chroma, 8); //for lowres
      ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
      ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
  
          s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
      s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
  
 +    if (ARCH_ALPHA)
 +        ff_MPV_common_init_axp(s);
      if (ARCH_ARM)
          ff_MPV_common_init_arm(s);
      if (ARCH_PPC)
  
  static int frame_size_alloc(MpegEncContext *s, int linesize)
  {
 -    int alloc_size = FFALIGN(FFABS(linesize) + 32, 32);
 +    int alloc_size = FFALIGN(FFABS(linesize) + 64, 32);
  
      // edge emu needs blocksize + filter length - 1
      // (= 17x17 for  halfpel / 21x21 for  h264)
      // VC1 computes luma and chroma simultaneously and needs 19X19 + 9x9
      // at uvlinesize. It supports only YUV420 so 24x24 is enough
      // linesize * interlaced * MBsize
 -    FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer, alloc_size * 2 * 24,
 +    FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer, alloc_size * 4 * 24,
                        fail);
  
 -    FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, alloc_size * 2 * 16 * 3,
 +    FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, alloc_size * 4 * 16 * 2,
                        fail)
      s->me.temp         = s->me.scratchpad;
      s->rd_scratchpad   = s->me.scratchpad;
@@@ -498,9 -505,6 +498,9 @@@ void ff_free_picture_tables(Picture *pi
  {
      int i;
  
 +    pic->alloc_mb_width  =
 +    pic->alloc_mb_height = 0;
 +
      av_buffer_unref(&pic->mb_var_buf);
      av_buffer_unref(&pic->mc_mb_var_buf);
      av_buffer_unref(&pic->mb_mean_buf);
@@@ -537,7 -541,7 +537,7 @@@ static int alloc_picture_tables(MpegEnc
              return AVERROR(ENOMEM);
      }
  
 -    if (s->out_format == FMT_H263 || s->encoding) {
 +    if (s->out_format == FMT_H263 || s->encoding || s->avctx->debug_mv) {
          int mv_size        = 2 * (b8_array_size + 4) * sizeof(int16_t);
          int ref_index_size = 4 * mb_array_size;
  
          }
      }
  
 +    pic->alloc_mb_width  = s->mb_width;
 +    pic->alloc_mb_height = s->mb_height;
 +
      return 0;
  }
  
@@@ -588,16 -589,11 +588,16 @@@ int ff_alloc_picture(MpegEncContext *s
  {
      int i, ret;
  
 +    if (pic->qscale_table_buf)
 +        if (   pic->alloc_mb_width  != s->mb_width
 +            || pic->alloc_mb_height != s->mb_height)
 +            ff_free_picture_tables(pic);
 +
      if (shared) {
 -        assert(pic->f.data[0]);
 +        av_assert0(pic->f.data[0]);
          pic->shared = 1;
      } else {
 -        assert(!pic->f.buf[0]);
 +        av_assert0(!pic->f.buf[0]);
  
          if (alloc_frame_buffer(s, pic) < 0)
              return -1;
@@@ -702,9 -698,6 +702,9 @@@ do {
          dst->ref_index[i]  = src->ref_index[i];
      }
  
 +    dst->alloc_mb_width  = src->alloc_mb_width;
 +    dst->alloc_mb_height = src->alloc_mb_height;
 +
      return 0;
  }
  
@@@ -762,9 -755,6 +762,9 @@@ static int init_duplicate_context(MpegE
      int yc_size = y_size + 2 * c_size;
      int i;
  
 +    if (s->mb_height & 1)
 +        yc_size += 2*s->b8_stride + 2*s->mb_stride;
 +
      s->edge_emu_buffer =
      s->me.scratchpad   =
      s->me.temp         =
@@@ -883,11 -873,9 +883,11 @@@ int ff_mpeg_update_thread_context(AVCod
      int i, ret;
      MpegEncContext *s = dst->priv_data, *s1 = src->priv_data;
  
 -    if (dst == src || !s1->context_initialized)
 +    if (dst == src)
          return 0;
  
 +    av_assert0(s != s1);
 +
      // FIXME can parameters change on I-frames?
      // in that case dst may need a reinit
      if (!s->context_initialized) {
          s->bitstream_buffer      = NULL;
          s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
  
 -        ff_MPV_common_init(s);
 +        if (s1->context_initialized){
 +//             s->picture_range_start  += MAX_PICTURE_COUNT;
 +//             s->picture_range_end    += MAX_PICTURE_COUNT;
 +            if((ret = ff_MPV_common_init(s)) < 0){
 +                memset(s, 0, sizeof(MpegEncContext));
 +                s->avctx = dst;
 +                return ret;
 +            }
 +        }
      }
  
      if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
 -        int err;
          s->context_reinit = 0;
          s->height = s1->height;
          s->width  = s1->width;
 -        if ((err = ff_MPV_common_frame_size_change(s)) < 0)
 -            return err;
 +        if ((ret = ff_MPV_common_frame_size_change(s)) < 0)
 +            return ret;
      }
  
      s->avctx->coded_height  = s1->avctx->coded_height;
      s->coded_picture_number = s1->coded_picture_number;
      s->picture_number       = s1->picture_number;
  
 +    av_assert0(!s->picture || s->picture != s1->picture);
 +    if(s->picture)
      for (i = 0; i < MAX_PICTURE_COUNT; i++) {
          ff_mpeg_unref_picture(s, &s->picture[i]);
          if (s1->picture[i].f.buf[0] &&
@@@ -955,7 -934,6 +955,7 @@@ do {
      // Error/bug resilience
      s->next_p_frame_damaged = s1->next_p_frame_damaged;
      s->workaround_bugs      = s1->workaround_bugs;
 +    s->padding_bug_score    = s1->padding_bug_score;
  
      // MPEG4 timing info
      memcpy(&s->last_time_base, &s1->last_time_base,
          } else {
              av_log(s->avctx, AV_LOG_ERROR, "Context scratch buffers could not "
                     "be allocated due to unknown size.\n");
 -            return AVERROR_BUG;
          }
  
      // MPEG2/interlacing info
@@@ -1112,35 -1091,44 +1112,35 @@@ static int init_context_frame(MpegEncCo
      c_size  = s->mb_stride * (s->mb_height + 1);
      yc_size = y_size + 2   * c_size;
  
 -    FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int),
 -                      fail); // error ressilience code looks cleaner with this
 +    if (s->mb_height & 1)
 +        yc_size += 2*s->b8_stride + 2*s->mb_stride;
 +
 +    FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int), fail); // error ressilience code looks cleaner with this
      for (y = 0; y < s->mb_height; y++)
          for (x = 0; x < s->mb_width; x++)
              s->mb_index2xy[x + y * s->mb_width] = x + y * s->mb_stride;
  
 -    s->mb_index2xy[s->mb_height * s->mb_width] =
 -        (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed?
 +    s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed?
  
      if (s->encoding) {
          /* Allocate MV tables */
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base,
 -                          mv_table_size * 2 * sizeof(int16_t), fail);
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base,
 -                          mv_table_size * 2 * sizeof(int16_t), fail);
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base,
 -                          mv_table_size * 2 * sizeof(int16_t), fail);
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base,
 -                          mv_table_size * 2 * sizeof(int16_t), fail);
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base,
 -                          mv_table_size * 2 * sizeof(int16_t), fail);
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base,
 -                          mv_table_size * 2 * sizeof(int16_t), fail);
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base,                 mv_table_size * 2 * sizeof(int16_t), fail)
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base,            mv_table_size * 2 * sizeof(int16_t), fail)
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base,            mv_table_size * 2 * sizeof(int16_t), fail)
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base,      mv_table_size * 2 * sizeof(int16_t), fail)
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base,      mv_table_size * 2 * sizeof(int16_t), fail)
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base,          mv_table_size * 2 * sizeof(int16_t), fail)
          s->p_mv_table            = s->p_mv_table_base + s->mb_stride + 1;
          s->b_forw_mv_table       = s->b_forw_mv_table_base + s->mb_stride + 1;
          s->b_back_mv_table       = s->b_back_mv_table_base + s->mb_stride + 1;
 -        s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base +
 -                                   s->mb_stride + 1;
 -        s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base +
 -                                   s->mb_stride + 1;
 +        s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 1;
 +        s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 1;
          s->b_direct_mv_table     = s->b_direct_mv_table_base + s->mb_stride + 1;
  
          /* Allocate MB type table */
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type, mb_array_size *
 -                          sizeof(uint16_t), fail); // needed for encoding
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type, mb_array_size * sizeof(uint16_t), fail) // needed for encoding
  
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size *
 -                          sizeof(int), fail);
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail)
  
          FF_ALLOC_OR_GOTO(s->avctx, s->cplx_tab,
                           mb_array_size * sizeof(float), fail);
                      s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] +
                                                     s->mb_stride + 1;
                  }
 -                FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j],
 -                                  mb_array_size * 2 * sizeof(uint8_t), fail);
 -                FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j],
 -                                  mv_table_size * 2 * sizeof(int16_t), fail);
 -                s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]
 -                                            + s->mb_stride + 1;
 +                FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail)
 +                FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail)
 +                s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1;
              }
 -            FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i],
 -                              mb_array_size * 2 * sizeof(uint8_t), fail);
 +            FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail)
          }
      }
      if (s->out_format == FMT_H263) {
          /* cbp values */
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size + (s->mb_height&1)*2*s->b8_stride, fail);
          s->coded_block = s->coded_block_base + s->b8_stride + 1;
  
          /* cbp, ac_pred, pred_dir */
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table,
 -                          mb_array_size * sizeof(uint8_t), fail);
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table,
 -                          mb_array_size * sizeof(uint8_t), fail);
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table     , mb_array_size * sizeof(uint8_t), fail);
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail);
      }
  
      if (s->h263_pred || s->h263_plus || !s->encoding) {
          /* dc values */
          // MN: we need these for  error resilience of intra-frames
 -        FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base,
 -                          yc_size * sizeof(int16_t), fail);
 +        FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail);
          s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
          s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
          s->dc_val[2] = s->dc_val[1] + c_size;
@@@ -1250,9 -1245,9 +1250,9 @@@ av_cold int ff_MPV_common_init(MpegEncC
      s->flags2 = s->avctx->flags2;
  
      /* set chroma shifts */
 -    av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
 -                                     &s->chroma_x_shift,
 -                                     &s->chroma_y_shift);
 +    avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,
 +                                  &s->chroma_x_shift,
 +                                  &s->chroma_y_shift);
  
      /* convert fourcc to upper case */
      s->codec_tag          = avpriv_toupper4(s->avctx->codec_tag);
      av_frame_unref(&s->last_picture.f);
      av_frame_unref(&s->current_picture.f);
  
 -    if (s->width && s->height) {
          if (init_context_frame(s))
              goto fail;
  
          s->parse_context.state = -1;
 -    }
  
 -    s->context_initialized = 1;
 -    s->thread_context[0]   = s;
 +        s->context_initialized = 1;
 +        s->thread_context[0]   = s;
  
 -    if (s->width && s->height) {
 +//     if (s->width && s->height) {
          if (nb_slices > 1) {
              for (i = 1; i < nb_slices; i++) {
                  s->thread_context[i] = av_malloc(sizeof(MpegEncContext));
              s->end_mb_y   = s->mb_height;
          }
          s->slice_context_count = nb_slices;
 -    }
 +//     }
  
      return 0;
   fail:
@@@ -1356,7 -1353,6 +1356,7 @@@ static int free_context_frame(MpegEncCo
      av_freep(&s->er.er_temp_buffer);
      av_freep(&s->mb_index2xy);
      av_freep(&s->lambda_table);
 +
      av_freep(&s->cplx_tab);
      av_freep(&s->bits_tab);
  
@@@ -1423,8 -1419,7 +1423,8 @@@ int ff_MPV_common_frame_size_change(Mpe
                          (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices;
              }
          } else {
 -            if (init_duplicate_context(s) < 0)
 +            err = init_duplicate_context(s);
 +            if (err < 0)
                  goto fail;
              s->start_mb_y = 0;
              s->end_mb_y   = s->mb_height;
@@@ -1587,8 -1582,6 +1587,8 @@@ static void release_unused_pictures(Mpe
  
  static inline int pic_is_unused(MpegEncContext *s, Picture *pic)
  {
 +    if (pic == s->last_picture_ptr)
 +        return 0;
      if (pic->f.buf[0] == NULL)
          return 1;
      if (pic->needs_realloc && !(pic->reference & DELAYED_PIC_REF))
@@@ -1602,7 -1595,7 +1602,7 @@@ static int find_unused_picture(MpegEncC
  
      if (shared) {
          for (i = 0; i < MAX_PICTURE_COUNT; i++) {
 -            if (s->picture[i].f.buf[0] == NULL)
 +            if (s->picture[i].f.buf[0] == NULL && &s->picture[i] != s->last_picture_ptr)
                  return i;
          }
      } else {
          }
      }
  
 -    return AVERROR_INVALIDDATA;
 +    av_log(s->avctx, AV_LOG_FATAL,
 +           "Internal error, picture buffer overflow\n");
 +    /* We could return -1, but the codec would crash trying to draw into a
 +     * non-existing frame anyway. This is safer than waiting for a random crash.
 +     * Also the return of this is never useful, an encoder must only allocate
 +     * as much as allowed in the specification. This has no relationship to how
 +     * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
 +     * enough for such valid streams).
 +     * Plus, a decoder has to check stream validity and remove frames if too
 +     * many reference frames are around. Waiting for "OOM" is not correct at
 +     * all. Similarly, missing reference frames have to be replaced by
 +     * interpolated/MC frames, anything else is a bug in the codec ...
 +     */
 +    abort();
 +    return -1;
  }
  
  int ff_find_unused_picture(MpegEncContext *s, int shared)
@@@ -1653,11 -1632,6 +1653,11 @@@ int ff_MPV_frame_start(MpegEncContext *
      Picture *pic;
      s->mb_skipped = 0;
  
 +    if (!ff_thread_can_start_frame(avctx)) {
 +        av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n");
 +        return -1;
 +    }
 +
      /* mark & release old frames */
      if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
          s->last_picture_ptr != s->next_picture_ptr &&
          int h_chroma_shift, v_chroma_shift;
          av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
                                           &h_chroma_shift, &v_chroma_shift);
 -        if (s->pict_type != AV_PICTURE_TYPE_I)
 +        if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f.buf[0])
 +            av_log(avctx, AV_LOG_DEBUG,
 +                   "allocating dummy last picture for B frame\n");
 +        else if (s->pict_type != AV_PICTURE_TYPE_I)
              av_log(avctx, AV_LOG_ERROR,
                     "warning: first frame is no keyframe\n");
          else if (s->picture_structure != PICT_FRAME)
 -            av_log(avctx, AV_LOG_INFO,
 +            av_log(avctx, AV_LOG_DEBUG,
                     "allocate dummy last picture for field based first keyframe\n");
  
          /* Allocate a dummy frame */
          s->last_picture_ptr = &s->picture[i];
  
          s->last_picture_ptr->reference   = 3;
 -        s->last_picture_ptr->f.pict_type = AV_PICTURE_TYPE_I;
 +        s->last_picture_ptr->f.key_frame = 0;
 +        s->last_picture_ptr->f.pict_type = AV_PICTURE_TYPE_P;
  
          if (ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) {
              s->last_picture_ptr = NULL;
              return -1;
          }
  
 -        memset(s->last_picture_ptr->f.data[0], 0,
 -               avctx->height * s->last_picture_ptr->f.linesize[0]);
 -        memset(s->last_picture_ptr->f.data[1], 0x80,
 -               (avctx->height >> v_chroma_shift) *
 -               s->last_picture_ptr->f.linesize[1]);
 -        memset(s->last_picture_ptr->f.data[2], 0x80,
 -               (avctx->height >> v_chroma_shift) *
 -               s->last_picture_ptr->f.linesize[2]);
 +        if (!avctx->hwaccel) {
 +            for(i=0; i<avctx->height; i++)
 +                memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i,
 +                       0x80, avctx->width);
 +            for(i=0; i<FF_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
 +                memset(s->last_picture_ptr->f.data[1] + s->last_picture_ptr->f.linesize[1]*i,
 +                       0x80, FF_CEIL_RSHIFT(avctx->width, h_chroma_shift));
 +                memset(s->last_picture_ptr->f.data[2] + s->last_picture_ptr->f.linesize[2]*i,
 +                       0x80, FF_CEIL_RSHIFT(avctx->width, h_chroma_shift));
 +            }
 +
 +            if(s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263){
 +                for(i=0; i<avctx->height; i++)
 +                memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, avctx->width);
 +            }
 +        }
  
          ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
          ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
          s->next_picture_ptr = &s->picture[i];
  
          s->next_picture_ptr->reference   = 3;
 -        s->next_picture_ptr->f.pict_type = AV_PICTURE_TYPE_I;
 +        s->next_picture_ptr->f.key_frame = 0;
 +        s->next_picture_ptr->f.pict_type = AV_PICTURE_TYPE_P;
  
          if (ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) {
              s->next_picture_ptr = NULL;
          ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
      }
  
 +#if 0 // BUFREF-FIXME
 +    memset(s->last_picture.f.data, 0, sizeof(s->last_picture.f.data));
 +    memset(s->next_picture.f.data, 0, sizeof(s->next_picture.f.data));
 +#endif
      if (s->last_picture_ptr) {
          ff_mpeg_unref_picture(s, &s->last_picture);
          if (s->last_picture_ptr->f.buf[0] &&
              return ret;
      }
  
 -    if (s->pict_type != AV_PICTURE_TYPE_I &&
 -        !(s->last_picture_ptr && s->last_picture_ptr->f.buf[0])) {
 -        av_log(s, AV_LOG_ERROR,
 -               "Non-reference picture received and no reference available\n");
 -        return AVERROR_INVALIDDATA;
 -    }
 +    av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
 +                                                 s->last_picture_ptr->f.buf[0]));
  
      if (s->picture_structure!= PICT_FRAME) {
          int i;
          s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
      }
  
 -#if FF_API_XVMC
 -FF_DISABLE_DEPRECATION_WARNINGS
 -    if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
 -        return ff_xvmc_field_start(s, avctx);
 -FF_ENABLE_DEPRECATION_WARNINGS
 -#endif /* FF_API_XVMC */
 -
      return 0;
  }
  
  /* called after a frame has been decoded. */
  void ff_MPV_frame_end(MpegEncContext *s)
  {
 -#if FF_API_XVMC
 -FF_DISABLE_DEPRECATION_WARNINGS
 -    /* redraw edges for the frame if decoding didn't complete */
 -    // just to make sure that all data is rendered.
 -    if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) {
 -        ff_xvmc_field_end(s);
 -    } else
 -FF_ENABLE_DEPRECATION_WARNINGS
 -#endif /* FF_API_XVMC */
 -
      emms_c();
  
      if (s->current_picture.reference)
  }
  
  /**
 + * Draw a line from (ex, ey) -> (sx, sy).
 + * @param w width of the image
 + * @param h height of the image
 + * @param stride stride/linesize of the image
 + * @param color color of the arrow
 + */
 +static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey,
 +                      int w, int h, int stride, int color)
 +{
 +    int x, y, fr, f;
 +
 +    sx = av_clip(sx, 0, w - 1);
 +    sy = av_clip(sy, 0, h - 1);
 +    ex = av_clip(ex, 0, w - 1);
 +    ey = av_clip(ey, 0, h - 1);
 +
 +    buf[sy * stride + sx] += color;
 +
 +    if (FFABS(ex - sx) > FFABS(ey - sy)) {
 +        if (sx > ex) {
 +            FFSWAP(int, sx, ex);
 +            FFSWAP(int, sy, ey);
 +        }
 +        buf += sx + sy * stride;
 +        ex  -= sx;
 +        f    = ((ey - sy) << 16) / ex;
 +        for (x = 0; x <= ex; x++) {
 +            y  = (x * f) >> 16;
 +            fr = (x * f) & 0xFFFF;
 +            buf[y * stride + x]       += (color * (0x10000 - fr)) >> 16;
 +            if(fr) buf[(y + 1) * stride + x] += (color *            fr ) >> 16;
 +        }
 +    } else {
 +        if (sy > ey) {
 +            FFSWAP(int, sx, ex);
 +            FFSWAP(int, sy, ey);
 +        }
 +        buf += sx + sy * stride;
 +        ey  -= sy;
 +        if (ey)
 +            f = ((ex - sx) << 16) / ey;
 +        else
 +            f = 0;
 +        for(y= 0; y <= ey; y++){
 +            x  = (y*f) >> 16;
 +            fr = (y*f) & 0xFFFF;
 +            buf[y * stride + x]     += (color * (0x10000 - fr)) >> 16;
 +            if(fr) buf[y * stride + x + 1] += (color *            fr ) >> 16;
 +        }
 +    }
 +}
 +
 +/**
 + * Draw an arrow from (ex, ey) -> (sx, sy).
 + * @param w width of the image
 + * @param h height of the image
 + * @param stride stride/linesize of the image
 + * @param color color of the arrow
 + */
 +static void draw_arrow(uint8_t *buf, int sx, int sy, int ex,
 +                       int ey, int w, int h, int stride, int color)
 +{
 +    int dx,dy;
 +
 +    sx = av_clip(sx, -100, w + 100);
 +    sy = av_clip(sy, -100, h + 100);
 +    ex = av_clip(ex, -100, w + 100);
 +    ey = av_clip(ey, -100, h + 100);
 +
 +    dx = ex - sx;
 +    dy = ey - sy;
 +
 +    if (dx * dx + dy * dy > 3 * 3) {
 +        int rx =  dx + dy;
 +        int ry = -dx + dy;
 +        int length = ff_sqrt((rx * rx + ry * ry) << 8);
 +
 +        // FIXME subpixel accuracy
 +        rx = ROUNDED_DIV(rx * 3 << 4, length);
 +        ry = ROUNDED_DIV(ry * 3 << 4, length);
 +
 +        draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
 +        draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
 +    }
 +    draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
 +}
 +
 +/**
   * Print debugging info for the given picture.
   */
 -void ff_print_debug_info(MpegEncContext *s, Picture *p)
 +void ff_print_debug_info2(AVCodecContext *avctx, Picture *p, AVFrame *pict, uint8_t *mbskip_table,
 +                         int *low_delay,
 +                         int mb_width, int mb_height, int mb_stride, int quarter_sample)
  {
 -    AVFrame *pict;
 -    if (s->avctx->hwaccel || !p || !p->mb_type)
 +    if (avctx->hwaccel || !p || !p->mb_type
 +        || (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU))
          return;
 -    pict = &p->f;
  
 -    if (s->avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
 +
 +    if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
          int x,y;
  
 -        av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: ");
 -        switch (pict->pict_type) {
 -        case AV_PICTURE_TYPE_I:
 -            av_log(s->avctx,AV_LOG_DEBUG,"I\n");
 -            break;
 -        case AV_PICTURE_TYPE_P:
 -            av_log(s->avctx,AV_LOG_DEBUG,"P\n");
 -            break;
 -        case AV_PICTURE_TYPE_B:
 -            av_log(s->avctx,AV_LOG_DEBUG,"B\n");
 -            break;
 -        case AV_PICTURE_TYPE_S:
 -            av_log(s->avctx,AV_LOG_DEBUG,"S\n");
 -            break;
 -        case AV_PICTURE_TYPE_SI:
 -            av_log(s->avctx,AV_LOG_DEBUG,"SI\n");
 -            break;
 -        case AV_PICTURE_TYPE_SP:
 -            av_log(s->avctx,AV_LOG_DEBUG,"SP\n");
 -            break;
 -        }
 -        for (y = 0; y < s->mb_height; y++) {
 -            for (x = 0; x < s->mb_width; x++) {
 -                if (s->avctx->debug & FF_DEBUG_SKIP) {
 -                    int count = s->mbskip_table[x + y * s->mb_stride];
 +        av_log(avctx, AV_LOG_DEBUG, "New frame, type: %c\n",
 +               av_get_picture_type_char(pict->pict_type));
 +        for (y = 0; y < mb_height; y++) {
 +            for (x = 0; x < mb_width; x++) {
 +                if (avctx->debug & FF_DEBUG_SKIP) {
 +                    int count = mbskip_table[x + y * mb_stride];
                      if (count > 9)
                          count = 9;
 -                    av_log(s->avctx, AV_LOG_DEBUG, "%1d", count);
 +                    av_log(avctx, AV_LOG_DEBUG, "%1d", count);
                  }
 -                if (s->avctx->debug & FF_DEBUG_QP) {
 -                    av_log(s->avctx, AV_LOG_DEBUG, "%2d",
 -                           p->qscale_table[x + y * s->mb_stride]);
 +                if (avctx->debug & FF_DEBUG_QP) {
 +                    av_log(avctx, AV_LOG_DEBUG, "%2d",
 +                           p->qscale_table[x + y * mb_stride]);
                  }
 -                if (s->avctx->debug & FF_DEBUG_MB_TYPE) {
 -                    int mb_type = p->mb_type[x + y * s->mb_stride];
 +                if (avctx->debug & FF_DEBUG_MB_TYPE) {
 +                    int mb_type = p->mb_type[x + y * mb_stride];
                      // Type & MV direction
                      if (IS_PCM(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "P");
 +                        av_log(avctx, AV_LOG_DEBUG, "P");
                      else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "A");
 +                        av_log(avctx, AV_LOG_DEBUG, "A");
                      else if (IS_INTRA4x4(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "i");
 +                        av_log(avctx, AV_LOG_DEBUG, "i");
                      else if (IS_INTRA16x16(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "I");
 +                        av_log(avctx, AV_LOG_DEBUG, "I");
                      else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "d");
 +                        av_log(avctx, AV_LOG_DEBUG, "d");
                      else if (IS_DIRECT(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "D");
 +                        av_log(avctx, AV_LOG_DEBUG, "D");
                      else if (IS_GMC(mb_type) && IS_SKIP(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "g");
 +                        av_log(avctx, AV_LOG_DEBUG, "g");
                      else if (IS_GMC(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "G");
 +                        av_log(avctx, AV_LOG_DEBUG, "G");
                      else if (IS_SKIP(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "S");
 +                        av_log(avctx, AV_LOG_DEBUG, "S");
                      else if (!USES_LIST(mb_type, 1))
 -                        av_log(s->avctx, AV_LOG_DEBUG, ">");
 +                        av_log(avctx, AV_LOG_DEBUG, ">");
                      else if (!USES_LIST(mb_type, 0))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "<");
 +                        av_log(avctx, AV_LOG_DEBUG, "<");
                      else {
 -                        assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
 -                        av_log(s->avctx, AV_LOG_DEBUG, "X");
 +                        av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
 +                        av_log(avctx, AV_LOG_DEBUG, "X");
                      }
  
                      // segmentation
                      if (IS_8X8(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "+");
 +                        av_log(avctx, AV_LOG_DEBUG, "+");
                      else if (IS_16X8(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "-");
 +                        av_log(avctx, AV_LOG_DEBUG, "-");
                      else if (IS_8X16(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "|");
 +                        av_log(avctx, AV_LOG_DEBUG, "|");
                      else if (IS_INTRA(mb_type) || IS_16X16(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, " ");
 +                        av_log(avctx, AV_LOG_DEBUG, " ");
                      else
 -                        av_log(s->avctx, AV_LOG_DEBUG, "?");
 +                        av_log(avctx, AV_LOG_DEBUG, "?");
  
  
                      if (IS_INTERLACED(mb_type))
 -                        av_log(s->avctx, AV_LOG_DEBUG, "=");
 +                        av_log(avctx, AV_LOG_DEBUG, "=");
                      else
 -                        av_log(s->avctx, AV_LOG_DEBUG, " ");
 +                        av_log(avctx, AV_LOG_DEBUG, " ");
 +                }
 +            }
 +            av_log(avctx, AV_LOG_DEBUG, "\n");
 +        }
 +    }
 +
 +    if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) ||
 +        (avctx->debug_mv)) {
 +        const int shift = 1 + quarter_sample;
 +        int mb_y;
 +        uint8_t *ptr;
 +        int i;
 +        int h_chroma_shift, v_chroma_shift, block_height;
 +        const int width          = avctx->width;
 +        const int height         = avctx->height;
 +        const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_SVQ3 ? 2 : 1;
 +        const int mv_stride      = (mb_width << mv_sample_log2) +
 +                                   (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
 +
 +        *low_delay = 0; // needed to see the vectors without trashing the buffers
 +
 +        avcodec_get_chroma_sub_sample(avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
 +
 +        av_frame_make_writable(pict);
 +
 +        pict->opaque = NULL;
 +        ptr          = pict->data[0];
 +        block_height = 16 >> v_chroma_shift;
 +
 +        for (mb_y = 0; mb_y < mb_height; mb_y++) {
 +            int mb_x;
 +            for (mb_x = 0; mb_x < mb_width; mb_x++) {
 +                const int mb_index = mb_x + mb_y * mb_stride;
 +                if ((avctx->debug_mv) && p->motion_val[0]) {
 +                    int type;
 +                    for (type = 0; type < 3; type++) {
 +                        int direction = 0;
 +                        switch (type) {
 +                        case 0:
 +                            if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_P_FOR)) ||
 +                                (pict->pict_type!= AV_PICTURE_TYPE_P))
 +                                continue;
 +                            direction = 0;
 +                            break;
 +                        case 1:
 +                            if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_FOR)) ||
 +                                (pict->pict_type!= AV_PICTURE_TYPE_B))
 +                                continue;
 +                            direction = 0;
 +                            break;
 +                        case 2:
 +                            if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_BACK)) ||
 +                                (pict->pict_type!= AV_PICTURE_TYPE_B))
 +                                continue;
 +                            direction = 1;
 +                            break;
 +                        }
 +                        if (!USES_LIST(p->mb_type[mb_index], direction))
 +                            continue;
 +
 +                        if (IS_8X8(p->mb_type[mb_index])) {
 +                            int i;
 +                            for (i = 0; i < 4; i++) {
 +                                int sx = mb_x * 16 + 4 + 8 * (i & 1);
 +                                int sy = mb_y * 16 + 4 + 8 * (i >> 1);
 +                                int xy = (mb_x * 2 + (i & 1) +
 +                                          (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
 +                                int mx = (p->motion_val[direction][xy][0] >> shift) + sx;
 +                                int my = (p->motion_val[direction][xy][1] >> shift) + sy;
 +                                draw_arrow(ptr, sx, sy, mx, my, width,
 +                                           height, pict->linesize[0], 100);
 +                            }
 +                        } else if (IS_16X8(p->mb_type[mb_index])) {
 +                            int i;
 +                            for (i = 0; i < 2; i++) {
 +                                int sx = mb_x * 16 + 8;
 +                                int sy = mb_y * 16 + 4 + 8 * i;
 +                                int xy = (mb_x * 2 + (mb_y * 2 + i) * mv_stride) << (mv_sample_log2 - 1);
 +                                int mx = (p->motion_val[direction][xy][0] >> shift);
 +                                int my = (p->motion_val[direction][xy][1] >> shift);
 +
 +                                if (IS_INTERLACED(p->mb_type[mb_index]))
 +                                    my *= 2;
 +
 +                            draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
 +                                       height, pict->linesize[0], 100);
 +                            }
 +                        } else if (IS_8X16(p->mb_type[mb_index])) {
 +                            int i;
 +                            for (i = 0; i < 2; i++) {
 +                                int sx = mb_x * 16 + 4 + 8 * i;
 +                                int sy = mb_y * 16 + 8;
 +                                int xy = (mb_x * 2 + i + mb_y * 2 * mv_stride) << (mv_sample_log2 - 1);
 +                                int mx = p->motion_val[direction][xy][0] >> shift;
 +                                int my = p->motion_val[direction][xy][1] >> shift;
 +
 +                                if (IS_INTERLACED(p->mb_type[mb_index]))
 +                                    my *= 2;
 +
 +                                draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
 +                                           height, pict->linesize[0], 100);
 +                            }
 +                        } else {
 +                              int sx= mb_x * 16 + 8;
 +                              int sy= mb_y * 16 + 8;
 +                              int xy= (mb_x + mb_y * mv_stride) << mv_sample_log2;
 +                              int mx= (p->motion_val[direction][xy][0]>>shift) + sx;
 +                              int my= (p->motion_val[direction][xy][1]>>shift) + sy;
 +                              draw_arrow(ptr, sx, sy, mx, my, width, height, pict->linesize[0], 100);
 +                        }
 +                    }
 +                }
 +                if ((avctx->debug & FF_DEBUG_VIS_QP)) {
 +                    uint64_t c = (p->qscale_table[mb_index] * 128 / 31) *
 +                                 0x0101010101010101ULL;
 +                    int y;
 +                    for (y = 0; y < block_height; y++) {
 +                        *(uint64_t *)(pict->data[1] + 8 * mb_x +
 +                                      (block_height * mb_y + y) *
 +                                      pict->linesize[1]) = c;
 +                        *(uint64_t *)(pict->data[2] + 8 * mb_x +
 +                                      (block_height * mb_y + y) *
 +                                      pict->linesize[2]) = c;
 +                    }
 +                }
 +                if ((avctx->debug & FF_DEBUG_VIS_MB_TYPE) &&
 +                    p->motion_val[0]) {
 +                    int mb_type = p->mb_type[mb_index];
 +                    uint64_t u,v;
 +                    int y;
 +#define COLOR(theta, r) \
 +    u = (int)(128 + r * cos(theta * 3.141592 / 180)); \
 +    v = (int)(128 + r * sin(theta * 3.141592 / 180));
 +
 +
 +                    u = v = 128;
 +                    if (IS_PCM(mb_type)) {
 +                        COLOR(120, 48)
 +                    } else if ((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) ||
 +                               IS_INTRA16x16(mb_type)) {
 +                        COLOR(30, 48)
 +                    } else if (IS_INTRA4x4(mb_type)) {
 +                        COLOR(90, 48)
 +                    } else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) {
 +                        // COLOR(120, 48)
 +                    } else if (IS_DIRECT(mb_type)) {
 +                        COLOR(150, 48)
 +                    } else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) {
 +                        COLOR(170, 48)
 +                    } else if (IS_GMC(mb_type)) {
 +                        COLOR(190, 48)
 +                    } else if (IS_SKIP(mb_type)) {
 +                        // COLOR(180, 48)
 +                    } else if (!USES_LIST(mb_type, 1)) {
 +                        COLOR(240, 48)
 +                    } else if (!USES_LIST(mb_type, 0)) {
 +                        COLOR(0, 48)
 +                    } else {
 +                        av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
 +                        COLOR(300,48)
 +                    }
 +
 +                    u *= 0x0101010101010101ULL;
 +                    v *= 0x0101010101010101ULL;
 +                    for (y = 0; y < block_height; y++) {
 +                        *(uint64_t *)(pict->data[1] + 8 * mb_x +
 +                                      (block_height * mb_y + y) * pict->linesize[1]) = u;
 +                        *(uint64_t *)(pict->data[2] + 8 * mb_x +
 +                                      (block_height * mb_y + y) * pict->linesize[2]) = v;
 +                    }
 +
 +                    // segmentation
 +                    if (IS_8X8(mb_type) || IS_16X8(mb_type)) {
 +                        *(uint64_t *)(pict->data[0] + 16 * mb_x + 0 +
 +                                      (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
 +                        *(uint64_t *)(pict->data[0] + 16 * mb_x + 8 +
 +                                      (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
 +                    }
 +                    if (IS_8X8(mb_type) || IS_8X16(mb_type)) {
 +                        for (y = 0; y < 16; y++)
 +                            pict->data[0][16 * mb_x + 8 + (16 * mb_y + y) *
 +                                          pict->linesize[0]] ^= 0x80;
 +                    }
 +                    if (IS_8X8(mb_type) && mv_sample_log2 >= 2) {
 +                        int dm = 1 << (mv_sample_log2 - 2);
 +                        for (i = 0; i < 4; i++) {
 +                            int sx = mb_x * 16 + 8 * (i & 1);
 +                            int sy = mb_y * 16 + 8 * (i >> 1);
 +                            int xy = (mb_x * 2 + (i & 1) +
 +                                     (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
 +                            // FIXME bidir
 +                            int32_t *mv = (int32_t *) &p->motion_val[0][xy];
 +                            if (mv[0] != mv[dm] ||
 +                                mv[dm * mv_stride] != mv[dm * (mv_stride + 1)])
 +                                for (y = 0; y < 8; y++)
 +                                    pict->data[0][sx + 4 + (sy + y) * pict->linesize[0]] ^= 0x80;
 +                            if (mv[0] != mv[dm * mv_stride] || mv[dm] != mv[dm * (mv_stride + 1)])
 +                                *(uint64_t *)(pict->data[0] + sx + (sy + 4) *
 +                                              pict->linesize[0]) ^= 0x8080808080808080ULL;
 +                        }
 +                    }
 +
 +                    if (IS_INTERLACED(mb_type) &&
 +                        avctx->codec->id == AV_CODEC_ID_H264) {
 +                        // hmm
 +                    }
 +                }
 +                mbskip_table[mb_index] = 0;
 +            }
 +        }
 +    }
 +}
 +
 +void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
 +{
 +    ff_print_debug_info2(s->avctx, p, pict, s->mbskip_table, &s->low_delay,
 +                         s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample);
 +}
 +
 +int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
 +{
 +    AVBufferRef *ref = av_buffer_ref(p->qscale_table_buf);
 +    int offset = 2*s->mb_stride + 1;
 +    if(!ref)
 +        return AVERROR(ENOMEM);
 +    av_assert0(ref->size >= offset + s->mb_stride * ((f->height+15)/16));
 +    ref->size -= offset;
 +    ref->data += offset;
 +    return av_frame_set_qp_table(f, ref, s->mb_stride, qp_type);
 +}
 +
 +static inline int hpel_motion_lowres(MpegEncContext *s,
 +                                     uint8_t *dest, uint8_t *src,
 +                                     int field_based, int field_select,
 +                                     int src_x, int src_y,
 +                                     int width, int height, ptrdiff_t stride,
 +                                     int h_edge_pos, int v_edge_pos,
 +                                     int w, int h, h264_chroma_mc_func *pix_op,
 +                                     int motion_x, int motion_y)
 +{
 +    const int lowres   = s->avctx->lowres;
 +    const int op_index = FFMIN(lowres, 3);
 +    const int s_mask   = (2 << lowres) - 1;
 +    int emu = 0;
 +    int sx, sy;
 +
 +    if (s->quarter_sample) {
 +        motion_x /= 2;
 +        motion_y /= 2;
 +    }
 +
 +    sx = motion_x & s_mask;
 +    sy = motion_y & s_mask;
 +    src_x += motion_x >> lowres + 1;
 +    src_y += motion_y >> lowres + 1;
 +
 +    src   += src_y * stride + src_x;
 +
 +    if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w,                 0) ||
 +        (unsigned)src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) {
 +        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
 +                                 s->linesize, s->linesize,
 +                                 w + 1, (h + 1) << field_based,
 +                                 src_x, src_y   << field_based,
 +                                 h_edge_pos, v_edge_pos);
 +        src = s->edge_emu_buffer;
 +        emu = 1;
 +    }
 +
 +    sx = (sx << 2) >> lowres;
 +    sy = (sy << 2) >> lowres;
 +    if (field_select)
 +        src += s->linesize;
 +    pix_op[op_index](dest, src, stride, h, sx, sy);
 +    return emu;
 +}
 +
 +/* apply one mpeg motion vector to the three components */
 +static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
 +                                                uint8_t *dest_y,
 +                                                uint8_t *dest_cb,
 +                                                uint8_t *dest_cr,
 +                                                int field_based,
 +                                                int bottom_field,
 +                                                int field_select,
 +                                                uint8_t **ref_picture,
 +                                                h264_chroma_mc_func *pix_op,
 +                                                int motion_x, int motion_y,
 +                                                int h, int mb_y)
 +{
 +    uint8_t *ptr_y, *ptr_cb, *ptr_cr;
 +    int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, sx, sy, uvsx, uvsy;
 +    ptrdiff_t uvlinesize, linesize;
 +    const int lowres     = s->avctx->lowres;
 +    const int op_index   = FFMIN(lowres-1+s->chroma_x_shift, 3);
 +    const int block_s    = 8>>lowres;
 +    const int s_mask     = (2 << lowres) - 1;
 +    const int h_edge_pos = s->h_edge_pos >> lowres;
 +    const int v_edge_pos = s->v_edge_pos >> lowres;
 +    linesize   = s->current_picture.f.linesize[0] << field_based;
 +    uvlinesize = s->current_picture.f.linesize[1] << field_based;
 +
 +    // FIXME obviously not perfect but qpel will not work in lowres anyway
 +    if (s->quarter_sample) {
 +        motion_x /= 2;
 +        motion_y /= 2;
 +    }
 +
 +    if(field_based){
 +        motion_y += (bottom_field - field_select)*((1 << lowres)-1);
 +    }
 +
 +    sx = motion_x & s_mask;
 +    sy = motion_y & s_mask;
 +    src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1);
 +    src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >> lowres + 1);
 +
 +    if (s->out_format == FMT_H263) {
 +        uvsx    = ((motion_x >> 1) & s_mask) | (sx & 1);
 +        uvsy    = ((motion_y >> 1) & s_mask) | (sy & 1);
 +        uvsrc_x = src_x >> 1;
 +        uvsrc_y = src_y >> 1;
 +    } else if (s->out_format == FMT_H261) {
 +        // even chroma mv's are full pel in H261
 +        mx      = motion_x / 4;
 +        my      = motion_y / 4;
 +        uvsx    = (2 * mx) & s_mask;
 +        uvsy    = (2 * my) & s_mask;
 +        uvsrc_x = s->mb_x * block_s + (mx >> lowres);
 +        uvsrc_y =    mb_y * block_s + (my >> lowres);
 +    } else {
 +        if(s->chroma_y_shift){
 +            mx      = motion_x / 2;
 +            my      = motion_y / 2;
 +            uvsx    = mx & s_mask;
 +            uvsy    = my & s_mask;
 +            uvsrc_x = s->mb_x * block_s                 + (mx >> lowres + 1);
 +            uvsrc_y =   (mb_y * block_s >> field_based) + (my >> lowres + 1);
 +        } else {
 +            if(s->chroma_x_shift){
 +            //Chroma422
 +                mx = motion_x / 2;
 +                uvsx = mx & s_mask;
 +                uvsy = motion_y & s_mask;
 +                uvsrc_y = src_y;
 +                uvsrc_x = s->mb_x*block_s               + (mx >> (lowres+1));
 +            } else {
 +            //Chroma444
 +                uvsx = motion_x & s_mask;
 +                uvsy = motion_y & s_mask;
 +                uvsrc_x = src_x;
 +                uvsrc_y = src_y;
 +            }
 +        }
 +    }
 +
 +    ptr_y  = ref_picture[0] + src_y   * linesize   + src_x;
 +    ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
 +    ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
 +
 +    if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s,       0) || uvsrc_y<0 ||
 +        (unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) {
 +        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,
 +                                 linesize >> field_based, linesize >> field_based,
 +                                 17, 17 + field_based,
 +                                src_x, src_y << field_based, h_edge_pos,
 +                                v_edge_pos);
 +        ptr_y = s->edge_emu_buffer;
 +        if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
 +            uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize;
 +            s->vdsp.emulated_edge_mc(uvbuf,  ptr_cb,
 +                                     uvlinesize >> field_based, uvlinesize >> field_based,
 +                                     9, 9 + field_based,
 +                                    uvsrc_x, uvsrc_y << field_based,
 +                                    h_edge_pos >> 1, v_edge_pos >> 1);
 +            s->vdsp.emulated_edge_mc(uvbuf + 16,  ptr_cr,
 +                                     uvlinesize >> field_based,uvlinesize >> field_based,
 +                                     9, 9 + field_based,
 +                                    uvsrc_x, uvsrc_y << field_based,
 +                                    h_edge_pos >> 1, v_edge_pos >> 1);
 +            ptr_cb = uvbuf;
 +            ptr_cr = uvbuf + 16;
 +        }
 +    }
 +
 +    // FIXME use this for field pix too instead of the obnoxious hack which changes picture.f.data
 +    if (bottom_field) {
 +        dest_y  += s->linesize;
 +        dest_cb += s->uvlinesize;
 +        dest_cr += s->uvlinesize;
 +    }
 +
 +    if (field_select) {
 +        ptr_y   += s->linesize;
 +        ptr_cb  += s->uvlinesize;
 +        ptr_cr  += s->uvlinesize;
 +    }
 +
 +    sx = (sx << 2) >> lowres;
 +    sy = (sy << 2) >> lowres;
 +    pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy);
 +
 +    if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
 +        int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
 +        uvsx = (uvsx << 2) >> lowres;
 +        uvsy = (uvsy << 2) >> lowres;
 +        if (hc) {
 +            pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy);
 +            pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy);
 +        }
 +    }
 +    // FIXME h261 lowres loop filter
 +}
 +
 +static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
 +                                            uint8_t *dest_cb, uint8_t *dest_cr,
 +                                            uint8_t **ref_picture,
 +                                            h264_chroma_mc_func * pix_op,
 +                                            int mx, int my)
 +{
 +    const int lowres     = s->avctx->lowres;
 +    const int op_index   = FFMIN(lowres, 3);
 +    const int block_s    = 8 >> lowres;
 +    const int s_mask     = (2 << lowres) - 1;
 +    const int h_edge_pos = s->h_edge_pos >> lowres + 1;
 +    const int v_edge_pos = s->v_edge_pos >> lowres + 1;
 +    int emu = 0, src_x, src_y, sx, sy;
 +    ptrdiff_t offset;
 +    uint8_t *ptr;
 +
 +    if (s->quarter_sample) {
 +        mx /= 2;
 +        my /= 2;
 +    }
 +
 +    /* In case of 8X8, we construct a single chroma motion vector
 +       with a special rounding */
 +    mx = ff_h263_round_chroma(mx);
 +    my = ff_h263_round_chroma(my);
 +
 +    sx = mx & s_mask;
 +    sy = my & s_mask;
 +    src_x = s->mb_x * block_s + (mx >> lowres + 1);
 +    src_y = s->mb_y * block_s + (my >> lowres + 1);
 +
 +    offset = src_y * s->uvlinesize + src_x;
 +    ptr = ref_picture[1] + offset;
 +    if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) ||
 +        (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) {
 +        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
 +                                 s->uvlinesize, s->uvlinesize,
 +                                 9, 9,
 +                                 src_x, src_y, h_edge_pos, v_edge_pos);
 +        ptr = s->edge_emu_buffer;
 +        emu = 1;
 +    }
 +    sx = (sx << 2) >> lowres;
 +    sy = (sy << 2) >> lowres;
 +    pix_op[op_index](dest_cb, ptr, s->uvlinesize, block_s, sx, sy);
 +
 +    ptr = ref_picture[2] + offset;
 +    if (emu) {
 +        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
 +                                 s->uvlinesize, s->uvlinesize,
 +                                 9, 9,
 +                                 src_x, src_y, h_edge_pos, v_edge_pos);
 +        ptr = s->edge_emu_buffer;
 +    }
 +    pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy);
 +}
 +
 +/**
 + * motion compensation of a single macroblock
 + * @param s context
 + * @param dest_y luma destination pointer
 + * @param dest_cb chroma cb/u destination pointer
 + * @param dest_cr chroma cr/v destination pointer
 + * @param dir direction (0->forward, 1->backward)
 + * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
 + * @param pix_op halfpel motion compensation function (average or put normally)
 + * the motion vectors are taken from s->mv and the MV type from s->mv_type
 + */
 +static inline void MPV_motion_lowres(MpegEncContext *s,
 +                                     uint8_t *dest_y, uint8_t *dest_cb,
 +                                     uint8_t *dest_cr,
 +                                     int dir, uint8_t **ref_picture,
 +                                     h264_chroma_mc_func *pix_op)
 +{
 +    int mx, my;
 +    int mb_x, mb_y, i;
 +    const int lowres  = s->avctx->lowres;
 +    const int block_s = 8 >>lowres;
 +
 +    mb_x = s->mb_x;
 +    mb_y = s->mb_y;
 +
 +    switch (s->mv_type) {
 +    case MV_TYPE_16X16:
 +        mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                           0, 0, 0,
 +                           ref_picture, pix_op,
 +                           s->mv[dir][0][0], s->mv[dir][0][1],
 +                           2 * block_s, mb_y);
 +        break;
 +    case MV_TYPE_8X8:
 +        mx = 0;
 +        my = 0;
 +        for (i = 0; i < 4; i++) {
 +            hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) *
 +                               s->linesize) * block_s,
 +                               ref_picture[0], 0, 0,
 +                               (2 * mb_x + (i & 1)) * block_s,
 +                               (2 * mb_y + (i >> 1)) * block_s,
 +                               s->width, s->height, s->linesize,
 +                               s->h_edge_pos >> lowres, s->v_edge_pos >> lowres,
 +                               block_s, block_s, pix_op,
 +                               s->mv[dir][i][0], s->mv[dir][i][1]);
 +
 +            mx += s->mv[dir][i][0];
 +            my += s->mv[dir][i][1];
 +        }
 +
 +        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:
 +        if (s->picture_structure == PICT_FRAME) {
 +            /* top field */
 +            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                               1, 0, s->field_select[dir][0],
 +                               ref_picture, pix_op,
 +                               s->mv[dir][0][0], s->mv[dir][0][1],
 +                               block_s, mb_y);
 +            /* bottom field */
 +            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                               1, 1, s->field_select[dir][1],
 +                               ref_picture, pix_op,
 +                               s->mv[dir][1][0], s->mv[dir][1][1],
 +                               block_s, mb_y);
 +        } else {
 +            if (s->picture_structure != s->field_select[dir][0] + 1 &&
 +                s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
 +                ref_picture = s->current_picture_ptr->f.data;
 +
 +            }
 +            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                               0, 0, s->field_select[dir][0],
 +                               ref_picture, pix_op,
 +                               s->mv[dir][0][0],
 +                               s->mv[dir][0][1], 2 * block_s, mb_y >> 1);
 +            }
 +        break;
 +    case MV_TYPE_16X8:
 +        for (i = 0; i < 2; i++) {
 +            uint8_t **ref2picture;
 +
 +            if (s->picture_structure == s->field_select[dir][i] + 1 ||
 +                s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
 +                ref2picture = ref_picture;
 +            } else {
 +                ref2picture = s->current_picture_ptr->f.data;
 +            }
 +
 +            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                               0, 0, s->field_select[dir][i],
 +                               ref2picture, pix_op,
 +                               s->mv[dir][i][0], s->mv[dir][i][1] +
 +                               2 * block_s * i, block_s, mb_y >> 1);
 +
 +            dest_y  +=  2 * block_s *  s->linesize;
 +            dest_cb += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize;
 +            dest_cr += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize;
 +        }
 +        break;
 +    case MV_TYPE_DMV:
 +        if (s->picture_structure == PICT_FRAME) {
 +            for (i = 0; i < 2; i++) {
 +                int j;
 +                for (j = 0; j < 2; j++) {
 +                    mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                                       1, j, j ^ i,
 +                                       ref_picture, pix_op,
 +                                       s->mv[dir][2 * i + j][0],
 +                                       s->mv[dir][2 * i + j][1],
 +                                       block_s, mb_y);
 +                }
 +                pix_op = s->h264chroma.avg_h264_chroma_pixels_tab;
 +            }
 +        } else {
 +            for (i = 0; i < 2; i++) {
 +                mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
 +                                   0, 0, s->picture_structure != i + 1,
 +                                   ref_picture, pix_op,
 +                                   s->mv[dir][2 * i][0],s->mv[dir][2 * i][1],
 +                                   2 * block_s, mb_y >> 1);
 +
 +                // after put we make avg of the same block
 +                pix_op = s->h264chroma.avg_h264_chroma_pixels_tab;
 +
 +                // opposite parity is always in the same
 +                // frame if this is second field
 +                if (!s->first_field) {
 +                    ref_picture = s->current_picture_ptr->f.data;
                  }
              }
 -            av_log(s->avctx, AV_LOG_DEBUG, "\n");
          }
 +        break;
 +    default:
 +        av_assert2(0);
      }
  }
  
@@@ -2768,15 -2069,18 +2768,15 @@@ void ff_clean_intra_table_entries(MpegE
   */
  static av_always_inline
  void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64],
 -                            int is_mpeg12)
 +                            int lowres_flag, int is_mpeg12)
  {
      const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
  
 -#if FF_API_XVMC
 -FF_DISABLE_DEPRECATION_WARNINGS
 -    if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration){
 -        ff_xvmc_decode_mb(s);//xvmc uses pblocks
 +    if (CONFIG_XVMC &&
 +        s->avctx->hwaccel && s->avctx->hwaccel->decode_mb) {
 +        s->avctx->hwaccel->decode_mb(s);//xvmc uses pblocks
          return;
      }
 -FF_ENABLE_DEPRECATION_WARNINGS
 -#endif /* FF_API_XVMC */
  
      if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
         /* print DCT coefficients */
      else if (!is_mpeg12 && (s->h263_pred || s->h263_aic))
          s->mbintra_table[mb_xy]=1;
  
 -    if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc
 +    if (   (s->flags&CODEC_FLAG_PSNR)
 +        || s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor
 +        || !(s->encoding && (s->intra_only || s->pict_type==AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc
          uint8_t *dest_y, *dest_cb, *dest_cr;
          int dct_linesize, dct_offset;
          op_pixels_func (*op_pix)[4];
          qpel_mc_func (*op_qpix)[16];
          const int linesize   = s->current_picture.f.linesize[0]; //not s->linesize as this would be wrong for field pics
          const int uvlinesize = s->current_picture.f.linesize[1];
 -        const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band;
 -        const int block_size = 8;
 +        const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
 +        const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
  
          /* avoid copy if macroblock skipped in last frame too */
          /* skip only during decoding as we might trash the buffers during encoding a bit */
  
              if (s->mb_skipped) {
                  s->mb_skipped= 0;
 -                assert(s->pict_type!=AV_PICTURE_TYPE_I);
 +                av_assert2(s->pict_type!=AV_PICTURE_TYPE_I);
                  *mbskip_ptr = 1;
              } else if(!s->current_picture.reference) {
                  *mbskip_ptr = 1;
                      }
                  }
  
 -                op_qpix= s->me.qpel_put;
 -                if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){
 -                    op_pix = s->hdsp.put_pixels_tab;
 +                if(lowres_flag){
 +                    h264_chroma_mc_func *op_pix = s->h264chroma.put_h264_chroma_pixels_tab;
 +
 +                    if (s->mv_dir & MV_DIR_FORWARD) {
 +                        MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix);
 +                        op_pix = s->h264chroma.avg_h264_chroma_pixels_tab;
 +                    }
 +                    if (s->mv_dir & MV_DIR_BACKWARD) {
 +                        MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix);
 +                    }
                  }else{
 -                    op_pix = s->hdsp.put_no_rnd_pixels_tab;
 -                }
 -                if (s->mv_dir & MV_DIR_FORWARD) {
 -                    ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix);
 -                    op_pix = s->hdsp.avg_pixels_tab;
 -                    op_qpix= s->me.qpel_avg;
 -                }
 -                if (s->mv_dir & MV_DIR_BACKWARD) {
 -                    ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix);
 +                    op_qpix = s->me.qpel_put;
 +                    if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){
 +                        op_pix = s->hdsp.put_pixels_tab;
 +                    }else{
 +                        op_pix = s->hdsp.put_no_rnd_pixels_tab;
 +                    }
 +                    if (s->mv_dir & MV_DIR_FORWARD) {
 +                        ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix);
 +                        op_pix = s->hdsp.avg_pixels_tab;
 +                        op_qpix= s->me.qpel_avg;
 +                    }
 +                    if (s->mv_dir & MV_DIR_BACKWARD) {
 +                        ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix);
 +                    }
                  }
              }
  
                      }else{
                          //chroma422
                          dct_linesize = uvlinesize << s->interlaced_dct;
 -                        dct_offset   = s->interlaced_dct ? uvlinesize : uvlinesize * 8;
 +                        dct_offset   = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
  
                          add_dct(s, block[4], 4, dest_cb, dct_linesize);
                          add_dct(s, block[5], 5, dest_cr, dct_linesize);
                          add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
                          add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
                          if(!s->chroma_x_shift){//Chroma444
 -                            add_dct(s, block[8], 8, dest_cb+8, dct_linesize);
 -                            add_dct(s, block[9], 9, dest_cr+8, dct_linesize);
 -                            add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize);
 -                            add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize);
 +                            add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize);
 +                            add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize);
 +                            add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize);
 +                            add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize);
                          }
                      }
                  }//fi gray
                      }else{
  
                          dct_linesize = uvlinesize << s->interlaced_dct;
 -                        dct_offset   = s->interlaced_dct ? uvlinesize : uvlinesize * 8;
 +                        dct_offset   = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
  
                          s->dsp.idct_put(dest_cb,              dct_linesize, block[4]);
                          s->dsp.idct_put(dest_cr,              dct_linesize, block[5]);
                          s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
                          s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
                          if(!s->chroma_x_shift){//Chroma444
 -                            s->dsp.idct_put(dest_cb + 8,              dct_linesize, block[8]);
 -                            s->dsp.idct_put(dest_cr + 8,              dct_linesize, block[9]);
 -                            s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
 -                            s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
 +                            s->dsp.idct_put(dest_cb + block_size,              dct_linesize, block[8]);
 +                            s->dsp.idct_put(dest_cr + block_size,              dct_linesize, block[9]);
 +                            s->dsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]);
 +                            s->dsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]);
                          }
                      }
                  }//gray
@@@ -3015,78 -2305,23 +3015,25 @@@ skip_idct
  void ff_MPV_decode_mb(MpegEncContext *s, int16_t block[12][64]){
  #if !CONFIG_SMALL
      if(s->out_format == FMT_MPEG1) {
 -        MPV_decode_mb_internal(s, block, 1);
 +        if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1, 1);
 +        else                 MPV_decode_mb_internal(s, block, 0, 1);
      } else
  #endif
 -        MPV_decode_mb_internal(s, block, 0);
 +    if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1, 0);
 +    else                  MPV_decode_mb_internal(s, block, 0, 0);
  }
  
- /**
-  * @param h is the normal height, this will be reduced automatically if needed for the last row
-  */
- void ff_draw_horiz_band(AVCodecContext *avctx,
-                         AVFrame *cur, AVFrame *last,
-                         int y, int h, int picture_structure,
-                         int first_field, int low_delay)
- {
-     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
-     int vshift = desc->log2_chroma_h;
-     const int field_pic = picture_structure != PICT_FRAME;
-     if(field_pic){
-         h <<= 1;
-         y <<= 1;
-     }
-     h = FFMIN(h, avctx->height - y);
-     if(field_pic && first_field && !(avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;
-     if (avctx->draw_horiz_band) {
-         AVFrame *src;
-         int offset[AV_NUM_DATA_POINTERS];
-         int i;
-         if (cur->pict_type == AV_PICTURE_TYPE_B || low_delay ||
-            (avctx->slice_flags & SLICE_FLAG_CODED_ORDER))
-             src = cur;
-         else if (last)
-             src = last;
-         else
-             return;
-         if (cur->pict_type == AV_PICTURE_TYPE_B &&
-             picture_structure == PICT_FRAME &&
-             avctx->codec_id != AV_CODEC_ID_SVQ3) {
-             for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
-                 offset[i] = 0;
-         }else{
-             offset[0]= y * src->linesize[0];
-             offset[1]=
-             offset[2]= (y >> vshift) * src->linesize[1];
-             for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
-                 offset[i] = 0;
-         }
-         emms_c();
-         avctx->draw_horiz_band(avctx, src, offset,
-                                y, picture_structure, h);
-     }
- }
  void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
  {
 -    ff_draw_horiz_band(s->avctx, &s->current_picture.f,
 -                       &s->last_picture.f, y, h, s->picture_structure,
 +    ff_draw_horiz_band(s->avctx, &s->current_picture_ptr->f,
 +                       &s->last_picture_ptr->f, y, h, s->picture_structure,
                         s->first_field, s->low_delay);
  }
  
  void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
      const int linesize   = s->current_picture.f.linesize[0]; //not s->linesize as this would be wrong for field pics
      const int uvlinesize = s->current_picture.f.linesize[1];
 -    const int mb_size= 4;
 +    const int mb_size= 4 - s->avctx->lowres;
  
      s->block_index[0]= s->b8_stride*(s->mb_y*2    ) - 2 + s->mb_x*2;
      s->block_index[1]= s->b8_stride*(s->mb_y*2    ) - 1 + s->mb_x*2;
              s->dest[0] += (s->mb_y>>1) *   linesize << mb_size;
              s->dest[1] += (s->mb_y>>1) * uvlinesize << (mb_size - s->chroma_y_shift);
              s->dest[2] += (s->mb_y>>1) * uvlinesize << (mb_size - s->chroma_y_shift);
 -            assert((s->mb_y&1) == (s->picture_structure == PICT_BOTTOM_FIELD));
 +            av_assert1((s->mb_y&1) == (s->picture_structure == PICT_BOTTOM_FIELD));
          }
      }
  }
@@@ -3160,7 -2395,6 +3107,7 @@@ void ff_mpeg_flush(AVCodecContext *avct
      ff_mpeg_unref_picture(s, &s->next_picture);
  
      s->mb_x= s->mb_y= 0;
 +    s->closed_gop= 0;
  
      s->parse_context.state= -1;
      s->parse_context.frame_start_found= 0;
@@@ -3200,7 -2434,6 +3147,7 @@@ void ff_mpeg_set_erpic(ERPicture *dst, 
  {
      int i;
  
 +    memset(dst, 0, sizeof(*dst));
      if (!src)
          return;
  
diff --combined libavcodec/mpegvideo.h
@@@ -3,20 -3,20 +3,20 @@@
   * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
   * Copyright (c) 2002-2004 Michael Niedermayer
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * 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.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * 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 Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -32,7 -32,6 +32,7 @@@
  #include "dsputil.h"
  #include "error_resilience.h"
  #include "get_bits.h"
 +#include "h264chroma.h"
  #include "h263dsp.h"
  #include "hpeldsp.h"
  #include "put_bits.h"
@@@ -44,7 -43,6 +44,7 @@@
  #include "videodsp.h"
  
  #include "libavutil/opt.h"
 +#include "libavutil/timecode.h"
  
  #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
  
@@@ -58,13 -56,14 +58,13 @@@ enum OutputFormat 
  #define MPEG_BUF_SIZE (16 * 1024)
  
  #define QMAT_SHIFT_MMX 16
 -#define QMAT_SHIFT 22
 +#define QMAT_SHIFT 21
  
  #define MAX_FCODE 7
 -#define MAX_MV 2048
 +#define MAX_MV 4096
  
 -#define MAX_THREADS 16
 -
 -#define MAX_PICTURE_COUNT 32
 +#define MAX_THREADS 32
 +#define MAX_PICTURE_COUNT 36
  
  #define MAX_B_FRAMES 16
  
@@@ -116,9 -115,6 +116,9 @@@ typedef struct Picture
      AVBufferRef *mc_mb_var_buf;
      uint16_t *mc_mb_var;        ///< Table for motion compensated MB variances
  
 +    int alloc_mb_width;         ///< mb_width used to allocate tables
 +    int alloc_mb_height;        ///< mb_height used to allocate tables
 +
      AVBufferRef *mb_mean_buf;
      uint8_t *mb_mean;           ///< Table for MB luminance
  
      int pic_id;                 /**< h264 pic_num (short -> no wrap version of pic_num,
                                       pic_num & max_pic_num; long -> long_pic_num) */
      int long_ref;               ///< 1->long term reference 0->short term reference
 -    int ref_poc[2][2][32];      ///< h264 POCs of the frames used as reference (FIXME need per slice)
 +    int ref_poc[2][2][32];      ///< h264 POCs of the frames/fields used as reference (FIXME need per slice)
      int ref_count[2][2];        ///< number of entries in ref_poc              (FIXME need per slice)
      int mbaff;                  ///< h264 1 -> MBAFF frame 0-> not MBAFF
      int field_picture;          ///< whether or not the picture was encoded in separate fields
      int mb_var_sum;             ///< sum of MB variance for current frame
      int mc_mb_var_sum;          ///< motion compensated MB variance for current frame
  
 -    int b_frame_score;          /* */
 +    int b_frame_score;
      int needs_realloc;          ///< Picture needs to be reallocated (eg due to a frame size change)
  
      int reference;
@@@ -326,7 -322,7 +326,7 @@@ typedef struct MpegEncContext 
      uint8_t *coded_block_base;
      uint8_t *coded_block;          ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
      int16_t (*ac_val_base)[16];
 -    int16_t (*ac_val[3])[16];      ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
 +    int16_t (*ac_val[3])[16];      ///< used for mpeg4 AC prediction, all 3 arrays must be continuous
      int mb_skipped;                ///< MUST BE SET only during DECODING
      uint8_t *mbskip_table;        /**< used to avoid copy if macroblock skipped (for black regions for example)
                                     and used for b-frame encoding & decoding (contains skip table of next P Frame) */
      int *lambda_table;
      int adaptive_quant;         ///< use adaptive quantization
      int dquant;                 ///< qscale difference to prev qscale
 +    int closed_gop;             ///< MPEG1/2 GOP is closed
      int pict_type;              ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
 +    int vbv_delay;
      int last_pict_type; //FIXME removes
      int last_non_b_pict_type;   ///< used for mpeg4 gmc b-frames & ratecontrol
      int droppable;
      int frame_rate_index;
 +    AVRational mpeg2_frame_rate_ext;
      int last_lambda_for[5];     ///< last lambda for a specific pict type
      int skipdct;                ///< skip dct and code zero residual
  
      int h263_long_vectors;      ///< use horrible h263v1 long vector mode
  
      DSPContext dsp;             ///< pointers for accelerated dsp functions
 +    H264ChromaContext h264chroma;
      HpelDSPContext hdsp;
      VideoDSPContext vdsp;
      H263DSPContext h263dsp;
      uint8_t *luma_dc_vlc_length;
  #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
  
 -    int coded_score[8];
 +    int coded_score[12];
  
      /** precomputed matrix (combine qscale and DCT renorm) */
      int (*q_intra_matrix)[64];
 +    int (*q_chroma_intra_matrix)[64];
      int (*q_inter_matrix)[64];
      /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
      uint16_t (*q_intra_matrix16)[2][64];
 +    uint16_t (*q_chroma_intra_matrix16)[2][64];
      uint16_t (*q_inter_matrix16)[2][64];
  
      /* noise reduction */
      /* bit rate control */
      int64_t total_bits;
      int frame_bits;                ///< bits used for the current frame
 +    int stuffing_bits;             ///< bits used for stuffing
      int next_lambda;               ///< next lambda used for retrying to encode a frame
      RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
  
      int prev_mb_info, last_mb_info;
      uint8_t *mb_info_ptr;
      int mb_info_size;
 +    int ehc_mode;
  
      /* H.263+ specific */
      int umvplus;                    ///< == H263+ && unrestricted_mv
  
      /* MJPEG specific */
      struct MJpegContext *mjpeg_ctx;
 +    int esc_pos;
  
      /* MSMPEG4 specific */
      int mv_table_index;
      /* RTP specific */
      int rtp_mode;
  
 +    char *tc_opt_str;        ///< timecode option string
 +    AVTimecode tc;           ///< timecode context
 +
      uint8_t *ptr_lastgob;
 +    int swap_uv;             //vcr2 codec is an MPEG-2 variant with U and V swapped
 +    int pack_pblocks;        //xvmc needs to keep blocks without gaps.
      int16_t (*pblocks[12])[64];
  
      int16_t (*block)[64]; ///< points to one of the following blocks
 -    int16_t (*blocks)[8][64]; // for HQ mode we need to keep the best block
 +    int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
      int (*decode_mb)(struct MpegEncContext *s, int16_t block[6][64]); // used by some codecs to avoid a switch()
  #define SLICE_OK         0
  #define SLICE_ERROR     -1
@@@ -723,25 -705,14 +723,22 @@@ int ff_MPV_encode_init(AVCodecContext *
  int ff_MPV_encode_end(AVCodecContext *avctx);
  int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
                            const AVFrame *frame, int *got_packet);
 -void ff_MPV_encode_init_x86(MpegEncContext *s);
 +void ff_dct_encode_init_x86(MpegEncContext *s);
  void ff_MPV_common_init_x86(MpegEncContext *s);
 +void ff_MPV_common_init_axp(MpegEncContext *s);
  void ff_MPV_common_init_arm(MpegEncContext *s);
  void ff_MPV_common_init_ppc(MpegEncContext *s);
  void ff_clean_intra_table_entries(MpegEncContext *s);
- void ff_draw_horiz_band(AVCodecContext *avctx, AVFrame *cur, AVFrame *last,
-                         int y, int h, int picture_structure, int first_field,
-                         int low_delay);
  void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h);
  void ff_mpeg_flush(AVCodecContext *avctx);
 -void ff_print_debug_info(MpegEncContext *s, Picture *p);
 +
 +void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict);
 +void ff_print_debug_info2(AVCodecContext *avctx, Picture *p, AVFrame *pict, uint8_t *mbskip_table,
 +                         int *low_delay,
 +                         int mb_width, int mb_height, int mb_stride, int quarter_sample);
 +
 +int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type);
 +
  void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
  int ff_find_unused_picture(MpegEncContext *s, int shared);
  void ff_denoise_dct(MpegEncContext *s, int16_t *block);
@@@ -756,7 -727,6 +753,7 @@@ void ff_mpeg_er_frame_start(MpegEncCont
  void ff_mpeg_set_erpic(ERPicture *dst, Picture *src);
  
  int ff_dct_common_init(MpegEncContext *s);
 +int ff_dct_encode_init(MpegEncContext *s);
  void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
                         const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
  int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow);
@@@ -785,7 -755,7 +782,7 @@@ extern const enum AVPixelFormat ff_pixf
  void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last);
  
  static inline void ff_update_block_index(MpegEncContext *s){
 -    const int block_size = 8;
 +    const int block_size= 8 >> s->avctx->lowres;
  
      s->block_index[0]+=2;
      s->block_index[1]+=2;
@@@ -878,5 -848,4 +875,5 @@@ int ff_mpeg_ref_picture(MpegEncContext 
  void ff_mpeg_unref_picture(MpegEncContext *s, Picture *picture);
  void ff_free_picture_tables(Picture *pic);
  
 +
  #endif /* AVCODEC_MPEGVIDEO_H */